From d76c1558b6a17d7ca581a4b5d103b768a3638602 Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Thu, 5 Jan 2023 08:05:29 -0700 Subject: [PATCH] feat!: MaxBorrow query and modify MaxWithdraw to return all denoms (#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) --- CHANGELOG.md | 5 + proto/umee/leverage/v1/query.proto | 36 +- swagger/swagger.yaml | 184 ++++++-- x/leverage/client/cli/query.go | 37 +- x/leverage/client/tests/tests.go | 92 +++- x/leverage/keeper/grpc_query.go | 102 +++- x/leverage/keeper/grpc_query_test.go | 88 +++- x/leverage/keeper/limits.go | 42 ++ x/leverage/keeper/oracle.go | 14 + x/leverage/types/errors.go | 1 + x/leverage/types/query.pb.go | 666 ++++++++++++++++++++++----- x/leverage/types/query.pb.gw.go | 83 ++++ 12 files changed, 1167 insertions(+), 183 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 517d28bfc5..b54266df33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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 diff --git a/proto/umee/leverage/v1/query.proto b/proto/umee/leverage/v1/query.proto index 4a81a04dc1..c327ac92ac 100644 --- a/proto/umee/leverage/v1/query.proto +++ b/proto/umee/leverage/v1/query.proto @@ -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 @@ -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" + ]; +} \ No newline at end of file diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index bcbac66698..f41824af74 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -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: >- @@ -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 @@ -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 @@ -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 diff --git a/x/leverage/client/cli/query.go b/x/leverage/client/cli/query.go index 1590416361..b701d46218 100644 --- a/x/leverage/client/cli/query.go +++ b/x/leverage/client/cli/query.go @@ -35,6 +35,7 @@ func GetQueryCmd() *cobra.Command { GetCmdQueryLiquidationTargets(), GetCmdQueryBadDebts(), GetCmdQueryMaxWithdraw(), + GetCmdQueryMaxBorrow(), ) return cmd @@ -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) @@ -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) @@ -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 +} diff --git a/x/leverage/client/tests/tests.go b/x/leverage/client/tests/tests.go index 1ccb9fa7fd..6ff414dfdf 100644 --- a/x/leverage/client/tests/tests.go +++ b/x/leverage/client/tests/tests.go @@ -140,8 +140,21 @@ func (s *IntegrationTestSuite) TestLeverageScenario() { false, &types.QueryMaxWithdrawResponse{}, &types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin("uumee", sdk.ZeroInt()), - UTokens: sdk.NewCoin("u/uumee", sdk.ZeroInt()), + Tokens: sdk.NewCoins(), + UTokens: sdk.NewCoins(), + }, + }, + { + "query max borrow (zero)", + cli.GetCmdQueryMaxBorrow(), + []string{ + val.Address.String(), + "uumee", + }, + false, + &types.QueryMaxBorrowResponse{}, + &types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(), }, }, } @@ -284,8 +297,21 @@ func (s *IntegrationTestSuite) TestLeverageScenario() { false, &types.QueryMaxWithdrawResponse{}, &types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin("uumee", sdk.ZeroInt()), - UTokens: sdk.NewCoin("u/uumee", sdk.ZeroInt()), + Tokens: sdk.NewCoins(), + UTokens: sdk.NewCoins(), + }, + }, + { + "query max borrow (borrow limit reached)", + cli.GetCmdQueryMaxBorrow(), + []string{ + val.Address.String(), + "uumee", + }, + false, + &types.QueryMaxBorrowResponse{}, + &types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(), }, }, } @@ -319,8 +345,58 @@ func (s *IntegrationTestSuite) TestLeverageScenario() { false, &types.QueryMaxWithdrawResponse{}, &types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin("uumee", sdk.NewInt(201)), - UTokens: sdk.NewCoin("u/uumee", sdk.NewInt(200)), + Tokens: sdk.NewCoins( + sdk.NewCoin("uumee", sdk.NewInt(201)), + ), + UTokens: sdk.NewCoins( + sdk.NewCoin("u/uumee", sdk.NewInt(200)), + ), + }, + }, + { + "query max borrow (after repay)", + cli.GetCmdQueryMaxBorrow(), + []string{ + val.Address.String(), + "uumee", + }, + false, + &types.QueryMaxBorrowResponse{}, + &types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins( + sdk.NewCoin("uumee", sdk.NewInt(25)), + ), + }, + }, + { + "query all max withdraw (after repay)", + cli.GetCmdQueryMaxWithdraw(), + []string{ + val.Address.String(), + }, + false, + &types.QueryMaxWithdrawResponse{}, + &types.QueryMaxWithdrawResponse{ + Tokens: sdk.NewCoins( + sdk.NewCoin("uumee", sdk.NewInt(201)), + ), + UTokens: sdk.NewCoins( + sdk.NewCoin("u/uumee", sdk.NewInt(200)), + ), + }, + }, + { + "query all max borrow (after repay)", + cli.GetCmdQueryMaxBorrow(), + []string{ + val.Address.String(), + }, + false, + &types.QueryMaxBorrowResponse{}, + &types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins( + sdk.NewCoin("uumee", sdk.NewInt(25)), + ), }, }, } @@ -351,8 +427,8 @@ func (s *IntegrationTestSuite) TestLeverageScenario() { false, &types.QueryMaxWithdrawResponse{}, &types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin("uumee", sdk.ZeroInt()), - UTokens: sdk.NewCoin("u/uumee", sdk.ZeroInt()), + Tokens: sdk.NewCoins(), + UTokens: sdk.NewCoins(), }, }, } diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index 0e7ca535fe..f8a0994126 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -288,27 +288,101 @@ func (q Querier) MaxWithdraw( return nil, err } - maxCurrentWithdraw, err := q.Keeper.maxWithdraw(ctx, addr, req.Denom, false) - if err != nil { - return nil, err + denoms := []string{} + maxUTokens := sdk.NewCoins() + maxTokens := sdk.NewCoins() + + if req.Denom != "" { + // Denom specified + denoms = []string{req.Denom} + } else { + // Denom not specified + for _, t := range q.Keeper.GetAllRegisteredTokens(ctx) { + denoms = append(denoms, t.BaseDenom) + } + } + + for _, denom := range denoms { + maxCurrentWithdraw, err := q.Keeper.maxWithdraw(ctx, addr, denom, false) + if err != nil { + return nil, err + } + maxHistoricWithdraw, err := q.Keeper.maxWithdraw(ctx, addr, denom, true) + if err != nil { + return nil, err + } + + uToken := sdk.NewCoin( + maxCurrentWithdraw.Denom, + sdk.MinInt(maxCurrentWithdraw.Amount, maxHistoricWithdraw.Amount), + ) + if uToken.IsPositive() { + token, err := q.Keeper.ExchangeUToken(ctx, uToken) + if err != nil { + return nil, err + } + maxUTokens = maxUTokens.Add(uToken) + maxTokens = maxTokens.Add(token) + } } - maxHistoricWithdraw, err := q.Keeper.maxWithdraw(ctx, addr, req.Denom, true) - if err != nil { - return nil, err + + return &types.QueryMaxWithdrawResponse{ + Tokens: maxTokens, + UTokens: maxUTokens, + }, nil +} + +func (q Querier) MaxBorrow( + goCtx context.Context, + req *types.QueryMaxBorrow, +) (*types.QueryMaxBorrowResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + if req.Address == "" { + return nil, status.Error(codes.InvalidArgument, "empty address") } - uToken := sdk.NewCoin( - maxCurrentWithdraw.Denom, - sdk.MinInt(maxCurrentWithdraw.Amount, maxHistoricWithdraw.Amount), - ) + ctx := sdk.UnwrapSDKContext(goCtx) - token, err := q.Keeper.ExchangeUToken(ctx, uToken) + addr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { return nil, err } - return &types.QueryMaxWithdrawResponse{ - Tokens: token, - UTokens: uToken, + denoms := []string{} + maxTokens := sdk.NewCoins() + + if req.Denom != "" { + // Denom specified + denoms = []string{req.Denom} + } else { + // Denom not specified + for _, t := range q.Keeper.GetAllRegisteredTokens(ctx) { + denoms = append(denoms, t.BaseDenom) + } + } + + for _, denom := range denoms { + currentMaxBorrow, err := q.Keeper.maxBorrow(ctx, addr, denom, false) + if err != nil { + return nil, err + } + historicMaxBorrow, err := q.Keeper.maxBorrow(ctx, addr, denom, true) + if err != nil { + return nil, err + } + maxBorrow := sdk.NewCoin( + currentMaxBorrow.Denom, + sdk.MinInt(currentMaxBorrow.Amount, historicMaxBorrow.Amount), + ) + if maxBorrow.IsPositive() { + maxTokens = maxTokens.Add(maxBorrow) + } + + } + + return &types.QueryMaxBorrowResponse{ + Tokens: maxTokens, }, nil } diff --git a/x/leverage/keeper/grpc_query_test.go b/x/leverage/keeper/grpc_query_test.go index a9a8e08f0e..ac9de8455a 100644 --- a/x/leverage/keeper/grpc_query_test.go +++ b/x/leverage/keeper/grpc_query_test.go @@ -157,8 +157,20 @@ func (s *IntegrationTestSuite) TestQuerier_MaxWithdraw() { require.NoError(err) expected := types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin(umeeDenom, sdk.NewInt(1000_000000)), - UTokens: sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(1000_000000)), + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(1000_000000))), + UTokens: sdk.NewCoins(sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(1000_000000))), + } + require.Equal(expected, *resp) + + // Also test all-denoms + resp, err = s.queryClient.MaxWithdraw(ctx.Context(), &types.QueryMaxWithdraw{ + Address: addr.String(), + }) + require.NoError(err) + + expected = types.QueryMaxWithdrawResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(1000_000000))), + UTokens: sdk.NewCoins(sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(1000_000000))), } require.Equal(expected, *resp) @@ -172,8 +184,76 @@ func (s *IntegrationTestSuite) TestQuerier_MaxWithdraw() { require.NoError(err) expected = types.QueryMaxWithdrawResponse{ - Tokens: sdk.NewCoin(umeeDenom, sdk.NewInt(600_000000)), - UTokens: sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(600_000000)), + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(600_000000))), + UTokens: sdk.NewCoins(sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(600_000000))), + } + require.Equal(expected, *resp) + + // Also test all-denoms + resp, err = s.queryClient.MaxWithdraw(ctx.Context(), &types.QueryMaxWithdraw{ + Address: addr.String(), + }) + require.NoError(err) + + expected = types.QueryMaxWithdrawResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(600_000000))), + UTokens: sdk.NewCoins(sdk.NewCoin("u/"+umeeDenom, sdk.NewInt(600_000000))), + } + require.Equal(expected, *resp) +} + +func (s *IntegrationTestSuite) TestQuerier_MaxBorrow() { + ctx, require := s.ctx, s.Require() + + // creates account which has supplied and collateralized 1000 UMEE + addr := s.newAccount(coin(umeeDenom, 1000_000000)) + s.supply(addr, coin(umeeDenom, 1000_000000)) + s.collateralize(addr, coin("u/"+umeeDenom, 1000_000000)) + + resp, err := s.queryClient.MaxBorrow(ctx.Context(), &types.QueryMaxBorrow{ + Address: addr.String(), + Denom: umeeDenom, + }) + require.NoError(err) + + expected := types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(250_000000))), + } + require.Equal(expected, *resp) + + // Also test all-denoms + resp, err = s.queryClient.MaxBorrow(ctx.Context(), &types.QueryMaxBorrow{ + Address: addr.String(), + }) + require.NoError(err) + + expected = types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(250_000000))), + } + require.Equal(expected, *resp) + + // borrow 100 UMEE for non-trivial query + s.borrow(addr, coin(umeeDenom, 100_000000)) + + resp, err = s.queryClient.MaxBorrow(ctx.Context(), &types.QueryMaxBorrow{ + Address: addr.String(), + Denom: umeeDenom, + }) + require.NoError(err) + + expected = types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(150_000000))), + } + require.Equal(expected, *resp) + + // Also test all-denoms + resp, err = s.queryClient.MaxBorrow(ctx.Context(), &types.QueryMaxBorrow{ + Address: addr.String(), + }) + require.NoError(err) + + expected = types.QueryMaxBorrowResponse{ + Tokens: sdk.NewCoins(sdk.NewCoin(umeeDenom, sdk.NewInt(150_000000))), } require.Equal(expected, *resp) } diff --git a/x/leverage/keeper/limits.go b/x/leverage/keeper/limits.go index cadf5cbeec..9cb555f9f4 100644 --- a/x/leverage/keeper/limits.go +++ b/x/leverage/keeper/limits.go @@ -76,6 +76,48 @@ func (k *Keeper) maxWithdraw(ctx sdk.Context, addr sdk.AccAddress, denom string, return sdk.NewCoin(uDenom, withdrawAmount), nil } +// maxBorrow calculates the maximum amount of a given token an account can currently borrow. +// input denom should be a base token. Uses either current or historic prices. +func (k *Keeper) maxBorrow(ctx sdk.Context, addr sdk.AccAddress, denom string, historic bool) (sdk.Coin, error) { + if types.HasUTokenPrefix(denom) { + return sdk.Coin{}, types.ErrUToken + } + availableTokens := k.AvailableLiquidity(ctx, denom) + + totalBorrowed := k.GetBorrowerBorrows(ctx, addr) + totalCollateral := k.GetBorrowerCollateral(ctx, addr) + + // calculate borrowed value for the account + borrowedValue, err := k.TotalTokenValue(ctx, totalBorrowed, historic) + if err != nil { + return sdk.Coin{}, err + } + + // calculate borrow limit for the account + borrowLimit, err := k.CalculateBorrowLimit(ctx, totalCollateral, historic) + if err != nil { + return sdk.Coin{}, err + } + // borrowers above their borrow limit cannot borrow + if borrowLimit.LTE(borrowedValue) { + return sdk.NewCoin(denom, sdk.ZeroInt()), nil + } + + // determine the USD amount of borrow limit that is currently unused + unusedBorrowLimit := borrowLimit.Sub(borrowedValue) + + // determine max borrow using current or historic prices + maxBorrow, err := k.TokenWithValue(ctx, denom, unusedBorrowLimit, historic) + if err != nil { + return sdk.Coin{}, err + } + + // also cap borrow amount at available liquidity + maxBorrow.Amount = sdk.MinInt(maxBorrow.Amount, availableTokens) + + return maxBorrow, nil +} + // maxCollateralFromShare calculates the maximum amount of collateral a utoken denom // is allowed to have, taking into account its associated token's MaxCollateralShare // under current market conditions diff --git a/x/leverage/keeper/oracle.go b/x/leverage/keeper/oracle.go index fa4295982a..67dbc179e3 100644 --- a/x/leverage/keeper/oracle.go +++ b/x/leverage/keeper/oracle.go @@ -131,6 +131,20 @@ func (k Keeper) TotalTokenValue(ctx sdk.Context, coins sdk.Coins, historic bool) return total, nil } +// TokenWithValue creates a token of a given denom with an given USD value, using either current +// or historic prices. Returns an error on invalid price or denom. +func (k Keeper) TokenWithValue(ctx sdk.Context, denom string, value sdk.Dec, historic bool) (sdk.Coin, error) { + // get token price (guaranteed positive if nil error) and exponent + price, exp, err := k.TokenDefaultDenomPrice(ctx, denom, historic) + if err != nil { + return sdk.Coin{}, err + } + + // amount = USD value * 10^exponent / symbol price + amount := exponent(value, int32(exp)).Quo(price) + return sdk.NewCoin(denom, amount.TruncateInt()), nil +} + // PriceRatio computes the ratio of the USD prices of two base tokens, as sdk.Dec(fromPrice/toPrice). // Will return an error if either token price is not positive, and guarantees a positive output. // Computation uses price of token's default denom to avoid rounding errors for exponent >= 18 tokens, diff --git a/x/leverage/types/errors.go b/x/leverage/types/errors.go index 9593fcbb73..befbd260de 100644 --- a/x/leverage/types/errors.go +++ b/x/leverage/types/errors.go @@ -56,4 +56,5 @@ var ( // 7XX = Disabled Functionality ErrNotLiquidatorNode = sdkerrors.Register(ModuleName, 700, "node has disabled liquidator queries") + ErrNotImplemented = sdkerrors.Register(ModuleName, 701, "not implemented") ) diff --git a/x/leverage/types/query.pb.go b/x/leverage/types/query.pb.go index 187a694701..1457b8a844 100644 --- a/x/leverage/types/query.pb.go +++ b/x/leverage/types/query.pb.go @@ -618,7 +618,8 @@ var xxx_messageInfo_QueryBadDebtsResponse proto.InternalMessageInfo // QueryMaxWithdraw defines the request structure for the MaxWithdraw gRPC service handler. type QueryMaxWithdraw struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // 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. Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` } @@ -658,9 +659,9 @@ var xxx_messageInfo_QueryMaxWithdraw proto.InternalMessageInfo // QueryMaxWithdrawResponse defines the response structure for the MaxWithdraw gRPC service handler. type QueryMaxWithdrawResponse struct { // uTokens is the maximum amount of uTokens that can be withdrawn - UTokens types.Coin `protobuf:"bytes,1,opt,name=uTokens,proto3" json:"uTokens"` + UTokens github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=uTokens,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"uTokens"` // Tokens is the equivalent of max uTokens converted to base tokens - Tokens types.Coin `protobuf:"bytes,2,opt,name=tokens,proto3" json:"tokens"` + Tokens github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=tokens,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"tokens"` } func (m *QueryMaxWithdrawResponse) Reset() { *m = QueryMaxWithdrawResponse{} } @@ -696,6 +697,86 @@ func (m *QueryMaxWithdrawResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryMaxWithdrawResponse proto.InternalMessageInfo +// QueryMaxBorrow defines the request structure for the MaxBorrow gRPC service handler. +type QueryMaxBorrow struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // denom is the base token denom to borrow. + // empty denom will query all registered tokens. + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryMaxBorrow) Reset() { *m = QueryMaxBorrow{} } +func (m *QueryMaxBorrow) String() string { return proto.CompactTextString(m) } +func (*QueryMaxBorrow) ProtoMessage() {} +func (*QueryMaxBorrow) Descriptor() ([]byte, []int) { + return fileDescriptor_1e8137dcabb0ccc7, []int{16} +} +func (m *QueryMaxBorrow) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryMaxBorrow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryMaxBorrow.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryMaxBorrow) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryMaxBorrow.Merge(m, src) +} +func (m *QueryMaxBorrow) XXX_Size() int { + return m.Size() +} +func (m *QueryMaxBorrow) XXX_DiscardUnknown() { + xxx_messageInfo_QueryMaxBorrow.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryMaxBorrow proto.InternalMessageInfo + +// QueryMaxBorrowResponse defines the response structure for the MaxBorrow gRPC service handler. +type QueryMaxBorrowResponse struct { + // Tokens is the maximum amount of tokens that can be borrowed + Tokens github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=tokens,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"tokens"` +} + +func (m *QueryMaxBorrowResponse) Reset() { *m = QueryMaxBorrowResponse{} } +func (m *QueryMaxBorrowResponse) String() string { return proto.CompactTextString(m) } +func (*QueryMaxBorrowResponse) ProtoMessage() {} +func (*QueryMaxBorrowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1e8137dcabb0ccc7, []int{17} +} +func (m *QueryMaxBorrowResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryMaxBorrowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryMaxBorrowResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryMaxBorrowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryMaxBorrowResponse.Merge(m, src) +} +func (m *QueryMaxBorrowResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryMaxBorrowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryMaxBorrowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryMaxBorrowResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*QueryParams)(nil), "umee.leverage.v1.QueryParams") proto.RegisterType((*QueryParamsResponse)(nil), "umee.leverage.v1.QueryParamsResponse") @@ -713,97 +794,102 @@ func init() { proto.RegisterType((*QueryBadDebtsResponse)(nil), "umee.leverage.v1.QueryBadDebtsResponse") proto.RegisterType((*QueryMaxWithdraw)(nil), "umee.leverage.v1.QueryMaxWithdraw") proto.RegisterType((*QueryMaxWithdrawResponse)(nil), "umee.leverage.v1.QueryMaxWithdrawResponse") + proto.RegisterType((*QueryMaxBorrow)(nil), "umee.leverage.v1.QueryMaxBorrow") + proto.RegisterType((*QueryMaxBorrowResponse)(nil), "umee.leverage.v1.QueryMaxBorrowResponse") } func init() { proto.RegisterFile("umee/leverage/v1/query.proto", fileDescriptor_1e8137dcabb0ccc7) } var fileDescriptor_1e8137dcabb0ccc7 = []byte{ - // 1349 bytes of a gzipped FileDescriptorProto + // 1399 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x98, 0xdf, 0x6f, 0xdb, 0x54, - 0x14, 0xc7, 0xeb, 0x74, 0xeb, 0xda, 0x93, 0xa6, 0xed, 0x2e, 0x1d, 0xf5, 0xb2, 0x2d, 0xe9, 0xbc, - 0x75, 0xeb, 0x06, 0x8d, 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0x1c, 0x1a, 0x91, 0x88, 0xfe, 0x83, 0x06, 0xf3, 0xc3, - 0x37, 0xdb, 0xa5, 0x11, 0xb1, 0x86, 0xec, 0xca, 0xb5, 0xf1, 0xec, 0x94, 0xaa, 0xab, 0x4c, 0xd5, - 0x45, 0x64, 0x64, 0x55, 0x61, 0xee, 0xd2, 0x68, 0x4a, 0x0d, 0xdf, 0x69, 0x30, 0x37, 0x54, 0xdf, - 0x57, 0x0e, 0x0f, 0x27, 0x33, 0xb5, 0x36, 0x96, 0x99, 0x12, 0x75, 0x85, 0x89, 0xba, 0x80, 0xce, - 0x8f, 0x16, 0x25, 0x73, 0xf5, 0x93, 0x06, 0x28, 0x5b, 0x46, 0xd0, 0x95, 0x11, 0x01, 0xb3, 0xa6, - 0xe5, 0xf5, 0xb1, 0x4d, 0x95, 0xbe, 0x35, 0xa6, 0xef, 0x32, 0x5a, 0xc9, 0xea, 0xdb, 0x57, 0x57, - 0x85, 0x98, 0x3e, 0x4c, 0xcb, 0xda, 0x84, 0xaa, 0x23, 0xa2, 0x49, 0x83, 0xf2, 0xe5, 0x57, 0x18, - 0x28, 0x11, 0x17, 0x98, 0x88, 0x73, 0xe8, 0x4c, 0x56, 0x44, 0x13, 0xdb, 0x0d, 0x9b, 0x85, 0xfb, - 0x4a, 0x83, 0x62, 0xba, 0x86, 0x19, 0x23, 0x5f, 0x59, 0x65, 0x53, 0xbe, 0xfa, 0x6a, 0x1b, 0x25, - 0xe2, 0x12, 0x13, 0xb1, 0x8c, 0x2a, 0x07, 0xbd, 0xd4, 0x3d, 0xd5, 0x62, 0xd6, 0xef, 0xee, 0xfe, - 0x55, 0x99, 0xd8, 0x7d, 0x5e, 0xd1, 0x9e, 0x3d, 0xaf, 0x68, 0x7f, 0x3e, 0xaf, 0x68, 0xdf, 0xbe, - 0xa8, 0x4c, 0x3c, 0x7b, 0x51, 0x99, 0xf8, 0xf5, 0x45, 0x65, 0xe2, 0xf1, 0xb5, 0xd4, 0x45, 0x93, - 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0xd7, 0x18, 0x48, 0x11, 0xe7, 0xa9, 0x88, 0xb3, 0xe8, 0x4c, + 0x56, 0x44, 0x0b, 0x9b, 0x4d, 0x93, 0x86, 0xfb, 0x5a, 0x81, 0x42, 0xba, 0xb8, 0x6b, 0x43, 0x1f, + 0x59, 0x69, 0x53, 0xba, 0xf2, 0x7a, 0x1b, 0x29, 0xe2, 0x22, 0x15, 0x51, 0x45, 0xe5, 0x83, 0x1e, + 0xea, 0x9e, 0x9c, 0xbd, 0xd1, 0x53, 0x98, 0x49, 0xca, 0x66, 0x75, 0x78, 0x00, 0x66, 0x51, 0x5a, + 0x7d, 0x9d, 0x85, 0x14, 0x70, 0x81, 0x0a, 0x28, 0xa3, 0xe5, 0x83, 0x05, 0xb0, 0x71, 0xa0, 0x7e, + 0x67, 0xf7, 0xaf, 0xf2, 0xd8, 0xee, 0xf3, 0xb2, 0xf2, 0xec, 0x79, 0x59, 0xf9, 0xf3, 0x79, 0x59, + 0xf9, 0xf6, 0x45, 0x79, 0xec, 0xd9, 0x8b, 0xf2, 0xd8, 0xaf, 0x2f, 0xca, 0x63, 0x8f, 0xae, 0xa6, + 0x2a, 0x69, 0x4c, 0x59, 0xf3, 0x48, 0xb4, 0xe3, 0x07, 0xdb, 0x0c, 0xd9, 0xbd, 0xae, 0xf7, 0x12, + 0x2e, 0xad, 0xab, 0xad, 0x49, 0xfa, 0x1f, 0xaa, 0xeb, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1e, + 0xda, 0xfd, 0x2e, 0x68, 0x13, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -834,6 +920,8 @@ type QueryClient interface { BadDebts(ctx context.Context, in *QueryBadDebts, opts ...grpc.CallOption) (*QueryBadDebtsResponse, error) // MaxWithdraw queries the maximum amount of a given token an address can withdraw. MaxWithdraw(ctx context.Context, in *QueryMaxWithdraw, opts ...grpc.CallOption) (*QueryMaxWithdrawResponse, error) + // MaxBorrow queries the maximum amount of a given token an address can borrow. + MaxBorrow(ctx context.Context, in *QueryMaxBorrow, opts ...grpc.CallOption) (*QueryMaxBorrowResponse, error) } type queryClient struct { @@ -916,6 +1004,15 @@ func (c *queryClient) MaxWithdraw(ctx context.Context, in *QueryMaxWithdraw, opt return out, nil } +func (c *queryClient) MaxBorrow(ctx context.Context, in *QueryMaxBorrow, opts ...grpc.CallOption) (*QueryMaxBorrowResponse, error) { + out := new(QueryMaxBorrowResponse) + err := c.cc.Invoke(ctx, "/umee.leverage.v1.Query/MaxBorrow", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Params queries the parameters of the x/leverage module. @@ -934,6 +1031,8 @@ type QueryServer interface { BadDebts(context.Context, *QueryBadDebts) (*QueryBadDebtsResponse, error) // MaxWithdraw queries the maximum amount of a given token an address can withdraw. MaxWithdraw(context.Context, *QueryMaxWithdraw) (*QueryMaxWithdrawResponse, error) + // MaxBorrow queries the maximum amount of a given token an address can borrow. + MaxBorrow(context.Context, *QueryMaxBorrow) (*QueryMaxBorrowResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -964,6 +1063,9 @@ func (*UnimplementedQueryServer) BadDebts(ctx context.Context, req *QueryBadDebt func (*UnimplementedQueryServer) MaxWithdraw(ctx context.Context, req *QueryMaxWithdraw) (*QueryMaxWithdrawResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MaxWithdraw not implemented") } +func (*UnimplementedQueryServer) MaxBorrow(ctx context.Context, req *QueryMaxBorrow) (*QueryMaxBorrowResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method MaxBorrow not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -1113,6 +1215,24 @@ func _Query_MaxWithdraw_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Query_MaxBorrow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryMaxBorrow) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).MaxBorrow(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/umee.leverage.v1.Query/MaxBorrow", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).MaxBorrow(ctx, req.(*QueryMaxBorrow)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "umee.leverage.v1.Query", HandlerType: (*QueryServer)(nil), @@ -1149,6 +1269,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "MaxWithdraw", Handler: _Query_MaxWithdraw_Handler, }, + { + MethodName: "MaxBorrow", + Handler: _Query_MaxBorrow_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "umee/leverage/v1/query.proto", @@ -1873,26 +1997,108 @@ func (m *QueryMaxWithdrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error _ = i var l int _ = l - { - size, err := m.Tokens.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.Tokens) > 0 { + for iNdEx := len(m.Tokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Tokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 - { - size, err := m.UTokens.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.UTokens) > 0 { + for iNdEx := len(m.UTokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.UTokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryMaxBorrow) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryMaxBorrow) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryMaxBorrow) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryMaxBorrowResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryMaxBorrowResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryMaxBorrowResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Tokens) > 0 { + for iNdEx := len(m.Tokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Tokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -2157,10 +2363,50 @@ func (m *QueryMaxWithdrawResponse) Size() (n int) { } var l int _ = l - l = m.UTokens.Size() - n += 1 + l + sovQuery(uint64(l)) - l = m.Tokens.Size() - n += 1 + l + sovQuery(uint64(l)) + if len(m.UTokens) > 0 { + for _, e := range m.UTokens { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if len(m.Tokens) > 0 { + for _, e := range m.Tokens { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryMaxBorrow) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryMaxBorrowResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Tokens) > 0 { + for _, e := range m.Tokens { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -4140,7 +4386,8 @@ func (m *QueryMaxWithdrawResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.UTokens.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.UTokens = append(m.UTokens, types.Coin{}) + if err := m.UTokens[len(m.UTokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -4173,7 +4420,206 @@ func (m *QueryMaxWithdrawResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Tokens.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Tokens = append(m.Tokens, types.Coin{}) + if err := m.Tokens[len(m.Tokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryMaxBorrow) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryMaxBorrow: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryMaxBorrow: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryMaxBorrowResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryMaxBorrowResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryMaxBorrowResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tokens = append(m.Tokens, types.Coin{}) + if err := m.Tokens[len(m.Tokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/leverage/types/query.pb.gw.go b/x/leverage/types/query.pb.gw.go index 12bc143860..fa9388c461 100644 --- a/x/leverage/types/query.pb.gw.go +++ b/x/leverage/types/query.pb.gw.go @@ -249,6 +249,42 @@ func local_request_Query_MaxWithdraw_0(ctx context.Context, marshaler runtime.Ma } +var ( + filter_Query_MaxBorrow_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_MaxBorrow_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryMaxBorrow + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_MaxBorrow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.MaxBorrow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_MaxBorrow_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryMaxBorrow + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_MaxBorrow_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.MaxBorrow(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -439,6 +475,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_MaxBorrow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_MaxBorrow_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_MaxBorrow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -640,6 +699,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_MaxBorrow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_MaxBorrow_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_MaxBorrow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -659,6 +738,8 @@ var ( pattern_Query_BadDebts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"umee", "leverage", "v1", "bad_debts"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_MaxWithdraw_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"umee", "leverage", "v1", "max_withdraw"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_MaxBorrow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"umee", "leverage", "v1", "max_borrow"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -677,4 +758,6 @@ var ( forward_Query_BadDebts_0 = runtime.ForwardResponseMessage forward_Query_MaxWithdraw_0 = runtime.ForwardResponseMessage + + forward_Query_MaxBorrow_0 = runtime.ForwardResponseMessage )