From dfea8cd507117a55ab9296d55ba421bfd9bc3c26 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 3 Jan 2024 16:53:27 -0600 Subject: [PATCH] feat!: bring back the cliff vesting command (#111) #271 --- 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 43927206c5efb..918134cb9aa6c 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "strconv" + "time" "github.com/spf13/cobra" @@ -16,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -43,6 +45,7 @@ func GetTxCmd(ac address.Codec) *cobra.Command { NewMsgCreatePermanentLockedAccountCmd(ac), NewMsgCreatePeriodicVestingAccountCmd(ac), NewMsgCreateClawbackVestingAccountCmd(), + NewMsgCreateCliffVestingAccountCmd(), NewMsgClawbackCmd(), ) @@ -375,3 +378,50 @@ func NewMsgClawbackCmd() *cobra.Command { flags.AddTxFlagsToCmd(cmd) 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 { + err = errors.Wrap(err, "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 +}