Skip to content

Commit

Permalink
major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Feb 19, 2025
1 parent a7bfcb7 commit cbe1404
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 353 deletions.
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
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
44 changes: 23 additions & 21 deletions cli/commands/checkpoint.go → cli/commands/prepectra/checkpoint.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package commands
package prepectra

import (
"context"

"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/commands"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/prepectra"
"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 +38,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{
commands.PrintAsJSON([]commands.Transaction{
{
Type: "checkpoint_start",
To: txn.To().Hex(),
Expand All @@ -78,37 +80,37 @@ 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"))
}
}

if isVerbose {
color.Green("pod has active checkpoint! checkpoint timestamp: %d", currentCheckpoint)
}

proof, err := core.GenerateCheckpointProof(ctx, args.EigenpodAddress, eth, chainId, beaconClient, isVerbose)
core.PanicOnError("failed to generate checkpoint proof", err)
proof, err := prepectra.GenerateCheckpointProof(ctx, args.EigenpodAddress, eth, chainId, beaconClient, isVerbose)
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)
txns, err := prepectra.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 {
return Transaction{
printableTxns := lo.Map(txns, func(txn *types.Transaction, _ int) commands.Transaction {
return commands.Transaction{
To: txn.To().Hex(),
CallData: common.Bytes2Hex(txn.Data()),
Type: "checkpoint_proof",
}
})
printAsJSON(printableTxns)
commands.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
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package commands
package prepectra

import (
"context"
"fmt"
"math"
"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/commands"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/prepectra"
"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 +39,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 @@ -48,16 +50,16 @@ func CredentialsCommand(args TCredentialCommandArgs) error {
}
}

validatorProofs, oracleBeaconTimestamp, err := core.GenerateValidatorProof(ctx, args.EigenpodAddress, eth, chainId, beaconClient, specificValidatorIndex, isVerbose)
validatorProofs, oracleBeaconTimestamp, err := prepectra.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 {
txns, indices, err := prepectra.SubmitValidatorProof(ctx, args.Sender, args.EigenpodAddress, chainId, eth, args.BatchSize, validatorProofs, oracleBeaconTimestamp, args.NoPrompt, args.SimulateTransaction, isVerbose)
utils.PanicOnError(fmt.Sprintf("failed to %s validator proof", func() string {
if args.SimulateTransaction {
return "simulate"
} else {
Expand All @@ -66,10 +68,10 @@ 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) commands.CredentialProofTransaction {
gas := txn.Gas()
return CredentialProofTransaction{
Transaction: Transaction{
return commands.CredentialProofTransaction{
Transaction: commands.Transaction{
Type: "credential_proof",
To: txn.To().Hex(),
CallData: common.Bytes2Hex(txn.Data()),
Expand All @@ -80,12 +82,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)
commands.PrintAsJSON(out)
} else {
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package commands
package prepectra

import (
"context"
"fmt"

"github.com/Layr-Labs/eigenpod-proofs-generation/cli/commands"
"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 +19,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)
commands.PrintAsJSON(results)
return nil
}

Expand Down
Loading

0 comments on commit cbe1404

Please sign in to comment.