From 5b97b03fb8daee00a1722c92b9d55299fec81cb0 Mon Sep 17 00:00:00 2001 From: Justin Brower Date: Mon, 9 Sep 2024 14:58:44 -0400 Subject: [PATCH] lint and adding support for overriding callOptions --- accounts/abi/bind/base.go | 8 ++++---- accounts/abi/multicall/api.go | 27 ++++++++++++++------------- accounts/abi/multicall/types.go | 9 +++++---- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index d888209f2e..b7d26619e3 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -120,12 +120,12 @@ type BoundContract struct { filterer ContractFilterer // Event filtering to interact with the blockchain } -func (b *BoundContract) Address() common.Address { - return b.address +func (c *BoundContract) Address() common.Address { + return c.address } -func (b *BoundContract) ABI() abi.ABI { - return b.abi +func (c *BoundContract) ABI() abi.ABI { + return c.abi } // NewBoundContract creates a low level contract interface through which calls diff --git a/accounts/abi/multicall/api.go b/accounts/abi/multicall/api.go index cac86561af..7d3fe112e1 100644 --- a/accounts/abi/multicall/api.go +++ b/accounts/abi/multicall/api.go @@ -15,10 +15,13 @@ import ( type MulticallClientOptions struct { // the address of the multicall3 contract. if unset, defaults to the usual address. // for sensible values, see: https://www.multicall3.com/deployments - address *common.Address + Address *common.Address // optional: if set, will batch requests to the node. Reasonable values for this include 2048 / 4096 byte chunks. - maxBatchSizeBytes *uint64 + MaxBatchSizeBytes *uint64 + + // optional: additional options to specify when performing the eth_call (e.g the block height / number) + OverrideCallOptions *bind.CallOpts } /** @@ -40,14 +43,14 @@ func NewClient(ctx context.Context, eth *ethclient.Client, opts *MulticallClient } contractAddress := func() common.Address { - if opts.address == nil { + if opts.Address == nil { // also taken from: https://www.multicall3.com/ -- it's deployed at the same addr on most chains return common.HexToAddress("0xcA11bde05977b3631167028862bE2a173976CA11") } - return *opts.address + return *opts.Address }() - return &MulticallClient{MaxBatchSize: opts.maxBatchSizeBytes, Context: ctx, ABI: &parsed, Contract: bind.NewBoundContract(contractAddress, parsed, eth, eth, eth)}, nil + return &MulticallClient{OverrideCallOptions: opts.OverrideCallOptions, MaxBatchSize: opts.MaxBatchSizeBytes, Context: ctx, ABI: &parsed, Contract: bind.NewBoundContract(contractAddress, parsed, eth, eth, eth)}, nil } /** @@ -74,7 +77,7 @@ func Perform[A any, B any](mc MulticallClient, a *MultiCallMetaData[A], b *Multi if err != nil { return nil, nil, fmt.Errorf("error performing multicall: %s", err.Error()) } - return any(res[0].Value).(*A), any(res[1].Value).(*B), nil + return res[0].Value.(*A), res[1].Value.(*B), nil } /** @@ -85,7 +88,7 @@ func Perform3[A any, B any, C any](mc MulticallClient, a *MultiCallMetaData[A], if err != nil { return nil, nil, nil, fmt.Errorf("error performing multicall: %s", err.Error()) } - return any(res[0].Value).(*A), any(res[1].Value).(*B), any(res[2].Value).(*C), nil + return res[0].Value.(*A), res[1].Value.(*B), res[2].Value.(*C), nil } /** @@ -96,7 +99,7 @@ func Perform4[A any, B any, C any, D any](mc MulticallClient, a *MultiCallMetaDa if err != nil { return nil, nil, nil, nil, fmt.Errorf("error performing multicall: %s", err.Error()) } - return any(res[0].Value).(*A), any(res[1].Value).(*B), any(res[2].Value).(*C), any(res[3].Value).(*D), nil + return res[0].Value.(*A), res[1].Value.(*B), res[2].Value.(*C), res[3].Value.(*D), nil } /** @@ -107,7 +110,7 @@ func Perform5[A any, B any, C any, D any, E any](mc MulticallClient, a *MultiCal if err != nil { return nil, nil, nil, nil, nil, fmt.Errorf("error performing multicall: %s", err.Error()) } - return any(res[0].Value).(*A), any(res[1].Value).(*B), any(res[2].Value).(*C), any(res[3].Value).(*D), any(res[4].Value).(*E), nil + return res[0].Value.(*A), res[1].Value.(*B), res[2].Value.(*C), res[3].Value.(*D), res[4].Value.(*E), nil } /** @@ -121,10 +124,8 @@ func PerformMany[A any](mc MulticallClient, requests ...*MultiCallMetaData[A]) ( return nil, fmt.Errorf("multicall failed: %s", err.Error()) } - // unwind results unwoundResults := mapArray(res, func(d DeserializedMulticall3Result, i uint64) A { - // force these back to A - return any(d.Value).(A) + return d.Value.(A) }) return &unwoundResults, nil } @@ -156,7 +157,7 @@ func doMultiCall(mc MulticallClient, calls ...RawMulticall) ([]DeserializedMulti for _, multicalls := range chunkedCalls { var res []interface{} // we can't use the generated abi, as we want an eth_call simulation (and aggregate3 is payable, which triggers an eth_sendTransaction in abigen) - err := mc.Contract.Call(&bind.CallOpts{}, &res, "aggregate3", multicalls) + err := mc.Contract.Call(mc.OverrideCallOptions, &res, "aggregate3", multicalls) if err != nil { return nil, fmt.Errorf("aggregate3 failed: %s", err) } diff --git a/accounts/abi/multicall/types.go b/accounts/abi/multicall/types.go index 3451539d7b..6e21e92e75 100644 --- a/accounts/abi/multicall/types.go +++ b/accounts/abi/multicall/types.go @@ -37,10 +37,11 @@ type RawMulticall struct { } type MulticallClient struct { - Contract *bind.BoundContract - ABI *abi.ABI - Context context.Context - MaxBatchSize *uint64 + Contract *bind.BoundContract + ABI *abi.ABI + Context context.Context + MaxBatchSize *uint64 + OverrideCallOptions *bind.CallOpts } type Multicall3Result struct {