Skip to content

Commit

Permalink
feat(op-dispute-mon): GetWithdrawals GameCaller Method (#9939)
Browse files Browse the repository at this point in the history
* feat(op-challenger): Delayed Weth Withdrawal Request Caller

* fix(op-challenger): withdrawal request field ordering

* fix(op-challenger): encapsulate delayed weth behind the fault dispute game contract binding

* feat(op-dispute-mon): get withdrawals game caller method

* fix(op-dispute-mon): revert service name changes

* fix(op-dispute-mon): revert extractor test name

* fix(op-dispute-mon): revert extractor changes

* fix(op-dispute-mon): revert newline add

* fix(op-dispute-mon): revert caller field reordering

* fix(op-challenger): make contract method private
  • Loading branch information
refcell authored and 0xfuturistic committed Apr 1, 2024
1 parent c80691e commit 50abaa3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion op-challenger/game/fault/contracts/faultdisputegame.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,16 @@ func (f *FaultDisputeGameContract) addGlobalDataTx(ctx context.Context, data *ty
return oracle.AddGlobalDataTx(data)
}

func (f *FaultDisputeGameContract) GetDelayedWETH(ctx context.Context) (*DelayedWETHContract, error) {
func (f *FaultDisputeGameContract) GetWithdrawals(ctx context.Context, block rpcblock.Block, gameAddr common.Address, recipients ...common.Address) ([]*WithdrawalRequest, error) {
defer f.metrics.StartContractRequest("GetWithdrawals")()
delayedWETH, err := f.getDelayedWETH(ctx)
if err != nil {
return nil, err
}
return delayedWETH.GetWithdrawals(ctx, block, gameAddr, recipients...)
}

func (f *FaultDisputeGameContract) getDelayedWETH(ctx context.Context) (*DelayedWETHContract, error) {
defer f.metrics.StartContractRequest("GetDelayedWETH")()
result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodWETH))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions op-dispute-mon/mon/extract/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type GameCallerMetrics interface {
caching.Metrics
contractMetrics.ContractMetricer
}

type GameCaller interface {
GetWithdrawals(context.Context, rpcblock.Block, common.Address, ...common.Address) ([]*contracts.WithdrawalRequest, error)
GetGameMetadata(context.Context, rpcblock.Block) (common.Hash, uint64, common.Hash, gameTypes.GameStatus, uint64, error)
GetAllClaims(context.Context, rpcblock.Block) ([]faultTypes.Claim, error)
BondCaller
Expand Down
16 changes: 16 additions & 0 deletions op-dispute-mon/mon/extract/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"testing"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -189,6 +190,21 @@ type mockGameCaller struct {
balanceErr error
balance *big.Int
balanceAddr common.Address
withdrawalsCalls int
withdrawalsErr error
}

func (m *mockGameCaller) GetWithdrawals(_ context.Context, _ rpcblock.Block, _ common.Address, _ ...common.Address) ([]*contracts.WithdrawalRequest, error) {
m.withdrawalsCalls++
if m.withdrawalsErr != nil {
return nil, m.withdrawalsErr
}
return []*contracts.WithdrawalRequest{
{
Timestamp: big.NewInt(1),
Amount: big.NewInt(2),
},
}, nil
}

func (m *mockGameCaller) GetGameMetadata(_ context.Context, _ rpcblock.Block) (common.Hash, uint64, common.Hash, types.GameStatus, uint64, error) {
Expand Down
4 changes: 4 additions & 0 deletions op-dispute-mon/mon/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"math/big"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -27,6 +28,9 @@ type EnrichedGameData struct {
// Credits records the paid out bonds for the game, keyed by recipient.
Credits map[common.Address]*big.Int

// WithdrawalRequests maps recipients with withdrawal requests in DelayedWETH for this game.
WithdrawalRequests map[common.Address]*contracts.WithdrawalRequest

// WETHContract is the address of the DelayedWETH contract used by this game
// The contract is potentially shared by multiple games.
WETHContract common.Address
Expand Down

0 comments on commit 50abaa3

Please sign in to comment.