Skip to content

Commit e873f52

Browse files
feat: extend show to latest non claimable root (#229)
* feat: extend show to latest non claimable root * update readme * update readme * addressed comments
1 parent 5ff7845 commit e873f52

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

pkg/rewards/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ eigenlayer rewards set-claimer \
121121
```bash
122122
eigenlayer rewards show --help
123123
NAME:
124-
eigenlayer rewards show - Show rewards for an address against the latest `active` `DistributionRoot` posted on-chain by the rewards updater.
124+
eigenlayer rewards show - Show rewards for an address against the `DistributionRoot` posted on-chain by the rewards updater
125125
126126
USAGE:
127127
show
@@ -130,10 +130,15 @@ DESCRIPTION:
130130
131131
Command to show rewards for earners
132132
133-
Currently supports past total rewards (claimed and unclaimed) and past unclaimed rewards
133+
Helpful flags
134+
- claim-type: Type of rewards to show. Can be 'all', 'claimed' or 'unclaimed'
135+
- claim-timestamp: Timestamp of the claim distribution root to use. Can be 'latest' or 'latest_active'.
136+
- 'latest' will show rewards for the latest root (can contain non-claimable rewards)
137+
- 'latest_active' will show rewards for the latest active root (only claimable rewards)
134138
135139
136140
OPTIONS:
141+
--claim-timestamp value, -c value Specify the timestamp. Only 'latest' and 'latest_active' are supported. 'latest' can be a from an inactive root which you can't claim yet. (default: "latest_active") [$CLAIM_TIMESTAMP]
137142
--claim-type value, --ct value Type of claim you want to see. Can be 'all', 'unclaimed', or 'claimed' (default: "all") [$REWARDS_CLAIM_TYPE]
138143
--earner-address value, --ea value Address of the earner [$REWARDS_EARNER_ADDRESS]
139144
--environment value, --env value Environment to use. Currently supports 'preprod' ,'testnet' and 'prod'. If not provided, it will be inferred based on network [$ENVIRONMENT]

pkg/rewards/claim.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/ethclient"
3333

3434
"github.com/urfave/cli/v2"
35-
"github.com/wk8/go-ordered-map/v2"
35+
orderedmap "github.com/wk8/go-ordered-map/v2"
3636
)
3737

3838
type elChainReader interface {
@@ -277,7 +277,7 @@ func getClaimDistributionRoot(
277277
elReader elChainReader,
278278
logger logging.Logger,
279279
) (string, uint32, error) {
280-
if claimTimestamp == "latest" {
280+
if claimTimestamp == LatestTimestamp {
281281
latestSubmittedTimestamp, err := elReader.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx})
282282
if err != nil {
283283
return "", 0, eigenSdkUtils.WrapError("failed to get latest submitted timestamp", err)
@@ -292,12 +292,11 @@ func getClaimDistributionRoot(
292292
rootIndex := uint32(rootCount.Uint64() - 1)
293293
logger.Debugf("Latest active rewards snapshot timestamp: %s, root index: %d", claimDate, rootIndex)
294294
return claimDate, rootIndex, nil
295-
} else if claimTimestamp == "latest_active" {
295+
} else if claimTimestamp == LatestActiveTimestamp {
296296
latestClaimableRoot, err := elReader.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx})
297297
if err != nil {
298298
return "", 0, eigenSdkUtils.WrapError("failed to get latest claimable root", err)
299299
}
300-
301300
rootIndex, err := elReader.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, latestClaimableRoot.Root)
302301
if err != nil {
303302
return "", 0, eigenSdkUtils.WrapError("failed to get root index from hash", err)

pkg/rewards/claim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/stretchr/testify/assert"
2626
"github.com/urfave/cli/v2"
27-
"github.com/wk8/go-ordered-map/v2"
27+
orderedmap "github.com/wk8/go-ordered-map/v2"
2828
)
2929

3030
type fakeELReader struct {

pkg/rewards/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
ClaimTimestampFlag = cli.StringFlag{
2222
Name: "claim-timestamp",
2323
Aliases: []string{"c"},
24-
Usage: "Specify the timestamp. Only 'latest' and 'latest_active' are supported. 'latest' can be an inactive root which you can't claim yet.",
24+
Usage: "Specify the timestamp. Only 'latest' and 'latest_active' are supported. 'latest' can be a from an inactive root which you can't claim yet.",
2525
Value: "latest_active",
2626
EnvVars: []string{"CLAIM_TIMESTAMP"},
2727
}

pkg/rewards/show.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
2121
"github.com/Layr-Labs/eigensdk-go/logging"
2222
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
23-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2423

24+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2525
gethcommon "github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/ethclient"
2727

@@ -38,17 +38,24 @@ const (
3838
All ClaimType = "all"
3939
Unclaimed ClaimType = "unclaimed"
4040
Claimed ClaimType = "claimed"
41+
42+
LatestTimestamp = "latest"
43+
LatestActiveTimestamp = "latest_active"
4144
)
4245

4346
func ShowCmd(p utils.Prompter) *cli.Command {
4447
showCmd := &cli.Command{
4548
Name: "show",
46-
Usage: "Show rewards for an address",
49+
Usage: "Show rewards for an address against the `DistributionRoot` posted on-chain by the rewards updater",
4750
UsageText: "show",
4851
Description: `
4952
Command to show rewards for earners
5053
51-
Currently supports past total rewards (claimed and unclaimed) and past unclaimed rewards
54+
Helpful flags
55+
- claim-type: Type of rewards to show. Can be 'all', 'claimed' or 'unclaimed'
56+
- claim-timestamp: Timestamp of the claim distribution root to use. Can be 'latest' or 'latest_active'.
57+
- 'latest' will show rewards for the latest root (can contain non-claimable rewards)
58+
- 'latest_active' will show rewards for the latest active root (only claimable rewards)
5259
`,
5360
After: telemetry.AfterRunAction(),
5461
Flags: getShowFlags(),
@@ -71,6 +78,7 @@ func getShowFlags() []cli.Flag {
7178
&EnvironmentFlag,
7279
&ClaimTypeFlag,
7380
&ProofStoreBaseURLFlag,
81+
&ClaimTimestampFlag,
7482
}
7583

7684
sort.Sort(cli.FlagsByName(baseFlags))
@@ -109,7 +117,7 @@ func ShowRewards(cCtx *cli.Context) error {
109117
http.DefaultClient,
110118
)
111119

112-
claimDate, _, err := getClaimDistributionRoot(ctx, "latest_active", elReader, logger)
120+
claimDate, _, err := getClaimDistributionRoot(ctx, config.ClaimTimestamp, elReader, logger)
113121
if err != nil {
114122
return eigenSdkUtils.WrapError("failed to get claim distribution root", err)
115123
}
@@ -125,7 +133,7 @@ func ShowRewards(cCtx *cli.Context) error {
125133
}
126134

127135
allRewards := make(map[gethcommon.Address]*big.Int)
128-
msg := "All Rewards"
136+
msg := "Lifetime Rewards"
129137
for pair := tokenAddressesMap.Oldest(); pair != nil; pair = pair.Next() {
130138
amt, _ := new(big.Int).SetString(pair.Value.String(), 10)
131139
allRewards[pair.Key] = amt
@@ -145,7 +153,7 @@ func ShowRewards(cCtx *cli.Context) error {
145153
msg = "Unclaimed Rewards"
146154
}
147155
}
148-
err = handleRewardsOutput(config.Output, config.OutputType, allRewards, msg)
156+
err = handleRewardsOutput(config, allRewards, msg)
149157
if err != nil {
150158
return err
151159
}
@@ -185,13 +193,11 @@ func calculateUnclaimedRewards(
185193
}
186194

187195
func handleRewardsOutput(
188-
outputFile string,
189-
outputType string,
196+
cfg *ShowConfig,
190197
rewards map[gethcommon.Address]*big.Int,
191198
msg string,
192199
) error {
193-
fmt.Println(strings.Repeat("-", 30), msg, strings.Repeat("-", 30))
194-
if outputType == "json" {
200+
if cfg.OutputType == "json" {
195201
allRewards := make(allRewardsJson, 0)
196202
for address, amount := range rewards {
197203
allRewards = append(allRewards, rewardsJson{
@@ -203,12 +209,20 @@ func handleRewardsOutput(
203209
if err != nil {
204210
return err
205211
}
206-
if outputFile != "" {
207-
return common.WriteToFile(out, outputFile)
212+
if cfg.Output != "" {
213+
return common.WriteToFile(out, cfg.Output)
208214
} else {
209215
fmt.Println(string(out))
210216
}
211217
} else {
218+
fmt.Println()
219+
if cfg.ClaimTimestamp == LatestTimestamp {
220+
fmt.Println("> Showing rewards for latest root (can contain non-claimable rewards)")
221+
} else {
222+
fmt.Println("> Showing rewards for latest active root (only claimable rewards)")
223+
}
224+
fmt.Println()
225+
fmt.Println(strings.Repeat("-", 30), msg, strings.Repeat("-", 30))
212226
printRewards(rewards)
213227
}
214228
return nil
@@ -295,6 +309,12 @@ func readAndValidateConfig(cCtx *cli.Context, logger logging.Logger) (*ShowConfi
295309
return nil, errors.New("claim type must be 'all', 'unclaimed' or 'claimed'")
296310
}
297311
logger.Debugf("Claim Type: %s", claimType)
312+
313+
claimTimestamp := cCtx.String(ClaimTimestampFlag.Name)
314+
if claimTimestamp != LatestTimestamp && claimTimestamp != LatestActiveTimestamp {
315+
return nil, errors.New("claim timestamp must be 'latest' or 'latest_active'")
316+
}
317+
298318
chainID := utils.NetworkNameToChainId(network)
299319
logger.Debugf("Using chain ID: %s", chainID.String())
300320

@@ -313,6 +333,7 @@ func readAndValidateConfig(cCtx *cli.Context, logger logging.Logger) (*ShowConfi
313333
OutputType: outputType,
314334
RPCUrl: ethRpcUrl,
315335
ProofStoreBaseURL: proofStoreBaseURL,
336+
ClaimTimestamp: claimTimestamp,
316337
RewardsCoordinatorAddress: gethcommon.HexToAddress(rewardsCoordinatorAddress),
317338
}, nil
318339
}

pkg/rewards/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ type ShowConfig struct {
5757
Output string
5858
OutputType string
5959
ProofStoreBaseURL string
60+
ClaimTimestamp string
6061
RewardsCoordinatorAddress gethcommon.Address
6162
}

0 commit comments

Comments
 (0)