Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proto)!: aggregate queries on account address to account_balances and account_summary queries #1199

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1130](https://github.com/umee-network/umee/pull/1130) Update proto json tag to lower case.
- [1140](https://github.com/umee-network/umee/pull/1140) Rename MarketSize query to TotalSuppliedValue, and TokenMarketSize to TotalSupplied.
- [1188](https://github.com/umee-network/umee/pull/1188) Remove all individual queries which duplicate market_summary fields.
- [1199](https://github.com/umee-network/umee/pull/1199) Move all queries which require address input (e.g. `supplied`, `collateral_value`, `borrow_limit`) into aggregate queries `acccount_summary` or `account_balances`.

### Features

Expand Down
318 changes: 100 additions & 218 deletions proto/umee/leverage/v1/query.proto

Large diffs are not rendered by default.

260 changes: 34 additions & 226 deletions x/leverage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,17 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

cmd.AddCommand(
GetCmdQueryAllRegisteredTokens(),
GetCmdQueryParams(),
GetCmdQueryBorrowed(),
GetCmdQueryBorrowedValue(),
GetCmdQuerySupplied(),
GetCmdQuerySuppliedValue(),
GetCmdQueryCollateral(),
GetCmdQueryCollateralValue(),
GetCmdQueryBorrowLimit(),
GetCmdQueryLiquidationThreshold(),
GetCmdQueryLiquidationTargets(),
GetCmdQueryRegisteredTokens(),
GetCmdQueryMarketSummary(),
GetCmdQueryAccountBalances(),
GetCmdQueryAccountSummary(),
GetCmdQueryLiquidationTargets(),
)

return cmd
}

// GetCmdQueryAllRegisteredTokens creates a Cobra command to query for all
// the registered tokens in the x/leverage module.
func GetCmdQueryAllRegisteredTokens() *cobra.Command {
cmd := &cobra.Command{
Use: "registered-tokens",
Args: cobra.NoArgs,
Short: "Query for all the current registered tokens",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.RegisteredTokens(cmd.Context(), &types.QueryRegisteredTokens{})
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryParams creates a Cobra command to query for the x/leverage
// module parameters.
func GetCmdQueryParams() *cobra.Command {
Expand All @@ -92,210 +62,75 @@ func GetCmdQueryParams() *cobra.Command {
return cmd
}

// GetCmdQueryBorrowed creates a Cobra command to query for the amount of
// total borrowed tokens for a given address.
func GetCmdQueryBorrowed() *cobra.Command {
cmd := &cobra.Command{
Use: "borrowed [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the total amount of borrowed tokens for an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryBorrowed{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
}
resp, err := queryClient.Borrowed(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryBorrowedValue creates a Cobra command to query for the USD
// value of total borrowed tokens for a given address.
func GetCmdQueryBorrowedValue() *cobra.Command {
cmd := &cobra.Command{
Use: "borrowed-value [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the total USD value of borrowed tokens for an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryBorrowedValue{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
}
resp, err := queryClient.BorrowedValue(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for value of only a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQuerySupplied creates a Cobra command to query for the amount of
// tokens supplied by a given address.
func GetCmdQuerySupplied() *cobra.Command {
cmd := &cobra.Command{
Use: "supplied [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the total amount of tokens supplied by an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QuerySupplied{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
}
resp, err := queryClient.Supplied(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQuerySuppliedValue creates a Cobra command to query for the USD value of
// total tokens supplied by a given address.
func GetCmdQuerySuppliedValue() *cobra.Command {
cmd := &cobra.Command{
Use: "supplied-value [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the USD value of tokens supplied by an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QuerySuppliedValue{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
}
resp, err := queryClient.SuppliedValue(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for value of only a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryCollateral creates a Cobra command to query for the amount of
// total collateral tokens for a given address.
func GetCmdQueryCollateral() *cobra.Command {
// GetCmdQueryRegisteredTokens creates a Cobra command to query for all
// the registered tokens in the x/leverage module.
func GetCmdQueryRegisteredTokens() *cobra.Command {
cmd := &cobra.Command{
Use: "collateral [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the total amount of collateral tokens for an address",
Use: "registered-tokens",
Args: cobra.NoArgs,
Short: "Query for all the current registered tokens",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryCollateral{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
}
resp, err := queryClient.Collateral(cmd.Context(), req)
resp, err := queryClient.RegisteredTokens(cmd.Context(), &types.QueryRegisteredTokens{})
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryCollateralValue creates a Cobra command to query for the USD
// value of total collateral tokens for a given address.
func GetCmdQueryCollateralValue() *cobra.Command {
// GetCmdQueryMarketSummary creates a Cobra command to query for the
// Market Summary of a specific token.
func GetCmdQueryMarketSummary() *cobra.Command {
cmd := &cobra.Command{
Use: "collateral-value [addr]",
Use: "market-summary [denom]",
Args: cobra.ExactArgs(1),
Short: "Query for the total USD value of collateral tokens for an address",
Short: "Query for the market summary of a specified denomination",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryCollateralValue{
Address: args[0],
}
if d, err := cmd.Flags().GetString(FlagDenom); len(d) > 0 && err == nil {
req.Denom = d
req := &types.QueryMarketSummary{
Denom: args[0],
}
resp, err := queryClient.CollateralValue(cmd.Context(), req)
resp, err := queryClient.MarketSummary(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

cmd.Flags().String(FlagDenom, "", "Query for value of only a specific denomination")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryBorrowLimit creates a Cobra command to query for the
// borrow limit of a specific borrower.
func GetCmdQueryBorrowLimit() *cobra.Command {
// GetCmdQueryAccountBalances creates a Cobra command to query for the
// supply, collateral, and borrow positions of an account.
func GetCmdQueryAccountBalances() *cobra.Command {
cmd := &cobra.Command{
Use: "borrow-limit [addr]",
Use: "account-balances [addr]",
Args: cobra.ExactArgs(1),
Short: "Query for the borrow limit of a specified borrower",
Short: "Query for the total supplied, collateral, and borrowed tokens for an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryBorrowLimit{
req := &types.QueryAccountBalances{
Address: args[0],
}
resp, err := queryClient.BorrowLimit(cmd.Context(), req)
resp, err := queryClient.AccountBalances(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}
Expand All @@ -305,51 +140,24 @@ func GetCmdQueryBorrowLimit() *cobra.Command {
return cmd
}

// GetCmdQueryLiquidationThreshold creates a Cobra command to query a
// liquidation threshold of a specific borrower.
func GetCmdQueryLiquidationThreshold() *cobra.Command {
// GetCmdQueryAccountSummary creates a Cobra command to query for USD
// values representing an account's positions and borrowing limits.
func GetCmdQueryAccountSummary() *cobra.Command {
cmd := &cobra.Command{
Use: "liquidation-threshold [addr]",
Use: "account-summary [addr]",
Args: cobra.ExactArgs(1),
Short: "Query a liquidation threshold of a specified borrower",
Short: "Query for position USD values and borrowing limits for an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryLiquidationThreshold{
req := &types.QueryAccountSummary{
Address: args[0],
}
resp, err := queryClient.LiquidationThreshold(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryMarketSummary creates a Cobra command to query for the
// Market Summary of a specific token.
func GetCmdQueryMarketSummary() *cobra.Command {
cmd := &cobra.Command{
Use: "market-summary [denom]",
Args: cobra.ExactArgs(1),
Short: "Query for the market summary of a specified denomination",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryMarketSummary{
Denom: args[0],
}
resp, err := queryClient.MarketSummary(cmd.Context(), req)
resp, err := queryClient.AccountSummary(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}
Expand All @@ -360,7 +168,7 @@ func GetCmdQueryMarketSummary() *cobra.Command {
}

// GetCmdQueryLiquidationTargets creates a Cobra command to query for
// all eligible liquidation targets
// all eligible liquidation targets.
func GetCmdQueryLiquidationTargets() *cobra.Command {
cmd := &cobra.Command{
Use: "liquidation-targets",
Expand Down
Loading