Skip to content

Commit

Permalink
feat(validator): remove the limit of validator subcommand amount flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seolaoh committed Apr 6, 2024
1 parent 05d5e24 commit 332889c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions kroma-validator/cmd/balance/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package balance

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

Expand All @@ -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 {
Expand All @@ -28,27 +29,32 @@ 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
}

return nil
}

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
}

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions kroma-validator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 332889c

Please sign in to comment.