Skip to content

Commit

Permalink
added constant getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Feb 13, 2025
1 parent 05e4069 commit 0b7c2e0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
47 changes: 47 additions & 0 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,53 @@ 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})
}

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})
}

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})
}

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})
}

// 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
40 changes: 39 additions & 1 deletion chainio/clients/elcontracts/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ func TestInvalidConfig(t *testing.T) {
require.Error(t, err)
})

t.Run("get operator set", func(t *testing.T) {
t.Run("get operator set split", func(t *testing.T) {
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS)
operatorSetId := uint32(1)
operatorSet := rewardscoordinator.OperatorSet{
Expand All @@ -893,6 +893,44 @@ func TestInvalidConfig(t *testing.T) {
require.Error(t, err)
})

// Get the interval in seconds at which the calculation for rewards distribution is done.
t.Run("get calculation interval seconds", func(t *testing.T) {
interval, err := chainReader.GetCalculationIntervalSeconds(context.Background())
require.Error(t, err)
// currently this is configured to zero but may be configured to 1 week in a future release, based on this
// comment:
// https://github.com/Layr-Labs/eigenlayer-contracts/blob/441339cbd570ad0d650a9c11bea9eed7f70a490d/src/contracts/core/RewardsCoordinatorStorage.sol#L64
require.Zero(t, interval)
})

//Get the maximum amount of time (seconds) that a rewards submission can span over
t.Run("get max duration seconds", func(t *testing.T) {
duration, err := chainReader.GetMaxRewardsDuration(context.Background())
require.Error(t, err)
require.Zero(t, duration)
})

/// Get the max amount of time (seconds) that a rewards submission can start in the past
t.Run("get max retroactive length", func(t *testing.T) {
length, err := chainReader.GetMaxRetroactiveLength(context.Background())
require.Error(t, err)
require.Zero(t, length)
})

/// Get the max amount of time (seconds) that a rewards submission can start in the future
t.Run("get max future length", func(t *testing.T) {
length, err := chainReader.GetMaxFutureLength(context.Background())
require.Error(t, err)
require.Zero(t, length)
})

/// Get the absolute min timestamp (seconds) that a rewards submission can start at
t.Run("get genesis rewards timestamp", func(t *testing.T) {
timestamp, err := chainReader.GetGenesisRewardsTimestamp(context.Background())
require.Error(t, err)
require.Zero(t, timestamp)
})

t.Run("try to get strategy and underlying token with wrong strategy address", func(t *testing.T) {
// Invalid strategy address
strategyAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS)
Expand Down

0 comments on commit 0b7c2e0

Please sign in to comment.