Skip to content

Commit

Permalink
add rewards methods for claim generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jul 2, 2024
1 parent 80be44e commit f88ef82
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
1 change: 1 addition & 0 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (config *BuildAllConfig) BuildELClients(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
logger,
ethHttpClient,
)
Expand Down
41 changes: 29 additions & 12 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elcontracts

import (
"errors"

"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -12,6 +13,7 @@ import (
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"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
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"
Expand Down Expand Up @@ -58,6 +60,8 @@ type ELReader interface {
CalculateOperatorAVSRegistrationDigestHash(
opts *bind.CallOpts, operator gethcommon.Address, avs gethcommon.Address, salt [32]byte, expiry *big.Int,
) ([32]byte, error)

GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error)
}

type Config struct {
Expand All @@ -67,12 +71,13 @@ type Config struct {
}

type ELChainReader struct {
logger logging.Logger
slasher slasher.ContractISlasherCalls
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractAVSDirectory
ethClient eth.Client
logger logging.Logger
slasher slasher.ContractISlasherCalls
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
ethClient eth.Client
}

// forces EthReader to implement the chainio.Reader interface
Expand All @@ -83,18 +88,20 @@ func NewELChainReader(
delegationManager *delegationmanager.ContractDelegationManager,
strategyManager *strategymanager.ContractStrategyManager,
avsDirectory *avsdirectory.ContractAVSDirectory,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
logger logging.Logger,
ethClient eth.Client,
) *ELChainReader {
logger = logger.With(logging.ComponentKey, "elcontracts/reader")

return &ELChainReader{
slasher: slasher,
delegationManager: delegationManager,
strategyManager: strategyManager,
avsDirectory: avsDirectory,
logger: logger,
ethClient: ethClient,
slasher: slasher,
delegationManager: delegationManager,
strategyManager: strategyManager,
avsDirectory: avsDirectory,
rewardsCoordinator: rewardsCoordinator,
logger: logger,
ethClient: ethClient,
}
}

Expand All @@ -120,6 +127,7 @@ func BuildELChainReader(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
), nil
Expand All @@ -143,6 +151,7 @@ func NewReaderFromConfig(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
), nil
Expand Down Expand Up @@ -294,3 +303,11 @@ func (r *ELChainReader) CalculateOperatorAVSRegistrationDigestHash(
opts, operator, avs, salt, expiry,
)
}

func (r *ELChainReader) GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error) {
if r.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
}

return r.rewardsCoordinator.GetDistributionRootsLength(opts)
}
36 changes: 35 additions & 1 deletion chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type ELWriter interface {
ctx context.Context,
claimer gethcommon.Address,
) (*gethtypes.Receipt, error)

ProcessClaim(
ctx context.Context,
claim rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim,
earnerAddress gethcommon.Address,
) (*gethtypes.Receipt, error)
}

type ELChainWriter struct {
Expand Down Expand Up @@ -112,14 +118,15 @@ func BuildELChainWriter(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
)
return NewELChainWriter(
elContractBindings.Slasher,
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
nil,
elContractBindings.RewardsCoordinator,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -149,6 +156,7 @@ func NewWriterFromConfig(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
logger,
ethClient,
)
Expand Down Expand Up @@ -329,3 +337,29 @@ func (w *ELChainWriter) SetClaimerFor(

return receipt, nil
}

func (w *ELChainWriter) ProcessClaim(
ctx context.Context,
claim rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim,
earnerAddress 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.ProcessClaim(noSendTxOpts, claim, earnerAddress)
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
}

0 comments on commit f88ef82

Please sign in to comment.