Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add set claimer for to EL writer #282

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, // this is nil because we don't have access to the rewards coordinator contract right now. we are going to refactor this method later
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,9 @@ package elcontracts
import (
"context"
"errors"

"github.com/Layr-Labs/eigensdk-go/utils"

"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -12,6 +15,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 +40,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 +62,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 +80,7 @@ func NewELChainWriter(
delegationManager: delegationManager,
strategyManager: strategyManager,
strategyManagerAddr: strategyManagerAddr,
rewardsCoordinator: rewardsCoordinator,
elChainReader: elChainReader,
logger: logger,
ethClient: ethClient,
Expand Down Expand Up @@ -107,6 +119,7 @@ func BuildELChainWriter(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
nil,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -143,6 +156,7 @@ func NewWriterFromConfig(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -290,3 +304,28 @@ 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")
}

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, utils.WrapError("failed to send tx", err)
}

return receipt, nil
}
15 changes: 15 additions & 0 deletions chainio/mocks/elContractsWriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading