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

fix: updates to support latest eigensdk #237

Merged
merged 4 commits into from
Oct 29, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Layr-Labs/eigenlayer-contracts v0.3.2-mainnet-rewards
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20240927005004-ed4b05c87610
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918
github.com/blang/semver/v4 v4.0.0
github.com/consensys/gnark-crypto v0.12.1
github.com/ethereum/go-ethereum v1.14.5
Expand All @@ -19,6 +19,7 @@ require (
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.27.2
github.com/wagslane/go-password-validator v0.3.0
github.com/wk8/go-ordered-map/v2 v2.1.8
go.uber.org/mock v0.4.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -100,7 +101,6 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/wealdtech/go-merkletree/v2 v2.5.2-0.20240302222400-69219c450662 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 h1:G5Q1SnLmFbEjhOkky3vIHk
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12/go.mod h1:OlJd1QjqEW53wfWG/lJyPCGvrXwWVEjPQsP4TV+gttQ=
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e h1:DvW0/kWHV9mZsbH2KOjEHKTSIONNPUj6X05FJvUohy4=
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e/go.mod h1:T7tYN8bTdca2pkMnz9G2+ZwXYWw5gWqQUIu4KLgC/vM=
github.com/Layr-Labs/eigensdk-go v0.1.11/go.mod h1:XcLVDtlB1vOPj63D236b451+SC75B8gwgkpNhYHSxNs=
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20240927005004-ed4b05c87610 h1:lGy4uSImJyOiaM8vSx0CEbsL3rbVfw0uEIuhGey/ubc=
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20240927005004-ed4b05c87610/go.mod h1:bA21qMfmUFZcUe+a1RsDeOGm25xZO802Kfll2GlS8Us=
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918 h1:Itl141PoMFzq58ZTo4Nu/CyH+x8f4BH6OmBNhZ6Z2/I=
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
Expand Down
5 changes: 1 addition & 4 deletions pkg/operator/get_delegation_approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -117,10 +116,8 @@ Use the --expiry flag to override the default expiration of 3600 seconds.
}
expiry := new(big.Int).SetInt64(time.Now().Unix() + approvalConfig.Expiry)

callOpts := &bind.CallOpts{Context: context.Background()}

hash, err := reader.CalculateDelegationApprovalDigestHash(
callOpts,
context.Background(),
staker,
operator,
delegationApprover,
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

Expand Down Expand Up @@ -91,7 +90,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command {
return err
}

status, err := elReader.IsOperatorRegistered(&bind.CallOpts{Context: ctx}, operatorCfg.Operator)
status, err := elReader.IsOperatorRegistered(ctx, operatorCfg.Operator)
if err != nil {
return err
}
Expand All @@ -101,6 +100,7 @@ func RegisterCmd(p utils.Prompter) *cli.Command {
if err != nil {
return err
}

common.PrintRegistrationInfo(
receipt.TxHash.String(),
gethcommon.HexToAddress(operatorCfg.Operator.Address),
Expand Down
7 changes: 2 additions & 5 deletions pkg/operator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
elContracts "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
eigensdkTypes "github.com/Layr-Labs/eigensdk-go/types"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

Expand Down Expand Up @@ -97,17 +96,15 @@ func StatusCmd(p utils.Prompter) *cli.Command {
return err
}

callOpts := &bind.CallOpts{Context: context.Background()}

status, err := reader.IsOperatorRegistered(callOpts, operatorCfg.Operator)
status, err := reader.IsOperatorRegistered(context.Background(), operatorCfg.Operator)
if err != nil {
return err
}

if status {
fmt.Println()
fmt.Printf("%s Operator is registered on EigenLayer\n", utils.EmojiCheckMark)
operatorDetails, err := reader.GetOperatorDetails(callOpts, operatorCfg.Operator)
operatorDetails, err := reader.GetOperatorDetails(context.Background(), operatorCfg.Operator)
if err != nil {
return err
}
Expand Down
19 changes: 9 additions & 10 deletions pkg/rewards/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/Layr-Labs/eigensdk-go/logging"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

Expand All @@ -36,12 +35,12 @@ import (
)

type elChainReader interface {
GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error)
GetRootIndexFromHash(opts *bind.CallOpts, hash [32]byte) (uint32, error)
GetDistributionRootsLength(ctx context.Context) (*big.Int, error)
GetRootIndexFromHash(ctx context.Context, hash [32]byte) (uint32, error)
GetCurrentClaimableDistributionRoot(
opts *bind.CallOpts,
ctx context.Context,
) (rewardscoordinator.IRewardsCoordinatorDistributionRoot, error)
CurrRewardsCalculationEndTimestamp(opts *bind.CallOpts) (uint32, error)
CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error)
}

func ClaimCmd(p utils.Prompter) *cli.Command {
Expand Down Expand Up @@ -153,7 +152,7 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
}

logger.Info("Validating claim proof...")
ok, err := elReader.CheckClaim(&bind.CallOpts{Context: ctx}, elClaim)
ok, err := elReader.CheckClaim(ctx, elClaim)
if err != nil {
return err
}
Expand Down Expand Up @@ -278,13 +277,13 @@ func getClaimDistributionRoot(
logger logging.Logger,
) (string, uint32, error) {
if claimTimestamp == LatestTimestamp {
latestSubmittedTimestamp, err := elReader.CurrRewardsCalculationEndTimestamp(&bind.CallOpts{Context: ctx})
latestSubmittedTimestamp, err := elReader.CurrRewardsCalculationEndTimestamp(ctx)
if err != nil {
return "", 0, eigenSdkUtils.WrapError("failed to get latest submitted timestamp", err)
}
claimDate := time.Unix(int64(latestSubmittedTimestamp), 0).UTC().Format(time.DateOnly)

rootCount, err := elReader.GetDistributionRootsLength(&bind.CallOpts{Context: ctx})
rootCount, err := elReader.GetDistributionRootsLength(ctx)
if err != nil {
return "", 0, eigenSdkUtils.WrapError("failed to get number of published roots", err)
}
Expand All @@ -293,11 +292,11 @@ func getClaimDistributionRoot(
logger.Debugf("Latest active rewards snapshot timestamp: %s, root index: %d", claimDate, rootIndex)
return claimDate, rootIndex, nil
} else if claimTimestamp == LatestActiveTimestamp {
latestClaimableRoot, err := elReader.GetCurrentClaimableDistributionRoot(&bind.CallOpts{Context: ctx})
latestClaimableRoot, err := elReader.GetCurrentClaimableDistributionRoot(ctx)
if err != nil {
return "", 0, eigenSdkUtils.WrapError("failed to get latest claimable root", err)
}
rootIndex, err := elReader.GetRootIndexFromHash(&bind.CallOpts{Context: ctx}, latestClaimableRoot.Root)
rootIndex, err := elReader.GetRootIndexFromHash(ctx, latestClaimableRoot.Root)
if err != nil {
return "", 0, eigenSdkUtils.WrapError("failed to get root index from hash", err)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/rewards/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
"github.com/Layr-Labs/eigensdk-go/logging"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -65,11 +64,11 @@ func newFakeELReader(now time.Time) *fakeELReader {
}
}

func (f *fakeELReader) GetDistributionRootsLength(opts *bind.CallOpts) (*big.Int, error) {
func (f *fakeELReader) GetDistributionRootsLength(ctx context.Context) (*big.Int, error) {
return big.NewInt(int64(len(f.roots))), nil
}

func (f *fakeELReader) GetRootIndexFromHash(opts *bind.CallOpts, hash [32]byte) (uint32, error) {
func (f *fakeELReader) GetRootIndexFromHash(ctx context.Context, hash [32]byte) (uint32, error) {
for i, root := range f.roots {
if root.Root == hash {
return uint32(i), nil
Expand All @@ -79,7 +78,7 @@ func (f *fakeELReader) GetRootIndexFromHash(opts *bind.CallOpts, hash [32]byte)
}

func (f *fakeELReader) GetCurrentClaimableDistributionRoot(
opts *bind.CallOpts,
ctx context.Context,
) (rewardscoordinator.IRewardsCoordinatorDistributionRoot, error) {
// iterate from end to start since we want the latest active root
// and the roots are sorted in ascending order of activation time
Expand All @@ -92,8 +91,8 @@ func (f *fakeELReader) GetCurrentClaimableDistributionRoot(
return rewardscoordinator.IRewardsCoordinatorDistributionRoot{}, errors.New("no active distribution root found")
}

func (f *fakeELReader) CurrRewardsCalculationEndTimestamp(opts *bind.CallOpts) (uint32, error) {
rootLen, err := f.GetDistributionRootsLength(opts)
func (f *fakeELReader) CurrRewardsCalculationEndTimestamp(ctx context.Context) (uint32, error) {
rootLen, err := f.GetDistributionRootsLength(ctx)
if err != nil {
return 0, err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/rewards/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/Layr-Labs/eigensdk-go/logging"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

Expand All @@ -32,7 +31,7 @@ import (
type ClaimType string

type ELReader interface {
GetCumulativeClaimed(opts *bind.CallOpts, earnerAddress, tokenAddress gethcommon.Address) (*big.Int, error)
GetCumulativeClaimed(ctx context.Context, earnerAddress, tokenAddress gethcommon.Address) (*big.Int, error)
}

const (
Expand Down Expand Up @@ -170,7 +169,7 @@ func getClaimedRewards(
) (map[gethcommon.Address]*big.Int, error) {
claimedRewards := make(map[gethcommon.Address]*big.Int)
for address := range allRewards {
claimed, err := elReader.GetCumulativeClaimed(&bind.CallOpts{Context: ctx}, earnerAddress, address)
claimed, err := elReader.GetCumulativeClaimed(ctx, earnerAddress, address)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/rewards/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -88,7 +87,7 @@ type FakeELReader struct {
}

func (f *FakeELReader) GetCumulativeClaimed(
opts *bind.CallOpts,
ctx context.Context,
earnerAddress, tokenAddress gethcommon.Address,
) (*big.Int, error) {
if f.shouldError {
Expand Down
Loading