From 332889cd3cf68ec7be3ed7f42d4f2e49d4a128dc Mon Sep 17 00:00:00 2001 From: seolaoh Date: Sat, 6 Apr 2024 16:19:16 +0900 Subject: [PATCH] feat(validator): remove the limit of validator subcommand amount flag Since the validator subcommand amount flag had a type of uint64, the flag was limited to a maximum value of about 18 ETH. By changing the type of the amount flag to string, it is possible to use unlimited values for the flag. --- kroma-validator/cmd/balance/cmd.go | 27 +++++++++++++++++++-------- kroma-validator/cmd/main.go | 4 ++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/kroma-validator/cmd/balance/cmd.go b/kroma-validator/cmd/balance/cmd.go index 906c79352..2edad65d2 100644 --- a/kroma-validator/cmd/balance/cmd.go +++ b/kroma-validator/cmd/balance/cmd.go @@ -2,6 +2,7 @@ package balance import ( "context" + "errors" "fmt" "math/big" @@ -16,7 +17,7 @@ import ( ) func Deposit(ctx *cli.Context) error { - depositAmount := ctx.Uint64("amount") + amount := ctx.String("amount") valpoolABI, err := bindings.ValidatorPoolMetaData.GetAbi() if err != nil { @@ -28,7 +29,7 @@ func Deposit(ctx *cli.Context) error { return fmt.Errorf("failed to create deposit transaction data: %w", err) } - if err = sendTransaction(ctx, txData, depositAmount); err != nil { + if err = sendTransaction(ctx, txData, amount); err != nil { return err } @@ -36,19 +37,24 @@ func Deposit(ctx *cli.Context) error { } func Withdraw(ctx *cli.Context) error { - withdrawAmount := ctx.Uint64("amount") + amount := ctx.String("amount") + + withdrawAmount, success := new(big.Int).SetString(amount, 10) + if !success { + return errors.New("failed to parse withdraw amount") + } valpoolABI, err := bindings.ValidatorPoolMetaData.GetAbi() if err != nil { return fmt.Errorf("failed to get ValidatorPool ABI: %w", err) } - txData, err := valpoolABI.Pack("withdraw", new(big.Int).SetUint64(withdrawAmount)) + txData, err := valpoolABI.Pack("withdraw", withdrawAmount) if err != nil { return fmt.Errorf("failed to create withdraw transaction data: %w", err) } - if err = sendTransaction(ctx, txData, 0); err != nil { + if err = sendTransaction(ctx, txData, "0"); err != nil { return err } @@ -66,14 +72,14 @@ func Unbond(ctx *cli.Context) error { return fmt.Errorf("failed to create unbond transaction data: %w", err) } - if err = sendTransaction(ctx, txData, 0); err != nil { + if err = sendTransaction(ctx, txData, "0"); err != nil { return err } return nil } -func sendTransaction(ctx *cli.Context, txData []byte, txValue uint64) error { +func sendTransaction(ctx *cli.Context, txData []byte, txValue string) error { txMgrConfig := txmgr.ReadCLIConfig(ctx) txManager, err := txmgr.NewSimpleTxManager("validator-balance", log.New(), &metrics.NoopTxMetrics{}, txMgrConfig) if err != nil { @@ -85,11 +91,16 @@ func sendTransaction(ctx *cli.Context, txData []byte, txValue uint64) error { return fmt.Errorf("failed to parse ValidatorPool address: %w", err) } + value, success := new(big.Int).SetString(txValue, 10) + if !success { + return errors.New("failed to parse tx value") + } + txCandidate := txmgr.TxCandidate{ TxData: txData, To: &valpoolAddr, GasLimit: 0, - Value: new(big.Int).SetUint64(txValue), + Value: value, } _, err = txManager.Send(context.Background(), txCandidate) diff --git a/kroma-validator/cmd/main.go b/kroma-validator/cmd/main.go index e05a89ec4..16519df2e 100644 --- a/kroma-validator/cmd/main.go +++ b/kroma-validator/cmd/main.go @@ -34,7 +34,7 @@ func main() { Name: "deposit", Usage: "Deposit ETH into ValidatorPool to be used as bond", Flags: []cli.Flag{ - &cli.Uint64Flag{ + &cli.StringFlag{ Name: "amount", Usage: "Amount to deposit into ValidatorPool (in wei)", Required: true, @@ -46,7 +46,7 @@ func main() { Name: "withdraw", Usage: "Withdraw ETH from ValidatorPool", Flags: []cli.Flag{ - &cli.Uint64Flag{ + &cli.StringFlag{ Name: "amount", Usage: "Amount to withdraw from ValidatorPool (in wei)", Required: true,