Skip to content

Commit

Permalink
add set claimer for
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jun 26, 2024
1 parent fcb5366 commit b812735
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 38 deletions.
5 changes: 3 additions & 2 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -206,6 +206,7 @@ func (config *BuildAllConfig) BuildELClients(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
nil,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethHttpClient,
Expand Down
54 changes: 36 additions & 18 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
51 changes: 45 additions & 6 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package elcontracts
import (
"context"
"errors"

"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -69,6 +78,7 @@ func NewELChainWriter(
delegationManager: delegationManager,
strategyManager: strategyManager,
strategyManagerAddr: strategyManagerAddr,
rewardsCoordinator: rewardsCoordinator,
elChainReader: elChainReader,
logger: logger,
ethClient: ethClient,
Expand Down Expand Up @@ -107,6 +117,7 @@ func BuildELChainWriter(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
nil,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -143,6 +154,7 @@ func NewWriterFromConfig(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -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
}

0 comments on commit b812735

Please sign in to comment.