Skip to content

Commit

Permalink
fix: updates to support latest eigensdk
Browse files Browse the repository at this point in the history
  • Loading branch information
gpabst committed Oct 29, 2024
1 parent 5653e62 commit d170c6d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
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(),

Check failure on line 120 in pkg/operator/get_delegation_approval.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.CalculateDelegationApprovalDigestHash

Check failure on line 120 in pkg/operator/get_delegation_approval.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.CalculateDelegationApprovalDigestHash

Check failure on line 120 in pkg/operator/get_delegation_approval.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.CalculateDelegationApprovalDigestHash

Check failure on line 120 in pkg/operator/get_delegation_approval.go

View workflow job for this annotation

GitHub Actions / Build

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.CalculateDelegationApprovalDigestHash
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)

Check failure on line 93 in pkg/operator/register.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.IsOperatorRegistered

Check failure on line 93 in pkg/operator/register.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.IsOperatorRegistered

Check failure on line 93 in pkg/operator/register.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.IsOperatorRegistered

Check failure on line 93 in pkg/operator/register.go

View workflow job for this annotation

GitHub Actions / Build

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.IsOperatorRegistered
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)

Check failure on line 99 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.IsOperatorRegistered

Check failure on line 99 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.IsOperatorRegistered

Check failure on line 99 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.IsOperatorRegistered

Check failure on line 99 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Build

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.IsOperatorRegistered
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)

Check failure on line 107 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.GetOperatorDetails (typecheck)

Check failure on line 107 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.GetOperatorDetails) (typecheck)

Check failure on line 107 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.GetOperatorDetails

Check failure on line 107 in pkg/operator/status.go

View workflow job for this annotation

GitHub Actions / Build

cannot use context.Background() (value of type "context".Context) as *bind.CallOpts value in argument to reader.GetOperatorDetails
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)

Check failure on line 155 in pkg/rewards/claim.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.CheckClaim

Check failure on line 155 in pkg/rewards/claim.go

View workflow job for this annotation

GitHub Actions / Build

cannot use ctx (variable of type "context".Context) as *bind.CallOpts value in argument to elReader.CheckClaim
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
2 changes: 1 addition & 1 deletion pkg/rewards/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 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

0 comments on commit d170c6d

Please sign in to comment.