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 rewards methods for claim generation #287

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

tx, err := w.rewardsCoordinator.ProcessClaim(noSendTxOpts, claim, earnerAddress)
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
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/elContractsReader.go

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

16 changes: 16 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