Skip to content

Commit

Permalink
Merge branch 'jb/withdrawals' of github.com:Layr-Labs/eigenpod-proofs…
Browse files Browse the repository at this point in the history
…-generation into jb/withdrawals
  • Loading branch information
jbrower95 committed Dec 18, 2024
2 parents d2a8aa6 + e271029 commit 45f86ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cli/commands/completeAllWithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error {

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
isExecutable := curBlockNumber >= uint64(withdrawal.StartBlock+minDelay)
isExecutable := curBlockNumber > uint64(withdrawal.StartBlock+minDelay)
if isBeaconWithdrawal && isExecutable {
return &withdrawal
}
Expand Down
37 changes: 13 additions & 24 deletions cli/commands/showWithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package commands
import (
"context"
"math/big"
"time"

lo "github.com/samber/lo"

"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod"
"github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IDelegationManager"
Expand All @@ -15,24 +12,18 @@ import (

type TShowWithdrawalArgs struct {
EthNode string
BeaconNode string
EigenPod string
Strategies common.Address
}

func ShowWithdrawalsCommand(args TShowWithdrawalArgs) error {
ctx := context.Background()
eth, _, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode, false /* isVerbose */)
eth, chainId, err := core.GetEthClient(ctx, args.EthNode)
core.PanicOnError("failed to reach eth and beacon node", err)

curBlock, err := eth.BlockByNumber(ctx, nil) /* head */
core.PanicOnError("failed to load curBlock", err)

genBlock, err := eth.BlockByNumber(ctx, big.NewInt(0)) /* head */
core.PanicOnError("failed to load genesis block", err)

timePerBlockSeconds := float64(curBlock.NumberU64()-genBlock.NumberU64()) / float64(curBlock.Time()-genBlock.Time())

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

Expand All @@ -47,12 +38,11 @@ func ShowWithdrawalsCommand(args TShowWithdrawalArgs) error {

type TWithdrawalInfo struct {
Staker string
Strategies []common.Address
AvailableAfter string
Strategy common.Address
CurrentBlock uint64
AvailableAfterBlock *big.Int
Ready bool
TotalAmountETH *big.Float
TotalAmountWei *big.Float
}

minDelay, err := dm.MinWithdrawalDelayBlocks(nil)
Expand All @@ -61,23 +51,22 @@ func ShowWithdrawalsCommand(args TShowWithdrawalArgs) error {
withdrawalInfo := []TWithdrawalInfo{}

for i, shares := range allWithdrawals.Shares {
withdrawalTotalValueWei := lo.Reduce(shares, func(accum *big.Int, item *big.Int, i int) *big.Int {
return new(big.Int).Add(item, accum)
}, big.NewInt(0))
withdrawal := allWithdrawals.Withdrawals[i]

targetBlock := new(big.Int).SetUint64(uint64(allWithdrawals.Withdrawals[i].StartBlock + minDelay))
// this cli is only for withdrawals of beaconstrategy for a single strategy
if withdrawal.Strategies[0].Cmp(core.BeaconStrategy()) != 0 || len(withdrawal.Strategies) != 1 {
continue
}

blockDeltaSeconds := (targetBlock.Uint64() - curBlock.NumberU64()) * uint64(timePerBlockSeconds)
availableAfter := time.Now().Add(time.Second * time.Duration(blockDeltaSeconds))
targetBlock := new(big.Int).SetUint64(uint64(allWithdrawals.Withdrawals[i].StartBlock + minDelay))

withdrawalInfo = append(withdrawalInfo, TWithdrawalInfo{
TotalAmountETH: core.GweiToEther(core.WeiToGwei(withdrawalTotalValueWei)),
TotalAmountWei: new(big.Float).SetInt(withdrawalTotalValueWei),
Strategies: allWithdrawals.Withdrawals[i].Strategies,
TotalAmountETH: core.GweiToEther(core.WeiToGwei(shares[0])),
Strategy: allWithdrawals.Withdrawals[i].Strategies[0],
Staker: allWithdrawals.Withdrawals[i].Staker.Hex(),
CurrentBlock: curBlock.NumberU64(),
AvailableAfterBlock: targetBlock,
AvailableAfter: availableAfter.String(),
Ready: targetBlock.Uint64() <= curBlock.NumberU64(),
Ready: targetBlock.Uint64() < curBlock.NumberU64(),
})
}

Expand Down
16 changes: 12 additions & 4 deletions cli/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,27 @@ func ForkVersions() map[uint64]string {
}
}

func GetClients(ctx context.Context, node, beaconNodeUri string, enableLogs bool) (*ethclient.Client, BeaconClient, *big.Int, error) {
func GetEthClient(ctx context.Context, node string) (*ethclient.Client, *big.Int, error) {
eth, err := ethclient.Dial(node)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to reach eth --node: %w", err)
return nil, nil, fmt.Errorf("failed to reach eth --node: %w", err)
}

chainId, err := eth.ChainID(ctx)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to fetch chain id: %w", err)
return nil, nil, fmt.Errorf("failed to fetch chain id: %w", err)
}

if chainId == nil || (chainId.Int64() != 17000 && chainId.Int64() != 1) {
return nil, nil, nil, errors.New("this tool only supports the Holesky and Mainnet Ethereum Networks")
return nil, nil, errors.New("this tool only supports the Holesky and Mainnet Ethereum Networks")
}
return eth, chainId, nil
}

func GetClients(ctx context.Context, node, beaconNodeUri string, enableLogs bool) (*ethclient.Client, BeaconClient, *big.Int, error) {
eth, chainId, err := GetEthClient(ctx, node)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to reach eth --node: %w", err)
}

beaconClient, err := GetBeaconClient(beaconNodeUri, enableLogs)
Expand Down

0 comments on commit 45f86ba

Please sign in to comment.