diff --git a/chainio/utils/bindings.go b/chainio/clients/avsregistry/bindings.go similarity index 59% rename from chainio/utils/bindings.go rename to chainio/clients/avsregistry/bindings.go index 6097aaee..40c6d0e2 100644 --- a/chainio/utils/bindings.go +++ b/chainio/clients/avsregistry/bindings.go @@ -1,88 +1,23 @@ -// bindings.go contains functions that create contract bindings for the Eigenlayer and AVS contracts. -// These functions are meant to be used by constructors of the chainio package. -package utils +package avsregistry import ( - "github.com/Layr-Labs/eigensdk-go/logging" - "github.com/Layr-Labs/eigensdk-go/utils" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - gethcommon "github.com/ethereum/go-ethereum/common" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory" blsapkregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSApkRegistry" - delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" - slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" indexregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IndexRegistry" opstateretriever "github.com/Layr-Labs/eigensdk-go/contracts/bindings/OperatorStateRetriever" regcoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator" servicemanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ServiceManagerBase" stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry" - strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" -) - -// Unclear to me 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 EigenlayerContractBindings 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 -} - -func NewEigenlayerContractBindings( - delegationManagerAddr gethcommon.Address, - avsDirectoryAddr gethcommon.Address, - ethclient eth.Client, - logger logging.Logger, -) (*EigenlayerContractBindings, error) { - contractDelegationManager, err := delegationmanager.NewContractDelegationManager(delegationManagerAddr, ethclient) - if err != nil { - return nil, utils.WrapError("Failed to create DelegationManager contract", err) - } - - slasherAddr, err := contractDelegationManager.Slasher(&bind.CallOpts{}) - if err != nil { - return nil, utils.WrapError("Failed to fetch Slasher address", err) - } - contractSlasher, err := slasher.NewContractISlasher(slasherAddr, ethclient) - if err != nil { - return nil, utils.WrapError("Failed to fetch Slasher contract", err) - } - - strategyManagerAddr, err := contractDelegationManager.StrategyManager(&bind.CallOpts{}) - if err != nil { - return nil, utils.WrapError("Failed to fetch StrategyManager address", err) - } - contractStrategyManager, err := strategymanager.NewContractStrategyManager(strategyManagerAddr, ethclient) - if err != nil { - return nil, utils.WrapError("Failed to fetch StrategyManager contract", err) - } - - avsDirectory, err := avsdirectory.NewContractAVSDirectory(avsDirectoryAddr, ethclient) - if err != nil { - return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err) - } + "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/utils" + "github.com/ethereum/go-ethereum/accounts/abi/bind" - return &EigenlayerContractBindings{ - SlasherAddr: slasherAddr, - StrategyManagerAddr: strategyManagerAddr, - DelegationManagerAddr: delegationManagerAddr, - AvsDirectoryAddr: avsDirectoryAddr, - Slasher: contractSlasher, - StrategyManager: contractStrategyManager, - DelegationManager: contractDelegationManager, - AvsDirectory: avsDirectory, - }, nil -} + gethcommon "github.com/ethereum/go-ethereum/common" +) -// Unclear to me why geth bindings don't store and expose the contract address... +// ContractBindings Unclear to me 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 AvsRegistryContractBindings struct { +type ContractBindings struct { // contract addresses ServiceManagerAddr gethcommon.Address RegistryCoordinatorAddr gethcommon.Address @@ -104,7 +39,7 @@ func NewAVSRegistryContractBindings( operatorStateRetrieverAddr gethcommon.Address, ethclient eth.Client, logger logging.Logger, -) (*AvsRegistryContractBindings, error) { +) (*ContractBindings, error) { contractBlsRegistryCoordinator, err := regcoordinator.NewContractRegistryCoordinator( registryCoordinatorAddr, ethclient, @@ -166,7 +101,7 @@ func NewAVSRegistryContractBindings( return nil, utils.WrapError("Failed to fetch OperatorStateRetriever contract", err) } - return &AvsRegistryContractBindings{ + return &ContractBindings{ ServiceManagerAddr: serviceManagerAddr, RegistryCoordinatorAddr: registryCoordinatorAddr, StakeRegistryAddr: stakeregistryAddr, diff --git a/chainio/clients/builder.go b/chainio/clients/builder.go index 9a7e1957..b082a566 100644 --- a/chainio/clients/builder.go +++ b/chainio/clients/builder.go @@ -10,7 +10,6 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" - chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" "github.com/Layr-Labs/eigensdk-go/signerv2" @@ -44,8 +43,8 @@ type Clients struct { EthWsClient eth.Client Wallet wallet.Wallet TxManager txmgr.TxManager - AvsRegistryContractBindings *chainioutils.AvsRegistryContractBindings - EigenlayerContractBindings *chainioutils.EigenlayerContractBindings + AvsRegistryContractBindings *avsregistry.ContractBindings + EigenlayerContractBindings *elcontracts.ContractBindings Metrics *metrics.EigenMetrics // exposes main avs node spec metrics that need to be incremented by avs code and used to start the metrics server PrometheusRegistry *prometheus.Registry // Used if avs teams need to register avs-specific metrics } @@ -132,8 +131,8 @@ func BuildAll( func (config *BuildAllConfig) buildAVSRegistryContractBindings( ethHttpClient eth.Client, logger logging.Logger, -) (*chainioutils.AvsRegistryContractBindings, error) { - avsRegistryContractBindings, err := chainioutils.NewAVSRegistryContractBindings( +) (*avsregistry.ContractBindings, error) { + avsRegistryContractBindings, err := avsregistry.NewAVSRegistryContractBindings( gethcommon.HexToAddress(config.RegistryCoordinatorAddr), gethcommon.HexToAddress(config.OperatorStateRetrieverAddr), ethHttpClient, @@ -149,16 +148,16 @@ func (config *BuildAllConfig) buildEigenLayerContractBindings( delegationManagerAddr, avsDirectoryAddr gethcommon.Address, ethHttpClient eth.Client, logger logging.Logger, -) (*chainioutils.EigenlayerContractBindings, error) { +) (*elcontracts.ContractBindings, error) { - elContractBindings, err := chainioutils.NewEigenlayerContractBindings( + elContractBindings, err := elcontracts.NewEigenlayerContractBindings( delegationManagerAddr, avsDirectoryAddr, ethHttpClient, logger, ) if err != nil { - return nil, utils.WrapError("Failed to create EigenlayerContractBindings", err) + return nil, utils.WrapError("Failed to create ContractBindings", err) } return elContractBindings, nil } @@ -168,7 +167,7 @@ func (config *BuildAllConfig) BuildELClients( txMgr txmgr.TxManager, logger logging.Logger, eigenMetrics *metrics.EigenMetrics, -) (*elcontracts.ELChainReader, *elcontracts.ELChainWriter, *chainioutils.EigenlayerContractBindings, error) { +) (*elcontracts.ELChainReader, *elcontracts.ELChainWriter, *elcontracts.ContractBindings, error) { avsRegistryContractBindings, err := config.buildAVSRegistryContractBindings(ethHttpClient, logger) if err != nil { return nil, nil, nil, err @@ -190,7 +189,7 @@ func (config *BuildAllConfig) BuildELClients( logger, ) if err != nil { - return nil, nil, nil, utils.WrapError("Failed to create EigenlayerContractBindings", err) + return nil, nil, nil, utils.WrapError("Failed to create ContractBindings", err) } // get the Reader for the EL contracts @@ -224,9 +223,9 @@ func (config *BuildAllConfig) BuildAVSRegistryClients( ethWsClient eth.Client, txMgr txmgr.TxManager, logger logging.Logger, -) (*avsregistry.AvsRegistryChainReader, *avsregistry.AvsRegistryChainSubscriber, *avsregistry.AvsRegistryChainWriter, *chainioutils.AvsRegistryContractBindings, error) { +) (*avsregistry.AvsRegistryChainReader, *avsregistry.AvsRegistryChainSubscriber, *avsregistry.AvsRegistryChainWriter, *avsregistry.ContractBindings, error) { - avsRegistryContractBindings, err := chainioutils.NewAVSRegistryContractBindings( + avsRegistryContractBindings, err := avsregistry.NewAVSRegistryContractBindings( gethcommon.HexToAddress(config.RegistryCoordinatorAddr), gethcommon.HexToAddress(config.OperatorStateRetrieverAddr), ethHttpClient, diff --git a/chainio/clients/elcontracts/bindings.go b/chainio/clients/elcontracts/bindings.go new file mode 100644 index 00000000..2896a691 --- /dev/null +++ b/chainio/clients/elcontracts/bindings.go @@ -0,0 +1,140 @@ +// Package elcontracts bindings.go contains functions that create contract bindings for the Eigenlayer Core contracts +// These functions are meant to be used by constructors of the chainio package. +package elcontracts + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + gethcommon "github.com/ethereum/go-ethereum/common" + + "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" + 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" + "github.com/Layr-Labs/eigensdk-go/utils" +) + +// ContractBindings contains the contract bindings for the EigenLayer Core contracts +// +// 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 +} + +func NewBindingsFromConfig( + cfg Config, + client eth.Client, + logger logging.Logger, +) (*ContractBindings, error) { + var contractDelegationManager *delegationmanager.ContractDelegationManager + var contractSlasher *slasher.ContractISlasher + var contractStrategyManager *strategymanager.ContractStrategyManager + var slasherAddr gethcommon.Address + var strategyManagerAddr gethcommon.Address + var avsDirectory *avsdirectory.ContractAVSDirectory + var err error + + if gethcommon.IsHexAddress(cfg.DelegationManagerAddress.String()) { + logger.Warn("DelegationManager address not provided, the calls to the contract will not work") + } else { + contractDelegationManager, err = delegationmanager.NewContractDelegationManager(cfg.DelegationManagerAddress, client) + if err != nil { + return nil, utils.WrapError("Failed to create DelegationManager contract", err) + } + + slasherAddr, err = contractDelegationManager.Slasher(&bind.CallOpts{}) + if err != nil { + return nil, utils.WrapError("Failed to fetch Slasher address", err) + } + contractSlasher, err = slasher.NewContractISlasher(slasherAddr, client) + if err != nil { + return nil, utils.WrapError("Failed to fetch Slasher contract", err) + } + + strategyManagerAddr, err = contractDelegationManager.StrategyManager(&bind.CallOpts{}) + if err != nil { + return nil, utils.WrapError("Failed to fetch StrategyManager address", err) + } + contractStrategyManager, err = strategymanager.NewContractStrategyManager(strategyManagerAddr, client) + if err != nil { + return nil, utils.WrapError("Failed to fetch StrategyManager contract", err) + } + } + + if gethcommon.IsHexAddress(cfg.AvsDirectoryAddress.String()) { + logger.Warn("AVSDirectory address not provided, the calls to the contract will not work") + } else { + avsDirectory, err = avsdirectory.NewContractAVSDirectory(cfg.AvsDirectoryAddress, client) + if err != nil { + return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err) + } + } + + return &ContractBindings{ + SlasherAddr: slasherAddr, + StrategyManagerAddr: strategyManagerAddr, + DelegationManagerAddr: cfg.DelegationManagerAddress, + AvsDirectoryAddr: cfg.AvsDirectoryAddress, + Slasher: contractSlasher, + StrategyManager: contractStrategyManager, + DelegationManager: contractDelegationManager, + AvsDirectory: avsDirectory, + }, nil +} + +// NewEigenlayerContractBindings creates a new ContractBindings struct with the provided contract addresses +// Deprecated: Use NewBindingsFromConfig instead +func NewEigenlayerContractBindings( + delegationManagerAddr gethcommon.Address, + avsDirectoryAddr gethcommon.Address, + ethclient eth.Client, + logger logging.Logger, +) (*ContractBindings, error) { + contractDelegationManager, err := delegationmanager.NewContractDelegationManager(delegationManagerAddr, ethclient) + if err != nil { + return nil, utils.WrapError("Failed to create DelegationManager contract", err) + } + + slasherAddr, err := contractDelegationManager.Slasher(&bind.CallOpts{}) + if err != nil { + return nil, utils.WrapError("Failed to fetch Slasher address", err) + } + contractSlasher, err := slasher.NewContractISlasher(slasherAddr, ethclient) + if err != nil { + return nil, utils.WrapError("Failed to fetch Slasher contract", err) + } + + strategyManagerAddr, err := contractDelegationManager.StrategyManager(&bind.CallOpts{}) + if err != nil { + return nil, utils.WrapError("Failed to fetch StrategyManager address", err) + } + contractStrategyManager, err := strategymanager.NewContractStrategyManager(strategyManagerAddr, ethclient) + if err != nil { + return nil, utils.WrapError("Failed to fetch StrategyManager contract", err) + } + + avsDirectory, err := avsdirectory.NewContractAVSDirectory(avsDirectoryAddr, ethclient) + if err != nil { + return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err) + } + + return &ContractBindings{ + SlasherAddr: slasherAddr, + StrategyManagerAddr: strategyManagerAddr, + DelegationManagerAddr: delegationManagerAddr, + AvsDirectoryAddr: avsDirectoryAddr, + Slasher: contractSlasher, + StrategyManager: contractStrategyManager, + DelegationManager: contractDelegationManager, + AvsDirectory: avsDirectory, + }, nil +} diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 71067de7..3e6efb07 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -1,6 +1,7 @@ package elcontracts import ( + "errors" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -8,7 +9,6 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" - chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" @@ -61,6 +61,11 @@ type ELReader interface { ) ([32]byte, error) } +type Config struct { + DelegationManagerAddress common.Address + AvsDirectoryAddress common.Address +} + type ELChainReader struct { logger logging.Logger slasher slasher.ContractISlasherCalls @@ -81,6 +86,8 @@ func NewELChainReader( logger logging.Logger, ethClient eth.Client, ) *ELChainReader { + logger = logger.With("module", "elcontracts/reader") + return &ELChainReader{ slasher: slasher, delegationManager: delegationManager, @@ -91,13 +98,15 @@ func NewELChainReader( } } +// BuildELChainReader creates a new ELChainReader +// Deprecated: Use BuildFromConfig instead func BuildELChainReader( delegationManagerAddr gethcommon.Address, avsDirectoryAddr gethcommon.Address, ethClient eth.Client, logger logging.Logger, ) (*ELChainReader, error) { - elContractBindings, err := chainioutils.NewEigenlayerContractBindings( + elContractBindings, err := NewEigenlayerContractBindings( delegationManagerAddr, avsDirectoryAddr, ethClient, @@ -116,7 +125,34 @@ func BuildELChainReader( ), nil } +func NewReaderFromConfig( + cfg Config, + ethClient eth.Client, + logger logging.Logger, +) (*ELChainReader, error) { + elContractBindings, err := NewBindingsFromConfig( + cfg, + ethClient, + logger, + ) + if err != nil { + return nil, err + } + return NewELChainReader( + elContractBindings.Slasher, + elContractBindings.DelegationManager, + elContractBindings.StrategyManager, + elContractBindings.AvsDirectory, + logger, + ethClient, + ), nil +} + func (r *ELChainReader) IsOperatorRegistered(opts *bind.CallOpts, operator types.Operator) (bool, error) { + if r.delegationManager == nil { + return false, errors.New("DelegationManager contract not provided") + } + isOperator, err := r.delegationManager.IsOperator( opts, gethcommon.HexToAddress(operator.Address), @@ -129,6 +165,10 @@ func (r *ELChainReader) IsOperatorRegistered(opts *bind.CallOpts, operator types } func (r *ELChainReader) GetOperatorDetails(opts *bind.CallOpts, operator types.Operator) (types.Operator, error) { + if r.delegationManager == nil { + return types.Operator{}, errors.New("DelegationManager contract not provided") + } + operatorDetails, err := r.delegationManager.OperatorDetails( opts, gethcommon.HexToAddress(operator.Address), @@ -185,6 +225,10 @@ func (r *ELChainReader) ServiceManagerCanSlashOperatorUntilBlock( operatorAddr gethcommon.Address, serviceManagerAddr gethcommon.Address, ) (uint32, error) { + if r.slasher == nil { + return uint32(0), errors.New("slasher contract not provided") + } + serviceManagerCanSlashOperatorUntilBlock, err := r.slasher.ContractCanSlashOperatorUntilBlock( opts, operatorAddr, serviceManagerAddr, ) @@ -195,6 +239,10 @@ func (r *ELChainReader) ServiceManagerCanSlashOperatorUntilBlock( } func (r *ELChainReader) OperatorIsFrozen(opts *bind.CallOpts, operatorAddr gethcommon.Address) (bool, error) { + if r.slasher == nil { + return false, errors.New("slasher contract not provided") + } + operatorIsFrozen, err := r.slasher.IsFrozen(opts, operatorAddr) if err != nil { return false, err @@ -207,6 +255,10 @@ func (r *ELChainReader) GetOperatorSharesInStrategy( operatorAddr gethcommon.Address, strategyAddr gethcommon.Address, ) (*big.Int, error) { + if r.delegationManager == nil { + return &big.Int{}, errors.New("DelegationManager contract not provided") + } + operatorSharesInStrategy, err := r.delegationManager.OperatorShares( opts, operatorAddr, @@ -222,6 +274,10 @@ func (r *ELChainReader) CalculateDelegationApprovalDigestHash( opts *bind.CallOpts, staker gethcommon.Address, operator gethcommon.Address, delegationApprover gethcommon.Address, approverSalt [32]byte, expiry *big.Int, ) ([32]byte, error) { + if r.delegationManager == nil { + return [32]byte{}, errors.New("DelegationManager contract not provided") + } + return r.delegationManager.CalculateDelegationApprovalDigestHash( opts, staker, operator, delegationApprover, approverSalt, expiry, ) @@ -230,6 +286,10 @@ func (r *ELChainReader) CalculateDelegationApprovalDigestHash( func (r *ELChainReader) CalculateOperatorAVSRegistrationDigestHash( opts *bind.CallOpts, operator gethcommon.Address, avs gethcommon.Address, salt [32]byte, expiry *big.Int, ) ([32]byte, error) { + if r.avsDirectory == nil { + return [32]byte{}, errors.New("AVSDirectory contract not provided") + } + return r.avsDirectory.CalculateOperatorAVSRegistrationDigestHash( opts, operator, avs, salt, expiry, ) diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index 06396b56..a0cfbf53 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -11,7 +11,6 @@ import ( "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" - chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" @@ -63,6 +62,8 @@ func NewELChainWriter( eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, ) *ELChainWriter { + logger = logger.With("module", "elcontracts/writer") + return &ELChainWriter{ slasher: slasher, delegationManager: delegationManager, @@ -75,6 +76,8 @@ func NewELChainWriter( } } +// BuildELChainWriter builds an ELChainWriter instance. +// Deprecated: Use NewWriterFromConfig instead. func BuildELChainWriter( delegationManagerAddr gethcommon.Address, avsDirectoryAddr gethcommon.Address, @@ -83,7 +86,7 @@ func BuildELChainWriter( eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, ) (*ELChainWriter, error) { - elContractBindings, err := chainioutils.NewEigenlayerContractBindings( + elContractBindings, err := NewEigenlayerContractBindings( delegationManagerAddr, avsDirectoryAddr, ethClient, @@ -113,10 +116,47 @@ func BuildELChainWriter( ), nil } -// TODO(madhur): we wait for txreceipts in these functions right now, but -// this will be changed once we have a better tx manager design implemented -// see https://github.com/Layr-Labs/eigensdk-go/pull/75 +func NewWriterFromConfig( + cfg Config, + ethClient eth.Client, + logger logging.Logger, + eigenMetrics metrics.Metrics, + txMgr txmgr.TxManager, +) (*ELChainWriter, error) { + elContractBindings, err := NewBindingsFromConfig( + cfg, + ethClient, + logger, + ) + if err != nil { + return nil, err + } + elChainReader := NewELChainReader( + elContractBindings.Slasher, + elContractBindings.DelegationManager, + elContractBindings.StrategyManager, + elContractBindings.AvsDirectory, + logger, + ethClient, + ) + return NewELChainWriter( + elContractBindings.Slasher, + elContractBindings.DelegationManager, + elContractBindings.StrategyManager, + elContractBindings.StrategyManagerAddr, + elChainReader, + ethClient, + logger, + eigenMetrics, + txMgr, + ), nil +} + func (w *ELChainWriter) RegisterAsOperator(ctx context.Context, operator types.Operator) (*gethtypes.Receipt, error) { + if w.delegationManager == nil { + return nil, errors.New("DelegationManager contract not provided") + } + w.logger.Infof("registering operator %s to EigenLayer", operator.Address) opDetails := delegationmanager.IDelegationManagerOperatorDetails{ DeprecatedEarningsReceiver: gethcommon.HexToAddress(operator.EarningsReceiverAddress), @@ -145,6 +185,9 @@ func (w *ELChainWriter) UpdateOperatorDetails( ctx context.Context, operator types.Operator, ) (*gethtypes.Receipt, error) { + if w.delegationManager == nil { + return nil, errors.New("DelegationManager contract not provided") + } w.logger.Infof("updating operator details of operator %s to EigenLayer", operator.Address) opDetails := delegationmanager.IDelegationManagerOperatorDetails{ @@ -178,6 +221,10 @@ func (w *ELChainWriter) UpdateOperatorDetails( } func (w *ELChainWriter) UpdateMetadataURI(ctx context.Context, uri string) (*gethtypes.Receipt, error) { + if w.delegationManager == nil { + return nil, errors.New("DelegationManager contract not provided") + } + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil { return nil, err @@ -205,6 +252,10 @@ func (w *ELChainWriter) DepositERC20IntoStrategy( strategyAddr gethcommon.Address, amount *big.Int, ) (*gethtypes.Receipt, error) { + if w.strategyManager == nil { + return nil, errors.New("StrategyManager contract not provided") + } + w.logger.Infof("depositing %s tokens into strategy %s", amount.String(), strategyAddr) noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() if err != nil {