From 4022b6a36c66d34b6a05ab3a2d1238ccf941c11b Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Mon, 14 Feb 2022 16:34:51 -0600 Subject: [PATCH] Add a command to make cliff lock vesting easier (#111) --- x/auth/vesting/client/cli/tx.go | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index 686a941e5de2..16353247bbdb 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -1,7 +1,9 @@ package cli import ( + "fmt" "strconv" + "time" "github.com/spf13/cobra" @@ -29,6 +31,7 @@ func GetTxCmd() *cobra.Command { txCmd.AddCommand( NewMsgCreateVestingAccountCmd(), + NewMsgCreateCliffVestingAccountCmd(), ) return txCmd @@ -79,3 +82,50 @@ timestamp.`, return cmd } + +// NewMsgCreateDelayedVestingAccountCmd returns a CLI command handler for creating a +// NewMsgCreateDelayedVestingAccountCmd transaction. +// This is hacky, but meant to mitigate the pain of a very specific use case. +// Namely, make it easy to make cliff locks to an address. +func NewMsgCreateCliffVestingAccountCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-cliff-vesting-account [to_address] [amount] [cliff_duration]", + Short: "Create a new cliff vesting account funded with an allocation of tokens.", + Long: `Create a new delayed vesting account funded with an allocation of tokens. All vesting accouts created will have their start time +set by the committed block's time. The cliff duration should be specified in hours.`, + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + toAddr, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + amount, err := sdk.ParseCoinsNormalized(args[1]) + if err != nil { + return err + } + + cliffDuration, err := time.ParseDuration(args[2]) + if err != nil { + fmt.Println("duration incorrectly formatted, see https://pkg.go.dev/time#ParseDuration") + return err + } + cliffVesting := true + + endTime := time.Now().Add(cliffDuration) + endEpochTime := endTime.Unix() + + msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endEpochTime, cliffVesting) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +}