Skip to content

Commit

Permalink
feat!: bring back the cliff vesting command (#111) #271
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Jan 3, 2024
1 parent cc29414 commit 6652b67
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"io/ioutil"
"os"
"strconv"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"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"
)

Expand Down Expand Up @@ -40,6 +42,7 @@ func GetTxCmd() *cobra.Command {
NewMsgCreatePermanentLockedAccountCmd(),
NewMsgCreatePeriodicVestingAccountCmd(),
NewMsgCreateClawbackVestingAccountCmd(),
NewMsgCreateCliffVestingAccountCmd(),
NewMsgClawbackCmd(),
)

Expand Down Expand Up @@ -377,3 +380,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
}

0 comments on commit 6652b67

Please sign in to comment.