2022-07-20 23:14:43 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-07-28 16:50:59 +00:00
|
|
|
"fmt"
|
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"
|
2022-07-28 16:50:59 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2022-07-20 23:14:43 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
|
|
)
|
|
|
|
|
2022-07-28 16:50:59 +00:00
|
|
|
// flags for cli queries
|
|
|
|
const (
|
|
|
|
flagDenom = "denom"
|
|
|
|
flagOwner = "owner"
|
|
|
|
)
|
|
|
|
|
2022-07-20 23:14:43 +00:00
|
|
|
// GetQueryCmd returns the cli query commands for the earn module
|
|
|
|
func GetQueryCmd() *cobra.Command {
|
|
|
|
earnQueryCommand := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: "Querying commands for the earn module",
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmds := []*cobra.Command{
|
|
|
|
queryParamsCmd(),
|
2022-07-28 16:50:59 +00:00
|
|
|
queryVaultsCmd(),
|
2022-09-12 17:50:35 +00:00
|
|
|
queryVaultCmd(),
|
2022-07-28 16:50:59 +00:00
|
|
|
queryDepositsCmd(),
|
2022-07-20 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
flags.AddQueryFlagsToCmd(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
earnQueryCommand.AddCommand(cmds...)
|
|
|
|
|
|
|
|
return earnQueryCommand
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryParamsCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "params",
|
|
|
|
Short: "get the earn module parameters",
|
|
|
|
Long: "Get the current earn module parameters.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
|
|
|
|
req := types.NewQueryParamsRequest()
|
|
|
|
res, err := queryClient.Params(context.Background(), req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return clientCtx.PrintProto(&res.Params)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 16:50:59 +00:00
|
|
|
|
|
|
|
func queryVaultsCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2022-09-12 17:50:35 +00:00
|
|
|
Use: "vaults",
|
|
|
|
Short: "get all earn vaults",
|
|
|
|
Long: "Get all earn module vaults.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
Example: fmt.Sprintf(`%[1]s q %[2]s vaults`, version.AppName, types.ModuleName),
|
2022-07-28 16:50:59 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
|
2022-09-12 17:50:35 +00:00
|
|
|
req := types.NewQueryVaultsRequest()
|
|
|
|
res, err := queryClient.Vaults(context.Background(), req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-07-28 16:50:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 17:50:35 +00:00
|
|
|
return clientCtx.PrintProto(res)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryVaultCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "vault",
|
|
|
|
Short: "get a earn vault",
|
|
|
|
Long: "Get a specific earn module vault by denom.",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Example: fmt.Sprintf(`%[1]s q %[2]s vault usdx`, version.AppName, types.ModuleName),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
|
|
|
|
req := types.NewQueryVaultRequest(args[0])
|
|
|
|
res, err := queryClient.Vault(context.Background(), req)
|
2022-07-28 16:50:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return clientCtx.PrintProto(res)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryDepositsCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "deposits",
|
|
|
|
Short: "get earn vault deposits",
|
|
|
|
Long: "Get earn vault deposits for all or specific accounts and vaults.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
Example: fmt.Sprintf(`%[1]s q %[2]s deposits
|
|
|
|
%[1]s q %[2]s deposits --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --denom usdx
|
|
|
|
%[1]s q %[2]s deposits --denom usdx`, version.AppName, types.ModuleName),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerBech, err := cmd.Flags().GetString(flagOwner)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
denom, err := cmd.Flags().GetString(flagDenom)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
queryClient := types.NewQueryClient(clientCtx)
|
|
|
|
|
|
|
|
req := types.NewQueryDepositsRequest(
|
|
|
|
ownerBech,
|
|
|
|
denom,
|
|
|
|
pageReq,
|
|
|
|
)
|
|
|
|
res, err := queryClient.Deposits(context.Background(), req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return clientCtx.PrintProto(res)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.AddPaginationFlagsToCmd(cmd, "deposits")
|
|
|
|
|
|
|
|
cmd.Flags().String(flagOwner, "", "(optional) filter for deposits by owner address")
|
|
|
|
cmd.Flags().String(flagDenom, "", "(optional) filter for deposits by vault denom")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|