mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
ed116b24ba
* Add IsDerivativeDenom and GetKavaForDerivatives methods to liquid * Add test case containing 2 different bkava denoms * Add doc to GetKavaForDerivatives * Remove logging statements, use keeper logger * Fix nil err use * Return error from GetKavaForDerivatives * Re-add ParseLiquidStakingTokenDenom * Add ParseLiquidStakingTokenDenom tests * Use DenomSeparator instead of str Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
109 lines
3.0 KiB
Go
109 lines
3.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
|
|
"github.com/kava-labs/kava/x/liquid/types"
|
|
)
|
|
|
|
// GetTxCmd returns the transaction commands for this module
|
|
func GetTxCmd() *cobra.Command {
|
|
liquidTxCmd := &cobra.Command{
|
|
Use: types.ModuleName,
|
|
Short: "liquid transactions subcommands",
|
|
DisableFlagParsing: true,
|
|
SuggestionsMinimumDistance: 2,
|
|
RunE: client.ValidateCmd,
|
|
}
|
|
|
|
cmds := []*cobra.Command{
|
|
getCmdMintDerivative(),
|
|
getCmdBurnDerivative(),
|
|
}
|
|
|
|
for _, cmd := range cmds {
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
}
|
|
|
|
liquidTxCmd.AddCommand(cmds...)
|
|
|
|
return liquidTxCmd
|
|
}
|
|
|
|
func getCmdMintDerivative() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "mint [validator-addr] [amount]",
|
|
Short: "mints staking derivative from a delegation",
|
|
Long: "Mint removes a portion of a user's staking delegation and issues them validator specific staking derivative tokens.",
|
|
Args: cobra.ExactArgs(2),
|
|
Example: fmt.Sprintf(
|
|
`%s tx %s mint kavavaloper16lnfpgn6llvn4fstg5nfrljj6aaxyee9z59jqd 10000000ukava --from <key>`, version.AppName, types.ModuleName,
|
|
),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
valAddr, err := sdk.ValAddressFromBech32(args[0])
|
|
if err != nil {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error())
|
|
}
|
|
|
|
coin, err := sdk.ParseCoinNormalized(args[1])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := types.NewMsgMintDerivative(clientCtx.GetFromAddress(), valAddr, coin)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
|
},
|
|
}
|
|
}
|
|
|
|
func getCmdBurnDerivative() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "burn [amount]",
|
|
Short: "burns staking derivative to redeem a delegation",
|
|
Long: "Burn removes some staking derivative from a user's account and converts it back to a staking delegation.",
|
|
Example: fmt.Sprintf(
|
|
`%s tx %s burn 10000000bkava-kavavaloper16lnfpgn6llvn4fstg5nfrljj6aaxyee9z59jqd --from <key>`, version.AppName, types.ModuleName,
|
|
),
|
|
Args: cobra.ExactArgs(1),
|
|
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
|
|
}
|
|
|
|
valAddr, err := types.ParseLiquidStakingTokenDenom(amount.Denom)
|
|
if err != nil {
|
|
return sdkerrors.Wrap(types.ErrInvalidDenom, err.Error())
|
|
}
|
|
|
|
msg := types.NewMsgBurnDerivative(clientCtx.GetFromAddress(), valAddr, amount)
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return err
|
|
}
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
|
},
|
|
}
|
|
}
|