0g-chain/x/earn/client/cli/tx.go

230 lines
5.9 KiB
Go
Raw Normal View History

package cli
import (
"fmt"
feat: add proposals for community pool deposits/withdrawals (#1304) * feat: community pool deposit/withdraw proposals * fix: check community pool balance in tests * add new msg type definitions * add msg methods and tests * add module and keeper skeleton * add deposit and withdraw methods (no delegation) * untested depsit/withdraw with delegation methods * add cli cmds * fix cli argument parsing * add tests for delegate/undelegate msgs * emit un/delegate events * add godoc comments * tally handler with liquid staking support * clean up * update for liquid keeper changes * Exclude non-bkava denoms from aggregate underlying ukava calculation * wip Add claim * Add distr keeper and claiming * Add claim test * Update claim test with failures * wip Add staking rewards * -S Fix savings to earn incentive methods * Use a single accural time for all earn incentives * Add additional required liquid methods * Update genesis to only include 1 accrual time for earn * Revert "Update genesis to only include 1 accrual time for earn" This reverts commit cc7e35347298681c0c8a4a0b9bf9b9b296c25531. * Revert "Use a single accural time for all earn incentives" This reverts commit aeb49c4622d4e3d99dc6421c8830932b1b546be9. * Update tests with incentive distribution * Add earn to incentive rewards query * add earn cli tx * Update claim example to use ukava large * add proposal to gov router * fix example tx formating * add proposal handlers to gov app module * fix: define gov router after earn keeper * fix: correct proposal type * remove outdated comment * refactor withdraw so that fee pool is allows adjusted by the actual withdraw amount * fix: lint proto file * use non blocked module account instead of dist acc * add fund mod account to app, enable receiving * update to new withdraw interface * add human readable apy test cases * remove duplicate changes from previous merge * remove deprecated io/ioutil package * standardize proposal type as a pointer (also matches sdk) * minior comments and formatting * use withdraw amount in router msgs Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Draco <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
2022-09-29 17:01:06 +00:00
"strings"
"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"
feat: add proposals for community pool deposits/withdrawals (#1304) * feat: community pool deposit/withdraw proposals * fix: check community pool balance in tests * add new msg type definitions * add msg methods and tests * add module and keeper skeleton * add deposit and withdraw methods (no delegation) * untested depsit/withdraw with delegation methods * add cli cmds * fix cli argument parsing * add tests for delegate/undelegate msgs * emit un/delegate events * add godoc comments * tally handler with liquid staking support * clean up * update for liquid keeper changes * Exclude non-bkava denoms from aggregate underlying ukava calculation * wip Add claim * Add distr keeper and claiming * Add claim test * Update claim test with failures * wip Add staking rewards * -S Fix savings to earn incentive methods * Use a single accural time for all earn incentives * Add additional required liquid methods * Update genesis to only include 1 accrual time for earn * Revert "Update genesis to only include 1 accrual time for earn" This reverts commit cc7e35347298681c0c8a4a0b9bf9b9b296c25531. * Revert "Use a single accural time for all earn incentives" This reverts commit aeb49c4622d4e3d99dc6421c8830932b1b546be9. * Update tests with incentive distribution * Add earn to incentive rewards query * add earn cli tx * Update claim example to use ukava large * add proposal to gov router * fix example tx formating * add proposal handlers to gov app module * fix: define gov router after earn keeper * fix: correct proposal type * remove outdated comment * refactor withdraw so that fee pool is allows adjusted by the actual withdraw amount * fix: lint proto file * use non blocked module account instead of dist acc * add fund mod account to app, enable receiving * update to new withdraw interface * add human readable apy test cases * remove duplicate changes from previous merge * remove deprecated io/ioutil package * standardize proposal type as a pointer (also matches sdk) * minior comments and formatting * use withdraw amount in router msgs Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Draco <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
2022-09-29 17:01:06 +00:00
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/kava-labs/kava/x/earn/types"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
earnTxCmd := &cobra.Command{
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)
}
earnTxCmd.AddCommand(cmds...)
return earnTxCmd
}
func getCmdDeposit() *cobra.Command {
return &cobra.Command{
Use: "deposit [amount] [strategy]",
Short: "deposit coins to an earn vault",
Example: fmt.Sprintf(
`%s tx %s deposit 10000000ukava hard --from <key>`,
version.AppName, types.ModuleName,
),
Args: cobra.ExactArgs(2),
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
}
strategy := types.NewStrategyTypeFromString(args[1])
if !strategy.IsValid() {
return fmt.Errorf("invalid strategy type: %s", args[1])
}
signer := clientCtx.GetFromAddress()
msg := types.NewMsgDeposit(signer.String(), amount, strategy)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
func getCmdWithdraw() *cobra.Command {
return &cobra.Command{
Use: "withdraw [amount] [strategy]",
Short: "withdraw coins from an earn vault",
Example: fmt.Sprintf(
`%s tx %s withdraw 10000000ukava hard --from <key>`,
version.AppName, types.ModuleName,
),
Args: cobra.ExactArgs(2),
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
}
strategy := types.NewStrategyTypeFromString(args[1])
if !strategy.IsValid() {
return fmt.Errorf("invalid strategy type: %s", args[1])
}
fromAddr := clientCtx.GetFromAddress()
msg := types.NewMsgWithdraw(fromAddr.String(), amount, strategy)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
feat: add proposals for community pool deposits/withdrawals (#1304) * feat: community pool deposit/withdraw proposals * fix: check community pool balance in tests * add new msg type definitions * add msg methods and tests * add module and keeper skeleton * add deposit and withdraw methods (no delegation) * untested depsit/withdraw with delegation methods * add cli cmds * fix cli argument parsing * add tests for delegate/undelegate msgs * emit un/delegate events * add godoc comments * tally handler with liquid staking support * clean up * update for liquid keeper changes * Exclude non-bkava denoms from aggregate underlying ukava calculation * wip Add claim * Add distr keeper and claiming * Add claim test * Update claim test with failures * wip Add staking rewards * -S Fix savings to earn incentive methods * Use a single accural time for all earn incentives * Add additional required liquid methods * Update genesis to only include 1 accrual time for earn * Revert "Update genesis to only include 1 accrual time for earn" This reverts commit cc7e35347298681c0c8a4a0b9bf9b9b296c25531. * Revert "Use a single accural time for all earn incentives" This reverts commit aeb49c4622d4e3d99dc6421c8830932b1b546be9. * Update tests with incentive distribution * Add earn to incentive rewards query * add earn cli tx * Update claim example to use ukava large * add proposal to gov router * fix example tx formating * add proposal handlers to gov app module * fix: define gov router after earn keeper * fix: correct proposal type * remove outdated comment * refactor withdraw so that fee pool is allows adjusted by the actual withdraw amount * fix: lint proto file * use non blocked module account instead of dist acc * add fund mod account to app, enable receiving * update to new withdraw interface * add human readable apy test cases * remove duplicate changes from previous merge * remove deprecated io/ioutil package * standardize proposal type as a pointer (also matches sdk) * minior comments and formatting * use withdraw amount in router msgs Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Draco <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
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)
msg, err := govtypes.NewMsgSubmitProposal(content, proposal.Deposit, from)
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)
msg, err := govtypes.NewMsgSubmitProposal(content, proposal.Deposit, from)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
return cmd
}