Skip to content

Commit

Permalink
feat!: MaxBorrow query and modify MaxWithdraw to return all denoms (#…
Browse files Browse the repository at this point in the history
…1683)

## Description

In addition to the existing historacle-enabled `MaxWithdraw` query, this PR implements the following:
- `MaxBorrow`

In addition, the `Denom` field in those queries is now optional, and they return `sdk.Coins` instead of `sdk.Coin`. If denom is not specified, calculates max borrow/withdraw for ALL registered tokens.

See proto file for query urls and data types.

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] added appropriate labels to the PR
- [x] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
toteki committed Jan 5, 2023
1 parent 13745da commit d76c155
Show file tree
Hide file tree
Showing 12 changed files with 1,167 additions and 183 deletions.
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
36 changes: 33 additions & 3 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
// denom is the base token denom associated with the uToken to withdraw.
// empty denom will query all registered tokens.
string denom = 2;
}

// 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.
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.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.Denom = args[1]
}
resp, err := queryClient.MaxBorrow(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit d76c155

Please sign in to comment.