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

[pectra] Eigenpod CLI updates #174

Merged
merged 4 commits into from
Feb 19, 2025
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
6 changes: 3 additions & 3 deletions cli/commands/assignSubmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/fatih/color"
Expand Down Expand Up @@ -39,7 +39,7 @@ func AssignSubmitterCommand(args TAssignSubmitterArgs) error {
return fmt.Errorf("failed to reach eth node for chain id: %w", err)
}

ownerAccount, err := core.PrepareAccount(&args.Sender, chainId, false /* noSend */)
ownerAccount, err := utils.PrepareAccount(&args.Sender, chainId, false /* noSend */)
if err != nil {
return fmt.Errorf("failed to parse --sender: %w", err)
}
Expand All @@ -60,7 +60,7 @@ func AssignSubmitterCommand(args TAssignSubmitterArgs) error {

if !args.NoPrompt {
fmt.Printf("Your pod's current proof submitter is %s.\n", currentSubmitter)
core.PanicIfNoConsent(fmt.Sprintf("This will update your EigenPod to allow %s to submit proofs on its behalf. As the EigenPod's owner, you can always change this later.", newSubmitter))
utils.PanicIfNoConsent(fmt.Sprintf("This will update your EigenPod to allow %s to submit proofs on its behalf. As the EigenPod's owner, you can always change this later.", newSubmitter))
}

txn, err := pod.SetProofSubmitter(ownerAccount.TransactionOptions, newSubmitter)
Expand Down
33 changes: 17 additions & 16 deletions cli/commands/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (

"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/utils"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/fatih/color"
"github.com/pkg/errors"
lo "github.com/samber/lo"
)

type TCheckpointCommandArgs struct {
Expand All @@ -36,31 +37,31 @@ func CheckpointCommand(args TCheckpointCommandArgs) error {
isGasEstimate := args.SimulateTransaction && args.Sender != ""
isVerbose := !args.SimulateTransaction || args.Verbose

eth, beaconClient, chainId, err := core.GetClients(ctx, args.Node, args.BeaconNode, isVerbose)
core.PanicOnError("failed to reach ethereum clients", err)
eth, beaconClient, chainId, err := utils.GetClients(ctx, args.Node, args.BeaconNode, isVerbose)
utils.PanicOnError("failed to reach ethereum clients", err)

currentCheckpoint, err := core.GetCurrentCheckpoint(args.EigenpodAddress, eth)
core.PanicOnError("failed to load checkpoint", err)
currentCheckpoint, err := utils.GetCurrentCheckpoint(args.EigenpodAddress, eth)
utils.PanicOnError("failed to load checkpoint", err)

eigenpod, err := EigenPod.NewEigenPod(common.HexToAddress(args.EigenpodAddress), eth)
core.PanicOnError("failed to connect to eigenpod", err)
utils.PanicOnError("failed to connect to eigenpod", err)

if currentCheckpoint == 0 {
if len(args.Sender) > 0 || args.SimulateTransaction {
if !args.NoPrompt && !args.SimulateTransaction {
core.PanicIfNoConsent(core.StartCheckpointProofConsent())
utils.PanicIfNoConsent(utils.StartCheckpointProofConsent())
}

txn, err := core.StartCheckpoint(ctx, args.EigenpodAddress, args.Sender, chainId, eth, args.ForceCheckpoint, args.SimulateTransaction)
core.PanicOnError("failed to start checkpoint", err)
txn, err := utils.StartCheckpoint(ctx, args.EigenpodAddress, args.Sender, chainId, eth, args.ForceCheckpoint, args.SimulateTransaction)
utils.PanicOnError("failed to start checkpoint", err)

if !args.SimulateTransaction {
color.Green("starting checkpoint: %s.. (waiting for txn to be mined)", txn.Hash().Hex())
bind.WaitMined(ctx, eth, txn)
color.Green("started checkpoint! txn: %s", txn.Hash().Hex())
} else {
gas := txn.Gas()
printAsJSON([]Transaction{
PrintAsJSON([]Transaction{
{
Type: "checkpoint_start",
To: txn.To().Hex(),
Expand All @@ -78,11 +79,11 @@ func CheckpointCommand(args TCheckpointCommandArgs) error {
}

newCheckpoint, err := eigenpod.CurrentCheckpointTimestamp(nil)
core.PanicOnError("failed to fetch current checkpoint", err)
utils.PanicOnError("failed to fetch current checkpoint", err)

currentCheckpoint = newCheckpoint
} else {
core.PanicOnError("no checkpoint active and no private key provided to start one", errors.New("no checkpoint"))
utils.PanicOnError("no checkpoint active and no private key provided to start one", errors.New("no checkpoint"))
}
}

Expand All @@ -91,24 +92,24 @@ func CheckpointCommand(args TCheckpointCommandArgs) error {
}

proof, err := core.GenerateCheckpointProof(ctx, args.EigenpodAddress, eth, chainId, beaconClient, isVerbose)
core.PanicOnError("failed to generate checkpoint proof", err)
utils.PanicOnError("failed to generate checkpoint proof", err)

txns, err := core.SubmitCheckpointProof(ctx, args.Sender, args.EigenpodAddress, chainId, proof, eth, args.BatchSize, args.NoPrompt, args.SimulateTransaction, args.Verbose)
if args.SimulateTransaction {
printableTxns := utils.Map(txns, func(txn *types.Transaction, _ uint64) Transaction {
printableTxns := lo.Map(txns, func(txn *types.Transaction, _ int) Transaction {
return Transaction{
To: txn.To().Hex(),
CallData: common.Bytes2Hex(txn.Data()),
Type: "checkpoint_proof",
}
})
printAsJSON(printableTxns)
PrintAsJSON(printableTxns)
} else {
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
}
}
core.PanicOnError("an error occurred while submitting your checkpoint proofs", err)
utils.PanicOnError("an error occurred while submitting your checkpoint proofs", err)

return nil
}
35 changes: 18 additions & 17 deletions cli/commands/completeAllWithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod"
"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IDelegationManager"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -43,35 +44,35 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error {
isSimulation := args.EstimateGas

eth, err := ethclient.DialContext(ctx, args.EthNode)
core.PanicOnError("failed to reach eth node", err)
utils.PanicOnError("failed to reach eth node", err)

chainId, err := eth.ChainID(ctx)
core.PanicOnError("failed to load chainId", err)
utils.PanicOnError("failed to load chainId", err)

acc, err := core.PrepareAccount(&args.Sender, chainId, isSimulation)
core.PanicOnError("failed to parse private key", err)
acc, err := utils.PrepareAccount(&args.Sender, chainId, isSimulation)
utils.PanicOnError("failed to parse private key", err)

curBlockNumber, err := eth.BlockNumber(ctx)
core.PanicOnError("failed to load current block number", err)
utils.PanicOnError("failed to load current block number", err)

pod, err := EigenPod.NewEigenPod(common.HexToAddress(args.EigenPod), eth)
core.PanicOnError("failed to reach eigenpod", err)
utils.PanicOnError("failed to reach eigenpod", err)

reg, err := pod.WithdrawableRestakedExecutionLayerGwei(nil)
core.PanicOnError("failed to fetch REG", err)
rew := core.GweiToWei(new(big.Float).SetUint64(reg))
utils.PanicOnError("failed to fetch REG", err)
rew := utils.GweiToWei(new(big.Float).SetUint64(reg))

podOwner, err := pod.PodOwner(nil)
core.PanicOnError("failed to read podOwner", err)
utils.PanicOnError("failed to read podOwner", err)

delegationManager, err := IDelegationManager.NewIDelegationManager(DelegationManager(chainId), eth)
core.PanicOnError("failed to reach delegation manager", err)
utils.PanicOnError("failed to reach delegation manager", err)

minDelay, err := delegationManager.MinWithdrawalDelayBlocks(nil)
core.PanicOnError("failed to read MinWithdrawalDelayBlocks", err)
utils.PanicOnError("failed to read MinWithdrawalDelayBlocks", err)

queuedWithdrawals, err := delegationManager.GetQueuedWithdrawals(nil, podOwner)
core.PanicOnError("failed to read queuedWithdrawals", err)
utils.PanicOnError("failed to read queuedWithdrawals", err)

eligibleWithdrawals := lo.Map(queuedWithdrawals.Withdrawals, func(withdrawal IDelegationManager.IDelegationManagerTypesWithdrawal, index int) *IDelegationManager.IDelegationManagerTypesWithdrawal {
isBeaconWithdrawal := len(withdrawal.Strategies) == 1 && withdrawal.Strategies[0].Cmp(core.BeaconStrategy()) == 0
Expand Down Expand Up @@ -128,10 +129,10 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error {

fmt.Printf("Your podOwner(%s) has %d withdrawal(s) that can be completed right now.\n", podOwner.Hex(), len(affordedWithdrawals))
runningSumWeiInt, _ := runningSumWei.Int(nil)
fmt.Printf("Total ETH on all withdrawals: %sETH\n", core.GweiToEther(core.WeiToGwei(runningSumWeiInt)).String())
fmt.Printf("Total ETH on all withdrawals: %sETH\n", utils.GweiToEther(utils.WeiToGwei(runningSumWeiInt)).String())

if !isSimulation {
core.PanicIfNoConsent("Would you like to continue?")
utils.PanicIfNoConsent("Would you like to continue?")
} else {
color.Yellow("THIS IS A SIMULATION. No transaction will be recorded onchain.\n")
}
Expand All @@ -149,15 +150,15 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error {
})

txn, err := delegationManager.CompleteQueuedWithdrawals(acc.TransactionOptions, withdrawals, tokens, receiveAsTokens)
core.PanicOnError("CompleteQueuedWithdrawals failed.", err)
utils.PanicOnError("CompleteQueuedWithdrawals failed.", err)

if !isSimulation {
_, err := bind.WaitMined(ctx, eth, txn)
core.PanicOnError("waitMined failed", err)
utils.PanicOnError("waitMined failed", err)

color.Green("%s\n", txn.Hash().Hex())
} else {
printAsJSON(Transaction{
PrintAsJSON(Transaction{
Type: "complete-withdrawals",
To: txn.To().Hex(),
CallData: common.Bytes2Hex(txn.Data()),
Expand Down
19 changes: 10 additions & 9 deletions cli/commands/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"math/big"

"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/utils"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/fatih/color"
lo "github.com/samber/lo"
)

type TCredentialCommandArgs struct {
Expand All @@ -37,8 +38,8 @@ func CredentialsCommand(args TCredentialCommandArgs) error {
isGasEstimate := args.SimulateTransaction && args.Sender != ""
isVerbose := (!args.UseJSON && !args.SimulateTransaction) || args.Verbose

eth, beaconClient, chainId, err := core.GetClients(ctx, args.Node, args.BeaconNode, isVerbose)
core.PanicOnError("failed to reach ethereum clients", err)
eth, beaconClient, chainId, err := utils.GetClients(ctx, args.Node, args.BeaconNode, isVerbose)
utils.PanicOnError("failed to reach ethereum clients", err)

var specificValidatorIndex *big.Int = nil
if args.SpecificValidator != math.MaxUint64 && args.SpecificValidator != 0 {
Expand All @@ -51,13 +52,13 @@ func CredentialsCommand(args TCredentialCommandArgs) error {
validatorProofs, oracleBeaconTimestamp, err := core.GenerateValidatorProof(ctx, args.EigenpodAddress, eth, chainId, beaconClient, specificValidatorIndex, isVerbose)

if err != nil || validatorProofs == nil {
core.PanicOnError("Failed to generate validator proof", err)
core.Panic("no inactive validators")
utils.PanicOnError("Failed to generate validator proof", err)
utils.Panic("no inactive validators")
}

if len(args.Sender) != 0 || args.SimulateTransaction {
txns, indices, err := core.SubmitValidatorProof(ctx, args.Sender, args.EigenpodAddress, chainId, eth, args.BatchSize, validatorProofs, oracleBeaconTimestamp, args.NoPrompt, args.SimulateTransaction, isVerbose)
core.PanicOnError(fmt.Sprintf("failed to %s validator proof", func() string {
utils.PanicOnError(fmt.Sprintf("failed to %s validator proof", func() string {
if args.SimulateTransaction {
return "simulate"
} else {
Expand All @@ -66,7 +67,7 @@ func CredentialsCommand(args TCredentialCommandArgs) error {
}()), err)

if args.SimulateTransaction {
out := utils.Map(txns, func(txn *types.Transaction, _ uint64) CredentialProofTransaction {
out := lo.Map(txns, func(txn *types.Transaction, _ int) CredentialProofTransaction {
gas := txn.Gas()
return CredentialProofTransaction{
Transaction: Transaction{
Expand All @@ -80,12 +81,12 @@ func CredentialsCommand(args TCredentialCommandArgs) error {
return nil
}(),
},
ValidatorIndices: utils.Map(utils.Flatten(indices), func(index *big.Int, _ uint64) uint64 {
ValidatorIndices: lo.Map(lo.Flatten(indices), func(index *big.Int, _ int) uint64 {
return index.Uint64()
}),
}
})
printAsJSON(out)
PrintAsJSON(out)
} else {
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
Expand Down
9 changes: 5 additions & 4 deletions cli/commands/findStalePods.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/utils"
"github.com/fatih/color"
)

Expand All @@ -17,14 +18,14 @@ type TFindStalePodsCommandArgs struct {

func FindStalePodsCommand(args TFindStalePodsCommandArgs) error {
ctx := context.Background()
eth, beacon, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode /* verbose */, args.Verbose)
core.PanicOnError("failed to dial clients", err)
eth, beacon, chainId, err := utils.GetClients(ctx, args.EthNode, args.BeaconNode /* verbose */, args.Verbose)
utils.PanicOnError("failed to dial clients", err)

results, err := core.FindStaleEigenpods(ctx, eth, args.EthNode, beacon, chainId, args.Verbose, args.Tolerance)
core.PanicOnError("failed to find stale eigenpods", err)
utils.PanicOnError("failed to find stale eigenpods", err)

if !args.Verbose {
printAsJSON(results)
PrintAsJSON(results)
return nil
}

Expand Down
Loading
Loading