Skip to content

Commit

Permalink
chore: clean up and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Aug 27, 2024
1 parent 93010df commit 482ea0e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 46 deletions.
27 changes: 7 additions & 20 deletions pkg/rewards/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

contractrewardscoordinator "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IRewardsCoordinator"
Expand All @@ -36,22 +35,11 @@ import (
"github.com/urfave/cli/v2"
)

type ClaimConfig struct {
Network string
RPCUrl string
EarnerAddress gethcommon.Address
RecipientAddress gethcommon.Address
ClaimerAddress gethcommon.Address
Output string
OutputType string
Broadcast bool
TokenAddresses []gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
ClaimTimestamp string
ChainID *big.Int
ProofStoreBaseURL string
Environment string
SignerConfig *types.SignerConfig
type elChainReader interface {
GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error)
GetRootIndexFromHash(opts *bind.CallOpts, hash [32]byte) (uint32, error)
GetCurrentClaimableDistributionRoot(opts *bind.CallOpts) (rewardscoordinator.IRewardsCoordinatorDistributionRoot, error)
CurrRewardsCalculationEndTimestamp(opts *bind.CallOpts) (uint32, error)
}

func ClaimCmd(p utils.Prompter) *cli.Command {
Expand Down Expand Up @@ -123,7 +111,7 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
http.DefaultClient,
)

claimDate, rootIndex, err := getClaimDistributionRoot(ctx, config.ClaimTimestamp, df, elReader, logger)
claimDate, rootIndex, err := getClaimDistributionRoot(ctx, config.ClaimTimestamp, elReader, logger)
if err != nil {
return eigenSdkUtils.WrapError("failed to get claim distribution root", err)
}
Expand Down Expand Up @@ -275,8 +263,7 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
func getClaimDistributionRoot(
ctx context.Context,
claimTimestamp string,
df *httpProofDataFetcher.HttpProofDataFetcher,
elReader *elcontracts.ChainReader,
elReader elChainReader,
logger logging.Logger,
) (string, uint32, error) {
if claimTimestamp == "latest" {
Expand Down
36 changes: 36 additions & 0 deletions pkg/rewards/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,39 @@ func TestReadAndValidateConfig_RecipientProvided(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, common.HexToAddress(recipientAddress), config.RecipientAddress)
}

func TestReadAndValidateConfig_NoClaimerProvided(t *testing.T) {
earnerAddress := testutils.GenerateRandomEthereumAddressString()
fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.String(flags.ETHRpcUrlFlag.Name, "rpc", "")
fs.String(EarnerAddressFlag.Name, earnerAddress, "")
fs.String(RewardsCoordinatorAddressFlag.Name, "0x1234", "")
fs.String(ClaimTimestampFlag.Name, "latest", "")
fs.String(ProofStoreBaseURLFlag.Name, "dummy-url", "")
cliCtx := cli.NewContext(nil, fs, nil)

logger := logging.NewJsonSLogger(os.Stdout, &logging.SLoggerOptions{})

config, err := readAndValidateClaimConfig(cliCtx, logger)

assert.NoError(t, err)
assert.Equal(t, common.HexToAddress(earnerAddress), config.ClaimerAddress)
}

func TestReadAndValidateConfig_ClaimerProvided(t *testing.T) {
claimerAddress := testutils.GenerateRandomEthereumAddressString()
fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.String(flags.ETHRpcUrlFlag.Name, "rpc", "")
fs.String(ClaimerAddressFlag.Name, claimerAddress, "")
fs.String(RewardsCoordinatorAddressFlag.Name, "0x1234", "")
fs.String(ClaimTimestampFlag.Name, "latest", "")
fs.String(ProofStoreBaseURLFlag.Name, "dummy-url", "")
cliCtx := cli.NewContext(nil, fs, nil)

logger := logging.NewJsonSLogger(os.Stdout, &logging.SLoggerOptions{})

config, err := readAndValidateClaimConfig(cliCtx, logger)

assert.NoError(t, err)
assert.Equal(t, common.HexToAddress(claimerAddress), config.ClaimerAddress)
}
15 changes: 0 additions & 15 deletions pkg/rewards/setclaimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package rewards
import (
"context"
"fmt"
"math/big"
"sort"

"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
Expand All @@ -23,19 +21,6 @@ import (
"github.com/urfave/cli/v2"
)

type SetClaimerConfig struct {
ClaimerAddress gethcommon.Address
Network string
RPCUrl string
Broadcast bool
RewardsCoordinatorAddress gethcommon.Address
ChainID *big.Int
SignerConfig *types.SignerConfig
EarnerAddress gethcommon.Address
Output string
OutputType string
}

func SetClaimerCmd(p utils.Prompter) *cli.Command {
setClaimerCmd := &cli.Command{
Name: "set-claimer",
Expand Down
10 changes: 0 additions & 10 deletions pkg/rewards/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ const (
GetEarnedTokensForStrategyEndpoint = "grpc/eigenlayer.RewardsService/GetEarnedTokensForStrategy"
)

type ShowConfig struct {
EarnerAddress gethcommon.Address
NumberOfDays int64
Network string
Environment string
ClaimType ClaimType
ChainID *big.Int
Output string
}

func ShowCmd(p utils.Prompter) *cli.Command {
showCmd := &cli.Command{
Name: "show",
Expand Down
48 changes: 47 additions & 1 deletion pkg/rewards/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package rewards

import "math/big"
import (
"math/big"

"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
gethcommon "github.com/ethereum/go-ethereum/common"
)

type RewardResponse struct {
Rewards []Reward `json:"rewards"`
Expand Down Expand Up @@ -37,3 +42,44 @@ type NormalizedUnclaimedReward struct {
TokenAddress string `csv:"tokenAddress"`
WeiAmount *big.Int `csv:"weiAmount"`
}

type ClaimConfig struct {
Network string
RPCUrl string
EarnerAddress gethcommon.Address
RecipientAddress gethcommon.Address
ClaimerAddress gethcommon.Address
Output string
OutputType string
Broadcast bool
TokenAddresses []gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
ClaimTimestamp string
ChainID *big.Int
ProofStoreBaseURL string
Environment string
SignerConfig *types.SignerConfig
}

type SetClaimerConfig struct {
ClaimerAddress gethcommon.Address
Network string
RPCUrl string
Broadcast bool
RewardsCoordinatorAddress gethcommon.Address
ChainID *big.Int
SignerConfig *types.SignerConfig
EarnerAddress gethcommon.Address
Output string
OutputType string
}

type ShowConfig struct {
EarnerAddress gethcommon.Address
NumberOfDays int64
Network string
Environment string
ClaimType ClaimType
ChainID *big.Int
Output string
}

0 comments on commit 482ea0e

Please sign in to comment.