diff --git a/chainio/clients/builder.go b/chainio/clients/builder.go index b082a566..e5033f1f 100644 --- a/chainio/clients/builder.go +++ b/chainio/clients/builder.go @@ -175,11 +175,11 @@ func (config *BuildAllConfig) BuildELClients( delegationManagerAddr, err := avsRegistryContractBindings.StakeRegistry.Delegation(&bind.CallOpts{}) if err != nil { - logger.Fatal("Failed to fetch Slasher contract", "err", err) + logger.Fatal("Failed to fetch DelegationManager contract", "err", err) } avsDirectoryAddr, err := avsRegistryContractBindings.ServiceManager.AvsDirectory(&bind.CallOpts{}) if err != nil { - logger.Fatal("Failed to fetch Slasher contract", "err", err) + logger.Fatal("Failed to fetch AVSDirectory contract", "err", err) } elContractBindings, err := config.buildEigenLayerContractBindings( @@ -206,6 +206,7 @@ func (config *BuildAllConfig) BuildELClients( elContractBindings.Slasher, elContractBindings.DelegationManager, elContractBindings.StrategyManager, + nil, elContractBindings.StrategyManagerAddr, elChainReader, ethHttpClient, diff --git a/chainio/clients/elcontracts/bindings.go b/chainio/clients/elcontracts/bindings.go index 2896a691..9c85d843 100644 --- a/chainio/clients/elcontracts/bindings.go +++ b/chainio/clients/elcontracts/bindings.go @@ -9,6 +9,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory" delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" + rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator" slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" "github.com/Layr-Labs/eigensdk-go/logging" @@ -20,14 +21,16 @@ import ( // Unclear why geth bindings don't store and expose the contract address, // so we also store them here in case the different constructors that use this struct need them type ContractBindings struct { - SlasherAddr gethcommon.Address - StrategyManagerAddr gethcommon.Address - DelegationManagerAddr gethcommon.Address - AvsDirectoryAddr gethcommon.Address - Slasher *slasher.ContractISlasher - DelegationManager *delegationmanager.ContractDelegationManager - StrategyManager *strategymanager.ContractStrategyManager - AvsDirectory *avsdirectory.ContractAVSDirectory + SlasherAddr gethcommon.Address + StrategyManagerAddr gethcommon.Address + DelegationManagerAddr gethcommon.Address + AvsDirectoryAddr gethcommon.Address + RewardsCoordinatorAddress gethcommon.Address + Slasher *slasher.ContractISlasher + DelegationManager *delegationmanager.ContractDelegationManager + StrategyManager *strategymanager.ContractStrategyManager + AvsDirectory *avsdirectory.ContractAVSDirectory + RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator } func NewBindingsFromConfig( @@ -41,9 +44,10 @@ func NewBindingsFromConfig( var slasherAddr gethcommon.Address var strategyManagerAddr gethcommon.Address var avsDirectory *avsdirectory.ContractAVSDirectory + var rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator var err error - if gethcommon.IsHexAddress(cfg.DelegationManagerAddress.String()) { + if isZeroAddress(cfg.DelegationManagerAddress) { logger.Warn("DelegationManager address not provided, the calls to the contract will not work") } else { contractDelegationManager, err = delegationmanager.NewContractDelegationManager(cfg.DelegationManagerAddress, client) @@ -70,7 +74,7 @@ func NewBindingsFromConfig( } } - if gethcommon.IsHexAddress(cfg.AvsDirectoryAddress.String()) { + if isZeroAddress(cfg.AvsDirectoryAddress) { logger.Warn("AVSDirectory address not provided, the calls to the contract will not work") } else { avsDirectory, err = avsdirectory.NewContractAVSDirectory(cfg.AvsDirectoryAddress, client) @@ -79,17 +83,31 @@ func NewBindingsFromConfig( } } + if isZeroAddress(cfg.RewardsCoordinatorAddress) { + logger.Warn("RewardsCoordinator address not provided, the calls to the contract will not work") + } else { + rewardsCoordinator, err = rewardscoordinator.NewContractIRewardsCoordinator(cfg.RewardsCoordinatorAddress, client) + if err != nil { + return nil, utils.WrapError("Failed to fetch RewardsCoordinator contract", err) + } + } + return &ContractBindings{ - SlasherAddr: slasherAddr, - StrategyManagerAddr: strategyManagerAddr, - DelegationManagerAddr: cfg.DelegationManagerAddress, - AvsDirectoryAddr: cfg.AvsDirectoryAddress, - Slasher: contractSlasher, - StrategyManager: contractStrategyManager, - DelegationManager: contractDelegationManager, - AvsDirectory: avsDirectory, + SlasherAddr: slasherAddr, + StrategyManagerAddr: strategyManagerAddr, + DelegationManagerAddr: cfg.DelegationManagerAddress, + AvsDirectoryAddr: cfg.AvsDirectoryAddress, + RewardsCoordinatorAddress: cfg.RewardsCoordinatorAddress, + Slasher: contractSlasher, + StrategyManager: contractStrategyManager, + DelegationManager: contractDelegationManager, + AvsDirectory: avsDirectory, + RewardsCoordinator: rewardsCoordinator, }, nil } +func isZeroAddress(address gethcommon.Address) bool { + return address == gethcommon.Address{} +} // NewEigenlayerContractBindings creates a new ContractBindings struct with the provided contract addresses // Deprecated: Use NewBindingsFromConfig instead diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 3e6efb07..ee9de49c 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -9,16 +9,15 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - "github.com/Layr-Labs/eigensdk-go/logging" - "github.com/Layr-Labs/eigensdk-go/types" - "github.com/Layr-Labs/eigensdk-go/utils" - avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory" delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20" slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" strategy "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IStrategy" 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 ELReader interface { @@ -62,16 +61,17 @@ type ELReader interface { } type Config struct { - DelegationManagerAddress common.Address - AvsDirectoryAddress common.Address + DelegationManagerAddress common.Address + AvsDirectoryAddress common.Address + RewardsCoordinatorAddress common.Address } type ELChainReader struct { logger logging.Logger slasher slasher.ContractISlasherCalls - delegationManager delegationmanager.ContractDelegationManagerCalls - strategyManager strategymanager.ContractStrategyManagerCalls - avsDirectory avsdirectory.ContractAVSDirectoryCalls + delegationManager *delegationmanager.ContractDelegationManager + strategyManager *strategymanager.ContractStrategyManager + avsDirectory *avsdirectory.ContractAVSDirectory ethClient eth.Client } @@ -80,9 +80,9 @@ var _ ELReader = (*ELChainReader)(nil) func NewELChainReader( slasher slasher.ContractISlasherCalls, - delegationManager delegationmanager.ContractDelegationManagerCalls, - strategyManager strategymanager.ContractStrategyManagerCalls, - avsDirectory avsdirectory.ContractAVSDirectoryCalls, + delegationManager *delegationmanager.ContractDelegationManager, + strategyManager *strategymanager.ContractStrategyManager, + avsDirectory *avsdirectory.ContractAVSDirectory, logger logging.Logger, ethClient eth.Client, ) *ELChainReader { diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index a0cfbf53..aa44dc38 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -3,6 +3,7 @@ package elcontracts import ( "context" "errors" + "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -12,6 +13,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" + rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator" slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" "github.com/Layr-Labs/eigensdk-go/logging" @@ -36,12 +38,18 @@ type ELWriter interface { strategyAddr gethcommon.Address, amount *big.Int, ) (*gethtypes.Receipt, error) + + SetClaimerFor( + ctx context.Context, + claimer gethcommon.Address, + ) (*gethtypes.Receipt, error) } type ELChainWriter struct { - slasher slasher.ContractISlasherTransacts - delegationManager delegationmanager.ContractDelegationManagerTransacts - strategyManager strategymanager.ContractStrategyManagerTransacts + slasher *slasher.ContractISlasher + delegationManager *delegationmanager.ContractDelegationManager + strategyManager *strategymanager.ContractStrategyManager + rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator strategyManagerAddr gethcommon.Address elChainReader ELReader ethClient eth.Client @@ -52,9 +60,10 @@ type ELChainWriter struct { var _ ELWriter = (*ELChainWriter)(nil) func NewELChainWriter( - slasher slasher.ContractISlasherTransacts, - delegationManager delegationmanager.ContractDelegationManagerTransacts, - strategyManager strategymanager.ContractStrategyManagerTransacts, + slasher *slasher.ContractISlasher, + delegationManager *delegationmanager.ContractDelegationManager, + strategyManager *strategymanager.ContractStrategyManager, + rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator, strategyManagerAddr gethcommon.Address, elChainReader ELReader, ethClient eth.Client, @@ -69,6 +78,7 @@ func NewELChainWriter( delegationManager: delegationManager, strategyManager: strategyManager, strategyManagerAddr: strategyManagerAddr, + rewardsCoordinator: rewardsCoordinator, elChainReader: elChainReader, logger: logger, ethClient: ethClient, @@ -107,6 +117,7 @@ func BuildELChainWriter( elContractBindings.Slasher, elContractBindings.DelegationManager, elContractBindings.StrategyManager, + nil, elContractBindings.StrategyManagerAddr, elChainReader, ethClient, @@ -143,6 +154,7 @@ func NewWriterFromConfig( elContractBindings.Slasher, elContractBindings.DelegationManager, elContractBindings.StrategyManager, + elContractBindings.RewardsCoordinator, elContractBindings.StrategyManagerAddr, elChainReader, ethClient, @@ -290,3 +302,30 @@ func (w *ELChainWriter) DepositERC20IntoStrategy( w.logger.Infof("deposited %s into strategy %s", amount.String(), strategyAddr) return receipt, nil } + +func (w *ELChainWriter) SetClaimerFor( + ctx context.Context, + claimer gethcommon.Address, +) (*gethtypes.Receipt, error) { + if w.rewardsCoordinator == nil { + return nil, errors.New("RewardsCoordinator contract not provided") + } + + w.logger.Infof("setting claimer %s", claimer) + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() + if err != nil { + return nil, err + } + + tx, err := w.rewardsCoordinator.SetClaimerFor(noSendTxOpts, claimer) + if err != nil { + return nil, err + } + receipt, err := w.txMgr.Send(ctx, tx) + if err != nil { + return nil, errors.New("failed to send tx with err: " + err.Error()) + } + + w.logger.Infof("set claimer %s successful", claimer) + return receipt, nil +}