Skip to content

Commit 43d1f84

Browse files
committed
add --amountWei field
1 parent 7f763dd commit 43d1f84

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

cli/commands/queueWithdrawal.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"math/big"
78

@@ -17,6 +18,7 @@ type TQueueWithdrawallArgs struct {
1718
EigenPod string
1819
Sender string
1920
EstimateGas bool
21+
AmountWei uint64
2022
}
2123

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

4244
_reg, err := pod.WithdrawableRestakedExecutionLayerGwei(nil)
4345
core.PanicOnError("failed to load REG", err)
44-
reg := new(big.Int).SetUint64(_reg)
46+
47+
// [withdrawable]RestakedExecutionlayerWei
48+
rew := core.GweiToWei(new(big.Float).SetUint64(_reg))
49+
if args.AmountWei > 0 && new(big.Float).SetUint64(args.AmountWei).Cmp(rew) > 0 {
50+
return errors.New("invalid --amountWei. must be in the range (0, pod.withdrawableRestakedExecutionLayerGwei() as wei]")
51+
}
4552

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

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

52-
_depositShares, err := dm.ConvertToDepositShares(nil, podOwner, []common.Address{core.BeaconStrategy()}, []*big.Int{res.WithdrawableShares[0]})
59+
reg := new(big.Int).SetUint64(_reg)
60+
61+
requestedWithdrawalSizeWei := func() *big.Int {
62+
if args.AmountWei == 0 {
63+
// if AmountWei isn't specified, we withdraw all the shares in the beacon strategy.
64+
return res.WithdrawableShares[0]
65+
}
66+
67+
// if it is specified, we withdraw the specific amount.
68+
return new(big.Int).SetUint64(args.AmountWei)
69+
}()
70+
requestedWithdrawalSizeGwei := core.WeiToGwei(requestedWithdrawalSizeWei)
71+
72+
if requestedWithdrawalSizeGwei.Cmp(new(big.Float).SetInt(res.WithdrawableShares[0])) > 0 {
73+
// requested to withdraw too many shares.
74+
return errors.New("the amount to withdraw is larger than the amount of withdrawable shares in the beacon strategy")
75+
}
76+
77+
_depositShares, err := dm.ConvertToDepositShares(nil, podOwner, []common.Address{core.BeaconStrategy()}, []*big.Int{requestedWithdrawalSizeWei})
5378
core.PanicOnError("failed to compute deposit shares", err)
5479
depositShares := _depositShares[0]
5580

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

62-
core.PanicOnError("failed to load minimum withdrawal delay", err)
63-
6487
depositSharesGwei := core.IGweiToWei(depositShares)
6588

66-
var amountToWithdrawDepositShares *big.Int = new(big.Int)
67-
*amountToWithdrawDepositShares = *depositSharesGwei
89+
var amountToWithdrawDepositSharesGwei *big.Int = new(big.Int)
90+
*amountToWithdrawDepositSharesGwei = *depositSharesGwei
6891

6992
fmt.Printf("In the Native ETH strategy, you have %sETH to be withdrawn.\n", core.GweiToEther(new(big.Float).SetInt(depositSharesGwei)))
7093
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")
7194

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

78101
if !isSimulation {
79-
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))
102+
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))
80103
} else {
81104
fmt.Printf("THIS IS A SIMULATION. No transaction will be recorded onchain.\n")
82105
}
83106
txn, err := dm.QueueWithdrawals(acc.TransactionOptions, []IDelegationManager.IDelegationManagerTypesQueuedWithdrawalParams{
84107
{
85108
Strategies: []common.Address{core.BeaconStrategy()},
86-
DepositShares: []*big.Int{amountToWithdrawDepositShares},
109+
DepositShares: []*big.Int{core.IGweiToWei(amountToWithdrawDepositSharesGwei)},
87110
Withdrawer: podOwner,
88111
},
89112
})

cli/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ var EstimateGasFlag = &cli.BoolFlag{
6060
Destination: &estimateGas,
6161
}
6262

63+
var AmountWeiFlag = &cli.Uint64Flag{
64+
Name: "amountWei",
65+
Aliases: []string{},
66+
Value: 0,
67+
Usage: "The amount, in Wei.",
68+
Destination: &amountWei,
69+
}
70+
6371
// Optional use for commands that support JSON output
6472
var PrintJSONFlag = &cli.BoolFlag{
6573
Name: "json",

cli/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var useJSON = false
1515
var specificValidator uint64 = math.MaxUint64
1616
var estimateGas = false
1717
var slashedValidatorIndex uint64
18+
var amountWei uint64
1819

1920
const DefaultHealthcheckTolerance = float64(5.0)
2021

@@ -224,13 +225,15 @@ func main() {
224225
PodAddressFlag,
225226
SenderPkFlag,
226227
EstimateGasFlag,
228+
AmountWeiFlag,
227229
},
228230
Action: func(_ *cli.Context) error {
229231
return commands.QueueWithdrawalCommand(commands.TQueueWithdrawallArgs{
230232
EthNode: node,
231233
EigenPod: eigenpodAddress,
232234
Sender: sender,
233235
EstimateGas: estimateGas,
236+
AmountWei: amountWei,
234237
})
235238
},
236239
},

0 commit comments

Comments
 (0)