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!: MaxBorrow query and modify MaxWithdraw to return all denoms #1683

Merged
merged 12 commits into from
Jan 5, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### API Breaking

- [1683](https://github.com/umee-network/umee/pull/1683) MaxWithdraw query now returns `sdk.Coins`, not `sdk.Coin` and will be empty (not zero coin) when returning a zero amount. Denom field in query is now optional.

### Fixes

- [1680](https://github.com/umee-network/umee/pull/1680) Add amino support for MsgMaxWithdraw.
Expand All @@ -58,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1588](https://github.com/umee-network/umee/pull/1588) Historacle proto.
- [1653](https://github.com/umee-network/umee/pull/1653) Incentive Msg Server interface implementation.
- [1654](https://github.com/umee-network/umee/pull/1654) Leverage historacle integration.
- [1683](https://github.com/umee-network/umee/pull/1683) Add MaxBorrow query and allow returning all denoms from MaxWithdraw.

## [v3.3.0](https://github.com/umee-network/umee/releases/tag/v3.3.0) - 2022-12-20

Expand Down
38 changes: 34 additions & 4 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ service Query {
returns (QueryMaxWithdrawResponse) {
option (google.api.http).get = "/umee/leverage/v1/max_withdraw";
}

// MaxBorrow queries the maximum amount of a given token an address can borrow.
rpc MaxBorrow(QueryMaxBorrow)
returns (QueryMaxBorrowResponse) {
option (google.api.http).get = "/umee/leverage/v1/max_borrow";
}
}

// QueryParams defines the request structure for the Params gRPC service
Expand Down Expand Up @@ -260,14 +266,38 @@ message QueryBadDebtsResponse {
// QueryMaxWithdraw defines the request structure for the MaxWithdraw gRPC service handler.
message QueryMaxWithdraw {
string address = 1;
// denom is the base token denom associated with the uToken to withdraw
string denom = 2;
// denom is the base token denom associated with the uToken to withdraw.
// empty denom will query all registered tokens.
optional string denom = 2;
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// QueryMaxWithdrawResponse defines the response structure for the MaxWithdraw gRPC service handler.
message QueryMaxWithdrawResponse {
// uTokens is the maximum amount of uTokens that can be withdrawn
cosmos.base.v1beta1.Coin uTokens = 1 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin uTokens = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// Tokens is the equivalent of max uTokens converted to base tokens
cosmos.base.v1beta1.Coin tokens = 2 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin tokens = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// QueryMaxBorrow defines the request structure for the MaxBorrow gRPC service handler.
message QueryMaxBorrow {
string address = 1;
// denom is the base token denom to borrow.
// empty denom will query all registered tokens.
optional string denom = 2;
}

// QueryMaxBorrowResponse defines the response structure for the MaxBorrow gRPC service handler.
message QueryMaxBorrowResponse {
// Tokens is the maximum amount of tokens that can be borrowed
repeated cosmos.base.v1beta1.Coin tokens = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
184 changes: 142 additions & 42 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,75 @@ paths:
type: string
tags:
- Query
/umee/leverage/v1/max_borrow:
get:
summary: >-
MaxBorrow queries the maximum amount of a given token an address can
borrow.
operationId: MaxBorrow
responses:
'200':
description: A successful response.
schema:
type: object
properties:
tokens:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
title: Tokens is the maximum amount of tokens that can be borrowed
description: >-
QueryMaxBorrowResponse defines the response structure for the
MaxBorrow gRPC service handler.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: address
in: query
required: false
type: string
- name: denom
description: |-
denom is the base token denom to borrow.
empty denom will query all registered tokens.
in: query
required: false
type: string
tags:
- Query
/umee/leverage/v1/max_withdraw:
get:
summary: >-
Expand All @@ -484,36 +553,40 @@ paths:
type: object
properties:
uTokens:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method
NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
signatures required by gogoproto.
title: uTokens is the maximum amount of uTokens that can be withdrawn
tokens:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method
NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
signatures required by gogoproto.
title: >-
Tokens is the equivalent of max uTokens converted to base
tokens
Expand Down Expand Up @@ -551,6 +624,8 @@ paths:
description: >-
denom is the base token denom associated with the uToken to
withdraw.

empty denom will query all registered tokens.
in: query
required: false
type: string
Expand Down Expand Up @@ -2102,34 +2177,59 @@ definitions:
description: >-
QueryMarketSummaryResponse defines the response structure for the
MarketSummary gRPC service handler.
umee.leverage.v1.QueryMaxBorrowResponse:
type: object
properties:
tokens:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
title: Tokens is the maximum amount of tokens that can be borrowed
description: >-
QueryMaxBorrowResponse defines the response structure for the MaxBorrow
gRPC service handler.
umee.leverage.v1.QueryMaxWithdrawResponse:
type: object
properties:
uTokens:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
title: uTokens is the maximum amount of uTokens that can be withdrawn
tokens:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
title: Tokens is the equivalent of max uTokens converted to base tokens
description: >-
QueryMaxWithdrawResponse defines the response structure for the
Expand Down
37 changes: 35 additions & 2 deletions x/leverage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryLiquidationTargets(),
GetCmdQueryBadDebts(),
GetCmdQueryMaxWithdraw(),
GetCmdQueryMaxBorrow(),
)

return cmd
Expand Down Expand Up @@ -224,7 +225,7 @@ func GetCmdQueryBadDebts() *cobra.Command {
func GetCmdQueryMaxWithdraw() *cobra.Command {
cmd := &cobra.Command{
Use: "max-withdraw [addr] [denom]",
Args: cobra.ExactArgs(2),
Args: cobra.RangeArgs(1, 2),
Short: "Query for the maximum amount of a given base token an address can withdraw",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -235,7 +236,9 @@ func GetCmdQueryMaxWithdraw() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryMaxWithdraw{
Address: args[0],
Denom: args[1],
}
if len(args) > 1 {
req.XDenom = &types.QueryMaxWithdraw_Denom{Denom: args[1]}
}
resp, err := queryClient.MaxWithdraw(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
Expand All @@ -246,3 +249,33 @@ func GetCmdQueryMaxWithdraw() *cobra.Command {

return cmd
}

// GetCmdQueryMaxBorrow creates a Cobra command to query for
// the maximum amount of a given token an address can borrow.
func GetCmdQueryMaxBorrow() *cobra.Command {
cmd := &cobra.Command{
Use: "max-borrow [addr] [denom]",
Args: cobra.RangeArgs(1, 2),
Short: "Query for the maximum amount of a given base token an address can borrow",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryMaxBorrow{
Address: args[0],
}
if len(args) > 1 {
req.XDenom = &types.QueryMaxBorrow_Denom{Denom: args[1]}
}
resp, err := queryClient.MaxBorrow(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading