diff --git a/chainio/clients/avsregistry/writer.go b/chainio/clients/avsregistry/writer.go index 151357e6..91a1b9d5 100644 --- a/chainio/clients/avsregistry/writer.go +++ b/chainio/clients/avsregistry/writer.go @@ -29,7 +29,7 @@ import ( type eLReader interface { CalculateOperatorAVSRegistrationDigestHash( - opts *bind.CallOpts, + ctx context.Context, operatorAddr gethcommon.Address, serviceManagerAddr gethcommon.Address, operatorToAvsRegistrationSigSalt [32]byte, @@ -233,7 +233,7 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator( // params to register operator in delegation manager's operator-avs mapping msgToSign, err := w.elReader.CalculateOperatorAVSRegistrationDigestHash( - &bind.CallOpts{}, + ctx, operatorAddr, w.serviceManagerAddr, operatorToAvsRegistrationSigSalt, @@ -355,7 +355,7 @@ func (w *ChainWriter) RegisterOperator( // params to register operator in delegation manager's operator-avs mapping msgToSign, err := w.elReader.CalculateOperatorAVSRegistrationDigestHash( - &bind.CallOpts{}, + ctx, operatorAddr, w.serviceManagerAddr, operatorToAvsRegistrationSigSalt, diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 2361be99..b4632bf3 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -1,6 +1,7 @@ package elcontracts import ( + "context" "errors" "math/big" @@ -112,13 +113,16 @@ func NewReaderFromConfig( ), nil } -func (r *ChainReader) IsOperatorRegistered(opts *bind.CallOpts, operator types.Operator) (bool, error) { +func (r *ChainReader) IsOperatorRegistered( + ctx context.Context, + operator types.Operator, +) (bool, error) { if r.delegationManager == nil { return false, errors.New("DelegationManager contract not provided") } isOperator, err := r.delegationManager.IsOperator( - opts, + &bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address), ) if err != nil { @@ -128,13 +132,16 @@ func (r *ChainReader) IsOperatorRegistered(opts *bind.CallOpts, operator types.O return isOperator, nil } -func (r *ChainReader) GetOperatorDetails(opts *bind.CallOpts, operator types.Operator) (types.Operator, error) { +func (r *ChainReader) GetOperatorDetails( + ctx context.Context, + operator types.Operator, +) (types.Operator, error) { if r.delegationManager == nil { return types.Operator{}, errors.New("DelegationManager contract not provided") } operatorDetails, err := r.delegationManager.OperatorDetails( - opts, + &bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address), ) if err != nil { @@ -150,13 +157,14 @@ func (r *ChainReader) GetOperatorDetails(opts *bind.CallOpts, operator types.Ope // GetStrategyAndUnderlyingToken returns the strategy contract and the underlying token address func (r *ChainReader) GetStrategyAndUnderlyingToken( - opts *bind.CallOpts, strategyAddr gethcommon.Address, + ctx context.Context, + strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, gethcommon.Address, error) { contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) if err != nil { return nil, common.Address{}, utils.WrapError("Failed to fetch strategy contract", err) } - underlyingTokenAddr, err := contractStrategy.UnderlyingToken(opts) + underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { return nil, common.Address{}, utils.WrapError("Failed to fetch token contract", err) } @@ -166,13 +174,14 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( // GetStrategyAndUnderlyingERC20Token returns the strategy contract, the erc20 bindings for the underlying token // and the underlying token address func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( - opts *bind.CallOpts, strategyAddr gethcommon.Address, + ctx context.Context, + strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, erc20.ContractIERC20Methods, gethcommon.Address, error) { contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) if err != nil { return nil, nil, common.Address{}, utils.WrapError("Failed to fetch strategy contract", err) } - underlyingTokenAddr, err := contractStrategy.UnderlyingToken(opts) + underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { return nil, nil, common.Address{}, utils.WrapError("Failed to fetch token contract", err) } @@ -184,7 +193,7 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( } func (r *ChainReader) ServiceManagerCanSlashOperatorUntilBlock( - opts *bind.CallOpts, + ctx context.Context, operatorAddr gethcommon.Address, serviceManagerAddr gethcommon.Address, ) (uint32, error) { @@ -193,20 +202,23 @@ func (r *ChainReader) ServiceManagerCanSlashOperatorUntilBlock( } return r.slasher.ContractCanSlashOperatorUntilBlock( - opts, operatorAddr, serviceManagerAddr, + &bind.CallOpts{Context: ctx}, operatorAddr, serviceManagerAddr, ) } -func (r *ChainReader) OperatorIsFrozen(opts *bind.CallOpts, operatorAddr gethcommon.Address) (bool, error) { +func (r *ChainReader) OperatorIsFrozen( + ctx context.Context, + operatorAddr gethcommon.Address, +) (bool, error) { if r.slasher == nil { return false, errors.New("slasher contract not provided") } - return r.slasher.IsFrozen(opts, operatorAddr) + return r.slasher.IsFrozen(&bind.CallOpts{Context: ctx}, operatorAddr) } func (r *ChainReader) GetOperatorSharesInStrategy( - opts *bind.CallOpts, + ctx context.Context, operatorAddr gethcommon.Address, strategyAddr gethcommon.Address, ) (*big.Int, error) { @@ -215,55 +227,72 @@ func (r *ChainReader) GetOperatorSharesInStrategy( } return r.delegationManager.OperatorShares( - opts, + &bind.CallOpts{Context: ctx}, operatorAddr, strategyAddr, ) } func (r *ChainReader) CalculateDelegationApprovalDigestHash( - opts *bind.CallOpts, staker gethcommon.Address, operator gethcommon.Address, - delegationApprover gethcommon.Address, approverSalt [32]byte, expiry *big.Int, + ctx context.Context, + staker gethcommon.Address, + operator gethcommon.Address, + delegationApprover gethcommon.Address, + approverSalt [32]byte, + expiry *big.Int, ) ([32]byte, error) { if r.delegationManager == nil { return [32]byte{}, errors.New("DelegationManager contract not provided") } return r.delegationManager.CalculateDelegationApprovalDigestHash( - opts, staker, operator, delegationApprover, approverSalt, expiry, + &bind.CallOpts{Context: ctx}, + staker, + operator, + delegationApprover, + approverSalt, + expiry, ) } func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( - opts *bind.CallOpts, operator gethcommon.Address, avs gethcommon.Address, salt [32]byte, expiry *big.Int, + ctx context.Context, + operator gethcommon.Address, + avs gethcommon.Address, + salt [32]byte, + expiry *big.Int, ) ([32]byte, error) { if r.avsDirectory == nil { return [32]byte{}, errors.New("AVSDirectory contract not provided") } return r.avsDirectory.CalculateOperatorAVSRegistrationDigestHash( - opts, operator, avs, salt, expiry, + &bind.CallOpts{Context: ctx}, + operator, + avs, + salt, + expiry, ) } -func (r *ChainReader) GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error) { +func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { if r.rewardsCoordinator == nil { return nil, errors.New("RewardsCoordinator contract not provided") } - return r.rewardsCoordinator.GetDistributionRootsLength(opts) + return r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) } -func (r *ChainReader) CurrRewardsCalculationEndTimestamp(opts *bind.CallOpts) (uint32, error) { +func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } - return r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(opts) + return r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) } func (r *ChainReader) GetCurrentClaimableDistributionRoot( - opts *bind.CallOpts, + ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorDistributionRoot, error) { if r.rewardsCoordinator == nil { return rewardscoordinator.IRewardsCoordinatorDistributionRoot{}, errors.New( @@ -271,19 +300,22 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( ) } - return r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(opts) + return r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) } -func (r *ChainReader) GetRootIndexFromHash(opts *bind.CallOpts, rootHash [32]byte) (uint32, error) { +func (r *ChainReader) GetRootIndexFromHash( + ctx context.Context, + rootHash [32]byte, +) (uint32, error) { if r.rewardsCoordinator == nil { return 0, errors.New("RewardsCoordinator contract not provided") } - return r.rewardsCoordinator.GetRootIndexFromHash(opts, rootHash) + return r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) } func (r *ChainReader) GetCumulativeClaimed( - opts *bind.CallOpts, + ctx context.Context, earner gethcommon.Address, token gethcommon.Address, ) (*big.Int, error) { @@ -291,16 +323,16 @@ func (r *ChainReader) GetCumulativeClaimed( return nil, errors.New("RewardsCoordinator contract not provided") } - return r.rewardsCoordinator.CumulativeClaimed(opts, earner, token) + return r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) } func (r *ChainReader) CheckClaim( - opts *bind.CallOpts, + ctx context.Context, claim rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim, ) (bool, error) { if r.rewardsCoordinator == nil { return false, errors.New("RewardsCoordinator contract not provided") } - return r.rewardsCoordinator.CheckClaim(opts, claim) + return r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) } diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 36d6a173..7eb3428a 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1,6 +1,7 @@ package elcontracts_test import ( + "context" "math/big" "testing" @@ -15,6 +16,7 @@ import ( func TestChainReader(t *testing.T) { clients, anvilHttpEndpoint := testclients.BuildTestClients(t) + ctx := context.Background() contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) operator := types.Operator{ @@ -22,13 +24,13 @@ func TestChainReader(t *testing.T) { } t.Run("is operator registered", func(t *testing.T) { - isOperator, err := clients.ElChainReader.IsOperatorRegistered(&bind.CallOpts{}, operator) + isOperator, err := clients.ElChainReader.IsOperatorRegistered(ctx, operator) assert.NoError(t, err) assert.Equal(t, isOperator, true) }) t.Run("get operator details", func(t *testing.T) { - operatorDetails, err := clients.ElChainReader.GetOperatorDetails(&bind.CallOpts{}, operator) + operatorDetails, err := clients.ElChainReader.GetOperatorDetails(ctx, operator) assert.NoError(t, err) assert.NotNil(t, operatorDetails) assert.Equal(t, operator.Address, operatorDetails.Address) @@ -37,7 +39,7 @@ func TestChainReader(t *testing.T) { t.Run("get strategy and underlying token", func(t *testing.T) { strategyAddr := contractAddrs.Erc20MockStrategy strategy, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken( - &bind.CallOpts{}, + ctx, strategyAddr, ) assert.NoError(t, err) @@ -55,7 +57,7 @@ func TestChainReader(t *testing.T) { t.Run("get strategy and underlying ERC20 token", func(t *testing.T) { strategyAddr := contractAddrs.Erc20MockStrategy strategy, contractUnderlyingToken, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingERC20Token( - &bind.CallOpts{}, + ctx, strategyAddr, ) assert.NoError(t, err) @@ -70,7 +72,7 @@ func TestChainReader(t *testing.T) { t.Run("service manager can slash operator until block", func(t *testing.T) { _, err := clients.ElChainReader.ServiceManagerCanSlashOperatorUntilBlock( - &bind.CallOpts{}, + ctx, common.HexToAddress(operator.Address), contractAddrs.ServiceManager, ) @@ -79,7 +81,7 @@ func TestChainReader(t *testing.T) { t.Run("operator is frozen", func(t *testing.T) { isFrozen, err := clients.ElChainReader.OperatorIsFrozen( - &bind.CallOpts{}, + ctx, common.HexToAddress(operator.Address), ) assert.NoError(t, err) @@ -88,7 +90,7 @@ func TestChainReader(t *testing.T) { t.Run("get operator shares in strategy", func(t *testing.T) { shares, err := clients.ElChainReader.GetOperatorSharesInStrategy( - &bind.CallOpts{}, + ctx, common.HexToAddress(operator.Address), contractAddrs.Erc20MockStrategy, ) @@ -102,7 +104,7 @@ func TestChainReader(t *testing.T) { approverSalt := [32]byte{} expiry := big.NewInt(0) digest, err := clients.ElChainReader.CalculateDelegationApprovalDigestHash( - &bind.CallOpts{}, + ctx, staker, common.HexToAddress(operator.Address), delegationApprover, @@ -118,7 +120,7 @@ func TestChainReader(t *testing.T) { salt := [32]byte{} expiry := big.NewInt(0) digest, err := clients.ElChainReader.CalculateOperatorAVSRegistrationDigestHash( - &bind.CallOpts{}, + ctx, common.HexToAddress(operator.Address), avs, salt, diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index c921c331..c08a7d0a 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -6,7 +6,6 @@ import ( "math/big" - "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" gethtypes "github.com/ethereum/go-ethereum/core/types" @@ -27,7 +26,7 @@ import ( type Reader interface { GetStrategyAndUnderlyingERC20Token( - opts *bind.CallOpts, strategyAddr gethcommon.Address, + ctx context.Context, strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, erc20.ContractIERC20Methods, gethcommon.Address, error) } @@ -276,7 +275,7 @@ func (w *ChainWriter) DepositERC20IntoStrategy( return nil, err } _, underlyingTokenContract, underlyingTokenAddr, err := w.elChainReader.GetStrategyAndUnderlyingERC20Token( - &bind.CallOpts{Context: ctx}, + ctx, strategyAddr, ) if err != nil { diff --git a/metrics/collectors/economic/economic.go b/metrics/collectors/economic/economic.go index 7403ece8..58c3b517 100644 --- a/metrics/collectors/economic/economic.go +++ b/metrics/collectors/economic/economic.go @@ -2,6 +2,7 @@ package economic import ( + "context" "errors" "strconv" @@ -14,7 +15,7 @@ import ( ) type eLReader interface { - OperatorIsFrozen(opts *bind.CallOpts, operatorAddr common.Address) (bool, error) + OperatorIsFrozen(ctx context.Context, operatorAddr common.Address) (bool, error) } type avsRegistryReader interface { @@ -153,7 +154,7 @@ func (ec *Collector) Collect(ch chan<- prometheus.Metric) { // 1. keep this collector format but query the OperatorFrozen event from a subgraph // 2. subscribe to the event and keep a local state of whether the operator has been slashed, exporting it via // normal prometheus instrumentation - operatorIsFrozen, err := ec.elReader.OperatorIsFrozen(nil, ec.operatorAddr) + operatorIsFrozen, err := ec.elReader.OperatorIsFrozen(context.Background(), ec.operatorAddr) if err != nil { ec.logger.Error("Failed to get slashing incurred", "err", err) } else { diff --git a/metrics/collectors/economic/economic_test.go b/metrics/collectors/economic/economic_test.go index 4e1ed81b..5d55903d 100644 --- a/metrics/collectors/economic/economic_test.go +++ b/metrics/collectors/economic/economic_test.go @@ -1,6 +1,7 @@ package economic import ( + "context" "math/big" "testing" @@ -29,7 +30,7 @@ func newFakeELReader() *fakeELReader { } } -func (f *fakeELReader) OperatorIsFrozen(opts *bind.CallOpts, operatorAddr common.Address) (bool, error) { +func (f *fakeELReader) OperatorIsFrozen(ctx context.Context, operatorAddr common.Address) (bool, error) { return f.registeredOperators[operatorAddr], nil }