mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
38a98ac4fc
* split up payout.go file * extract genesis builders to new testutil package * move claim integration tests out of keeper * convert claim integration tests to handler tests * combine claim usdx minting keeper methods * combine hard claim keeper methods * combine delegator claim keeper methods * add multiply coins helper method * rename file to better match contents * add basic claiming unit tests * add claiming subset of delegator reward denoms * refactor msg tests * add msg ValidateBasic tests * connect swap hooks into keeper methods * tidy up delegator handler tests * add swap claiming msgs and keeper method * add swap claiming to client * add subset claiming to other msg types * split up handler test file * connect up subset claiming for swap * make multiplier name validation more strict * fix: struct tag typo in swap incentives * connect up subset claiming for hard * connect up subset claiming for delegator * fix: register cli tx routes for swp claiming * fix claim amount in claim event * fix token name in cli help docs * remove unused field in msg tests * tidy up swap and delegator handler tests * refactor hard handler tests * refactor usdx handler tests * remove unused constant Co-authored-by: karzak <kjydavis3@gmail.com>
313 lines
12 KiB
Go
313 lines
12 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
)
|
|
|
|
// GetTxCmd returns the transaction cli commands for the incentive module
|
|
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|
incentiveTxCmd := &cobra.Command{
|
|
Use: types.ModuleName,
|
|
Short: "transaction commands for the incentive module",
|
|
}
|
|
|
|
incentiveTxCmd.AddCommand(flags.PostCommands(
|
|
getCmdClaimCdp(cdc),
|
|
getCmdClaimCdpVVesting(cdc),
|
|
getCmdClaimHard(cdc),
|
|
getCmdClaimHardVVesting(cdc),
|
|
getCmdClaimDelegator(cdc),
|
|
getCmdClaimDelegatorVVesting(cdc),
|
|
getCmdClaimSwap(cdc),
|
|
getCmdClaimSwapVVesting(cdc),
|
|
)...)
|
|
|
|
return incentiveTxCmd
|
|
}
|
|
|
|
func getCmdClaimCdp(cdc *codec.Codec) *cobra.Command {
|
|
|
|
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.`,
|
|
Example: fmt.Sprintf(` $ %s tx %s claim-cdp large`, version.ClientName, types.ModuleName),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
|
|
msg := types.NewMsgClaimUSDXMintingReward(sender, multiplier)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimCdpVVesting(cdc *codec.Codec) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-cdp-vesting [multiplier] [receiver]",
|
|
Short: "claim USDX minting rewards using a given multiplier on behalf of a validator vesting account",
|
|
Long: `Claim sender's outstanding USDX minting rewards on behalf of a validator vesting using a given multiplier.
|
|
A receiver address for the rewards is needed as validator vesting accounts cannot receive locked tokens.`,
|
|
Example: fmt.Sprintf(` $ %s tx %s claim-cdp-vesting large kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw`, version.ClientName, types.ModuleName),
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
receiverStr := args[1]
|
|
receiver, err := sdk.AccAddressFromBech32(receiverStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := types.NewMsgClaimUSDXMintingRewardVVesting(sender, receiver, multiplier)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimHard(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-hard [multiplier]",
|
|
Short: "claim sender's Hard module rewards using a given multiplier",
|
|
Long: `Claim sender's outstanding Hard rewards for deposit/borrow using given multiplier`,
|
|
Example: fmt.Sprintf(` $ %s tx %s claim-hard large`, version.ClientName, types.ModuleName),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
|
|
msg := types.NewMsgClaimHardReward(sender, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimHardVVesting(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-hard-vesting [multiplier] [receiver]",
|
|
Short: "claim Hard module rewards on behalf of a validator vesting account using a given multiplier",
|
|
Long: `Claim sender's outstanding hard supply/borrow rewards on behalf of a validator vesting account using given multiplier
|
|
A receiver address for the rewards is needed as validator vesting accounts cannot receive locked tokens.
|
|
Optionally claim only certain denoms from the rewards. Specifying none will claim all of them.`,
|
|
Example: strings.Join([]string{
|
|
fmt.Sprintf(" $ %s tx %s claim-hard-vesting large kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw", version.ClientName, types.ModuleName),
|
|
fmt.Sprintf(" $ %s tx %s claim-hard-vesting small kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw --claim-only swp,hard", version.ClientName, types.ModuleName),
|
|
}, "\n"),
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
receiverStr := args[1]
|
|
receiver, err := sdk.AccAddressFromBech32(receiverStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := types.NewMsgClaimHardRewardVVesting(sender, receiver, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimDelegator(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-delegator [multiplier]",
|
|
Short: "claim sender's delegator rewards using a given multiplier",
|
|
Long: `Claim sender's outstanding delegator rewards using given multiplier.
|
|
Optionally claim only certain denoms from the rewards. Specifying none will claim all of them.`,
|
|
Example: strings.Join([]string{
|
|
fmt.Sprintf(" $ %s tx %s claim-delegator large", version.ClientName, types.ModuleName),
|
|
fmt.Sprintf(" $ %s tx %s claim-delegator large --claim-only swp,hard", version.ClientName, types.ModuleName),
|
|
}, "\n"),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
|
|
msg := types.NewMsgClaimDelegatorReward(sender, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimDelegatorVVesting(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-delegator-vesting [multiplier] [receiver]",
|
|
Short: "claim delegator rewards on behalf of a validator vesting account using a given multiplier",
|
|
Long: `Claim sender's outstanding delegator rewards on behalf of a validator vesting account using given multiplier
|
|
A receiver address for the rewards is needed as validator vesting accounts cannot receive locked tokens.
|
|
Optionally claim only certain denoms from the rewards. Specifying none will claim all of them.`,
|
|
Example: strings.Join([]string{
|
|
fmt.Sprintf(" $ %s tx %s claim-delegator-vesting large kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw", version.ClientName, types.ModuleName),
|
|
fmt.Sprintf(" $ %s tx %s claim-delegator-vesting small kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw --claim-only swp,hard", version.ClientName, types.ModuleName),
|
|
}, "\n"),
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
receiverStr := args[1]
|
|
receiver, err := sdk.AccAddressFromBech32(receiverStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := types.NewMsgClaimDelegatorRewardVVesting(sender, receiver, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimSwap(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-swap [multiplier]",
|
|
Short: "claim sender's swap rewards using a given multiplier",
|
|
Long: `Claim sender's outstanding swap rewards using given multiplier.
|
|
Optionally claim only certain denoms from the rewards. Specifying none will claim all of them.`,
|
|
Example: strings.Join([]string{
|
|
fmt.Sprintf(" $ %s tx %s claim-swap large", version.ClientName, types.ModuleName),
|
|
fmt.Sprintf(" $ %s tx %s claim-swap large --claim-only swp,hard", version.ClientName, types.ModuleName),
|
|
}, "\n"),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
|
|
msg := types.NewMsgClaimSwapReward(sender, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func getCmdClaimSwapVVesting(cdc *codec.Codec) *cobra.Command {
|
|
var denomsToClaim []string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "claim-swap-vesting [multiplier] [receiver]",
|
|
Short: "claim swap rewards on behalf of a validator vesting account using a given multiplier",
|
|
Long: `Claim sender's outstanding swap rewards on behalf of a validator vesting account using given multiplier
|
|
A receiver address for the rewards is needed as validator vesting accounts cannot receive locked tokens.
|
|
Optionally claim only certain denoms from the rewards. Specifying none will claim all of them.`,
|
|
Example: strings.Join([]string{
|
|
fmt.Sprintf(" $ %s tx %s claim-swap-vesting large kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw", version.ClientName, types.ModuleName),
|
|
fmt.Sprintf(" $ %s tx %s claim-swap-vesting small kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw --claim-only swp,hard", version.ClientName, types.ModuleName),
|
|
}, "\n"),
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
|
|
sender := cliCtx.GetFromAddress()
|
|
multiplier := args[0]
|
|
receiverStr := args[1]
|
|
receiver, err := sdk.AccAddressFromBech32(receiverStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := types.NewMsgClaimSwapRewardVVesting(sender, receiver, multiplier, denomsToClaim)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&denomsToClaim, "claim-only", nil, "claim only these denoms, otherwise claim all denoms")
|
|
|
|
return cmd
|
|
}
|