2022-07-20 23:14:43 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-09-29 17:01:06 +00:00
|
|
|
"strings"
|
2022-07-20 23:14:43 +00:00
|
|
|
|
|
|
|
"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/version"
|
2023-04-04 00:08:45 +00:00
|
|
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2022-07-20 23:14:43 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetTxCmd returns the transaction commands for this module
|
|
|
|
func GetTxCmd() *cobra.Command {
|
2022-07-28 16:39:57 +00:00
|
|
|
earnTxCmd := &cobra.Command{
|
2022-07-20 23:14:43 +00:00
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmds := []*cobra.Command{
|
|
|
|
getCmdDeposit(),
|
|
|
|
getCmdWithdraw(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
}
|
|
|
|
|
2022-07-28 16:39:57 +00:00
|
|
|
earnTxCmd.AddCommand(cmds...)
|
2022-07-20 23:14:43 +00:00
|
|
|
|
2022-07-28 16:39:57 +00:00
|
|
|
return earnTxCmd
|
2022-07-20 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getCmdDeposit() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2022-09-12 16:43:59 +00:00
|
|
|
Use: "deposit [amount] [strategy]",
|
2022-07-20 23:14:43 +00:00
|
|
|
Short: "deposit coins to an earn vault",
|
|
|
|
Example: fmt.Sprintf(
|
2022-09-12 16:43:59 +00:00
|
|
|
`%s tx %s deposit 10000000ukava hard --from <key>`,
|
2022-07-20 23:14:43 +00:00
|
|
|
version.AppName, types.ModuleName,
|
|
|
|
),
|
2022-09-12 16:43:59 +00:00
|
|
|
Args: cobra.ExactArgs(2),
|
2022-07-20 23:14:43 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
amount, err := sdk.ParseCoinNormalized(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-12 16:43:59 +00:00
|
|
|
strategy := types.NewStrategyTypeFromString(args[1])
|
|
|
|
if !strategy.IsValid() {
|
|
|
|
return fmt.Errorf("invalid strategy type: %s", args[1])
|
|
|
|
}
|
|
|
|
|
2022-07-20 23:14:43 +00:00
|
|
|
signer := clientCtx.GetFromAddress()
|
2022-09-12 16:43:59 +00:00
|
|
|
msg := types.NewMsgDeposit(signer.String(), amount, strategy)
|
2022-07-20 23:14:43 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCmdWithdraw() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2022-09-12 16:43:59 +00:00
|
|
|
Use: "withdraw [amount] [strategy]",
|
2022-07-20 23:14:43 +00:00
|
|
|
Short: "withdraw coins from an earn vault",
|
|
|
|
Example: fmt.Sprintf(
|
2022-09-12 16:43:59 +00:00
|
|
|
`%s tx %s withdraw 10000000ukava hard --from <key>`,
|
2022-07-20 23:14:43 +00:00
|
|
|
version.AppName, types.ModuleName,
|
|
|
|
),
|
2022-09-12 16:43:59 +00:00
|
|
|
Args: cobra.ExactArgs(2),
|
2022-07-20 23:14:43 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
amount, err := sdk.ParseCoinNormalized(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-12 16:43:59 +00:00
|
|
|
strategy := types.NewStrategyTypeFromString(args[1])
|
|
|
|
if !strategy.IsValid() {
|
|
|
|
return fmt.Errorf("invalid strategy type: %s", args[1])
|
|
|
|
}
|
|
|
|
|
2022-07-20 23:14:43 +00:00
|
|
|
fromAddr := clientCtx.GetFromAddress()
|
2022-09-12 16:43:59 +00:00
|
|
|
msg := types.NewMsgWithdraw(fromAddr.String(), amount, strategy)
|
2022-07-20 23:14:43 +00:00
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-09-29 17:01:06 +00:00
|
|
|
|
|
|
|
// GetCmdSubmitCommunityPoolDepositProposal implements the command to submit a community-pool deposit proposal
|
|
|
|
func GetCmdSubmitCommunityPoolDepositProposal() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "community-pool-deposit [proposal-file]",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Short: "Submit a community pool deposit proposal",
|
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Submit a community pool deposit proposal along with an initial deposit.
|
|
|
|
The proposal details must be supplied via a JSON file.
|
|
|
|
Example:
|
|
|
|
$ %s tx gov submit-proposal community-pool-deposit <path/to/proposal.json> --from=<key_or_address>
|
|
|
|
Where proposal.json contains:
|
|
|
|
{
|
|
|
|
"title": "Community Pool Deposit",
|
|
|
|
"description": "Deposit some KAVA from community pool!",
|
|
|
|
"amount":
|
|
|
|
{
|
|
|
|
"denom": "ukava",
|
|
|
|
"amount": "100000000000"
|
|
|
|
},
|
|
|
|
"deposit": [
|
|
|
|
{
|
|
|
|
"denom": "ukava",
|
|
|
|
"amount": "1000000000"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
version.AppName,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
proposal, err := ParseCommunityPoolDepositProposalJSON(clientCtx.Codec, args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
from := clientCtx.GetFromAddress()
|
|
|
|
content := types.NewCommunityPoolDepositProposal(proposal.Title, proposal.Description, proposal.Amount)
|
2023-04-04 00:08:45 +00:00
|
|
|
msg, err := govv1beta1.NewMsgSubmitProposal(content, proposal.Deposit, from)
|
2022-09-29 17:01:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCmdSubmitCommunityPoolWithdrawProposal implements the command to submit a community-pool withdraw proposal
|
|
|
|
func GetCmdSubmitCommunityPoolWithdrawProposal() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "community-pool-withdraw [proposal-file]",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Short: "Submit a community pool withdraw proposal",
|
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Submit a community pool withdraw proposal along with an initial deposit.
|
|
|
|
The proposal details must be supplied via a JSON file.
|
|
|
|
Example:
|
|
|
|
$ %s tx gov submit-proposal community-pool-withdraw <path/to/proposal.json> --from=<key_or_address>
|
|
|
|
Where proposal.json contains:
|
|
|
|
{
|
|
|
|
"title": "Community Pool Withdraw",
|
|
|
|
"description": "Withdraw some KAVA from community pool!",
|
|
|
|
"amount":
|
|
|
|
{
|
|
|
|
"denom": "ukava",
|
|
|
|
"amount": "100000000000"
|
|
|
|
},
|
|
|
|
"deposit": [
|
|
|
|
{
|
|
|
|
"denom": "ukava",
|
|
|
|
"amount": "1000000000"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
version.AppName,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
proposal, err := ParseCommunityPoolWithdrawProposalJSON(clientCtx.Codec, args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
from := clientCtx.GetFromAddress()
|
|
|
|
content := types.NewCommunityPoolWithdrawProposal(proposal.Title, proposal.Description, proposal.Amount)
|
2023-04-04 00:08:45 +00:00
|
|
|
msg, err := govv1beta1.NewMsgSubmitProposal(content, proposal.Deposit, from)
|
2022-09-29 17:01:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|