Skip to content

Commit

Permalink
cmd/geth: add restake and update setCommissionRate
Browse files Browse the repository at this point in the history
  • Loading branch information
4000D committed Apr 21, 2020
1 parent a62f3f2 commit 8e3b7a0
Showing 1 changed file with 107 additions and 1 deletion.
108 changes: 107 additions & 1 deletion cmd/geth/stakecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,35 @@ Stake WTON
CAVEAT: <amount> should be a float
NOTE:
use --rootchain.ton, --rootchain.wton, --rootchain.depositmanager, --rootchain.seigmanager flags to use already deployed token contracts
`,
},
{
Name: "restake",
Usage: "Restake pending withdrawal request",
ArgsUsage: "<numRequests?>",
Action: utils.MigrateFlags(restake),
Category: "TON STAKING COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.RootChainUrlFlag,
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.RootChainSenderFlag,
utils.RootChainTONFlag,
utils.RootChainWTONFlag,
utils.RootChainDepositManagerFlag,
utils.RootChainSeigManagerFlag,
utils.RootChainGasPriceFlag,
},
Description: `
geth staking restake <numRequests?>
Restake pending request withdrawal
If <numRequests> is not provided or zero, restake all pending requests
NOTE:
use --rootchain.ton, --rootchain.wton, --rootchain.depositmanager, --rootchain.seigmanager flags to use already deployed token contracts
`,
Expand Down Expand Up @@ -1136,7 +1165,9 @@ func setCommissionRate(ctx *cli.Context) error {

log.Info("Set commission rate", "rootchain", rootchainAddr, "commissionRate", params.ToRayFloat64(rate))

tx, err := seigManager.SetCommissionRate(opt, rootchainAddr, rate)
isCommissionRateNegative := rate.Cmp(big.NewInt(0)) < 0
absRate := new(big.Int).Abs(rate)
tx, err := seigManager.SetCommissionRate(opt, rootchainAddr, absRate, isCommissionRateNegative)
if err != nil {
utils.Fatalf("Failed to send transaction: %v", err)
}
Expand Down Expand Up @@ -1660,6 +1691,81 @@ func stakeWTON(ctx *cli.Context) error {
return nil
}

func restake(ctx *cli.Context) error {
if len(ctx.Args()) > 1 {
utils.Fatalf("Expected 1 or 0 parameters, not %d", len(ctx.Args()))
}

stack, cfg := makeConfigNode(ctx)
opt, backend := initOpts(ctx, stack, &cfg.Pls)

stakedb, err := stack.OpenDatabase("stakingdata", 0, 0, "")
defer stakedb.Close()
if err != nil {
utils.Fatalf("Failed to open database: %v", err)
}
managers := getManagerConfig(stakedb, ctx, true)
rootchainAddr := getRootChainAddr(cfg.Node.DataDir)

var (
n int
numPendingRequests *big.Int
numRequests *big.Int

tx *types.Transaction
)

if len(ctx.Args()) == 1 {
if n, err = strconv.Atoi(ctx.Args().Get(0)); err != nil {
return err
}
}

if (managers.TON == common.Address{}) ||
(managers.WTON == common.Address{}) ||
(managers.DepositManager == common.Address{}) ||
(managers.RootChainRegistry == common.Address{}) ||
(managers.SeigManager == common.Address{}) {
return errors.New("manager contract addresses is empty. please write contracts before register using `geth staking setManagers`")
}

logManagers(managers)

var (
depositManager *depositmanager.DepositManager
)

if depositManager, err = depositmanager.NewDepositManager(managers.DepositManager, backend); err != nil {
utils.Fatalf("Failed to load DepositManager contract: %v", err)
}

if numPendingRequests, err = depositManager.NumPendingRequests(&bind.CallOpts{Pending: false}, rootchainAddr, opt.From); err != nil {
utils.Fatalf("Failed to read the number of pending requests: %v", err)
}

if n == 0 {
numRequests = new(big.Int).Set(numPendingRequests)
} else {
numRequests = big.NewInt(int64(n))
}

if numRequests.Cmp(numPendingRequests) < 0 {
utils.Fatalf("the number of pending request is less than the number of request to restake (pendingRequest=%d, numRequest=%d)", numPendingRequests.Uint64(), numRequests.Uint64())
}

if tx, err = depositManager.RedepositMulti(opt, rootchainAddr, numRequests); err != nil {
return err
}

if err = plasma.WaitTx(backend, tx.Hash()); err != nil {
return err
}

log.Info("Redeposit pending requests", "rootchain", rootchainAddr, "numRequests", numRequests, "tx", tx.Hash())

return nil
}

func requestWithdrawal(ctx *cli.Context) error {
if len(ctx.Args()) > 1 {
utils.Fatalf("Expected 1 or 0 parameters, not %d", len(ctx.Args()))
Expand Down

0 comments on commit 8e3b7a0

Please sign in to comment.