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

feat: Add RewardsCoordinatorStorage functions #565

Merged
merged 10 commits into from
Feb 14, 2025
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lint: ## runs all linters

___BINDINGS___: ##

core_default := "DelegationManager IRewardsCoordinator StrategyManager EigenPod EigenPodManager IStrategy AVSDirectory AllocationManager PermissionController"
core_default := "DelegationManager RewardsCoordinator StrategyManager EigenPod EigenPodManager IStrategy AVSDirectory AllocationManager PermissionController"
core_location := "./lib/eigenlayer-middleware/lib/eigenlayer-contracts"
core_bindings_location := "../../../../bindings"

Expand Down
8 changes: 4 additions & 4 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory"
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RewardsCoordinator"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/utils"
Expand All @@ -30,7 +30,7 @@ type ContractBindings struct {
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractAVSDirectory
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
RewardsCoordinator *rewardscoordinator.ContractRewardsCoordinator
AllocationManager *allocationmanager.ContractAllocationManager
PermissionController *permissioncontroller.ContractPermissionController
}
Expand All @@ -49,7 +49,7 @@ func NewBindingsFromConfig(
strategyManagerAddr gethcommon.Address
allocationManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
rewardsCoordinator *rewardscoordinator.ContractRewardsCoordinator
permissionController *permissioncontroller.ContractPermissionController
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func NewBindingsFromConfig(
if isZeroAddress(cfg.RewardsCoordinatorAddress) {
logger.Debug("RewardsCoordinator address not provided, the calls to the contract will not work")
} else {
rewardsCoordinator, err = rewardscoordinator.NewContractIRewardsCoordinator(cfg.RewardsCoordinatorAddress, client)
rewardsCoordinator, err = rewardscoordinator.NewContractRewardsCoordinator(cfg.RewardsCoordinatorAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch RewardsCoordinator contract", err)
}
Expand Down
192 changes: 189 additions & 3 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager"
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"
strategy "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IStrategy"
permissioncontroller "github.com/Layr-Labs/eigensdk-go/contracts/bindings/PermissionController"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RewardsCoordinator"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"
Expand All @@ -35,7 +35,7 @@ type ChainReader struct {
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
rewardsCoordinator *rewardscoordinator.ContractRewardsCoordinator
allocationManager *allocationmanager.ContractAllocationManager
permissionController *permissioncontroller.ContractPermissionController
ethClient eth.HttpBackend
Expand All @@ -48,7 +48,7 @@ func NewChainReader(
delegationManager *delegationmanager.ContractDelegationManager,
strategyManager *strategymanager.ContractStrategyManager,
avsDirectory *avsdirectory.ContractAVSDirectory,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
rewardsCoordinator *rewardscoordinator.ContractRewardsCoordinator,
allocationManager *allocationmanager.ContractAllocationManager,
permissionController *permissioncontroller.ContractPermissionController,
logger logging.Logger,
Expand Down Expand Up @@ -415,6 +415,192 @@ func (r *ChainReader) GetOperatorSetSplit(
return r.rewardsCoordinator.GetOperatorSetSplit(&bind.CallOpts{Context: ctx}, operator, operatorSet)
}

// Gets the interval in seconds at which the calculation for rewards distribution is done.
func (r *ChainReader) GetCalculationIntervalSeconds(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.CALCULATIONINTERVALSECONDS(&bind.CallOpts{Context: ctx})
}

// Gets the maximum amount of time (seconds) that a rewards submission can span over
func (r *ChainReader) GetMaxRewardsDuration(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.MAXREWARDSDURATION(&bind.CallOpts{Context: ctx})
}

// Get the max amount of time (seconds) that a rewards submission can start in the past
func (r *ChainReader) GetMaxRetroactiveLength(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.MAXRETROACTIVELENGTH(&bind.CallOpts{Context: ctx})
}

// Get the max amount of time (seconds) that a rewards submission can start in the future
func (r *ChainReader) GetMaxFutureLength(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.MAXFUTURELENGTH(&bind.CallOpts{Context: ctx})
}

// Get absolute min timestamp (seconds) that a rewards submission can start at
func (r *ChainReader) GetGenesisRewardsTimestamp(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.GENESISREWARDSTIMESTAMP(&bind.CallOpts{Context: ctx})
}

// Get the address of the entity that can update the contract with new merkle roots
func (r *ChainReader) GetRewardsUpdater(
ctx context.Context,
) (gethcommon.Address, error) {
if r.rewardsCoordinator == nil {
return gethcommon.Address{}, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.RewardsUpdater(&bind.CallOpts{Context: ctx})
}

// Get delay in timestamp (seconds) before a posted root can be claimed against
func (r *ChainReader) GetActivationDelay(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.ActivationDelay(&bind.CallOpts{Context: ctx})
}

// Get timestamp for last submitted DistributionRoot
func (r *ChainReader) GetCurrRewardsCalculationEndTimestamp(
ctx context.Context,
) (uint32, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx})
}

// Get the default split for all operators across all avss in bips.
func (r *ChainReader) GetDefaultOperatorSplitBips(
ctx context.Context,
) (uint16, error) {
if r.rewardsCoordinator == nil {
return 0, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.DefaultOperatorSplitBips(&bind.CallOpts{Context: ctx})
}

func (r *ChainReader) GetClaimerFor(
ctx context.Context,
earner gethcommon.Address,
) (gethcommon.Address, error) {
if r.rewardsCoordinator == nil {
return gethcommon.Address{}, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.ClaimerFor(&bind.CallOpts{Context: ctx}, earner)
}

// Returns the submission nonce for an avs
func (r *ChainReader) GetSubmissionNonce(
ctx context.Context,
avs gethcommon.Address,
) (*big.Int, error) {
if r.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.SubmissionNonce(&bind.CallOpts{Context: ctx}, avs)
}

// Returns whether a hash is a valid rewards submission hash for a given avs
func (r *ChainReader) GetIsAVSRewardsSubmissionHash(
ctx context.Context,
avs gethcommon.Address,
hash [32]byte,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsAVSRewardsSubmissionHash(&bind.CallOpts{Context: ctx}, avs, hash)
}

// Returns whether a hash is a valid rewards submission for all hash for a given avs
func (r *ChainReader) GetIsRewardsSubmissionForAllHash(
ctx context.Context,
avs gethcommon.Address,
hash [32]byte,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsRewardsSubmissionForAllHash(&bind.CallOpts{Context: ctx}, avs, hash)
}

// Returns whether a submitter is a valid rewards for all submitter
func (r *ChainReader) GetIsRewardsForAllSubmitter(
ctx context.Context,
submitter gethcommon.Address,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsRewardsForAllSubmitter(&bind.CallOpts{Context: ctx}, submitter)
}

// Returns whether a hash is a valid rewards submission for all earners hash for a given avs
func (r *ChainReader) GetIsRewardsSubmissionForAllEarnersHash(
ctx context.Context,
avs gethcommon.Address,
hash [32]byte,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsRewardsSubmissionForAllEarnersHash(&bind.CallOpts{Context: ctx}, avs, hash)
}

// Returns whether a hash is a valid operator set performance rewards submission hash for a given avs
func (r *ChainReader) GetIsOperatorDirectedAVSRewardsSubmissionHash(
ctx context.Context,
avs gethcommon.Address,
hash [32]byte,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsOperatorDirectedAVSRewardsSubmissionHash(&bind.CallOpts{Context: ctx}, avs, hash)
}

// Returns whether a hash is a valid operator set performance rewards submission hash for a given avs
func (r *ChainReader) GetIsOperatorDirectedOperatorSetRewardsSubmissionHash(
ctx context.Context,
avs gethcommon.Address,
hash [32]byte,
) (bool, error) {
if r.rewardsCoordinator == nil {
return false, errors.New("RewardsCoordinator contract not provided")
}
return r.rewardsCoordinator.IsOperatorDirectedOperatorSetRewardsSubmissionHash(
&bind.CallOpts{Context: ctx},
avs,
hash,
)
}

// Returns the amount of magnitude on a strategy not currently allocated to any operator set,
// by an operator.
// Can return an error if the `AllocationManager` contract address was not provided, or due to
Expand Down
Loading
Loading