Skip to content

Commit

Permalink
add --amountWei field
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Dec 18, 2024

Verified

This commit was signed with the committer’s verified signature.
natanfelles Natan Felles
1 parent 7f763dd commit 43d1f84
Showing 3 changed files with 43 additions and 9 deletions.
41 changes: 32 additions & 9 deletions cli/commands/queueWithdrawal.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package commands

import (
"context"
"errors"
"fmt"
"math/big"

@@ -17,6 +18,7 @@ type TQueueWithdrawallArgs struct {
EigenPod string
Sender string
EstimateGas bool
AmountWei uint64
}

func QueueWithdrawalCommand(args TQueueWithdrawallArgs) error {
@@ -41,15 +43,38 @@ func QueueWithdrawalCommand(args TQueueWithdrawallArgs) error {

_reg, err := pod.WithdrawableRestakedExecutionLayerGwei(nil)
core.PanicOnError("failed to load REG", err)
reg := new(big.Int).SetUint64(_reg)

// [withdrawable]RestakedExecutionlayerWei
rew := core.GweiToWei(new(big.Float).SetUint64(_reg))
if args.AmountWei > 0 && new(big.Float).SetUint64(args.AmountWei).Cmp(rew) > 0 {
return errors.New("invalid --amountWei. must be in the range (0, pod.withdrawableRestakedExecutionLayerGwei() as wei]")
}

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

res, err := dm.GetWithdrawableShares(nil, podOwner, []common.Address{core.BeaconStrategy()})
core.PanicOnError("failed to read beacon strategy withdrawable shares", err)

_depositShares, err := dm.ConvertToDepositShares(nil, podOwner, []common.Address{core.BeaconStrategy()}, []*big.Int{res.WithdrawableShares[0]})
reg := new(big.Int).SetUint64(_reg)

requestedWithdrawalSizeWei := func() *big.Int {
if args.AmountWei == 0 {
// if AmountWei isn't specified, we withdraw all the shares in the beacon strategy.
return res.WithdrawableShares[0]
}

// if it is specified, we withdraw the specific amount.
return new(big.Int).SetUint64(args.AmountWei)
}()
requestedWithdrawalSizeGwei := core.WeiToGwei(requestedWithdrawalSizeWei)

if requestedWithdrawalSizeGwei.Cmp(new(big.Float).SetInt(res.WithdrawableShares[0])) > 0 {
// requested to withdraw too many shares.
return errors.New("the amount to withdraw is larger than the amount of withdrawable shares in the beacon strategy")
}

_depositShares, err := dm.ConvertToDepositShares(nil, podOwner, []common.Address{core.BeaconStrategy()}, []*big.Int{requestedWithdrawalSizeWei})
core.PanicOnError("failed to compute deposit shares", err)
depositShares := _depositShares[0]

@@ -59,31 +84,29 @@ func QueueWithdrawalCommand(args TQueueWithdrawallArgs) error {
curBlock, err := eth.BlockNumber(ctx)
core.PanicOnError("failed to load current block number", err)

core.PanicOnError("failed to load minimum withdrawal delay", err)

depositSharesGwei := core.IGweiToWei(depositShares)

var amountToWithdrawDepositShares *big.Int = new(big.Int)
*amountToWithdrawDepositShares = *depositSharesGwei
var amountToWithdrawDepositSharesGwei *big.Int = new(big.Int)
*amountToWithdrawDepositSharesGwei = *depositSharesGwei

fmt.Printf("In the Native ETH strategy, you have %sETH to be withdrawn.\n", core.GweiToEther(new(big.Float).SetInt(depositSharesGwei)))
fmt.Printf("NOTE: If you were or become slashed on EigenLayer during the withdrawal period, the total amount received will be less any slashed amount.\n")

if depositSharesGwei.Cmp(reg) > 0 {
fmt.Printf("Queueing a partial withdrawal. Your pod only had %sETH available to satisfy withdrawals.", core.GweiToEther(new(big.Float).SetInt(reg)).String())
fmt.Printf("Checkpointing may update this balance, if you have any uncheckpointed native eth or beacon rewards.")
*amountToWithdrawDepositShares = *reg
*amountToWithdrawDepositSharesGwei = *reg
}

if !isSimulation {
core.PanicIfNoConsent(fmt.Sprintf("Would you like to queue a withdrawal %sETH from the Native ETH strategy? This will be withdrawable after approximately block #%d (current block: %d)\n", amountToWithdrawDepositShares, curBlock+uint64(minWithdrawalDelay), curBlock))
core.PanicIfNoConsent(fmt.Sprintf("Would you like to queue a withdrawal %sETH from the Native ETH strategy? This will be withdrawable after approximately block #%d (current block: %d)\n", core.GweiToEther(new(big.Float).SetInt(amountToWithdrawDepositSharesGwei)), curBlock+uint64(minWithdrawalDelay), curBlock))
} else {
fmt.Printf("THIS IS A SIMULATION. No transaction will be recorded onchain.\n")
}
txn, err := dm.QueueWithdrawals(acc.TransactionOptions, []IDelegationManager.IDelegationManagerTypesQueuedWithdrawalParams{
{
Strategies: []common.Address{core.BeaconStrategy()},
DepositShares: []*big.Int{amountToWithdrawDepositShares},
DepositShares: []*big.Int{core.IGweiToWei(amountToWithdrawDepositSharesGwei)},
Withdrawer: podOwner,
},
})
8 changes: 8 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
@@ -60,6 +60,14 @@ var EstimateGasFlag = &cli.BoolFlag{
Destination: &estimateGas,
}

var AmountWeiFlag = &cli.Uint64Flag{
Name: "amountWei",
Aliases: []string{},
Value: 0,
Usage: "The amount, in Wei.",
Destination: &amountWei,
}

// Optional use for commands that support JSON output
var PrintJSONFlag = &cli.BoolFlag{
Name: "json",
3 changes: 3 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ var useJSON = false
var specificValidator uint64 = math.MaxUint64
var estimateGas = false
var slashedValidatorIndex uint64
var amountWei uint64

const DefaultHealthcheckTolerance = float64(5.0)

@@ -224,13 +225,15 @@ func main() {
PodAddressFlag,
SenderPkFlag,
EstimateGasFlag,
AmountWeiFlag,
},
Action: func(_ *cli.Context) error {
return commands.QueueWithdrawalCommand(commands.TQueueWithdrawallArgs{
EthNode: node,
EigenPod: eigenpodAddress,
Sender: sender,
EstimateGas: estimateGas,
AmountWei: amountWei,
})
},
},

0 comments on commit 43d1f84

Please sign in to comment.