From 08311e15ca906fafdd3b7b9cc808a401e6c76f75 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 27 Jan 2025 17:57:44 -0300 Subject: [PATCH 01/33] Create error generic struct --- chainio/clients/elcontracts/error.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 chainio/clients/elcontracts/error.go diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go new file mode 100644 index 000000000..460719d17 --- /dev/null +++ b/chainio/clients/elcontracts/error.go @@ -0,0 +1,19 @@ +package elcontracts + +import "fmt" + +type Error struct { + code int + message string + description string + cause error + // metadata map[string]interface{} +} + +func (e Error) Error() string { + if e.cause != nil { + return fmt.Sprintf("%s(%d) - %s: %s", e.message, e.code, e.description, e.cause.Error()) + } else { + return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) + } +} From 64d8d09097c1c88414bd5229cec5015d9928b037 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 27 Jan 2025 17:58:34 -0300 Subject: [PATCH 02/33] Use generic error in some functions --- chainio/clients/elcontracts/reader.go | 71 +++++++++++++++++++++------ 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 1f46ab3d7..f0cbbccb9 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -96,10 +96,17 @@ func (r *ChainReader) IsOperatorRegistered( operator types.Operator, ) (bool, error) { if r.delegationManager == nil { - return false, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return false, wrappedError } - return r.delegationManager.IsOperator(&bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address)) + isRegistered, err := r.delegationManager.IsOperator(&bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address)) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.IsOperator", err} + return false, wrappedError + } + + return isRegistered, nil } // GetStakerShares returns the amount of shares that a staker has in all of the strategies in which they have nonzero @@ -109,9 +116,17 @@ func (r *ChainReader) GetStakerShares( stakerAddress gethcommon.Address, ) ([]gethcommon.Address, []*big.Int, error) { if r.delegationManager == nil { - return nil, nil, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return nil, nil, wrappedError } - return r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) + + addresses, shares, err := r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetDepositedShares", err} + return nil, nil, wrappedError + } + + return addresses, shares, nil } // GetDelegatedOperator returns the operator that a staker has delegated to @@ -121,9 +136,17 @@ func (r *ChainReader) GetDelegatedOperator( blockNumber *big.Int, ) (gethcommon.Address, error) { if r.delegationManager == nil { - return gethcommon.Address{}, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return gethcommon.Address{}, wrappedError } - return r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) + + delegatedOperator, err := r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.DelegatedTo", err} + return gethcommon.Address{}, wrappedError + } + + return delegatedOperator, nil } func (r *ChainReader) GetOperatorDetails( @@ -131,7 +154,8 @@ func (r *ChainReader) GetOperatorDetails( operator types.Operator, ) (types.Operator, error) { if r.delegationManager == nil { - return types.Operator{}, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return types.Operator{}, wrappedError } delegationManagerAddress, err := r.delegationManager.DelegationApprover( @@ -140,9 +164,11 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail since it's a getter if err != nil { - return types.Operator{}, err + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.DelegationApprover", err} + return types.Operator{}, wrappedError } + // Should we check if (allocationManager != nil)? isSet, delay, err := r.allocationManager.GetAllocationDelay( &bind.CallOpts{ Context: ctx, @@ -151,7 +177,8 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail if err != nil { - return types.Operator{}, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocationDelay", err} + return types.Operator{}, wrappedError } var allocationDelay uint32 @@ -176,11 +203,13 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) + wrappedError := Error{2, "Binding error", "Error happened while fetching strategy contract", err} + return nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) + wrappedError := Error{2, "Binding error", "Error happened while fetching token contract", err} + return nil, gethcommon.Address{}, wrappedError } return contractStrategy, underlyingTokenAddr, nil } @@ -194,16 +223,19 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) + wrappedError := Error{2, "Binding error", "Error happened while fetching strategy contract", err} + return nil, nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) + wrappedError := Error{2, "Binding error", "Error happened while fetching token contract", err} + return nil, nil, gethcommon.Address{}, wrappedError } contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient) // This call should not fail, if the strategy does not have an underlying token then it would enter the if above if err != nil { - return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) + wrappedError := Error{2, "Binding error", "Error happened while fetching erc20 token contract", err} + return nil, nil, gethcommon.Address{}, wrappedError } return contractStrategy, contractUnderlyingToken, underlyingTokenAddr, nil } @@ -214,14 +246,21 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr gethcommon.Address, ) (*big.Int, error) { if r.delegationManager == nil { - return &big.Int{}, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return &big.Int{}, wrappedError } - return r.delegationManager.OperatorShares( + shares, err := r.delegationManager.OperatorShares( &bind.CallOpts{Context: ctx}, operatorAddr, strategyAddr, ) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.OperatorShares", err} + return &big.Int{}, wrappedError + } + + return shares, nil } func (r *ChainReader) CalculateDelegationApprovalDigestHash( From 71567321be5e3b1cae1742d43bd52aecaeb7dbee Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 27 Jan 2025 17:59:37 -0300 Subject: [PATCH 03/33] Check returned string in one test case --- chainio/clients/elcontracts/error.go | 4 ++++ chainio/clients/elcontracts/reader_test.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 460719d17..366b76cb1 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -17,3 +17,7 @@ func (e Error) Error() string { return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) } } + +func CommonErrorMissingContract(contractName string) string { + return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) +} diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 9244c6986..31520e5d4 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -926,7 +926,8 @@ func TestInvalidConfig(t *testing.T) { t.Run("try to get a staker shares with invalid config", func(t *testing.T) { // GetStakerShares needs a correct DelegationManagerAddress _, _, err := chainReader.GetStakerShares(context.Background(), common.HexToAddress(operator.Address)) - require.Error(t, err) + assert.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) }) t.Run("try to get the delegated operator shares with invalid config", func(t *testing.T) { From f65a3ae8ead6f708721670c73d42b5f1b9e0db71 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:29:02 -0300 Subject: [PATCH 04/33] Fix output err assert in TestContractErrorCases --- chainio/clients/elcontracts/reader_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 31520e5d4..e09ae2c96 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -771,13 +771,13 @@ func TestContractErrorCases(t *testing.T) { t.Run("GetStrategyAndUnderlyingToken", func(t *testing.T) { _, _, err := chainReader.GetStrategyAndUnderlyingToken(ctx, strategyAddr) assert.Error(t, err) - assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") + assert.Equal(t, err.Error(), "Binding error(2) - Error happened while fetching token contract: no contract code at given address") }) t.Run("GetStrategyAndUnderlyingERC20Token", func(t *testing.T) { _, _, _, err := chainReader.GetStrategyAndUnderlyingERC20Token(ctx, strategyAddr) assert.Error(t, err) - assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") + assert.Equal(t, err.Error(), "Binding error(2) - Error happened while fetching token contract: no contract code at given address") }) } From 905b68f67d842982cef1457b2d52a535ae0eec63 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:52:13 -0300 Subject: [PATCH 05/33] Use error interface in DigestHash reader functions --- chainio/clients/elcontracts/reader.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index f0cbbccb9..f30a9ec10 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -272,10 +272,11 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.delegationManager == nil { - return [32]byte{}, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return [32]byte{}, wrappedError } - return r.delegationManager.CalculateDelegationApprovalDigestHash( + digestHash, err := r.delegationManager.CalculateDelegationApprovalDigestHash( &bind.CallOpts{Context: ctx}, staker, operator, @@ -283,6 +284,12 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( approverSalt, expiry, ) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.CalculateDelegationApprovalDigestHash", err} + return [32]byte{}, wrappedError + } + + return digestHash, nil } func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( @@ -293,16 +300,23 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.avsDirectory == nil { - return [32]byte{}, errors.New("AVSDirectory contract not provided") + wrappedError := Error{1, "Missing needed contract", "AVSDirectory contract not provided", nil} + return [32]byte{}, wrappedError } - return r.avsDirectory.CalculateOperatorAVSRegistrationDigestHash( + digestHash, err := r.avsDirectory.CalculateOperatorAVSRegistrationDigestHash( &bind.CallOpts{Context: ctx}, operator, avs, salt, expiry, ) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err} + return [32]byte{}, wrappedError + } + + return digestHash, nil } func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { From 6210794df17c239762302d27cfb325b8cef20591 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:53:40 -0300 Subject: [PATCH 06/33] Use error interface in rewards coord related functions --- chainio/clients/elcontracts/reader.go | 90 +++++++++++++++++++++------ 1 file changed, 72 insertions(+), 18 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index f30a9ec10..03eeadd5d 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -321,30 +321,49 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { if r.rewardsCoordinator == nil { - return nil, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return &big.Int{}, wrappedError + } + + distributionRootsLength, err := r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetDistributionRootsLength", err} + return &big.Int{}, wrappedError } - return r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) + return distributionRootsLength, nil } func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { if r.rewardsCoordinator == nil { - return 0, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return 0, wrappedError + } + + endTimestamp, err := r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err} + return 0, wrappedError } - return r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) + return endTimestamp, nil } func (r *ChainReader) GetCurrentClaimableDistributionRoot( ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) { if r.rewardsCoordinator == nil { - return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, errors.New( - "RewardsCoordinator contract not provided", - ) + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError + } + + distributionRoot, err := r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetCurrentClaimableDistributionRoot", err} + return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } - return r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) + return distributionRoot, nil } func (r *ChainReader) GetRootIndexFromHash( @@ -352,10 +371,17 @@ func (r *ChainReader) GetRootIndexFromHash( rootHash [32]byte, ) (uint32, error) { if r.rewardsCoordinator == nil { - return 0, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return 0, wrappedError + } + + rootIndex, err := r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetRootIndexFromHash", err} + return 0, wrappedError } - return r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) + return rootIndex, nil } func (r *ChainReader) GetCumulativeClaimed( @@ -364,10 +390,17 @@ func (r *ChainReader) GetCumulativeClaimed( token gethcommon.Address, ) (*big.Int, error) { if r.rewardsCoordinator == nil { - return nil, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return nil, wrappedError } - return r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) + cumulativeClaimed, err := r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CumulativeClaimed", err} + return nil, wrappedError + } + + return cumulativeClaimed, nil } func (r *ChainReader) CheckClaim( @@ -375,10 +408,17 @@ func (r *ChainReader) CheckClaim( claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim, ) (bool, error) { if r.rewardsCoordinator == nil { - return false, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return false, wrappedError + } + + claimChecked, err := r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CheckClaim", err} + return false, wrappedError } - return r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) + return claimChecked, nil } func (r *ChainReader) GetOperatorAVSSplit( @@ -387,10 +427,17 @@ func (r *ChainReader) GetOperatorAVSSplit( avs gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - return 0, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return 0, wrappedError + } + + operatorSplit, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetOperatorAVSSplit", err} + return 0, wrappedError } - return r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) + return operatorSplit, nil } func (r *ChainReader) GetOperatorPISplit( @@ -398,10 +445,17 @@ func (r *ChainReader) GetOperatorPISplit( operator gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - return 0, errors.New("RewardsCoordinator contract not provided") + wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + return 0, wrappedError + } + + operatorSplit, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetOperatorPISplit", err} + return 0, wrappedError } - return r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) + return operatorSplit, nil } func (r *ChainReader) GetAllocatableMagnitude( From e2c7e03bc817ca2ebd109e5a59dcd942e9d15a0f Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:54:40 -0300 Subject: [PATCH 07/33] Use error interface in allocationManager related funcs --- chainio/clients/elcontracts/reader.go | 45 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 03eeadd5d..62bb0b561 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -464,10 +464,17 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress gethcommon.Address, ) (uint64, error) { if r.allocationManager == nil { - return 0, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return 0, wrappedError + } + + allocatableMagnitude, err := r.allocationManager.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddress) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatableMagnitude", err} + return 0, wrappedError } - return r.allocationManager.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddress) + return allocatableMagnitude, nil } func (r *ChainReader) GetMaxMagnitudes( @@ -476,10 +483,17 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses []gethcommon.Address, ) ([]uint64, error) { if r.allocationManager == nil { - return []uint64{}, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return []uint64{}, wrappedError } - return r.allocationManager.GetMaxMagnitudes0(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddresses) + maxMagnitudes, err := r.allocationManager.GetMaxMagnitudes0(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddresses) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMaxMagnitudes0", err} + return []uint64{}, wrappedError + } + + return maxMagnitudes, nil } func (r *ChainReader) GetAllocationInfo( @@ -488,7 +502,8 @@ func (r *ChainReader) GetAllocationInfo( strategyAddress gethcommon.Address, ) ([]AllocationInfo, error) { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } opSets, allocationInfo, err := r.allocationManager.GetStrategyAllocations( @@ -498,7 +513,8 @@ func (r *ChainReader) GetAllocationInfo( ) // This call should not fail since it's a getter if err != nil { - return nil, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetStrategyAllocations", err} + return nil, wrappedError } allocationsInfo := make([]AllocationInfo, len(opSets)) @@ -547,11 +563,13 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( operatorAddress gethcommon.Address, ) (*big.Int, error) { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - return nil, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatedSets", err} + return nil, wrappedError } return big.NewInt(int64(len(opSets))), nil } @@ -563,11 +581,18 @@ func (r *ChainReader) GetOperatorSetsForOperator( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to // paginate? - return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) + allocatedSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatedSets", err} + return nil, wrappedError + } + + return allocatedSets, nil } // IsOperatorRegisteredWithOperatorSet returns if an operator is registered with a specific operator set From 29302b901ffaf233f9a919700fdf54b2f8119044 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:56:06 -0300 Subject: [PATCH 08/33] Use error interface in slashing related functions --- chainio/clients/elcontracts/reader.go | 122 ++++++++++++++++++++------ 1 file changed, 94 insertions(+), 28 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 62bb0b561..a3012a5db 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -537,12 +537,19 @@ func (r *ChainReader) GetOperatorShares( strategyAddresses []gethcommon.Address, ) ([]*big.Int, error) { if r.delegationManager == nil { - return nil, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return nil, wrappedError } - return r.delegationManager.GetOperatorShares(&bind.CallOpts{ + operatorShares, err := r.delegationManager.GetOperatorShares(&bind.CallOpts{ Context: ctx, }, operatorAddress, strategyAddresses) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetOperatorShares", err} + return nil, wrappedError + } + + return operatorShares, nil } func (r *ChainReader) GetOperatorsShares( @@ -551,9 +558,17 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses []gethcommon.Address, ) ([][]*big.Int, error) { if r.delegationManager == nil { - return nil, errors.New("DelegationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + return nil, wrappedError + } + + operatorsShares, err := r.delegationManager.GetOperatorsShares(&bind.CallOpts{Context: ctx}, operatorAddresses, strategyAddresses) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetOperatorsShares", err} + return nil, wrappedError } - return r.delegationManager.GetOperatorsShares(&bind.CallOpts{Context: ctx}, operatorAddresses, strategyAddresses) + + return operatorsShares, nil } // GetNumOperatorSetsForOperator returns the number of operator sets that an operator is part of @@ -604,24 +619,28 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( if operatorSet.Id == 0 { // this is an M2 AVS if r.avsDirectory == nil { - return false, errors.New("AVSDirectory contract not provided") + wrappedError := Error{1, "Missing needed contract", "AVSDirectory contract not provided", nil} + return false, wrappedError } status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) // This call should not fail since it's a getter if err != nil { - return false, err + wrappedError := Error{0, "Binding error", "Error happened while calling avsDirectory.AvsOperatorStatus", err} + return false, wrappedError } return status == 1, nil } else { if r.allocationManager == nil { - return false, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return false, wrappedError } registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - return false, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetRegisteredSets", err} + return false, wrappedError } for _, registeredOperatorSet := range registeredOperatorSets { if registeredOperatorSet.Id == operatorSet.Id && registeredOperatorSet.Avs == operatorSet.Avs { @@ -643,10 +662,17 @@ func (r *ChainReader) GetOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } - return r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet) + members, err := r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMembers", err} + return nil, wrappedError + } + + return members, nil } } @@ -659,10 +685,17 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError + } + + memberCount, err := r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMemberCount", err} + return nil, wrappedError } - return r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet) + return memberCount, nil } } @@ -676,10 +709,17 @@ func (r *ChainReader) GetStrategiesForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } - return r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet) + strategiesInSet, err := r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetStrategiesInOperatorSet", err} + return nil, wrappedError + } + + return strategiesInSet, nil } } @@ -690,13 +730,15 @@ func (r *ChainReader) GetSlashableShares( strategies []gethcommon.Address, ) (map[gethcommon.Address]*big.Int, error) { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError } currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - return nil, err + wrappedError := Error{2, "Binding error", "Error happened while fetching block number", err} + return nil, wrappedError } slashableShares, err := r.allocationManager.GetMinimumSlashableStake( @@ -708,10 +750,12 @@ func (r *ChainReader) GetSlashableShares( ) // This call should not fail since it's a getter if err != nil { - return nil, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMinimumSlashableStake", err} + return nil, wrappedError } if len(slashableShares) == 0 { - return nil, errors.New("no slashable shares found for operator") + wrappedError := Error{3, "Other errors", "No slashable shares found for operator", err} + return nil, wrappedError } slashableShareStrategyMap := make(map[gethcommon.Address]*big.Int) @@ -733,9 +777,17 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - return nil, err + wrappedError := Error{2, "Binding error", "Error happened while fetching block number", err} + return nil, wrappedError } - return r.GetSlashableSharesForOperatorSetsBefore(ctx, operatorSets, uint32(currentBlock)) + + operatorSetStakes, err := r.GetSlashableSharesForOperatorSetsBefore(ctx, operatorSets, uint32(currentBlock)) + if err != nil { + wrappedError := Error{2, "Nested error", "Error happened while calling GetSlashableSharesForOperatorSetsBefore", err} + return nil, wrappedError + } + + return operatorSetStakes, nil } // GetSlashableSharesForOperatorSetsBefore returns the strategies the operatorSets take into account, their @@ -752,13 +804,15 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) if err != nil { - return nil, err + wrappedError := Error{2, "Nested error", "Error happened while calling GetOperatorsForOperatorSet", err} + return nil, wrappedError } strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet) // If operator setId is 0 will fail on if above if err != nil { - return nil, err + wrappedError := Error{2, "Nested error", "Error happened while calling GetStrategiesForOperatorSet", err} + return nil, wrappedError } slashableShares, err := r.allocationManager.GetMinimumSlashableStake( @@ -773,7 +827,8 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( ) // This call should not fail since it's a getter if err != nil { - return nil, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMinimumSlashableStake", err} + return nil, wrappedError } operatorSetStakes[i] = OperatorSetStakes{ @@ -792,15 +847,18 @@ func (r *ChainReader) GetAllocationDelay( operatorAddress gethcommon.Address, ) (uint32, error) { if r.allocationManager == nil { - return 0, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return 0, wrappedError } isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - return 0, err + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocationDelay", err} + return 0, wrappedError } if !isSet { - return 0, errors.New("allocation delay not set") + wrappedError := Error{3, "Other errors", "Allocation delay not set", err} + return 0, wrappedError } return delay, nil } @@ -810,9 +868,17 @@ func (r *ChainReader) GetRegisteredSets( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") + wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + return nil, wrappedError + } + + registeredSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) + if err != nil { + wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetRegisteredSets", err} + return nil, wrappedError } - return r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) + + return registeredSets, nil } func (r *ChainReader) CanCall( From f728fa99d59bee90c440a9549f6e7873b9c6f526 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 09:57:25 -0300 Subject: [PATCH 09/33] Run make fmt --- chainio/clients/elcontracts/reader.go | 198 ++++++++++++++++++--- chainio/clients/elcontracts/reader_test.go | 12 +- 2 files changed, 179 insertions(+), 31 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index a3012a5db..a88fa8c66 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -100,7 +100,10 @@ func (r *ChainReader) IsOperatorRegistered( return false, wrappedError } - isRegistered, err := r.delegationManager.IsOperator(&bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address)) + isRegistered, err := r.delegationManager.IsOperator( + &bind.CallOpts{Context: ctx}, + gethcommon.HexToAddress(operator.Address), + ) if err != nil { wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.IsOperator", err} return false, wrappedError @@ -122,7 +125,12 @@ func (r *ChainReader) GetStakerShares( addresses, shares, err := r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetDepositedShares", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling delegationManager.GetDepositedShares", + err, + } return nil, nil, wrappedError } @@ -164,7 +172,12 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.DelegationApprover", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling delegationManager.DelegationApprover", + err, + } return types.Operator{}, wrappedError } @@ -177,7 +190,12 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocationDelay", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetAllocationDelay", + err, + } return types.Operator{}, wrappedError } @@ -285,7 +303,12 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry, ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.CalculateDelegationApprovalDigestHash", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling delegationManager.CalculateDelegationApprovalDigestHash", + err, + } return [32]byte{}, wrappedError } @@ -312,7 +335,12 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry, ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling avsDirectory.CalculateOperatorAVSRegistrationDigestHash", + err, + } return [32]byte{}, wrappedError } @@ -327,7 +355,12 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, distributionRootsLength, err := r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetDistributionRootsLength", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.GetDistributionRootsLength", + err, + } return &big.Int{}, wrappedError } @@ -342,7 +375,12 @@ func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (u endTimestamp, err := r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.CurrRewardsCalculationEndTimestamp", + err, + } return 0, wrappedError } @@ -359,7 +397,12 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( distributionRoot, err := r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetCurrentClaimableDistributionRoot", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.GetCurrentClaimableDistributionRoot", + err, + } return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -377,7 +420,12 @@ func (r *ChainReader) GetRootIndexFromHash( rootIndex, err := r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetRootIndexFromHash", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.GetRootIndexFromHash", + err, + } return 0, wrappedError } @@ -396,7 +444,12 @@ func (r *ChainReader) GetCumulativeClaimed( cumulativeClaimed, err := r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CumulativeClaimed", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.CumulativeClaimed", + err, + } return nil, wrappedError } @@ -433,7 +486,12 @@ func (r *ChainReader) GetOperatorAVSSplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetOperatorAVSSplit", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.GetOperatorAVSSplit", + err, + } return 0, wrappedError } @@ -451,7 +509,12 @@ func (r *ChainReader) GetOperatorPISplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.GetOperatorPISplit", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling rewardsCoordinator.GetOperatorPISplit", + err, + } return 0, wrappedError } @@ -468,9 +531,18 @@ func (r *ChainReader) GetAllocatableMagnitude( return 0, wrappedError } - allocatableMagnitude, err := r.allocationManager.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddress) + allocatableMagnitude, err := r.allocationManager.GetAllocatableMagnitude( + &bind.CallOpts{Context: ctx}, + operatorAddress, + strategyAddress, + ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatableMagnitude", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetAllocatableMagnitude", + err, + } return 0, wrappedError } @@ -487,9 +559,18 @@ func (r *ChainReader) GetMaxMagnitudes( return []uint64{}, wrappedError } - maxMagnitudes, err := r.allocationManager.GetMaxMagnitudes0(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddresses) + maxMagnitudes, err := r.allocationManager.GetMaxMagnitudes0( + &bind.CallOpts{Context: ctx}, + operatorAddress, + strategyAddresses, + ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMaxMagnitudes0", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetMaxMagnitudes0", + err, + } return []uint64{}, wrappedError } @@ -513,7 +594,12 @@ func (r *ChainReader) GetAllocationInfo( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetStrategyAllocations", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetStrategyAllocations", + err, + } return nil, wrappedError } @@ -545,7 +631,12 @@ func (r *ChainReader) GetOperatorShares( Context: ctx, }, operatorAddress, strategyAddresses) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetOperatorShares", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling delegationManager.GetOperatorShares", + err, + } return nil, wrappedError } @@ -562,9 +653,18 @@ func (r *ChainReader) GetOperatorsShares( return nil, wrappedError } - operatorsShares, err := r.delegationManager.GetOperatorsShares(&bind.CallOpts{Context: ctx}, operatorAddresses, strategyAddresses) + operatorsShares, err := r.delegationManager.GetOperatorsShares( + &bind.CallOpts{Context: ctx}, + operatorAddresses, + strategyAddresses, + ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.GetOperatorsShares", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling delegationManager.GetOperatorsShares", + err, + } return nil, wrappedError } @@ -583,7 +683,12 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatedSets", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetAllocatedSets", + err, + } return nil, wrappedError } return big.NewInt(int64(len(opSets))), nil @@ -603,7 +708,12 @@ func (r *ChainReader) GetOperatorSetsForOperator( // paginate? allocatedSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocatedSets", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetAllocatedSets", + err, + } return nil, wrappedError } @@ -626,7 +736,12 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling avsDirectory.AvsOperatorStatus", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling avsDirectory.AvsOperatorStatus", + err, + } return false, wrappedError } @@ -750,7 +865,12 @@ func (r *ChainReader) GetSlashableShares( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMinimumSlashableStake", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetMinimumSlashableStake", + err, + } return nil, wrappedError } if len(slashableShares) == 0 { @@ -783,7 +903,12 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( operatorSetStakes, err := r.GetSlashableSharesForOperatorSetsBefore(ctx, operatorSets, uint32(currentBlock)) if err != nil { - wrappedError := Error{2, "Nested error", "Error happened while calling GetSlashableSharesForOperatorSetsBefore", err} + wrappedError := Error{ + 2, + "Nested error", + "Error happened while calling GetSlashableSharesForOperatorSetsBefore", + err, + } return nil, wrappedError } @@ -827,7 +952,12 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMinimumSlashableStake", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetMinimumSlashableStake", + err, + } return nil, wrappedError } @@ -853,7 +983,12 @@ func (r *ChainReader) GetAllocationDelay( isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetAllocationDelay", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetAllocationDelay", + err, + } return 0, wrappedError } if !isSet { @@ -874,7 +1009,12 @@ func (r *ChainReader) GetRegisteredSets( registeredSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetRegisteredSets", err} + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling allocationManager.GetRegisteredSets", + err, + } return nil, wrappedError } diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index e09ae2c96..423f097e9 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -771,13 +771,21 @@ func TestContractErrorCases(t *testing.T) { t.Run("GetStrategyAndUnderlyingToken", func(t *testing.T) { _, _, err := chainReader.GetStrategyAndUnderlyingToken(ctx, strategyAddr) assert.Error(t, err) - assert.Equal(t, err.Error(), "Binding error(2) - Error happened while fetching token contract: no contract code at given address") + assert.Equal( + t, + err.Error(), + "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + ) }) t.Run("GetStrategyAndUnderlyingERC20Token", func(t *testing.T) { _, _, _, err := chainReader.GetStrategyAndUnderlyingERC20Token(ctx, strategyAddr) assert.Error(t, err) - assert.Equal(t, err.Error(), "Binding error(2) - Error happened while fetching token contract: no contract code at given address") + assert.Equal( + t, + err.Error(), + "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + ) }) } From e865d244bbe184206f8069f770e99ed02ee09f9b Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 10:21:17 -0300 Subject: [PATCH 10/33] Use error interface in admin functions --- chainio/clients/elcontracts/reader.go | 92 ++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 8 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index a88fa8c66..a1fe3bb79 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -19,7 +19,6 @@ import ( strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/types" - "github.com/Layr-Labs/eigensdk-go/utils" ) type Config struct { @@ -1028,6 +1027,11 @@ func (r *ChainReader) CanCall( target gethcommon.Address, selector [4]byte, ) (bool, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return false, wrappedError + } + canCall, err := r.permissionController.CanCall( &bind.CallOpts{Context: ctx}, accountAddress, @@ -1037,7 +1041,13 @@ func (r *ChainReader) CanCall( ) // This call should not fail since it's a getter if err != nil { - return false, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.CanCall", + err, + } + return false, wrappedError } return canCall, nil } @@ -1048,6 +1058,11 @@ func (r *ChainReader) ListAppointees( target gethcommon.Address, selector [4]byte, ) ([]gethcommon.Address, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return nil, wrappedError + } + appointees, err := r.permissionController.GetAppointees( &bind.CallOpts{Context: ctx}, accountAddress, @@ -1056,7 +1071,13 @@ func (r *ChainReader) ListAppointees( ) // This call should not fail since it's a getter if err != nil { - return nil, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.GetAppointees", + err, + } + return nil, wrappedError } return appointees, nil } @@ -1066,6 +1087,11 @@ func (r *ChainReader) ListAppointeePermissions( accountAddress gethcommon.Address, appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return nil, nil, wrappedError + } + targets, selectors, err := r.permissionController.GetAppointeePermissions( &bind.CallOpts{Context: ctx}, accountAddress, @@ -1073,7 +1099,13 @@ func (r *ChainReader) ListAppointeePermissions( ) // This call should not fail since it's a getter if err != nil { - return nil, nil, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.GetAppointeePermissions", + err, + } + return nil, nil, wrappedError } return targets, selectors, nil } @@ -1082,10 +1114,21 @@ func (r *ChainReader) ListPendingAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return nil, wrappedError + } + pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - return nil, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.GetPendingAdmins", + err, + } + return nil, wrappedError } return pendingAdmins, nil } @@ -1094,10 +1137,21 @@ func (r *ChainReader) ListAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return nil, wrappedError + } + pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - return nil, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.GetAdmins", + err, + } + return nil, wrappedError } return pendingAdmins, nil } @@ -1107,6 +1161,11 @@ func (r *ChainReader) IsPendingAdmin( accountAddress gethcommon.Address, pendingAdminAddress gethcommon.Address, ) (bool, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return false, wrappedError + } + isPendingAdmin, err := r.permissionController.IsPendingAdmin( &bind.CallOpts{Context: ctx}, accountAddress, @@ -1114,7 +1173,13 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - return false, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.IsPendingAdmin", + err, + } + return false, wrappedError } return isPendingAdmin, nil } @@ -1124,10 +1189,21 @@ func (r *ChainReader) IsAdmin( accountAddress gethcommon.Address, adminAddress gethcommon.Address, ) (bool, error) { + if r.permissionController == nil { + wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + return false, wrappedError + } + isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - return false, utils.WrapError("call to permission controller failed", err) + wrappedError := Error{ + 0, + "Binding error", + "Error happened while calling permissionController.IsAdmin", + err, + } + return false, wrappedError } return isAdmin, nil } From 0173da59f0be80b6b854997b0cfdf09ec0b9ec94 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 10:23:20 -0300 Subject: [PATCH 11/33] Fix error assert in TestGetRootIndexFromRootHash --- chainio/clients/elcontracts/reader_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 423f097e9..8410ab374 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -348,7 +348,10 @@ func TestGetRootIndexFromRootHash(t *testing.T) { root, ) assert.Error(t, err) - assert.Equal(t, err.Error(), "execution reverted: custom error 0x504570e3", + assert.Equal( + t, + err.Error(), + "Binding error(0) - Error happened while calling rewardsCoordinator.GetRootIndexFromHash: execution reverted: custom error 0x504570e3", "GetRootIndexFromHash should return an InvalidRoot() error", ) assert.Zero(t, root_index) From 650ee6d2cdb9f2d86e57bd81ef0fa394cbcc9288 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 11:56:03 -0300 Subject: [PATCH 12/33] Add error text assert when expecting errors at reader tests --- chainio/clients/elcontracts/reader_test.go | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 8410ab374..599fb0bf5 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -815,12 +815,22 @@ func TestInvalidConfig(t *testing.T) { // IsOperatorRegistered needs a correct DelegationManagerAddress _, err := chainReader.IsOperatorRegistered(context.Background(), operator) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - DelegationManager contract not provided", + ) }) t.Run("get operator details with invalid config", func(t *testing.T) { // GetOperatorDetails needs a correct DelegationManagerAddress _, err := chainReader.GetOperatorDetails(context.Background(), operator) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - DelegationManager contract not provided", + ) }) t.Run("get operator avs", func(t *testing.T) { @@ -830,9 +840,19 @@ func TestInvalidConfig(t *testing.T) { common.MaxAddress, ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) _, err = chainReader.GetOperatorPISplit(context.Background(), common.HexToAddress(operatorAddr)) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) }) t.Run("try to get strategy and underlying token with wrong strategy address", func(t *testing.T) { @@ -843,10 +863,20 @@ func TestInvalidConfig(t *testing.T) { // GetOperatorSharesInStrategy needs a correct DelegationManagerAddress _, err := chainReader.GetOperatorSharesInStrategy(context.Background(), operatorAddr, strategyAddr) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - DelegationManager contract not provided", + ) // GetStrategyAndUnderlyingToken needs a correct StrategyAddress _, _, err = chainReader.GetStrategyAndUnderlyingToken(context.Background(), strategyAddr) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + ) _, _, _, err = chainReader.GetStrategyAndUnderlyingERC20Token(context.Background(), strategyAddr) require.Error(t, err) @@ -868,6 +898,11 @@ func TestInvalidConfig(t *testing.T) { expiry, ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - DelegationManager contract not provided", + ) // CalculateOperatorAVSRegistrationDigestHash needs a correct AvsDirectoryAddress _, err = chainReader.CalculateOperatorAVSRegistrationDigestHash(context.Background(), @@ -875,19 +910,39 @@ func TestInvalidConfig(t *testing.T) { staker, approverSalt, expiry) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - AVSDirectory contract not provided", + ) }) t.Run("get root with invalid config", func(t *testing.T) { // GetDistributionRootsLength needs a correct RewardsCoordinatorAddress _, err := chainReader.GetDistributionRootsLength(context.Background()) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) // GetRootIndexFromHash needs a correct RewardsCoordinatorAddress _, err = chainReader.GetRootIndexFromHash(context.Background(), [32]byte{}) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) _, err = chainReader.GetCurrentClaimableDistributionRoot(context.Background()) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) }) t.Run("get magnitudes, rewards and claims with invalid config", func(t *testing.T) { @@ -896,6 +951,11 @@ func TestInvalidConfig(t *testing.T) { _, err = chainReader.GetCurrentClaimableDistributionRoot(context.Background()) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) _, err := chainReader.GetCumulativeClaimed( context.Background(), @@ -903,6 +963,11 @@ func TestInvalidConfig(t *testing.T) { common.HexToAddress(testutils.ANVIL_SECOND_ADDRESS), ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) _, err = chainReader.GetMaxMagnitudes( context.Background(), @@ -910,6 +975,11 @@ func TestInvalidConfig(t *testing.T) { []common.Address{strategyAddr}, ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - AllocationManager contract not provided", + ) _, err = chainReader.GetAllocatableMagnitude( context.Background(), @@ -917,21 +987,46 @@ func TestInvalidConfig(t *testing.T) { strategyAddr, ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - AllocationManager contract not provided", + ) _, err = chainReader.GetAllocationInfo(context.Background(), common.HexToAddress(operatorAddr), strategyAddr) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - AllocationManager contract not provided", + ) _, err = chainReader.GetAllocationDelay(context.Background(), common.HexToAddress(operatorAddr)) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - AllocationManager contract not provided", + ) _, err = chainReader.CheckClaim( context.Background(), rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim{}, ) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) _, err = chainReader.CurrRewardsCalculationEndTimestamp(context.Background()) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Missing needed contract(1) - RewardsCoordinator contract not provided", + ) }) t.Run("try to get a staker shares with invalid config", func(t *testing.T) { @@ -949,18 +1044,21 @@ func TestInvalidConfig(t *testing.T) { big.NewInt(0), ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) }) t.Run("try to get the number of operator sets for an operator with invalid config", func(t *testing.T) { // GetNumOperatorSetsForOperator needs a correct AllocationManagerAddress _, err := chainReader.GetNumOperatorSetsForOperator(context.Background(), common.HexToAddress(operator.Address)) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }) t.Run("try to get the operator sets for an operator with invalid config", func(t *testing.T) { // GetOperatorSetsForOperator needs a correct AllocationManagerAddress _, err := chainReader.GetOperatorSetsForOperator(context.Background(), common.HexToAddress(operator.Address)) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }) t.Run("try to check if the operator is registered in an operator set with set id 0 and an invalid config", @@ -978,6 +1076,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AVSDirectory")) }, ) @@ -996,6 +1095,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AVSDirectory")) }, ) @@ -1013,6 +1113,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }, ) @@ -1030,6 +1131,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }, ) @@ -1047,6 +1149,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }, ) } @@ -1236,12 +1339,15 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { t.Run("test operator set with invalid id", func(t *testing.T) { _, err := chainReader.GetOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) + assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") _, err = chainReader.GetNumOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) + assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") _, err = chainReader.GetStrategiesForOperatorSet(ctx, operatorSet) require.Error(t, err) + assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") strategies := []common.Address{contractAddrs.Erc20MockStrategy} @@ -1252,6 +1358,8 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { strategies, ) require.Error(t, err) + // This is the returned error, but i don't think it's the inteded + // assert.Equal(t, err.Error(), "Missing needed contract(1) - AllocationManager contract not provided") }) t.Run("get slashable shares with invalid operatorSet", func(t *testing.T) { @@ -1266,6 +1374,7 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 10) require.Error(t, err) + assert.Equal(t, err.Error(), "Nested error(2) - Error happened while calling GetOperatorsForOperatorSet: Other errors(3) - Method not supported for legacy AVSs") }) } From 6a561faa4a54d2b7ce97e75cc88f919cad6cb16b Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 11:56:52 -0300 Subject: [PATCH 13/33] Change errLegacyAVSsNotSupported to use the error interface --- chainio/clients/elcontracts/reader.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index a1fe3bb79..95f15b312 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -2,7 +2,6 @@ package elcontracts import ( "context" - "errors" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -39,7 +38,7 @@ type ChainReader struct { ethClient eth.HttpBackend } -var errLegacyAVSsNotSupported = errors.New("method not supported for legacy AVSs") +var errLegacyAVSsNotSupported = Error{3, "Other errors", "Method not supported for legacy AVSs", nil} func NewChainReader( delegationManager *delegationmanager.ContractDelegationManager, From 977091764237c7fab1be7197a741ade871cac0b9 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 11:58:34 -0300 Subject: [PATCH 14/33] Return err interface if init fails and add testcase --- chainio/clients/elcontracts/reader.go | 3 ++- chainio/clients/elcontracts/reader_test.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 95f15b312..237d412cf 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -75,7 +75,8 @@ func NewReaderFromConfig( logger, ) if err != nil { - return nil, err + wrappedError := Error{3, "Other errors", "Error happened while calling NewBindingsFromConfig", err} + return nil, wrappedError } return NewChainReader( elContractBindings.DelegationManager, diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 599fb0bf5..bcea7befd 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1374,7 +1374,11 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 10) require.Error(t, err) - assert.Equal(t, err.Error(), "Nested error(2) - Error happened while calling GetOperatorsForOperatorSet: Other errors(3) - Method not supported for legacy AVSs") + assert.Equal( + t, + err.Error(), + "Nested error(2) - Error happened while calling GetOperatorsForOperatorSet: Other errors(3) - Method not supported for legacy AVSs", + ) }) } @@ -1404,5 +1408,10 @@ func TestCreateRederFromConfig(t *testing.T) { _, err = elcontracts.NewReaderFromConfig(config, ethHttpClient, logger) require.Error(t, err) + assert.Equal( + t, + err.Error(), + "Other errors(3) - Error happened while calling NewBindingsFromConfig: Failed to fetch StrategyManager address: no contract code at given address", + ) }) } From f9663e633dbeb7aa596019efbf3ec72784193002 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 12:05:03 -0300 Subject: [PATCH 15/33] Use CommonErrorMissingContract to avoid hardcoded strings --- chainio/clients/elcontracts/reader_test.go | 108 ++++----------------- 1 file changed, 18 insertions(+), 90 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index bcea7befd..65cde40d8 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -815,22 +815,14 @@ func TestInvalidConfig(t *testing.T) { // IsOperatorRegistered needs a correct DelegationManagerAddress _, err := chainReader.IsOperatorRegistered(context.Background(), operator) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - DelegationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) }) t.Run("get operator details with invalid config", func(t *testing.T) { // GetOperatorDetails needs a correct DelegationManagerAddress _, err := chainReader.GetOperatorDetails(context.Background(), operator) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - DelegationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) }) t.Run("get operator avs", func(t *testing.T) { @@ -840,19 +832,11 @@ func TestInvalidConfig(t *testing.T) { common.MaxAddress, ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) _, err = chainReader.GetOperatorPISplit(context.Background(), common.HexToAddress(operatorAddr)) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) }) t.Run("try to get strategy and underlying token with wrong strategy address", func(t *testing.T) { @@ -863,11 +847,7 @@ func TestInvalidConfig(t *testing.T) { // GetOperatorSharesInStrategy needs a correct DelegationManagerAddress _, err := chainReader.GetOperatorSharesInStrategy(context.Background(), operatorAddr, strategyAddr) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - DelegationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) // GetStrategyAndUnderlyingToken needs a correct StrategyAddress _, _, err = chainReader.GetStrategyAndUnderlyingToken(context.Background(), strategyAddr) @@ -898,11 +878,7 @@ func TestInvalidConfig(t *testing.T) { expiry, ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - DelegationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("DelegationManager")) // CalculateOperatorAVSRegistrationDigestHash needs a correct AvsDirectoryAddress _, err = chainReader.CalculateOperatorAVSRegistrationDigestHash(context.Background(), @@ -910,39 +886,23 @@ func TestInvalidConfig(t *testing.T) { staker, approverSalt, expiry) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - AVSDirectory contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AVSDirectory")) }) t.Run("get root with invalid config", func(t *testing.T) { // GetDistributionRootsLength needs a correct RewardsCoordinatorAddress _, err := chainReader.GetDistributionRootsLength(context.Background()) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) // GetRootIndexFromHash needs a correct RewardsCoordinatorAddress _, err = chainReader.GetRootIndexFromHash(context.Background(), [32]byte{}) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) _, err = chainReader.GetCurrentClaimableDistributionRoot(context.Background()) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) }) t.Run("get magnitudes, rewards and claims with invalid config", func(t *testing.T) { @@ -951,11 +911,7 @@ func TestInvalidConfig(t *testing.T) { _, err = chainReader.GetCurrentClaimableDistributionRoot(context.Background()) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) _, err := chainReader.GetCumulativeClaimed( context.Background(), @@ -963,11 +919,7 @@ func TestInvalidConfig(t *testing.T) { common.HexToAddress(testutils.ANVIL_SECOND_ADDRESS), ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) _, err = chainReader.GetMaxMagnitudes( context.Background(), @@ -975,11 +927,7 @@ func TestInvalidConfig(t *testing.T) { []common.Address{strategyAddr}, ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - AllocationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) _, err = chainReader.GetAllocatableMagnitude( context.Background(), @@ -987,46 +935,26 @@ func TestInvalidConfig(t *testing.T) { strategyAddr, ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - AllocationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) _, err = chainReader.GetAllocationInfo(context.Background(), common.HexToAddress(operatorAddr), strategyAddr) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - AllocationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) _, err = chainReader.GetAllocationDelay(context.Background(), common.HexToAddress(operatorAddr)) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - AllocationManager contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) _, err = chainReader.CheckClaim( context.Background(), rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim{}, ) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) _, err = chainReader.CurrRewardsCalculationEndTimestamp(context.Background()) require.Error(t, err) - assert.Equal( - t, - err.Error(), - "Missing needed contract(1) - RewardsCoordinator contract not provided", - ) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("RewardsCoordinator")) }) t.Run("try to get a staker shares with invalid config", func(t *testing.T) { From db33f935dc43b478a6261cd4ced3cbf6107cab97 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 12:27:53 -0300 Subject: [PATCH 16/33] Fix failing test --- chainio/clients/elcontracts/reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 65cde40d8..f6f5148f9 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1023,7 +1023,7 @@ func TestInvalidConfig(t *testing.T) { operatorSet, ) require.Error(t, err) - assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AVSDirectory")) + assert.Equal(t, err.Error(), elcontracts.CommonErrorMissingContract("AllocationManager")) }, ) From 9be131ade3e6165eac7a8e626ee2e05b01ab114a Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 12:28:39 -0300 Subject: [PATCH 17/33] Use function to create missing contract errors at reader --- chainio/clients/elcontracts/error.go | 5 ++ chainio/clients/elcontracts/reader.go | 74 +++++++++++++-------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 366b76cb1..85e23f38a 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -18,6 +18,11 @@ func (e Error) Error() string { } } +func CreateForMissingContractErr(contractName string) Error { + errDescription := fmt.Sprintf("%s contract not provided", contractName) + return Error{1, "Missing needed contract", errDescription, nil} +} + func CommonErrorMissingContract(contractName string) string { return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) } diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 237d412cf..01f5660c6 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -95,7 +95,7 @@ func (r *ChainReader) IsOperatorRegistered( operator types.Operator, ) (bool, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return false, wrappedError } @@ -118,7 +118,7 @@ func (r *ChainReader) GetStakerShares( stakerAddress gethcommon.Address, ) ([]gethcommon.Address, []*big.Int, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return nil, nil, wrappedError } @@ -143,7 +143,7 @@ func (r *ChainReader) GetDelegatedOperator( blockNumber *big.Int, ) (gethcommon.Address, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return gethcommon.Address{}, wrappedError } @@ -161,7 +161,7 @@ func (r *ChainReader) GetOperatorDetails( operator types.Operator, ) (types.Operator, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return types.Operator{}, wrappedError } @@ -263,7 +263,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr gethcommon.Address, ) (*big.Int, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return &big.Int{}, wrappedError } @@ -289,7 +289,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return [32]byte{}, wrappedError } @@ -322,7 +322,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.avsDirectory == nil { - wrappedError := Error{1, "Missing needed contract", "AVSDirectory contract not provided", nil} + wrappedError := CreateForMissingContractErr("AVSDirectory") return [32]byte{}, wrappedError } @@ -348,7 +348,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return &big.Int{}, wrappedError } @@ -368,7 +368,7 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return 0, wrappedError } @@ -390,7 +390,7 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -413,7 +413,7 @@ func (r *ChainReader) GetRootIndexFromHash( rootHash [32]byte, ) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return 0, wrappedError } @@ -437,7 +437,7 @@ func (r *ChainReader) GetCumulativeClaimed( token gethcommon.Address, ) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return nil, wrappedError } @@ -460,7 +460,7 @@ func (r *ChainReader) CheckClaim( claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim, ) (bool, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return false, wrappedError } @@ -479,7 +479,7 @@ func (r *ChainReader) GetOperatorAVSSplit( avs gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return 0, wrappedError } @@ -502,7 +502,7 @@ func (r *ChainReader) GetOperatorPISplit( operator gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := Error{1, "Missing needed contract", "RewardsCoordinator contract not provided", nil} + wrappedError := CreateForMissingContractErr("RewardsCoordinator") return 0, wrappedError } @@ -526,7 +526,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress gethcommon.Address, ) (uint64, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return 0, wrappedError } @@ -554,7 +554,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses []gethcommon.Address, ) ([]uint64, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return []uint64{}, wrappedError } @@ -582,7 +582,7 @@ func (r *ChainReader) GetAllocationInfo( strategyAddress gethcommon.Address, ) ([]AllocationInfo, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -622,7 +622,7 @@ func (r *ChainReader) GetOperatorShares( strategyAddresses []gethcommon.Address, ) ([]*big.Int, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return nil, wrappedError } @@ -648,7 +648,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses []gethcommon.Address, ) ([][]*big.Int, error) { if r.delegationManager == nil { - wrappedError := Error{1, "Missing needed contract", "DelegationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("DelegationManager") return nil, wrappedError } @@ -677,7 +677,7 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( operatorAddress gethcommon.Address, ) (*big.Int, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -700,7 +700,7 @@ func (r *ChainReader) GetOperatorSetsForOperator( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to @@ -728,7 +728,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( if operatorSet.Id == 0 { // this is an M2 AVS if r.avsDirectory == nil { - wrappedError := Error{1, "Missing needed contract", "AVSDirectory contract not provided", nil} + wrappedError := CreateForMissingContractErr("AVSDirectory") return false, wrappedError } @@ -747,7 +747,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( return status == 1, nil } else { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return false, wrappedError } registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -776,7 +776,7 @@ func (r *ChainReader) GetOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -799,7 +799,7 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -823,7 +823,7 @@ func (r *ChainReader) GetStrategiesForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -844,7 +844,7 @@ func (r *ChainReader) GetSlashableShares( strategies []gethcommon.Address, ) (map[gethcommon.Address]*big.Int, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -976,7 +976,7 @@ func (r *ChainReader) GetAllocationDelay( operatorAddress gethcommon.Address, ) (uint32, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return 0, wrappedError } isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -1002,7 +1002,7 @@ func (r *ChainReader) GetRegisteredSets( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := Error{1, "Missing needed contract", "AllocationManager contract not provided", nil} + wrappedError := CreateForMissingContractErr("AllocationManager") return nil, wrappedError } @@ -1028,7 +1028,7 @@ func (r *ChainReader) CanCall( selector [4]byte, ) (bool, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return false, wrappedError } @@ -1059,7 +1059,7 @@ func (r *ChainReader) ListAppointees( selector [4]byte, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return nil, wrappedError } @@ -1088,7 +1088,7 @@ func (r *ChainReader) ListAppointeePermissions( appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return nil, nil, wrappedError } @@ -1115,7 +1115,7 @@ func (r *ChainReader) ListPendingAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return nil, wrappedError } @@ -1138,7 +1138,7 @@ func (r *ChainReader) ListAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return nil, wrappedError } @@ -1162,7 +1162,7 @@ func (r *ChainReader) IsPendingAdmin( pendingAdminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return false, wrappedError } @@ -1190,7 +1190,7 @@ func (r *ChainReader) IsAdmin( adminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := Error{1, "Missing needed contract", "PermissionController contract not provided", nil} + wrappedError := CreateForMissingContractErr("PermissionController") return false, wrappedError } From f0a1f0f662be1253db4b9caa47d512d813bd034f Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 12:32:11 -0300 Subject: [PATCH 18/33] Rename error creation function --- chainio/clients/elcontracts/error.go | 2 +- chainio/clients/elcontracts/reader.go | 74 +++++++++++++-------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 85e23f38a..4504d1d50 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -18,7 +18,7 @@ func (e Error) Error() string { } } -func CreateForMissingContractErr(contractName string) Error { +func CreateErrorForMissingContract(contractName string) Error { errDescription := fmt.Sprintf("%s contract not provided", contractName) return Error{1, "Missing needed contract", errDescription, nil} } diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 01f5660c6..63534ba02 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -95,7 +95,7 @@ func (r *ChainReader) IsOperatorRegistered( operator types.Operator, ) (bool, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return false, wrappedError } @@ -118,7 +118,7 @@ func (r *ChainReader) GetStakerShares( stakerAddress gethcommon.Address, ) ([]gethcommon.Address, []*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return nil, nil, wrappedError } @@ -143,7 +143,7 @@ func (r *ChainReader) GetDelegatedOperator( blockNumber *big.Int, ) (gethcommon.Address, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return gethcommon.Address{}, wrappedError } @@ -161,7 +161,7 @@ func (r *ChainReader) GetOperatorDetails( operator types.Operator, ) (types.Operator, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return types.Operator{}, wrappedError } @@ -263,7 +263,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr gethcommon.Address, ) (*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return &big.Int{}, wrappedError } @@ -289,7 +289,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return [32]byte{}, wrappedError } @@ -322,7 +322,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.avsDirectory == nil { - wrappedError := CreateForMissingContractErr("AVSDirectory") + wrappedError := CreateErrorForMissingContract("AVSDirectory") return [32]byte{}, wrappedError } @@ -348,7 +348,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return &big.Int{}, wrappedError } @@ -368,7 +368,7 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return 0, wrappedError } @@ -390,7 +390,7 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -413,7 +413,7 @@ func (r *ChainReader) GetRootIndexFromHash( rootHash [32]byte, ) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return 0, wrappedError } @@ -437,7 +437,7 @@ func (r *ChainReader) GetCumulativeClaimed( token gethcommon.Address, ) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return nil, wrappedError } @@ -460,7 +460,7 @@ func (r *ChainReader) CheckClaim( claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim, ) (bool, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return false, wrappedError } @@ -479,7 +479,7 @@ func (r *ChainReader) GetOperatorAVSSplit( avs gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return 0, wrappedError } @@ -502,7 +502,7 @@ func (r *ChainReader) GetOperatorPISplit( operator gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateForMissingContractErr("RewardsCoordinator") + wrappedError := CreateErrorForMissingContract("RewardsCoordinator") return 0, wrappedError } @@ -526,7 +526,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress gethcommon.Address, ) (uint64, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return 0, wrappedError } @@ -554,7 +554,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses []gethcommon.Address, ) ([]uint64, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return []uint64{}, wrappedError } @@ -582,7 +582,7 @@ func (r *ChainReader) GetAllocationInfo( strategyAddress gethcommon.Address, ) ([]AllocationInfo, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -622,7 +622,7 @@ func (r *ChainReader) GetOperatorShares( strategyAddresses []gethcommon.Address, ) ([]*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return nil, wrappedError } @@ -648,7 +648,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses []gethcommon.Address, ) ([][]*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateForMissingContractErr("DelegationManager") + wrappedError := CreateErrorForMissingContract("DelegationManager") return nil, wrappedError } @@ -677,7 +677,7 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( operatorAddress gethcommon.Address, ) (*big.Int, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -700,7 +700,7 @@ func (r *ChainReader) GetOperatorSetsForOperator( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to @@ -728,7 +728,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( if operatorSet.Id == 0 { // this is an M2 AVS if r.avsDirectory == nil { - wrappedError := CreateForMissingContractErr("AVSDirectory") + wrappedError := CreateErrorForMissingContract("AVSDirectory") return false, wrappedError } @@ -747,7 +747,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( return status == 1, nil } else { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return false, wrappedError } registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -776,7 +776,7 @@ func (r *ChainReader) GetOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -799,7 +799,7 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -823,7 +823,7 @@ func (r *ChainReader) GetStrategiesForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -844,7 +844,7 @@ func (r *ChainReader) GetSlashableShares( strategies []gethcommon.Address, ) (map[gethcommon.Address]*big.Int, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -976,7 +976,7 @@ func (r *ChainReader) GetAllocationDelay( operatorAddress gethcommon.Address, ) (uint32, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return 0, wrappedError } isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) @@ -1002,7 +1002,7 @@ func (r *ChainReader) GetRegisteredSets( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := CreateForMissingContractErr("AllocationManager") + wrappedError := CreateErrorForMissingContract("AllocationManager") return nil, wrappedError } @@ -1028,7 +1028,7 @@ func (r *ChainReader) CanCall( selector [4]byte, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return false, wrappedError } @@ -1059,7 +1059,7 @@ func (r *ChainReader) ListAppointees( selector [4]byte, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return nil, wrappedError } @@ -1088,7 +1088,7 @@ func (r *ChainReader) ListAppointeePermissions( appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return nil, nil, wrappedError } @@ -1115,7 +1115,7 @@ func (r *ChainReader) ListPendingAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return nil, wrappedError } @@ -1138,7 +1138,7 @@ func (r *ChainReader) ListAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return nil, wrappedError } @@ -1162,7 +1162,7 @@ func (r *ChainReader) IsPendingAdmin( pendingAdminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return false, wrappedError } @@ -1190,7 +1190,7 @@ func (r *ChainReader) IsAdmin( adminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateForMissingContractErr("PermissionController") + wrappedError := CreateErrorForMissingContract("PermissionController") return false, wrappedError } From 0cd9f20ab68c9eb723ef4dcdefd1dc155639cc95 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 12:52:32 -0300 Subject: [PATCH 19/33] Use function to create binding errors at reader --- chainio/clients/elcontracts/error.go | 10 ++ chainio/clients/elcontracts/reader.go | 233 +++++--------------------- 2 files changed, 49 insertions(+), 194 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 4504d1d50..d66c38ed4 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -23,6 +23,16 @@ func CreateErrorForMissingContract(contractName string) Error { return Error{1, "Missing needed contract", errDescription, nil} } +func CreateForBindingError(bindingName string, errorCause error) Error { + errDescription := fmt.Sprintf("Error happened while calling %s", bindingName) + return Error{ + 0, + "Binding error", + errDescription, + errorCause, + } +} + func CommonErrorMissingContract(contractName string) string { return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) } diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 63534ba02..f9615d7b5 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -104,7 +104,7 @@ func (r *ChainReader) IsOperatorRegistered( gethcommon.HexToAddress(operator.Address), ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.IsOperator", err} + wrappedError := CreateForBindingError("delegationManager.IsOperator", err) return false, wrappedError } @@ -124,12 +124,7 @@ func (r *ChainReader) GetStakerShares( addresses, shares, err := r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling delegationManager.GetDepositedShares", - err, - } + wrappedError := CreateForBindingError("delegationManager.GetDepositedShares", err) return nil, nil, wrappedError } @@ -149,7 +144,7 @@ func (r *ChainReader) GetDelegatedOperator( delegatedOperator, err := r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.DelegatedTo", err} + wrappedError := CreateForBindingError("delegationManager.DelegatedTo", err) return gethcommon.Address{}, wrappedError } @@ -171,12 +166,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling delegationManager.DelegationApprover", - err, - } + wrappedError := CreateForBindingError("delegationManager.DelegationApprover", err) return types.Operator{}, wrappedError } @@ -189,12 +179,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetAllocationDelay", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetAllocationDelay", err) return types.Operator{}, wrappedError } @@ -273,7 +258,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr, ) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling delegationManager.OperatorShares", err} + wrappedError := CreateForBindingError("delegationManager.OperatorShares", err) return &big.Int{}, wrappedError } @@ -302,12 +287,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry, ) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling delegationManager.CalculateDelegationApprovalDigestHash", - err, - } + wrappedError := CreateForBindingError("delegationManager.CalculateDelegationApprovalDigestHash", err) return [32]byte{}, wrappedError } @@ -334,12 +314,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry, ) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling avsDirectory.CalculateOperatorAVSRegistrationDigestHash", - err, - } + wrappedError := CreateForBindingError("avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err) return [32]byte{}, wrappedError } @@ -354,12 +329,7 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, distributionRootsLength, err := r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.GetDistributionRootsLength", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.GetDistributionRootsLength", err) return &big.Int{}, wrappedError } @@ -374,12 +344,7 @@ func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (u endTimestamp, err := r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.CurrRewardsCalculationEndTimestamp", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err) return 0, wrappedError } @@ -396,12 +361,7 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( distributionRoot, err := r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.GetCurrentClaimableDistributionRoot", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.GetCurrentClaimableDistributionRoot", err) return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -419,12 +379,7 @@ func (r *ChainReader) GetRootIndexFromHash( rootIndex, err := r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.GetRootIndexFromHash", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.GetRootIndexFromHash", err) return 0, wrappedError } @@ -443,12 +398,7 @@ func (r *ChainReader) GetCumulativeClaimed( cumulativeClaimed, err := r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.CumulativeClaimed", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.CumulativeClaimed", err) return nil, wrappedError } @@ -466,7 +416,7 @@ func (r *ChainReader) CheckClaim( claimChecked, err := r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling rewardsCoordinator.CheckClaim", err} + wrappedError := CreateForBindingError("rewardsCoordinator.CheckClaim", err) return false, wrappedError } @@ -485,12 +435,7 @@ func (r *ChainReader) GetOperatorAVSSplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.GetOperatorAVSSplit", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.GetOperatorAVSSplit", err) return 0, wrappedError } @@ -508,12 +453,7 @@ func (r *ChainReader) GetOperatorPISplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling rewardsCoordinator.GetOperatorPISplit", - err, - } + wrappedError := CreateForBindingError("rewardsCoordinator.GetOperatorPISplit", err) return 0, wrappedError } @@ -536,12 +476,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress, ) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetAllocatableMagnitude", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetAllocatableMagnitude", err) return 0, wrappedError } @@ -564,12 +499,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses, ) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetMaxMagnitudes0", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetMaxMagnitudes0", err) return []uint64{}, wrappedError } @@ -593,12 +523,7 @@ func (r *ChainReader) GetAllocationInfo( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetStrategyAllocations", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetStrategyAllocations", err) return nil, wrappedError } @@ -630,12 +555,7 @@ func (r *ChainReader) GetOperatorShares( Context: ctx, }, operatorAddress, strategyAddresses) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling delegationManager.GetOperatorShares", - err, - } + wrappedError := CreateForBindingError("delegationManager.GetOperatorShares", err) return nil, wrappedError } @@ -658,12 +578,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses, ) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling delegationManager.GetOperatorsShares", - err, - } + wrappedError := CreateForBindingError("delegationManager.GetOperatorsShares", err) return nil, wrappedError } @@ -682,12 +597,7 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetAllocatedSets", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetAllocatedSets", err) return nil, wrappedError } return big.NewInt(int64(len(opSets))), nil @@ -707,12 +617,7 @@ func (r *ChainReader) GetOperatorSetsForOperator( // paginate? allocatedSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetAllocatedSets", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetAllocatedSets", err) return nil, wrappedError } @@ -735,12 +640,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling avsDirectory.AvsOperatorStatus", - err, - } + wrappedError := CreateForBindingError("avsDirectory.AvsOperatorStatus", err) return false, wrappedError } @@ -753,7 +653,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetRegisteredSets", err} + wrappedError := CreateForBindingError("allocationManager.GetRegisteredSets", err) return false, wrappedError } for _, registeredOperatorSet := range registeredOperatorSets { @@ -782,7 +682,7 @@ func (r *ChainReader) GetOperatorsForOperatorSet( members, err := r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMembers", err} + wrappedError := CreateForBindingError("allocationManager.GetMembers", err) return nil, wrappedError } @@ -805,7 +705,7 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( memberCount, err := r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetMemberCount", err} + wrappedError := CreateForBindingError("allocationManager.GetMemberCount", err) return nil, wrappedError } @@ -829,7 +729,7 @@ func (r *ChainReader) GetStrategiesForOperatorSet( strategiesInSet, err := r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := Error{0, "Binding error", "Error happened while calling allocationManager.GetStrategiesInOperatorSet", err} + wrappedError := CreateForBindingError("allocationManager.GetStrategiesInOperatorSet", err) return nil, wrappedError } @@ -864,12 +764,7 @@ func (r *ChainReader) GetSlashableShares( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetMinimumSlashableStake", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetMinimumSlashableStake", err) return nil, wrappedError } if len(slashableShares) == 0 { @@ -951,12 +846,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetMinimumSlashableStake", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetMinimumSlashableStake", err) return nil, wrappedError } @@ -982,12 +872,7 @@ func (r *ChainReader) GetAllocationDelay( isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetAllocationDelay", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetAllocationDelay", err) return 0, wrappedError } if !isSet { @@ -1008,12 +893,7 @@ func (r *ChainReader) GetRegisteredSets( registeredSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling allocationManager.GetRegisteredSets", - err, - } + wrappedError := CreateForBindingError("allocationManager.GetRegisteredSets", err) return nil, wrappedError } @@ -1041,12 +921,7 @@ func (r *ChainReader) CanCall( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.CanCall", - err, - } + wrappedError := CreateForBindingError("permissionController.CanCall", err) return false, wrappedError } return canCall, nil @@ -1071,12 +946,7 @@ func (r *ChainReader) ListAppointees( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.GetAppointees", - err, - } + wrappedError := CreateForBindingError("permissionController.GetAppointees", err) return nil, wrappedError } return appointees, nil @@ -1099,12 +969,7 @@ func (r *ChainReader) ListAppointeePermissions( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.GetAppointeePermissions", - err, - } + wrappedError := CreateForBindingError("permissionController.GetAppointeePermissions", err) return nil, nil, wrappedError } return targets, selectors, nil @@ -1122,12 +987,7 @@ func (r *ChainReader) ListPendingAdmins( pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.GetPendingAdmins", - err, - } + wrappedError := CreateForBindingError("permissionController.GetPendingAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -1145,12 +1005,7 @@ func (r *ChainReader) ListAdmins( pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.GetAdmins", - err, - } + wrappedError := CreateForBindingError("permissionController.GetAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -1173,12 +1028,7 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.IsPendingAdmin", - err, - } + wrappedError := CreateForBindingError("permissionController.IsPendingAdmin", err) return false, wrappedError } return isPendingAdmin, nil @@ -1197,12 +1047,7 @@ func (r *ChainReader) IsAdmin( isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{ - 0, - "Binding error", - "Error happened while calling permissionController.IsAdmin", - err, - } + wrappedError := CreateForBindingError("permissionController.IsAdmin", err) return false, wrappedError } return isAdmin, nil From 2701a623fc134d9193eb8ae8f9eaf4fcbd0fce30 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 13:03:11 -0300 Subject: [PATCH 20/33] Turn type 2 binding errors into Binding errors --- chainio/clients/elcontracts/reader.go | 14 +++++++------- chainio/clients/elcontracts/reader_test.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index f9615d7b5..92a918bb9 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -205,12 +205,12 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching strategy contract", err} + wrappedError := CreateForBindingError("strategy contract", err) return nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching token contract", err} + wrappedError := CreateForBindingError("token contract", err) return nil, gethcommon.Address{}, wrappedError } return contractStrategy, underlyingTokenAddr, nil @@ -225,18 +225,18 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching strategy contract", err} + wrappedError := CreateForBindingError("strategy contract", err) return nil, nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching token contract", err} + wrappedError := CreateForBindingError("token contract", err) return nil, nil, gethcommon.Address{}, wrappedError } contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient) // This call should not fail, if the strategy does not have an underlying token then it would enter the if above if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching erc20 token contract", err} + wrappedError := CreateForBindingError("erc20 token contract", err) return nil, nil, gethcommon.Address{}, wrappedError } return contractStrategy, contractUnderlyingToken, underlyingTokenAddr, nil @@ -751,7 +751,7 @@ func (r *ChainReader) GetSlashableShares( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching block number", err} + wrappedError := CreateForBindingError("ethClient.BlockNumber", err) return nil, wrappedError } @@ -791,7 +791,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := Error{2, "Binding error", "Error happened while fetching block number", err} + wrappedError := CreateForBindingError("ethClient.BlockNumber", err) return nil, wrappedError } diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index f6f5148f9..997c942ae 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -777,7 +777,7 @@ func TestContractErrorCases(t *testing.T) { assert.Equal( t, err.Error(), - "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + "Binding error(0) - Error happened while calling token contract: no contract code at given address", ) }) @@ -787,7 +787,7 @@ func TestContractErrorCases(t *testing.T) { assert.Equal( t, err.Error(), - "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + "Binding error(0) - Error happened while calling token contract: no contract code at given address", ) }) } @@ -855,7 +855,7 @@ func TestInvalidConfig(t *testing.T) { assert.Equal( t, err.Error(), - "Binding error(2) - Error happened while fetching token contract: no contract code at given address", + "Binding error(0) - Error happened while calling token contract: no contract code at given address", ) _, _, _, err = chainReader.GetStrategyAndUnderlyingERC20Token(context.Background(), strategyAddr) From c2b80049abe48e46d0a08e89981bb313bf731d88 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 13:09:32 -0300 Subject: [PATCH 21/33] Use function to create nested errors at reader --- chainio/clients/elcontracts/error.go | 10 ++++++++++ chainio/clients/elcontracts/reader.go | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index d66c38ed4..8a5d66d6f 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -33,6 +33,16 @@ func CreateForBindingError(bindingName string, errorCause error) Error { } } +func CreateForNestedError(functionName string, errorCause error) Error { + errDescription := fmt.Sprintf("Error happened while calling %s", functionName) + return Error{ + 2, + "Nested error", + errDescription, + errorCause, + } +} + func CommonErrorMissingContract(contractName string) string { return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) } diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 92a918bb9..291a6d7cc 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -797,12 +797,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( operatorSetStakes, err := r.GetSlashableSharesForOperatorSetsBefore(ctx, operatorSets, uint32(currentBlock)) if err != nil { - wrappedError := Error{ - 2, - "Nested error", - "Error happened while calling GetSlashableSharesForOperatorSetsBefore", - err, - } + wrappedError := CreateForNestedError("GetSlashableSharesForOperatorSetsBefore", err) return nil, wrappedError } @@ -823,14 +818,14 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) if err != nil { - wrappedError := Error{2, "Nested error", "Error happened while calling GetOperatorsForOperatorSet", err} + wrappedError := CreateForNestedError("GetOperatorsForOperatorSet", err) return nil, wrappedError } strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet) // If operator setId is 0 will fail on if above if err != nil { - wrappedError := Error{2, "Nested error", "Error happened while calling GetStrategiesForOperatorSet", err} + wrappedError := CreateForNestedError("GetStrategiesForOperatorSet", err) return nil, wrappedError } From 8af90637efa63dcfd60ebe99d58a104369145445 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 28 Jan 2025 13:10:18 -0300 Subject: [PATCH 22/33] Turn NewReaderFromConfig returned err into a Nested one --- chainio/clients/elcontracts/reader.go | 2 +- chainio/clients/elcontracts/reader_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 291a6d7cc..447de1c9f 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -75,7 +75,7 @@ func NewReaderFromConfig( logger, ) if err != nil { - wrappedError := Error{3, "Other errors", "Error happened while calling NewBindingsFromConfig", err} + wrappedError := CreateForNestedError("NewBindingsFromConfig", err) return nil, wrappedError } return NewChainReader( diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 997c942ae..621a65803 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1339,7 +1339,7 @@ func TestCreateRederFromConfig(t *testing.T) { assert.Equal( t, err.Error(), - "Other errors(3) - Error happened while calling NewBindingsFromConfig: Failed to fetch StrategyManager address: no contract code at given address", + "Nested error(2) - Error happened while calling NewBindingsFromConfig: Failed to fetch StrategyManager address: no contract code at given address", ) }) } From f97103491e9fccde4c354cc1e0ed46450fc657a4 Mon Sep 17 00:00:00 2001 From: Maximo Palopoli <96491141+maximopalopoli@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:04:20 -0300 Subject: [PATCH 23/33] Update chainio/clients/elcontracts/error.go Co-authored-by: Damian Ramirez --- chainio/clients/elcontracts/error.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 8a5d66d6f..637d7c1d6 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -13,9 +13,8 @@ type Error struct { func (e Error) Error() string { if e.cause != nil { return fmt.Sprintf("%s(%d) - %s: %s", e.message, e.code, e.description, e.cause.Error()) - } else { - return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) } + return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) } func CreateErrorForMissingContract(contractName string) Error { From 6978c58de04fcbaf3586307da739f3583bc72552 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 29 Jan 2025 10:29:02 -0300 Subject: [PATCH 24/33] Remove metadata attribute in custom Error struct --- chainio/clients/elcontracts/error.go | 1 - 1 file changed, 1 deletion(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 637d7c1d6..8728f1457 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -7,7 +7,6 @@ type Error struct { message string description string cause error - // metadata map[string]interface{} } func (e Error) Error() string { From 38396761b769713471cba7d55b3e761d932cccea Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 29 Jan 2025 14:21:10 -0300 Subject: [PATCH 25/33] Add Unwrap method to get the underlying error --- chainio/clients/elcontracts/error.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 8728f1457..432f38fc5 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -16,6 +16,10 @@ func (e Error) Error() string { return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) } +func (e Error) Unwrap() error { + return e.cause +} + func CreateErrorForMissingContract(contractName string) Error { errDescription := fmt.Sprintf("%s contract not provided", contractName) return Error{1, "Missing needed contract", errDescription, nil} From 6ce8886b03085f34cf2710edca3bdcc3266743d7 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 3 Feb 2025 17:38:10 -0300 Subject: [PATCH 26/33] Rename custom error builders and its occurrences --- chainio/clients/elcontracts/error.go | 6 +- chainio/clients/elcontracts/reader.go | 174 +++++++++++++------------- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 432f38fc5..9512b1e77 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -20,12 +20,12 @@ func (e Error) Unwrap() error { return e.cause } -func CreateErrorForMissingContract(contractName string) Error { +func MissingContractError(contractName string) Error { errDescription := fmt.Sprintf("%s contract not provided", contractName) return Error{1, "Missing needed contract", errDescription, nil} } -func CreateForBindingError(bindingName string, errorCause error) Error { +func BindingError(bindingName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", bindingName) return Error{ 0, @@ -35,7 +35,7 @@ func CreateForBindingError(bindingName string, errorCause error) Error { } } -func CreateForNestedError(functionName string, errorCause error) Error { +func NestedError(functionName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", functionName) return Error{ 2, diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 447de1c9f..fca4bd8cd 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -75,7 +75,7 @@ func NewReaderFromConfig( logger, ) if err != nil { - wrappedError := CreateForNestedError("NewBindingsFromConfig", err) + wrappedError := NestedError("NewBindingsFromConfig", err) return nil, wrappedError } return NewChainReader( @@ -95,7 +95,7 @@ func (r *ChainReader) IsOperatorRegistered( operator types.Operator, ) (bool, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return false, wrappedError } @@ -104,7 +104,7 @@ func (r *ChainReader) IsOperatorRegistered( gethcommon.HexToAddress(operator.Address), ) if err != nil { - wrappedError := CreateForBindingError("delegationManager.IsOperator", err) + wrappedError := BindingError("delegationManager.IsOperator", err) return false, wrappedError } @@ -118,13 +118,13 @@ func (r *ChainReader) GetStakerShares( stakerAddress gethcommon.Address, ) ([]gethcommon.Address, []*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return nil, nil, wrappedError } addresses, shares, err := r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := CreateForBindingError("delegationManager.GetDepositedShares", err) + wrappedError := BindingError("delegationManager.GetDepositedShares", err) return nil, nil, wrappedError } @@ -138,13 +138,13 @@ func (r *ChainReader) GetDelegatedOperator( blockNumber *big.Int, ) (gethcommon.Address, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return gethcommon.Address{}, wrappedError } delegatedOperator, err := r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := CreateForBindingError("delegationManager.DelegatedTo", err) + wrappedError := BindingError("delegationManager.DelegatedTo", err) return gethcommon.Address{}, wrappedError } @@ -156,7 +156,7 @@ func (r *ChainReader) GetOperatorDetails( operator types.Operator, ) (types.Operator, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return types.Operator{}, wrappedError } @@ -166,7 +166,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("delegationManager.DelegationApprover", err) + wrappedError := BindingError("delegationManager.DelegationApprover", err) return types.Operator{}, wrappedError } @@ -179,7 +179,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetAllocationDelay", err) + wrappedError := BindingError("allocationManager.GetAllocationDelay", err) return types.Operator{}, wrappedError } @@ -205,12 +205,12 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - wrappedError := CreateForBindingError("strategy contract", err) + wrappedError := BindingError("strategy contract", err) return nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := CreateForBindingError("token contract", err) + wrappedError := BindingError("token contract", err) return nil, gethcommon.Address{}, wrappedError } return contractStrategy, underlyingTokenAddr, nil @@ -225,18 +225,18 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) // This call should not fail since it's an init if err != nil { - wrappedError := CreateForBindingError("strategy contract", err) + wrappedError := BindingError("strategy contract", err) return nil, nil, gethcommon.Address{}, wrappedError } underlyingTokenAddr, err := contractStrategy.UnderlyingToken(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := CreateForBindingError("token contract", err) + wrappedError := BindingError("token contract", err) return nil, nil, gethcommon.Address{}, wrappedError } contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient) // This call should not fail, if the strategy does not have an underlying token then it would enter the if above if err != nil { - wrappedError := CreateForBindingError("erc20 token contract", err) + wrappedError := BindingError("erc20 token contract", err) return nil, nil, gethcommon.Address{}, wrappedError } return contractStrategy, contractUnderlyingToken, underlyingTokenAddr, nil @@ -248,7 +248,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr gethcommon.Address, ) (*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return &big.Int{}, wrappedError } @@ -258,7 +258,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr, ) if err != nil { - wrappedError := CreateForBindingError("delegationManager.OperatorShares", err) + wrappedError := BindingError("delegationManager.OperatorShares", err) return &big.Int{}, wrappedError } @@ -274,7 +274,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return [32]byte{}, wrappedError } @@ -287,7 +287,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry, ) if err != nil { - wrappedError := CreateForBindingError("delegationManager.CalculateDelegationApprovalDigestHash", err) + wrappedError := BindingError("delegationManager.CalculateDelegationApprovalDigestHash", err) return [32]byte{}, wrappedError } @@ -302,7 +302,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry *big.Int, ) ([32]byte, error) { if r.avsDirectory == nil { - wrappedError := CreateErrorForMissingContract("AVSDirectory") + wrappedError := MissingContractError("AVSDirectory") return [32]byte{}, wrappedError } @@ -314,7 +314,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry, ) if err != nil { - wrappedError := CreateForBindingError("avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err) + wrappedError := BindingError("avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err) return [32]byte{}, wrappedError } @@ -323,13 +323,13 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return &big.Int{}, wrappedError } distributionRootsLength, err := r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.GetDistributionRootsLength", err) + wrappedError := BindingError("rewardsCoordinator.GetDistributionRootsLength", err) return &big.Int{}, wrappedError } @@ -338,13 +338,13 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return 0, wrappedError } endTimestamp, err := r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err) + wrappedError := BindingError("rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err) return 0, wrappedError } @@ -355,13 +355,13 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( ctx context.Context, ) (rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } distributionRoot, err := r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.GetCurrentClaimableDistributionRoot", err) + wrappedError := BindingError("rewardsCoordinator.GetCurrentClaimableDistributionRoot", err) return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -373,13 +373,13 @@ func (r *ChainReader) GetRootIndexFromHash( rootHash [32]byte, ) (uint32, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return 0, wrappedError } rootIndex, err := r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.GetRootIndexFromHash", err) + wrappedError := BindingError("rewardsCoordinator.GetRootIndexFromHash", err) return 0, wrappedError } @@ -392,13 +392,13 @@ func (r *ChainReader) GetCumulativeClaimed( token gethcommon.Address, ) (*big.Int, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return nil, wrappedError } cumulativeClaimed, err := r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.CumulativeClaimed", err) + wrappedError := BindingError("rewardsCoordinator.CumulativeClaimed", err) return nil, wrappedError } @@ -410,13 +410,13 @@ func (r *ChainReader) CheckClaim( claim rewardscoordinator.IRewardsCoordinatorTypesRewardsMerkleClaim, ) (bool, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return false, wrappedError } claimChecked, err := r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.CheckClaim", err) + wrappedError := BindingError("rewardsCoordinator.CheckClaim", err) return false, wrappedError } @@ -429,13 +429,13 @@ func (r *ChainReader) GetOperatorAVSSplit( avs gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return 0, wrappedError } operatorSplit, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.GetOperatorAVSSplit", err) + wrappedError := BindingError("rewardsCoordinator.GetOperatorAVSSplit", err) return 0, wrappedError } @@ -447,13 +447,13 @@ func (r *ChainReader) GetOperatorPISplit( operator gethcommon.Address, ) (uint16, error) { if r.rewardsCoordinator == nil { - wrappedError := CreateErrorForMissingContract("RewardsCoordinator") + wrappedError := MissingContractError("RewardsCoordinator") return 0, wrappedError } operatorSplit, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) if err != nil { - wrappedError := CreateForBindingError("rewardsCoordinator.GetOperatorPISplit", err) + wrappedError := BindingError("rewardsCoordinator.GetOperatorPISplit", err) return 0, wrappedError } @@ -466,7 +466,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress gethcommon.Address, ) (uint64, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return 0, wrappedError } @@ -476,7 +476,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress, ) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetAllocatableMagnitude", err) + wrappedError := BindingError("allocationManager.GetAllocatableMagnitude", err) return 0, wrappedError } @@ -489,7 +489,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses []gethcommon.Address, ) ([]uint64, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return []uint64{}, wrappedError } @@ -499,7 +499,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses, ) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetMaxMagnitudes0", err) + wrappedError := BindingError("allocationManager.GetMaxMagnitudes0", err) return []uint64{}, wrappedError } @@ -512,7 +512,7 @@ func (r *ChainReader) GetAllocationInfo( strategyAddress gethcommon.Address, ) ([]AllocationInfo, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } @@ -523,7 +523,7 @@ func (r *ChainReader) GetAllocationInfo( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetStrategyAllocations", err) + wrappedError := BindingError("allocationManager.GetStrategyAllocations", err) return nil, wrappedError } @@ -547,7 +547,7 @@ func (r *ChainReader) GetOperatorShares( strategyAddresses []gethcommon.Address, ) ([]*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return nil, wrappedError } @@ -555,7 +555,7 @@ func (r *ChainReader) GetOperatorShares( Context: ctx, }, operatorAddress, strategyAddresses) if err != nil { - wrappedError := CreateForBindingError("delegationManager.GetOperatorShares", err) + wrappedError := BindingError("delegationManager.GetOperatorShares", err) return nil, wrappedError } @@ -568,7 +568,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses []gethcommon.Address, ) ([][]*big.Int, error) { if r.delegationManager == nil { - wrappedError := CreateErrorForMissingContract("DelegationManager") + wrappedError := MissingContractError("DelegationManager") return nil, wrappedError } @@ -578,7 +578,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses, ) if err != nil { - wrappedError := CreateForBindingError("delegationManager.GetOperatorsShares", err) + wrappedError := BindingError("delegationManager.GetOperatorsShares", err) return nil, wrappedError } @@ -592,12 +592,12 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( operatorAddress gethcommon.Address, ) (*big.Int, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetAllocatedSets", err) + wrappedError := BindingError("allocationManager.GetAllocatedSets", err) return nil, wrappedError } return big.NewInt(int64(len(opSets))), nil @@ -610,14 +610,14 @@ func (r *ChainReader) GetOperatorSetsForOperator( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to // paginate? allocatedSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetAllocatedSets", err) + wrappedError := BindingError("allocationManager.GetAllocatedSets", err) return nil, wrappedError } @@ -633,27 +633,27 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( if operatorSet.Id == 0 { // this is an M2 AVS if r.avsDirectory == nil { - wrappedError := CreateErrorForMissingContract("AVSDirectory") + wrappedError := MissingContractError("AVSDirectory") return false, wrappedError } status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("avsDirectory.AvsOperatorStatus", err) + wrappedError := BindingError("avsDirectory.AvsOperatorStatus", err) return false, wrappedError } return status == 1, nil } else { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return false, wrappedError } registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetRegisteredSets", err) + wrappedError := BindingError("allocationManager.GetRegisteredSets", err) return false, wrappedError } for _, registeredOperatorSet := range registeredOperatorSets { @@ -676,13 +676,13 @@ func (r *ChainReader) GetOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } members, err := r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetMembers", err) + wrappedError := BindingError("allocationManager.GetMembers", err) return nil, wrappedError } @@ -699,13 +699,13 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } memberCount, err := r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetMemberCount", err) + wrappedError := BindingError("allocationManager.GetMemberCount", err) return nil, wrappedError } @@ -723,13 +723,13 @@ func (r *ChainReader) GetStrategiesForOperatorSet( return nil, errLegacyAVSsNotSupported } else { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } strategiesInSet, err := r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetStrategiesInOperatorSet", err) + wrappedError := BindingError("allocationManager.GetStrategiesInOperatorSet", err) return nil, wrappedError } @@ -744,14 +744,14 @@ func (r *ChainReader) GetSlashableShares( strategies []gethcommon.Address, ) (map[gethcommon.Address]*big.Int, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("ethClient.BlockNumber", err) + wrappedError := BindingError("ethClient.BlockNumber", err) return nil, wrappedError } @@ -764,7 +764,7 @@ func (r *ChainReader) GetSlashableShares( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetMinimumSlashableStake", err) + wrappedError := BindingError("allocationManager.GetMinimumSlashableStake", err) return nil, wrappedError } if len(slashableShares) == 0 { @@ -791,13 +791,13 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("ethClient.BlockNumber", err) + wrappedError := BindingError("ethClient.BlockNumber", err) return nil, wrappedError } operatorSetStakes, err := r.GetSlashableSharesForOperatorSetsBefore(ctx, operatorSets, uint32(currentBlock)) if err != nil { - wrappedError := CreateForNestedError("GetSlashableSharesForOperatorSetsBefore", err) + wrappedError := NestedError("GetSlashableSharesForOperatorSetsBefore", err) return nil, wrappedError } @@ -818,14 +818,14 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) if err != nil { - wrappedError := CreateForNestedError("GetOperatorsForOperatorSet", err) + wrappedError := NestedError("GetOperatorsForOperatorSet", err) return nil, wrappedError } strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet) // If operator setId is 0 will fail on if above if err != nil { - wrappedError := CreateForNestedError("GetStrategiesForOperatorSet", err) + wrappedError := NestedError("GetStrategiesForOperatorSet", err) return nil, wrappedError } @@ -841,7 +841,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetMinimumSlashableStake", err) + wrappedError := BindingError("allocationManager.GetMinimumSlashableStake", err) return nil, wrappedError } @@ -861,13 +861,13 @@ func (r *ChainReader) GetAllocationDelay( operatorAddress gethcommon.Address, ) (uint32, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return 0, wrappedError } isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetAllocationDelay", err) + wrappedError := BindingError("allocationManager.GetAllocationDelay", err) return 0, wrappedError } if !isSet { @@ -882,13 +882,13 @@ func (r *ChainReader) GetRegisteredSets( operatorAddress gethcommon.Address, ) ([]allocationmanager.OperatorSet, error) { if r.allocationManager == nil { - wrappedError := CreateErrorForMissingContract("AllocationManager") + wrappedError := MissingContractError("AllocationManager") return nil, wrappedError } registeredSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := CreateForBindingError("allocationManager.GetRegisteredSets", err) + wrappedError := BindingError("allocationManager.GetRegisteredSets", err) return nil, wrappedError } @@ -903,7 +903,7 @@ func (r *ChainReader) CanCall( selector [4]byte, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return false, wrappedError } @@ -916,7 +916,7 @@ func (r *ChainReader) CanCall( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.CanCall", err) + wrappedError := BindingError("permissionController.CanCall", err) return false, wrappedError } return canCall, nil @@ -929,7 +929,7 @@ func (r *ChainReader) ListAppointees( selector [4]byte, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return nil, wrappedError } @@ -941,7 +941,7 @@ func (r *ChainReader) ListAppointees( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.GetAppointees", err) + wrappedError := BindingError("permissionController.GetAppointees", err) return nil, wrappedError } return appointees, nil @@ -953,7 +953,7 @@ func (r *ChainReader) ListAppointeePermissions( appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return nil, nil, wrappedError } @@ -964,7 +964,7 @@ func (r *ChainReader) ListAppointeePermissions( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.GetAppointeePermissions", err) + wrappedError := BindingError("permissionController.GetAppointeePermissions", err) return nil, nil, wrappedError } return targets, selectors, nil @@ -975,14 +975,14 @@ func (r *ChainReader) ListPendingAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return nil, wrappedError } pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.GetPendingAdmins", err) + wrappedError := BindingError("permissionController.GetPendingAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -993,14 +993,14 @@ func (r *ChainReader) ListAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return nil, wrappedError } pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.GetAdmins", err) + wrappedError := BindingError("permissionController.GetAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -1012,7 +1012,7 @@ func (r *ChainReader) IsPendingAdmin( pendingAdminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return false, wrappedError } @@ -1023,7 +1023,7 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.IsPendingAdmin", err) + wrappedError := BindingError("permissionController.IsPendingAdmin", err) return false, wrappedError } return isPendingAdmin, nil @@ -1035,14 +1035,14 @@ func (r *ChainReader) IsAdmin( adminAddress gethcommon.Address, ) (bool, error) { if r.permissionController == nil { - wrappedError := CreateErrorForMissingContract("PermissionController") + wrappedError := MissingContractError("PermissionController") return false, wrappedError } isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := CreateForBindingError("permissionController.IsAdmin", err) + wrappedError := BindingError("permissionController.IsAdmin", err) return false, wrappedError } return isAdmin, nil From b56b255007b0fbb1702b04f4b4af83d6fa1199af Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 13:30:54 -0300 Subject: [PATCH 27/33] Use full syntax when creating errors --- chainio/clients/elcontracts/error.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 9512b1e77..3d93ce475 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -28,20 +28,20 @@ func MissingContractError(contractName string) Error { func BindingError(bindingName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", bindingName) return Error{ - 0, - "Binding error", - errDescription, - errorCause, + code: 0, + message: "Binding error", + description: errDescription, + cause: errorCause, } } func NestedError(functionName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", functionName) return Error{ - 2, - "Nested error", - errDescription, - errorCause, + code: 2, + message: "Nested error", + description: errDescription, + cause: errorCause, } } From 7e6a276cdc4ed0af3e0139cec35ce7959c5ed75d Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 13:38:35 -0300 Subject: [PATCH 28/33] Rename contracts names at errors following the solidity casing --- chainio/clients/elcontracts/reader.go | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index fca4bd8cd..38a0c0829 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -104,7 +104,7 @@ func (r *ChainReader) IsOperatorRegistered( gethcommon.HexToAddress(operator.Address), ) if err != nil { - wrappedError := BindingError("delegationManager.IsOperator", err) + wrappedError := BindingError("DelegationManager.isOperator", err) return false, wrappedError } @@ -124,7 +124,7 @@ func (r *ChainReader) GetStakerShares( addresses, shares, err := r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := BindingError("delegationManager.GetDepositedShares", err) + wrappedError := BindingError("DelegationManager.getDepositedShares", err) return nil, nil, wrappedError } @@ -144,7 +144,7 @@ func (r *ChainReader) GetDelegatedOperator( delegatedOperator, err := r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress) if err != nil { - wrappedError := BindingError("delegationManager.DelegatedTo", err) + wrappedError := BindingError("DelegationManager.delegatedTo", err) return gethcommon.Address{}, wrappedError } @@ -166,7 +166,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("delegationManager.DelegationApprover", err) + wrappedError := BindingError("DelegationManager.delegationApprover", err) return types.Operator{}, wrappedError } @@ -179,7 +179,7 @@ func (r *ChainReader) GetOperatorDetails( ) // This call should not fail if err != nil { - wrappedError := BindingError("allocationManager.GetAllocationDelay", err) + wrappedError := BindingError("AllocationManager.getAllocationDelay", err) return types.Operator{}, wrappedError } @@ -258,7 +258,7 @@ func (r *ChainReader) GetOperatorSharesInStrategy( strategyAddr, ) if err != nil { - wrappedError := BindingError("delegationManager.OperatorShares", err) + wrappedError := BindingError("DelegationManager.operatorShares", err) return &big.Int{}, wrappedError } @@ -287,7 +287,7 @@ func (r *ChainReader) CalculateDelegationApprovalDigestHash( expiry, ) if err != nil { - wrappedError := BindingError("delegationManager.CalculateDelegationApprovalDigestHash", err) + wrappedError := BindingError("DelegationManager.calculateDelegationApprovalDigestHash", err) return [32]byte{}, wrappedError } @@ -314,7 +314,7 @@ func (r *ChainReader) CalculateOperatorAVSRegistrationDigestHash( expiry, ) if err != nil { - wrappedError := BindingError("avsDirectory.CalculateOperatorAVSRegistrationDigestHash", err) + wrappedError := BindingError("AvsDirectory.calculateOperatorAVSRegistrationDigestHash", err) return [32]byte{}, wrappedError } @@ -329,7 +329,7 @@ func (r *ChainReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, distributionRootsLength, err := r.rewardsCoordinator.GetDistributionRootsLength(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := BindingError("rewardsCoordinator.GetDistributionRootsLength", err) + wrappedError := BindingError("RewardsCoordinator.getDistributionRootsLength", err) return &big.Int{}, wrappedError } @@ -344,7 +344,7 @@ func (r *ChainReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (u endTimestamp, err := r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := BindingError("rewardsCoordinator.CurrRewardsCalculationEndTimestamp", err) + wrappedError := BindingError("RewardsCoordinator.currRewardsCalculationEndTimestamp", err) return 0, wrappedError } @@ -361,7 +361,7 @@ func (r *ChainReader) GetCurrentClaimableDistributionRoot( distributionRoot, err := r.rewardsCoordinator.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx}) if err != nil { - wrappedError := BindingError("rewardsCoordinator.GetCurrentClaimableDistributionRoot", err) + wrappedError := BindingError("RewardsCoordinator.getCurrentClaimableDistributionRoot", err) return rewardscoordinator.IRewardsCoordinatorTypesDistributionRoot{}, wrappedError } @@ -379,7 +379,7 @@ func (r *ChainReader) GetRootIndexFromHash( rootIndex, err := r.rewardsCoordinator.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, rootHash) if err != nil { - wrappedError := BindingError("rewardsCoordinator.GetRootIndexFromHash", err) + wrappedError := BindingError("RewardsCoordinator.getRootIndexFromHash", err) return 0, wrappedError } @@ -398,7 +398,7 @@ func (r *ChainReader) GetCumulativeClaimed( cumulativeClaimed, err := r.rewardsCoordinator.CumulativeClaimed(&bind.CallOpts{Context: ctx}, earner, token) if err != nil { - wrappedError := BindingError("rewardsCoordinator.CumulativeClaimed", err) + wrappedError := BindingError("RewardsCoordinator.cumulativeClaimed", err) return nil, wrappedError } @@ -416,7 +416,7 @@ func (r *ChainReader) CheckClaim( claimChecked, err := r.rewardsCoordinator.CheckClaim(&bind.CallOpts{Context: ctx}, claim) if err != nil { - wrappedError := BindingError("rewardsCoordinator.CheckClaim", err) + wrappedError := BindingError("RewardsCoordinator.checkClaim", err) return false, wrappedError } @@ -435,7 +435,7 @@ func (r *ChainReader) GetOperatorAVSSplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) if err != nil { - wrappedError := BindingError("rewardsCoordinator.GetOperatorAVSSplit", err) + wrappedError := BindingError("RewardsCoordinator.getOperatorAVSSplit", err) return 0, wrappedError } @@ -453,7 +453,7 @@ func (r *ChainReader) GetOperatorPISplit( operatorSplit, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) if err != nil { - wrappedError := BindingError("rewardsCoordinator.GetOperatorPISplit", err) + wrappedError := BindingError("RewardsCoordinator.getOperatorPISplit", err) return 0, wrappedError } @@ -476,7 +476,7 @@ func (r *ChainReader) GetAllocatableMagnitude( strategyAddress, ) if err != nil { - wrappedError := BindingError("allocationManager.GetAllocatableMagnitude", err) + wrappedError := BindingError("AllocationManager.getAllocatableMagnitude", err) return 0, wrappedError } @@ -499,7 +499,7 @@ func (r *ChainReader) GetMaxMagnitudes( strategyAddresses, ) if err != nil { - wrappedError := BindingError("allocationManager.GetMaxMagnitudes0", err) + wrappedError := BindingError("AllocationManager.getMaxMagnitudes0", err) return []uint64{}, wrappedError } @@ -523,7 +523,7 @@ func (r *ChainReader) GetAllocationInfo( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("allocationManager.GetStrategyAllocations", err) + wrappedError := BindingError("AllocationManager.getStrategyAllocations", err) return nil, wrappedError } @@ -555,7 +555,7 @@ func (r *ChainReader) GetOperatorShares( Context: ctx, }, operatorAddress, strategyAddresses) if err != nil { - wrappedError := BindingError("delegationManager.GetOperatorShares", err) + wrappedError := BindingError("DelegationManager.getOperatorShares", err) return nil, wrappedError } @@ -578,7 +578,7 @@ func (r *ChainReader) GetOperatorsShares( strategyAddresses, ) if err != nil { - wrappedError := BindingError("delegationManager.GetOperatorsShares", err) + wrappedError := BindingError("DelegationManager.getOperatorsShares", err) return nil, wrappedError } @@ -597,7 +597,7 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( } opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := BindingError("allocationManager.GetAllocatedSets", err) + wrappedError := BindingError("AllocationManager.getAllocatedSets", err) return nil, wrappedError } return big.NewInt(int64(len(opSets))), nil @@ -617,7 +617,7 @@ func (r *ChainReader) GetOperatorSetsForOperator( // paginate? allocatedSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := BindingError("allocationManager.GetAllocatedSets", err) + wrappedError := BindingError("AllocationManager.getAllocatedSets", err) return nil, wrappedError } @@ -640,7 +640,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("avsDirectory.AvsOperatorStatus", err) + wrappedError := BindingError("AvsDirectory.avsOperatorStatus", err) return false, wrappedError } @@ -653,7 +653,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("allocationManager.GetRegisteredSets", err) + wrappedError := BindingError("AllocationManager.getRegisteredSets", err) return false, wrappedError } for _, registeredOperatorSet := range registeredOperatorSets { @@ -682,7 +682,7 @@ func (r *ChainReader) GetOperatorsForOperatorSet( members, err := r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := BindingError("allocationManager.GetMembers", err) + wrappedError := BindingError("AllocationManager.getMembers", err) return nil, wrappedError } @@ -705,7 +705,7 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet( memberCount, err := r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := BindingError("allocationManager.GetMemberCount", err) + wrappedError := BindingError("AllocationManager.getMemberCount", err) return nil, wrappedError } @@ -729,7 +729,7 @@ func (r *ChainReader) GetStrategiesForOperatorSet( strategiesInSet, err := r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet) if err != nil { - wrappedError := BindingError("allocationManager.GetStrategiesInOperatorSet", err) + wrappedError := BindingError("AllocationManager.getStrategiesInOperatorSet", err) return nil, wrappedError } @@ -751,7 +751,7 @@ func (r *ChainReader) GetSlashableShares( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("ethClient.BlockNumber", err) + wrappedError := BindingError("EthClient.blockNumber", err) return nil, wrappedError } @@ -764,7 +764,7 @@ func (r *ChainReader) GetSlashableShares( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("allocationManager.GetMinimumSlashableStake", err) + wrappedError := BindingError("AllocationManager.getMinimumSlashableStake", err) return nil, wrappedError } if len(slashableShares) == 0 { @@ -791,7 +791,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( currentBlock, err := r.ethClient.BlockNumber(ctx) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("ethClient.BlockNumber", err) + wrappedError := BindingError("EthClient.blockNumber", err) return nil, wrappedError } @@ -841,7 +841,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("allocationManager.GetMinimumSlashableStake", err) + wrappedError := BindingError("AllocationManager.getMinimumSlashableStake", err) return nil, wrappedError } @@ -867,7 +867,7 @@ func (r *ChainReader) GetAllocationDelay( isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("allocationManager.GetAllocationDelay", err) + wrappedError := BindingError("AllocationManager.getAllocationDelay", err) return 0, wrappedError } if !isSet { @@ -888,7 +888,7 @@ func (r *ChainReader) GetRegisteredSets( registeredSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { - wrappedError := BindingError("allocationManager.GetRegisteredSets", err) + wrappedError := BindingError("AllocationManager.getRegisteredSets", err) return nil, wrappedError } @@ -916,7 +916,7 @@ func (r *ChainReader) CanCall( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.CanCall", err) + wrappedError := BindingError("PermissionController.canCall", err) return false, wrappedError } return canCall, nil @@ -941,7 +941,7 @@ func (r *ChainReader) ListAppointees( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.GetAppointees", err) + wrappedError := BindingError("PermissionController.getAppointees", err) return nil, wrappedError } return appointees, nil @@ -964,7 +964,7 @@ func (r *ChainReader) ListAppointeePermissions( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.GetAppointeePermissions", err) + wrappedError := BindingError("PermissionController.getAppointeePermissions", err) return nil, nil, wrappedError } return targets, selectors, nil @@ -982,7 +982,7 @@ func (r *ChainReader) ListPendingAdmins( pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.GetPendingAdmins", err) + wrappedError := BindingError("PermissionController.getPendingAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -1000,7 +1000,7 @@ func (r *ChainReader) ListAdmins( pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.GetAdmins", err) + wrappedError := BindingError("PermissionController.getAdmins", err) return nil, wrappedError } return pendingAdmins, nil @@ -1023,7 +1023,7 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.IsPendingAdmin", err) + wrappedError := BindingError("PermissionController.isPendingAdmin", err) return false, wrappedError } return isPendingAdmin, nil @@ -1042,7 +1042,7 @@ func (r *ChainReader) IsAdmin( isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - wrappedError := BindingError("permissionController.IsAdmin", err) + wrappedError := BindingError("PermissionController.isAdmin", err) return false, wrappedError } return isAdmin, nil From 3fda64757681645dd37a0a8ea19dd91d80bfcc0f Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 13:44:10 -0300 Subject: [PATCH 29/33] Use ErrorContains instead of comparing long literals --- chainio/clients/elcontracts/reader_test.go | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 621a65803..3101cc165 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -348,10 +348,10 @@ func TestGetRootIndexFromRootHash(t *testing.T) { root, ) assert.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Binding error(0) - Error happened while calling rewardsCoordinator.GetRootIndexFromHash: execution reverted: custom error 0x504570e3", + err, + "execution reverted: custom error 0x504570e3", "GetRootIndexFromHash should return an InvalidRoot() error", ) assert.Zero(t, root_index) @@ -774,20 +774,20 @@ func TestContractErrorCases(t *testing.T) { t.Run("GetStrategyAndUnderlyingToken", func(t *testing.T) { _, _, err := chainReader.GetStrategyAndUnderlyingToken(ctx, strategyAddr) assert.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Binding error(0) - Error happened while calling token contract: no contract code at given address", + err, + "no contract code at given address", ) }) t.Run("GetStrategyAndUnderlyingERC20Token", func(t *testing.T) { _, _, _, err := chainReader.GetStrategyAndUnderlyingERC20Token(ctx, strategyAddr) assert.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Binding error(0) - Error happened while calling token contract: no contract code at given address", + err, + "no contract code at given address", ) }) } @@ -852,10 +852,10 @@ func TestInvalidConfig(t *testing.T) { // GetStrategyAndUnderlyingToken needs a correct StrategyAddress _, _, err = chainReader.GetStrategyAndUnderlyingToken(context.Background(), strategyAddr) require.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Binding error(0) - Error happened while calling token contract: no contract code at given address", + err, + "no contract code at given address", ) _, _, _, err = chainReader.GetStrategyAndUnderlyingERC20Token(context.Background(), strategyAddr) @@ -1302,10 +1302,10 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 10) require.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Nested error(2) - Error happened while calling GetOperatorsForOperatorSet: Other errors(3) - Method not supported for legacy AVSs", + err, + "Method not supported for legacy AVSs", ) }) } @@ -1336,10 +1336,10 @@ func TestCreateRederFromConfig(t *testing.T) { _, err = elcontracts.NewReaderFromConfig(config, ethHttpClient, logger) require.Error(t, err) - assert.Equal( + assert.ErrorContains( t, - err.Error(), - "Nested error(2) - Error happened while calling NewBindingsFromConfig: Failed to fetch StrategyManager address: no contract code at given address", + err, + "no contract code at given address", ) }) } From 134908320dab836d1ff0f7772a4a6f0d7374b797 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 14:53:37 -0300 Subject: [PATCH 30/33] Move MissingContractError creation function --- chainio/clients/elcontracts/error.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 3d93ce475..03f56956d 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -20,11 +20,6 @@ func (e Error) Unwrap() error { return e.cause } -func MissingContractError(contractName string) Error { - errDescription := fmt.Sprintf("%s contract not provided", contractName) - return Error{1, "Missing needed contract", errDescription, nil} -} - func BindingError(bindingName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", bindingName) return Error{ @@ -35,6 +30,16 @@ func BindingError(bindingName string, errorCause error) Error { } } +func MissingContractError(contractName string) Error { + errDescription := fmt.Sprintf("%s contract not provided", contractName) + return Error{ + code: 1, + message: "Missing needed contract", + description: errDescription, + cause: nil, + } +} + func NestedError(functionName string, errorCause error) Error { errDescription := fmt.Sprintf("Error happened while calling %s", functionName) return Error{ From 15ed4db5c24e5a59965cb976e4837d3dc2e30bf8 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 15:07:39 -0300 Subject: [PATCH 31/33] Create and use OtherError msg wrapper --- chainio/clients/elcontracts/error.go | 9 +++++++++ chainio/clients/elcontracts/reader.go | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/chainio/clients/elcontracts/error.go b/chainio/clients/elcontracts/error.go index 03f56956d..ec63ee8f8 100644 --- a/chainio/clients/elcontracts/error.go +++ b/chainio/clients/elcontracts/error.go @@ -50,6 +50,15 @@ func NestedError(functionName string, errorCause error) Error { } } +func OtherError(errDescription string, errorCause error) Error { + return Error{ + code: 3, + message: "Other error", + description: errDescription, + cause: errorCause, + } +} + func CommonErrorMissingContract(contractName string) string { return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) } diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 38a0c0829..72f438053 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -38,7 +38,7 @@ type ChainReader struct { ethClient eth.HttpBackend } -var errLegacyAVSsNotSupported = Error{3, "Other errors", "Method not supported for legacy AVSs", nil} +var errLegacyAVSsNotSupported = OtherError("Method not supported for legacy AVSs", nil) func NewChainReader( delegationManager *delegationmanager.ContractDelegationManager, @@ -768,7 +768,7 @@ func (r *ChainReader) GetSlashableShares( return nil, wrappedError } if len(slashableShares) == 0 { - wrappedError := Error{3, "Other errors", "No slashable shares found for operator", err} + wrappedError := OtherError("No slashable shares found for operator", err) return nil, wrappedError } @@ -871,7 +871,7 @@ func (r *ChainReader) GetAllocationDelay( return 0, wrappedError } if !isSet { - wrappedError := Error{3, "Other errors", "Allocation delay not set", err} + wrappedError := OtherError("Allocation delay not set", err) return 0, wrappedError } return delay, nil From 2f4befa8fd386d1ce8c7ca8683221c19a7180195 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 15:08:03 -0300 Subject: [PATCH 32/33] Create only once legacyAVSsNotSupportedErrorMsg string --- chainio/clients/elcontracts/reader_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 3101cc165..36bd94f7b 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1265,17 +1265,18 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { require.NoError(t, err) t.Run("test operator set with invalid id", func(t *testing.T) { + legacyAVSsNotSupportedErrorMsg := elcontracts.OtherError("Method not supported for legacy AVSs", nil).Error() _, err := chainReader.GetOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) - assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") + assert.EqualError(t, err, legacyAVSsNotSupportedErrorMsg) _, err = chainReader.GetNumOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) - assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") + assert.EqualError(t, err, legacyAVSsNotSupportedErrorMsg) _, err = chainReader.GetStrategiesForOperatorSet(ctx, operatorSet) require.Error(t, err) - assert.Equal(t, err.Error(), "Other errors(3) - Method not supported for legacy AVSs") + assert.EqualError(t, err, legacyAVSsNotSupportedErrorMsg) strategies := []common.Address{contractAddrs.Erc20MockStrategy} From c4d5c237867063129673c87a959cb945cec5013b Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Wed, 5 Feb 2025 15:25:09 -0300 Subject: [PATCH 33/33] Fix failing test --- chainio/clients/elcontracts/reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 3b61fe492..101002efa 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -1367,7 +1367,7 @@ func TestFailingNetwork(t *testing.T) { contractAddrs.Erc20MockStrategy, ) assert.Error(t, err) - assert.Zero(t, shares) + assert.Zero(t, shares.Int64()) }) t.Run("calculate delegation approval digest hash", func(t *testing.T) {