2020-04-24 15:20:34 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2020-04-30 14:23:41 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-04-24 15:20:34 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
2020-04-24 15:20:34 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
2020-04-24 15:20:34 +00:00
|
|
|
)
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
const multiplierFlag = "multiplier"
|
|
|
|
const multiplierFlagShort = "m"
|
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
// GetTxCmd returns the transaction cli commands for the incentive module
|
2022-01-08 00:39:27 +00:00
|
|
|
func GetTxCmd() *cobra.Command {
|
2020-04-24 15:20:34 +00:00
|
|
|
incentiveTxCmd := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: "transaction commands for the incentive module",
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
cmds := []*cobra.Command{
|
|
|
|
getCmdClaimCdp(),
|
|
|
|
getCmdClaimHard(),
|
|
|
|
getCmdClaimDelegator(),
|
|
|
|
getCmdClaimSwap(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
incentiveTxCmd.AddCommand(cmds...)
|
2020-04-24 15:20:34 +00:00
|
|
|
|
|
|
|
return incentiveTxCmd
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func getCmdClaimCdp() *cobra.Command {
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "claim-cdp [multiplier]",
|
|
|
|
Short: "claim USDX minting rewards using a given multiplier",
|
|
|
|
Long: `Claim sender's outstanding USDX minting rewards using a given multiplier.`,
|
2022-01-08 00:39:27 +00:00
|
|
|
Example: fmt.Sprintf(` $ %s tx %s claim-cdp large`, version.AppName, types.ModuleName),
|
2021-07-15 14:05:54 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
2020-04-24 15:20:34 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
2020-04-24 15:20:34 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-06-07 14:04:32 +00:00
|
|
|
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
|
|
multiplier := args[0]
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
msg := types.NewMsgClaimUSDXMintingReward(sender.String(), multiplier)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
|
2021-07-15 14:05:54 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func getCmdClaimHard() *cobra.Command {
|
2021-08-04 14:55:29 +00:00
|
|
|
var denomsToClaim map[string]string
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2021-08-04 14:55:29 +00:00
|
|
|
Use: "claim-hard",
|
|
|
|
Short: "claim sender's Hard module rewards using given multipliers",
|
|
|
|
Long: `Claim sender's outstanding Hard rewards for deposit/borrow using given multipliers`,
|
|
|
|
Example: strings.Join([]string{
|
2022-01-08 00:39:27 +00:00
|
|
|
fmt.Sprintf(` $ %s tx %s claim-hard --%s hard=large --%s ukava=small`, version.AppName, types.ModuleName, multiplierFlag, multiplierFlag),
|
|
|
|
fmt.Sprintf(` $ %s tx %s claim-hard --%s hard=large,ukava=small`, version.AppName, types.ModuleName, multiplierFlag),
|
2021-08-04 14:55:29 +00:00
|
|
|
}, "\n"),
|
|
|
|
Args: cobra.NoArgs,
|
2021-07-15 14:05:54 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
2021-06-07 14:04:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sender := cliCtx.GetFromAddress()
|
2021-08-04 14:55:29 +00:00
|
|
|
selections := types.NewSelectionsFromMap(denomsToClaim)
|
2021-06-07 14:04:32 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
msg := types.NewMsgClaimHardReward(sender.String(), selections)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
2021-06-07 14:04:32 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
|
2020-04-24 15:20:34 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
cmd.Flags().StringToStringVarP(&denomsToClaim, multiplierFlag, multiplierFlagShort, nil, "specify the denoms to claim, each with a multiplier lockup")
|
2022-01-08 00:39:27 +00:00
|
|
|
if err := cmd.MarkFlagRequired(multiplierFlag); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-07-15 14:05:54 +00:00
|
|
|
return cmd
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
2021-01-26 11:52:34 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func getCmdClaimDelegator() *cobra.Command {
|
2021-08-04 14:55:29 +00:00
|
|
|
var denomsToClaim map[string]string
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2021-08-04 14:55:29 +00:00
|
|
|
Use: "claim-delegator",
|
|
|
|
Short: "claim sender's non-sdk delegator rewards using given multipliers",
|
|
|
|
Long: `Claim sender's outstanding delegator rewards using given multipliers`,
|
2021-07-15 14:05:54 +00:00
|
|
|
Example: strings.Join([]string{
|
2022-01-08 00:39:27 +00:00
|
|
|
fmt.Sprintf(` $ %s tx %s claim-delegator --%s hard=large --%s swp=small`, version.AppName, types.ModuleName, multiplierFlag, multiplierFlag),
|
|
|
|
fmt.Sprintf(` $ %s tx %s claim-delegator --%s hard=large,swp=small`, version.AppName, types.ModuleName, multiplierFlag),
|
2021-07-15 14:05:54 +00:00
|
|
|
}, "\n"),
|
2021-08-04 14:55:29 +00:00
|
|
|
Args: cobra.NoArgs,
|
2021-01-26 11:52:34 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
2021-07-15 14:05:54 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sender := cliCtx.GetFromAddress()
|
2021-08-04 14:55:29 +00:00
|
|
|
selections := types.NewSelectionsFromMap(denomsToClaim)
|
2021-07-15 14:05:54 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
msg := types.NewMsgClaimDelegatorReward(sender.String(), selections)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
|
2021-01-26 11:52:34 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
cmd.Flags().StringToStringVarP(&denomsToClaim, multiplierFlag, multiplierFlagShort, nil, "specify the denoms to claim, each with a multiplier lockup")
|
2022-01-08 00:39:27 +00:00
|
|
|
if err := cmd.MarkFlagRequired(multiplierFlag); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-07-15 14:05:54 +00:00
|
|
|
return cmd
|
2021-01-26 11:52:34 +00:00
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func getCmdClaimSwap() *cobra.Command {
|
2021-08-04 14:55:29 +00:00
|
|
|
var denomsToClaim map[string]string
|
2021-07-07 16:50:14 +00:00
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
cmd := &cobra.Command{
|
2021-08-04 14:55:29 +00:00
|
|
|
Use: "claim-swap",
|
|
|
|
Short: "claim sender's swap rewards using given multipliers",
|
|
|
|
Long: `Claim sender's outstanding swap rewards using given multipliers`,
|
2021-07-15 14:05:54 +00:00
|
|
|
Example: strings.Join([]string{
|
2022-01-08 00:39:27 +00:00
|
|
|
fmt.Sprintf(` $ %s tx %s claim-swap --%s swp=large --%s ukava=small`, version.AppName, types.ModuleName, multiplierFlag, multiplierFlag),
|
|
|
|
fmt.Sprintf(` $ %s tx %s claim-swap --%s swp=large,ukava=small`, version.AppName, types.ModuleName, multiplierFlag),
|
2021-07-15 14:05:54 +00:00
|
|
|
}, "\n"),
|
2021-08-04 14:55:29 +00:00
|
|
|
Args: cobra.NoArgs,
|
2021-07-07 16:50:14 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
2021-07-07 16:50:14 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sender := cliCtx.GetFromAddress()
|
2021-08-04 14:55:29 +00:00
|
|
|
selections := types.NewSelectionsFromMap(denomsToClaim)
|
2021-07-07 16:50:14 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
msg := types.NewMsgClaimSwapReward(sender.String(), selections)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
2021-07-07 16:50:14 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
|
2021-07-07 16:50:14 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
cmd.Flags().StringToStringVarP(&denomsToClaim, multiplierFlag, multiplierFlagShort, nil, "specify the denoms to claim, each with a multiplier lockup")
|
2022-01-08 00:39:27 +00:00
|
|
|
if err := cmd.MarkFlagRequired(multiplierFlag); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-07-15 14:05:54 +00:00
|
|
|
return cmd
|
2021-07-07 16:50:14 +00:00
|
|
|
}
|