From d70a87ae83b055dcb577f32222574f8779dddbf2 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Wed, 10 Aug 2022 00:29:58 -0500 Subject: [PATCH 1/3] docs(perp): events #wip --- proto/perp/v1/event.proto | 6 +- x/perp/spec/04_events.md | 128 ++++++++++++++++++++++++-------------- 2 files changed, 87 insertions(+), 47 deletions(-) diff --git a/proto/perp/v1/event.proto b/proto/perp/v1/event.proto index c9ccb0d80..0327ca95e 100644 --- a/proto/perp/v1/event.proto +++ b/proto/perp/v1/event.proto @@ -59,7 +59,8 @@ message PositionChangedEvent { (gogoproto.nullable) = false ]; - // Amount of bad debt cleared by the PerpEF during the change. Bad debt is negative net margin past the liquidation point of a position. + // Amount of bad debt cleared by the PerpEF during the change. + // Bad debt is negative net margin past the liquidation point of a position. cosmos.base.v1beta1.Coin bad_debt = 10 [(gogoproto.nullable) = false]; // amt of margin (y) lost due to liquidation @@ -68,7 +69,8 @@ message PositionChangedEvent { (gogoproto.nullable) = false ]; - // vPrice defined as yRes / xRes for a vpool, where yRes is the quote reserves and xRes is the base reserves. + // Spot price, synonymous with mark price in this context, is the quotient of + // the quote reserves and base reserves string spot_price = 12 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/perp/spec/04_events.md b/x/perp/spec/04_events.md index e3f19c0fd..f4ee8ffff 100644 --- a/x/perp/spec/04_events.md +++ b/x/perp/spec/04_events.md @@ -14,51 +14,89 @@ For more information, see the [Tendermint Core ABCI methods and types specificat # Event Types -- [`transfer`](#transfer): Emitted when assets are transferred between addresses as a result of a Nibiru protocol. -- [`position_change`](#position_change): Emitted when a position state changes. -- [`position_liquidate`](#position_liquidate): -- [`position_settle`](#position_settle): -- [`margin_ratio_change`](#margin_ratio_change): -- [`margin_change`](#margin_change): Emitted when the margin of a single -- [`internal_position_response`](#internal_position_response): +- [`nibiru.perp.v1.PositionChangedEvent`](#nibiruperpv1positionchangedevent): Event omitted when a position changes +- [`nibiru.perp.v1.PositionLiquidatedEvent`](#nibiruperpv1positionliquidatedevent): Event emitted when a position is liquidated. +- [`nibiru.perp.v1.PositionSettledEvent`](#nibiruperpv1positionsettledevent): Event emitted when a position is settled. +- [`nibiru.perp.v1.FundingRateChangedEvent`](#nibiruperpv1fundingratechangedevent): -## `transfer` - -Attributes - "transfer: - -- "from": Sender address -- "to": Receiver address -- "denom": Cosmos-SDK token Bech 32 address for the token -- "amount": Amount of tokens sent in the transfer - - -## `position_change` - -Attributes - "position_change": - -- "owner": Address -- "vpool": -- "margin": -- "notional": -- "vsizeChange": magnitude of the change to the position size. Recall that the position size is the number of base assets for the perp position. E.g. an ETH:USD perp with 3 ETH of exposure has a posiiton size of 3. -- "txFee": -- "vsizeAfter": -- "realizedPnlAfter": -- "bad_debt": -- "unrealized_pnl_after": -- "liquidation_penalty": -- "mark_price": -- "funding_payment": A funding payment made or received by the trader on the current position. A "funding_payment" is positive if 'owner' is the sender and negative if 'owner' is the receiver of the payment. Its magnitude is abs(size * fundingRate). Funding payments act to converge the mark price and index price (average price on major spot exchanges). - -## `position_liquidate` - - -## `position_settle` - -## `margin_ratio_change` - -## `margin_change` - -## `internal_position_response` \ No newline at end of file +```ts +interface Coin { + denom: string; // Cosmos token Bech 32 address + amount: number; // Amount of tokens +} +``` + +## `nibiru.perp.v1.PositionChangedEvent` + +| Attribute (type) | Description | +| ---------------- | ---------- | +| "trader_address" (`string`) | Owner of the position | +| "pair" (`string`) | Identifier for the virtual pool corresponding to the position | +| "margin" (`Coin`) | Amount of margin backing the position | +| "position_notional" (`Dec`) | | +| "exchanged_position_size" (`Dec`) | magnitude of the change to the position size. Recall that the position size is the number of base assets for the perp position. E.g. an ETH:USD perp with 3 ETH of exposure has a posiiton size of 3. | +| "transaction_fee" (`Coin`) | Transaction fee paid | +| "position_size" (`Dec`) | Position size (base asset value) after the change | +| "realized_pnl" (`Dec`) | Realized profits and losses after the change | +| "bad_debt" (`Coin`) | Amount of bad debt cleared by the PerpEF during the change. Bad debt is negative net margin past the liquidation point of a position. | +| "unrealized_pnl_after" (`Dec`) | Unrealized PnL after the change | +| "liquidation_penalty" (`Dec`) | Amount of margin lost due to liquidation, whether partial or full. | +| "spot_price" (`Dec`) | Spot price, synonymous with mark price in this context, is the quotient of the quote reserves and base reserves. | +| "funding_payment" (`Dec`) | A funding payment made or received by the trader on the current position. A "funding_payment" is positive if 'owner' is the sender and negative if 'owner' is the receiver of the payment. Its magnitude is abs(size * fundingRate). Funding payments act to converge the mark price and index price (average price on major spot exchanges). | +| block_height (`int64`) | Block number at which the position changed | +| block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | + +## `nibiru.perp.v1.PositionLiquidatedEvent` + +Event emitted when a position is liquidated. +Corresponds to the proto message, `PositionLiquidatedEvent`. + +| Attribute (type) | Description | +| ---------------- | ---------- | +| bad_debt (`Coin`) | Bad debt (margin units) cleared by the PerpEF during the tx. Bad debt is negative net margin past the liquidation point of a position. | +| block_height (`int64`) | Block number at which the position changed | +| block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | +| exchanged_position_size (`Dec`) | TODOExchanged | +| exchanged_quote_amount (`Dec`) | TODOExchanged | +| fee_to_liquidator (`Coin`) | TODOdescr | +| fee_to_ecosystem_fund (`Coin`) | TODOdescr | +| liquidator_address (`string`) | Address of the account that executed the tx | +| mark_price (`Dec`) | Spot price of the virtual pool after liquidation | +| margin (`Coin`) | Amount of margin remaining in the position after the liquidation | +| pair (`string`) | Identifier for the virtual pool corresponding to the position | +| position_notional (`Dec`) | Reamining position notional (quote units) after liquiation | +| position_size (`Dec`) | Remaing position size (base units) after liquidation | +| trader_address (`string`) | Owner of the position | +| unrealized_pnl (`Dec`) | Unrealized PnL in the position after liquidation | + +## `nibiru.perp.v1.PositionSettledEvent` + +| Attribute (type) | Description | +| ---------------- | ---------- | +| attribute (`type`) | TODOdescr | +| attribute (`type`) | TODOdescr | +| attribute (`type`) | TODOdescr | +| attribute (`type`) | TODOdescr | + + +## `nibiru.perp.v1.FundingRateChangedEvent` + +| Attribute (type) | Description | +| ---------------- | ---------- | +| block_height (`int64`) | Block number at which the position changed | +| block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | +| cumulative_funding_rate (`Dec`) | TODOdescr | +| index_price (`Dec`) | TODOdescr | +| latest_funding_rate (`Dec`) | TODOdescr | +| mark_price (`Dec`) | TODOdescr | +| pair (`string`) | TODOdescr | + + From 5262add465af76445b0f32eb8364e5badbd2f7ab Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Wed, 10 Aug 2022 01:47:35 -0500 Subject: [PATCH 2/3] docs(perp): Added events specification for the perp module. --- CHANGELOG.md | 4 +++ x/README.md | 2 ++ x/perp/README.md | 32 ++------------------ x/perp/spec/04_events.md | 63 +++++++++++++++++++--------------------- 4 files changed, 38 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 586d110cb..f018aed2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features * [#791](https://github.com/NibiruChain/nibiru/pull/791) Add the x/oracle module +### Documentation + +* [#814](https://github.com/NibiruChain/nibiru/pull/814) - docs(perp): Added events specification for the perp module. + ## [v0.12.1](https://github.com/NibiruChain/nibiru/releases/tag/v0.12.1) - 2022-08-04 * [#796](https://github.com/NibiruChain/nibiru/pull/796) - fix bug that caused that epochKeeper was nil when running epoch hook from Perp module diff --git a/x/README.md b/x/README.md index 5bbc2bfcd..4879c9d93 100644 --- a/x/README.md +++ b/x/README.md @@ -8,6 +8,8 @@ - [pricefeed](pricefeed/spec/README.md): Handles the posting of prices for various asset pairs by whitelisted oracles and the logic for querying these prices. +- [perp](perp/README.md): The `x/perp` module powers the Nibi-Perps exchange. This module enables traders to open long and short leveraged positions and houses all of the PnL calculation and liquidation logic. + - [stablecoin](stablecoin/spec/README.md): `x/stablecoin` is resonsible for handling mint and redeem transactions with NUSD. - [testutil](testutil/spec/README.md): Helper functions for unit and integration tests. diff --git a/x/perp/README.md b/x/perp/README.md index 6d83ff438..a87fd7c3b 100644 --- a/x/perp/README.md +++ b/x/perp/README.md @@ -20,39 +20,11 @@ nibid tx perp --help nibid query perp --help ``` -CLI code is contained in the `/perp/client/cli` directory. +The implementation for this module's portion of the `nibid` CLI is contained within the `/perp/client/cli` directory. ## Perp Ecosystem Fund (PerpEF) The PerpEF is a module account on Nibiru Protocol. All of its interactions can be encapsulated in two keeper methods. - `WithdrawFromPerpEF()` -- `DepositToPerpEF()` - - -## Queries - - - -#### QueryPositionInfo - -Given the `vpool` and `trader`, one could query the -`QueryPositionInfo(vpool string, trader sdk.AccAddress) -> PositionInfo` - -```go -// A single trader's position information on a given Vpool. -type PositionInfo struct { - MarginRatio sdk.Dec - Position perptypes.Position -} -``` - -#### QueryAllVpools - -`QueryAllVpools() -> []string`: Returns a list of all of the pool names. - -#### QueryVpoolPrices - -`QueryVpoolPrices() -> map[string]sdk.Dec`: Returns ech virtual pool and its corresponding price. - - +- `DepositToPerpEF()` \ No newline at end of file diff --git a/x/perp/spec/04_events.md b/x/perp/spec/04_events.md index f4ee8ffff..df7227e0e 100644 --- a/x/perp/spec/04_events.md +++ b/x/perp/spec/04_events.md @@ -1,6 +1,6 @@ # Events -Here, we list and describe the event types used in x/perp. +Here, we document the event types used in the `x/perp` module. Events in the Cosmos-SDK are Tendermint application blockchain interface (ABCI) events. These are returned by ABCI methods such as CheckTx, DeliverTx, and Query. @@ -19,7 +19,6 @@ For more information, see the [Tendermint Core ABCI methods and types specificat - [`nibiru.perp.v1.PositionSettledEvent`](#nibiruperpv1positionsettledevent): Event emitted when a position is settled. - [`nibiru.perp.v1.FundingRateChangedEvent`](#nibiruperpv1fundingratechangedevent): - ```ts interface Coin { @@ -32,21 +31,21 @@ interface Coin { | Attribute (type) | Description | | ---------------- | ---------- | -| "trader_address" (`string`) | Owner of the position | -| "pair" (`string`) | Identifier for the virtual pool corresponding to the position | -| "margin" (`Coin`) | Amount of margin backing the position | -| "position_notional" (`Dec`) | | -| "exchanged_position_size" (`Dec`) | magnitude of the change to the position size. Recall that the position size is the number of base assets for the perp position. E.g. an ETH:USD perp with 3 ETH of exposure has a posiiton size of 3. | -| "transaction_fee" (`Coin`) | Transaction fee paid | -| "position_size" (`Dec`) | Position size (base asset value) after the change | -| "realized_pnl" (`Dec`) | Realized profits and losses after the change | -| "bad_debt" (`Coin`) | Amount of bad debt cleared by the PerpEF during the change. Bad debt is negative net margin past the liquidation point of a position. | -| "unrealized_pnl_after" (`Dec`) | Unrealized PnL after the change | -| "liquidation_penalty" (`Dec`) | Amount of margin lost due to liquidation, whether partial or full. | -| "spot_price" (`Dec`) | Spot price, synonymous with mark price in this context, is the quotient of the quote reserves and base reserves. | -| "funding_payment" (`Dec`) | A funding payment made or received by the trader on the current position. A "funding_payment" is positive if 'owner' is the sender and negative if 'owner' is the receiver of the payment. Its magnitude is abs(size * fundingRate). Funding payments act to converge the mark price and index price (average price on major spot exchanges). | +| bad_debt (`Coin`) | Amount of bad debt cleared by the PerpEF during the change. Bad debt is negative net margin past the liquidation point of a position. | | block_height (`int64`) | Block number at which the position changed | | block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | +| exchanged_position_size (`Dec`) | magnitude of the change to the position size. Recall that the position size is the number of base assets for the perp position. E.g. an ETH:USD perp with 3 ETH of exposure has a posiiton size of 3. | +| funding_payment (`Dec`) | A funding payment made or received by the trader on the current position. A "funding_payment" is positive if 'owner' is the sender and negative if 'owner' is the receiver of the payment. Its magnitude is abs(size * fundingRate). Funding payments act to converge the mark price and index price (average price on major spot exchanges). | +| liquidation_penalty (`Dec`) | Amount of margin lost due to liquidation, whether partial or full. | +| margin (`Coin`) | Amount of margin backing the position | +| pair (`string`) | Identifier for the virtual pool corresponding to the position. A pair is of the form `basedenom:quote`. E.g. `uatom:unusd`. | +| position_notional (`Dec`) | | +| position_size (`Dec`) | Position size (base asset value) after the change | +| realized_pnl (`Dec`) | Realized profits and losses after the change | +| spot_price (`Dec`) | Spot price, synonymous with mark price in this context, is the quotient of the quote reserves and base reserves. | +| trader_address (`string`) | Owner of the position | +| transaction_fee (`Coin`) | Transaction fee paid | +| unrealized_pnl_after (`Dec`) | Unrealized PnL after the change | ## `nibiru.perp.v1.PositionLiquidatedEvent` @@ -58,14 +57,14 @@ Corresponds to the proto message, `PositionLiquidatedEvent`. | bad_debt (`Coin`) | Bad debt (margin units) cleared by the PerpEF during the tx. Bad debt is negative net margin past the liquidation point of a position. | | block_height (`int64`) | Block number at which the position changed | | block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | -| exchanged_position_size (`Dec`) | TODOExchanged | -| exchanged_quote_amount (`Dec`) | TODOExchanged | -| fee_to_liquidator (`Coin`) | TODOdescr | -| fee_to_ecosystem_fund (`Coin`) | TODOdescr | +| exchanged_position_size (`Dec`) | magnitude of the change to the position size (base) | +| exchanged_quote_amount (`Dec`) | magnitude of the change to the position notional (quote) | +| fee_to_liquidator (`Coin`) | Transaction fee paid to the liquidator | +| fee_to_ecosystem_fund (`Coin`) | Transaction fee paid to the Nibi-Perps Ecosystem Fund | | liquidator_address (`string`) | Address of the account that executed the tx | | mark_price (`Dec`) | Spot price of the virtual pool after liquidation | | margin (`Coin`) | Amount of margin remaining in the position after the liquidation | -| pair (`string`) | Identifier for the virtual pool corresponding to the position | +| pair (`string`) | Identifier for the virtual pool corresponding to the position. A pair is of the form `basedenom:quote`. E.g. `uatom:unusd`. | | position_notional (`Dec`) | Reamining position notional (quote units) after liquiation | | position_size (`Dec`) | Remaing position size (base units) after liquidation | | trader_address (`string`) | Owner of the position | @@ -75,11 +74,9 @@ Corresponds to the proto message, `PositionLiquidatedEvent`. | Attribute (type) | Description | | ---------------- | ---------- | -| attribute (`type`) | TODOdescr | -| attribute (`type`) | TODOdescr | -| attribute (`type`) | TODOdescr | -| attribute (`type`) | TODOdescr | - +| pair (`string`) | Identifier for the virtual pool corresponding to the position. A pair is of the form `basedenom:quote`. E.g. `uatom:unusd`. | +| settled_coins (`[]Coin`) | Coins transferred during the settlement | +| trader_address (`string`) | Owner of the position | ## `nibiru.perp.v1.FundingRateChangedEvent` @@ -87,16 +84,16 @@ Corresponds to the proto message, `PositionLiquidatedEvent`. | ---------------- | ---------- | | block_height (`int64`) | Block number at which the position changed | | block_time_ms (`int64`) | Block time in Unix milliseconds at which the position changed. | -| cumulative_funding_rate (`Dec`) | TODOdescr | -| index_price (`Dec`) | TODOdescr | -| latest_funding_rate (`Dec`) | TODOdescr | -| mark_price (`Dec`) | TODOdescr | -| pair (`string`) | TODOdescr | +| cumulative_funding_rate (`Dec`) | Cumulative funding rate. The sum of the cumulative premium fractions (CFPs) for the pair. The funding payment paid by a user is the `(latestCPF - lastUpdateCPF) * positionSize`, where `lastUpdateCPF` is the last cumulative funding payment the position applied and `latestCPF` is the most recent CPF for the virtual pool. | +| index_price (`Dec`) | Price of the "underlying" for the perpetual swap. | +| latest_funding_rate (`Dec`) | Most recent value for the funding rate. | +| mark_price (`Dec`) | Instantaneous derivate price for the perp position. Equivalent to the quotient of the quote and base reserves. | +| pair (`string`) | Identifier for the virtual pool corresponding to the position. A pair is of the form `basedenom:quote`. E.g. `uatom:unusd`. | From 9618e9206c95590c4c627699e11aa4f61a5a4f41 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Fri, 12 Aug 2022 18:03:50 -0500 Subject: [PATCH 3/3] Squashed commit of the following: commit b496438338d5cd136661e6cf79a694e47a8198b9 Author: Unique-Divine Date: Fri Aug 12 18:03:02 2022 -0500 remove deperecated docs from x/perp/README commit fc260a5a69ed76034766361c3ea34b5d1e7e14cc Author: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Thu Aug 11 16:37:34 2022 -0500 chore: release v0.12.1-alpha (#820) update changelog commit 8ec477ae6b181c67f486d1b7d2d2f04e4bbc3dba Author: AgentSmithMatrix <98403347+AgentSmithMatrix@users.noreply.github.com> Date: Thu Aug 11 19:47:03 2022 +0200 feat: add golangci-lint to makefile (#819) * add linter to makefile * update changelog commit 208a102cce439535d87febe81c40235187c1292c Author: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Wed Aug 10 13:17:05 2022 -0500 fix: missing max leverage on the pools in app_state.vpool.vpools (#818) commit 75e8f032bf9a9ff5b65b83235e9064f388f33a41 Author: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Wed Aug 10 07:38:00 2022 -0500 feat(vpool): expose markPrice, markTwap, indexPrice, (and blockHeight?) on the all-pools query #789 (#813) * (vpool): add logger to keeper.go * feat: GetPoolPrices, fn to return the mark price, mark twap, index price, and swap inv. for a pool * docs: fix the fn description for GetCurrentTWAP * feat(vpool): implemenet PoolPrices and add it to 'nibid q vpool all-pools' command * update changelog * (vpool): add block number to all-pools.prices. Fix changelog Co-authored-by: AgentSmithMatrix <98403347+AgentSmithMatrix@users.noreply.github.com> Co-authored-by: Agent Smith commit 674da1b94d2a2c08731881a68f3cd51701ff8231 Author: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Wed Aug 10 07:01:20 2022 -0500 feat(perp): expose 'marginRatioIndex' and block number on QueryTraderPosition (#810) * feat(x/perp): add marginRatioIndex to the position query * add blockNumber to QueryTraderPosition * update CHANGELOG.md #763 * fix(CHANGELOG) commit c6ad354e2e5cb0a819b7696df276130e9c3c574d Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed Aug 10 01:52:40 2022 -0500 chore(deps): bump github.com/cosmos/ibc-go/v3 from 3.1.0 to 3.1.1 (#804) * chore(deps): bump github.com/cosmos/ibc-go/v3 from 3.1.0 to 3.1.1 Bumps [github.com/cosmos/ibc-go/v3](https://github.com/cosmos/ibc-go) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/cosmos/ibc-go/releases) - [Changelog](https://github.com/cosmos/ibc-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/cosmos/ibc-go/compare/v3.1.0...v3.1.1) --- updated-dependencies: - dependency-name: github.com/cosmos/ibc-go/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Update CHANGELOG.md Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Co-authored-by: AgentSmithMatrix <98403347+AgentSmithMatrix@users.noreply.github.com> --- CHANGELOG.md | 10 +- Makefile | 7 + go.mod | 2 +- go.sum | 4 +- proto/perp/v1/query.proto | 17 +- proto/vpool/v1/query.proto | 3 + proto/vpool/v1/vpool.proto | 37 ++- scripts/localnet.sh | 2 + x/oracle/types/oracle.pb.go | 2 +- x/perp/README.md | 6 +- x/perp/client/cli/cli_test.go | 10 +- x/perp/client/cli/query.go | 2 +- x/perp/keeper/grpc_query.go | 14 +- x/perp/keeper/grpc_query_test.go | 6 +- x/perp/types/query.pb.go | 192 ++++++++++---- x/perp/types/query.pb.gw.go | 30 +-- x/vpool/keeper/keeper.go | 5 + x/vpool/keeper/pool_state.go | 21 ++ x/vpool/keeper/prices.go | 7 +- x/vpool/keeper/query_server.go | 7 +- x/vpool/types/query.pb.go | 138 +++++++--- x/vpool/types/vpool.pb.go | 435 ++++++++++++++++++++++++++++--- 22 files changed, 784 insertions(+), 173 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f018aed2b..9912a56b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [v0.12.1-alpha](https://github.com/NibiruChain/nibiru/releases/tag/v0.12.1-alpha) - 2022-08-11 ### CI @@ -51,9 +51,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#798](https://github.com/NibiruChain/nibiru/pull/798) - fix integration tests caused by PR #786 * [#801](https://github.com/NibiruChain/nibiru/pull/801) - remove unused pair constants * [#788](https://github.com/NibiruChain/nibiru/pull/788) - add --overwrite flag to the nibid init call of localnet.sh +* [#804](https://github.com/NibiruChain/nibiru/pull/804) - bump ibc-go to v3.1.1 +* [#818](https://github.com/NibiruChain/nibiru/pull/818) - fix(localnet.sh): add max leverage to vpools in genesis to fix open-position +* [#819](https://github.com/NibiruChain/nibiru/pull/819) - add golangci-linter using docker in Makefile ### Features + * [#791](https://github.com/NibiruChain/nibiru/pull/791) Add the x/oracle module +- [#813](https://github.com/NibiruChain/nibiru/pull/813) - (vpool): Expose mark price, mark TWAP, index price, and k (swap invariant) in the all-pools query +* [#810](https://github.com/NibiruChain/nibiru/pull/810) - feat(x/perp): expose 'marginRatioIndex' and block number on QueryTraderPosition ### Documentation @@ -73,7 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#767](https://github.com/NibiruChain/nibiru/pull/767) - add fluctuation limit checks on `OpenPosition`. * [#786](https://github.com/NibiruChain/nibiru/pull/786) - add genesis params in localnet script. * [#770](https://github.com/NibiruChain/nibiru/pull/770) - Return err in case of zero time elapsed and zero snapshots on `GetCurrentTWAP` func. If zero time has elapsed, and snapshots exists, return the instantaneous average. - + ### Bug Fixes * [#766](https://github.com/NibiruChain/nibiru/pull/766) - Fixed margin ratio calculation for trader position. diff --git a/Makefile b/Makefile index db6c9e688..2e30d1412 100644 --- a/Makefile +++ b/Makefile @@ -162,6 +162,13 @@ test-sim-benchmark-invariants: -Enabled=true -NumBlocks=1000 -BlockSize=200 \ -Period=1 -Commit=true -Seed=57 -v -timeout 24h +############################################################################### +### Lint ### +############################################################################### + +lint: + docker run -v $(CURDIR):/code -w /code golangci/golangci-lint:v1.47.3-alpine golangci-lint run + .PHONY: \ test-sim-nondeterminism \ test-sim-custom-genesis-fast \ diff --git a/go.mod b/go.mod index 4818c8feb..0d6152413 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/cosmos/cosmos-sdk v0.45.6 - github.com/cosmos/ibc-go/v3 v3.1.0 + github.com/cosmos/ibc-go/v3 v3.1.1 github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.2 diff --git a/go.sum b/go.sum index e55704ba5..e2469c472 100644 --- a/go.sum +++ b/go.sum @@ -226,8 +226,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.17.3 h1:s2N819a2olOmiauVa0WAhoIJq9EhSXE9HDBAoR9k+8Y= github.com/cosmos/iavl v0.17.3/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w= -github.com/cosmos/ibc-go/v3 v3.1.0 h1:aVPqkrGBluz6t9+d/sLZIG/zQ9O1KJzVeR4UlL/IFTQ= -github.com/cosmos/ibc-go/v3 v3.1.0/go.mod h1:DbOlOa4yKumaHGKApKkJN90L88PCjSD9ZBdAfL9tT40= +github.com/cosmos/ibc-go/v3 v3.1.1 h1:Yodps4ezxbKS8u0TNJkdYsf+MCb0XzUuIuxIkSUMwbA= +github.com/cosmos/ibc-go/v3 v3.1.1/go.mod h1:IR1bpjywC1i0YcElPa4d2IevNUBZehKoD5bscQlbDyM= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= diff --git a/proto/perp/v1/query.proto b/proto/perp/v1/query.proto index dd0bfd083..dc7b2b895 100644 --- a/proto/perp/v1/query.proto +++ b/proto/perp/v1/query.proto @@ -15,7 +15,7 @@ service Query { option (google.api.http).get = "/nibiru/perp/params"; } - rpc TraderPosition(QueryTraderPositionRequest) returns (QueryTraderPositionResponse) { + rpc QueryTraderPosition(QueryTraderPositionRequest) returns (QueryTraderPositionResponse) { option (google.api.http).get = "/nibiru/perp/trader_position"; } } @@ -54,10 +54,21 @@ message QueryTraderPositionResponse { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; - // The position's margin ratio, calculated from margin, unrealized PnL, and position notional. - string margin_ratio = 4 [ + /* margin ratio of the position based on the mark price, mark TWAP. The higher + value of the possible margin ratios (TWAP and instantaneous) is taken to be + 'marginRatioMark'. Calculated from margin, unrealized PnL, and position notional. */ + string margin_ratio_mark = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + + /* margin ratio of the position based on the index price. Calculated from margin, + unrealized PnL, and position notional. */ + string margin_ratio_index = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false]; + + // BlockNumber is current block number at the time of query. + int64 block_number = 7; } // ---------------------------------------- OtherQuery \ No newline at end of file diff --git a/proto/vpool/v1/query.proto b/proto/vpool/v1/query.proto index c3c6ad3f3..a6c4cfabe 100644 --- a/proto/vpool/v1/query.proto +++ b/proto/vpool/v1/query.proto @@ -55,6 +55,9 @@ message QueryAllPoolsRequest { message QueryAllPoolsResponse { repeated Pool pools = 1; + repeated PoolPrices prices = 2 [ + (gogoproto.nullable) = false + ]; } // ---------------------------------------- BaseAssetPrice diff --git a/proto/vpool/v1/vpool.proto b/proto/vpool/v1/vpool.proto index 413cba2ac..bb7b09513 100644 --- a/proto/vpool/v1/vpool.proto +++ b/proto/vpool/v1/vpool.proto @@ -87,11 +87,42 @@ message Pool { string maintenance_margin_ratio = 7 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false - ]; + ]; // max_leverage string max_leverage = 8 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false - ]; -} \ No newline at end of file + ]; +} + +message PoolPrices { + // MarkPrice is the instantaneous price of the perp. + // Equivalent to quoteAssetReserve / baseAssetReserve. + string mark_price = 10 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // IndexPrice is the price of the "underlying" for the perp + string index_price = 11 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // TwapMark is the time-weighted average (mark) price. + string twap_mark = 12 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // SwapInvariant is the product of the reserves, commonly referred to as "k". + string swap_invariant = 13 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"swap_invariant\"", + (gogoproto.nullable) = false + ]; + + // The block number corresponding to each price + int64 block_number = 14; +} diff --git a/scripts/localnet.sh b/scripts/localnet.sh index ad9f5dbe7..8ca2c2ee6 100755 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -156,6 +156,7 @@ cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[0].trade_limi cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[0].fluctuation_limit_ratio = "0.1"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[0].max_oracle_spread_ratio = "0.1"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[0].maintenance_margin_ratio = "0.0625"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json +cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[0].max_leverage = "12"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json # ETH:NUSD cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].pair = {token0:"ueth",token1:"unusd"}' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].base_asset_reserve = "666666000000"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json # 666k ETH @@ -164,6 +165,7 @@ cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].trade_limi cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].fluctuation_limit_ratio = "0.1"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].max_oracle_spread_ratio = "0.1"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].maintenance_margin_ratio = "0.0625"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json +cat $HOME/.nibid/config/genesis.json | jq '.app_state.vpool.vpools[1].max_leverage = "10"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json # x/perp cat $HOME/.nibid/config/genesis.json | jq '.app_state.perp.params.stopped = false' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json cat $HOME/.nibid/config/genesis.json | jq '.app_state.perp.params.fee_pool_fee_ratio = "0.001"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json diff --git a/x/oracle/types/oracle.pb.go b/x/oracle/types/oracle.pb.go index 3a38a56b1..6a3b1f6d0 100644 --- a/x/oracle/types/oracle.pb.go +++ b/x/oracle/types/oracle.pb.go @@ -137,7 +137,7 @@ var xxx_messageInfo_Pair proto.InternalMessageInfo // struct for aggregate prevoting on the ExchangeRateVote. // The purpose of aggregate prevote is to hide vote exchange rates with hash -// which is formatted as hex string in SHA256("{salt}:({pair},{exchange_rate})|...|({pair},{exchange_rate}):{voter}") +// which is formatted as hex string in SHA256("{salt}:({pair},{exchange_rate})|...,({pair},{exchange_rate}):{voter}") type AggregateExchangeRatePrevote struct { Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty" yaml:"hash"` Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty" yaml:"voter"` diff --git a/x/perp/README.md b/x/perp/README.md index a87fd7c3b..63d29a94e 100644 --- a/x/perp/README.md +++ b/x/perp/README.md @@ -22,9 +22,5 @@ nibid query perp --help The implementation for this module's portion of the `nibid` CLI is contained within the `/perp/client/cli` directory. -## Perp Ecosystem Fund (PerpEF) - -The PerpEF is a module account on Nibiru Protocol. All of its interactions can be encapsulated in two keeper methods. -- `WithdrawFromPerpEF()` -- `DepositToPerpEF()` \ No newline at end of file + diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 1b5a7f48f..5b62a362c 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -153,6 +153,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } +// TODO test: Include checks for queryResp.MarginRatioIndex +// https://github.com/NibiruChain/nibiru/issues/809 func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] @@ -200,7 +202,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("999999.999999999999999359"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000641"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.NewDec(1), queryResp.MarginRatio) + s.EqualValues(sdk.NewDec(1), queryResp.MarginRatioMark) s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") args = []string{ @@ -226,7 +228,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(3_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("3000000.000000000000000938"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000938"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatio) + s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatioMark) s.T().Log("D. Open a reverse position smaller than the existing position") args = []string{ @@ -260,7 +262,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("2999899.999999999999999506"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000494"), queryResp.UnrealizedPnl) - s.EqualValues(sdk.MustNewDecFromStr("0.666688889629654322"), queryResp.MarginRatio) + s.EqualValues(sdk.MustNewDecFromStr("0.666688889629654322"), queryResp.MarginRatioMark) s.T().Log("E. Open a reverse position larger than the existing position") args = []string{ @@ -288,7 +290,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(sdk.MustNewDecFromStr("1000099.999999999999999651"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000843"), queryResp.UnrealizedPnl) // there is a random delta due to twap margin ratio calculation and random block times in the in-process network - s.InDelta(1, queryResp.MarginRatio.MustFloat64(), 0.001) + s.InDelta(1, queryResp.MarginRatioMark.MustFloat64(), 0.001) s.T().Log("F. Close position") args = []string{ diff --git a/x/perp/client/cli/query.go b/x/perp/client/cli/query.go index 041e4be23..d18753f95 100644 --- a/x/perp/client/cli/query.go +++ b/x/perp/client/cli/query.go @@ -88,7 +88,7 @@ func CmdQueryPosition() *cobra.Command { return err } - res, err := queryClient.TraderPosition( + res, err := queryClient.QueryTraderPosition( cmd.Context(), &types.QueryTraderPositionRequest{ Trader: trader.String(), TokenPair: tokenPair.String(), diff --git a/x/perp/keeper/grpc_query.go b/x/perp/keeper/grpc_query.go index ff1da0401..adb04f320 100644 --- a/x/perp/keeper/grpc_query.go +++ b/x/perp/keeper/grpc_query.go @@ -21,7 +21,7 @@ func NewQuerier(k Keeper) queryServer { var _ types.QueryServer = queryServer{} -func (q queryServer) TraderPosition( +func (q queryServer) QueryTraderPosition( goCtx context.Context, req *types.QueryTraderPositionRequest, ) (*types.QueryTraderPositionResponse, error) { if req == nil { @@ -49,16 +49,24 @@ func (q queryServer) TraderPosition( return nil, err } - marginRatio, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_MAX_PNL) + marginRatioMark, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_MAX_PNL) if err != nil { return nil, err } + marginRatioIndex, err := q.Keeper.GetMarginRatio(ctx, *position, types.MarginCalculationPriceOption_INDEX) + if err != nil { + // The index portion of the query fails silently as not to distrupt all + // position queries when oracles aren't posting prices. + q.Keeper.Logger(ctx).Error(err.Error()) + } return &types.QueryTraderPositionResponse{ Position: position, PositionNotional: positionNotional, UnrealizedPnl: unrealizedPnl, - MarginRatio: marginRatio, + MarginRatioMark: marginRatioMark, + MarginRatioIndex: marginRatioIndex, + BlockNumber: ctx.BlockHeight(), }, nil } diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index a15afa744..8299b7152 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -117,7 +117,7 @@ func TestQueryPosition(t *testing.T) { t.Log("query position") ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Second)) - resp, err := queryServer.TraderPosition( + resp, err := queryServer.QueryTraderPosition( sdk.WrapSDKContext(ctx), &types.QueryTraderPositionRequest{ Trader: traderAddr.String(), @@ -131,7 +131,9 @@ func TestQueryPosition(t *testing.T) { assert.Equal(t, tc.expectedPositionNotional, resp.PositionNotional) assert.Equal(t, tc.expectedUnrealizedPnl, resp.UnrealizedPnl) - assert.Equal(t, tc.expectedMarginRatio, resp.MarginRatio) + assert.Equal(t, tc.expectedMarginRatio, resp.MarginRatioMark) + // assert.Equal(t, tc.expectedMarginRatioIndex, resp.MarginRatioIndex) + // TODO https://github.com/NibiruChain/nibiru/issues/809 }) } } diff --git a/x/perp/types/query.pb.go b/x/perp/types/query.pb.go index 4f6682eb5..2e1506cf0 100644 --- a/x/perp/types/query.pb.go +++ b/x/perp/types/query.pb.go @@ -174,8 +174,15 @@ type QueryTraderPositionResponse struct { PositionNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=position_notional,json=positionNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_notional"` // The position's unrealized PnL. UnrealizedPnl github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=unrealized_pnl,json=unrealizedPnl,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"unrealized_pnl"` - // The position's margin ratio, calculated from margin, unrealized PnL, and position notional. - MarginRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=margin_ratio,json=marginRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio"` + // margin ratio of the position based on the mark price, mark TWAP. The higher + // value of the possible margin ratios (TWAP and instantaneous) is taken to be + // 'marginRatioMark'. Calculated from margin, unrealized PnL, and position notional. + MarginRatioMark github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=margin_ratio_mark,json=marginRatioMark,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio_mark"` + // margin ratio of the position based on the index price. Calculated from margin, + // unrealized PnL, and position notional. + MarginRatioIndex github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=margin_ratio_index,json=marginRatioIndex,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin_ratio_index"` + // BlockNumber is current block number at the time of query. + BlockNumber int64 `protobuf:"varint,7,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` } func (m *QueryTraderPositionResponse) Reset() { *m = QueryTraderPositionResponse{} } @@ -218,6 +225,13 @@ func (m *QueryTraderPositionResponse) GetPosition() *Position { return nil } +func (m *QueryTraderPositionResponse) GetBlockNumber() int64 { + if m != nil { + return m.BlockNumber + } + return 0 +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "nibiru.perp.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "nibiru.perp.v1.QueryParamsResponse") @@ -228,38 +242,41 @@ func init() { func init() { proto.RegisterFile("perp/v1/query.proto", fileDescriptor_8212d8958be09421) } var fileDescriptor_8212d8958be09421 = []byte{ - // 485 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xcf, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x9b, 0x32, 0x2a, 0xe6, 0x41, 0x05, 0xee, 0x98, 0xa2, 0x6c, 0x64, 0x28, 0x20, 0x84, - 0x86, 0x88, 0xb5, 0xc1, 0x5f, 0x50, 0x76, 0x43, 0x9a, 0xba, 0x00, 0x17, 0x38, 0x44, 0x6e, 0x6b, - 0x65, 0xd6, 0x52, 0xdb, 0xb3, 0x9d, 0x89, 0x71, 0xe4, 0xc6, 0x09, 0x24, 0xfe, 0xa9, 0x1d, 0x27, - 0x71, 0x41, 0x3b, 0x4c, 0xa8, 0xe5, 0x0f, 0x41, 0xfe, 0x91, 0x42, 0x58, 0x85, 0xd0, 0x4e, 0x76, - 0xdf, 0xfb, 0xfa, 0xf3, 0xbe, 0x7d, 0xef, 0x05, 0xf4, 0x04, 0x91, 0x02, 0x1d, 0x6f, 0xa3, 0xa3, - 0x8a, 0xc8, 0x93, 0x54, 0x48, 0xae, 0x39, 0xec, 0x32, 0x3a, 0xa4, 0xb2, 0x4a, 0x4d, 0x2e, 0x3d, - 0xde, 0x8e, 0x56, 0x0b, 0x5e, 0x70, 0x9b, 0x42, 0xe6, 0xe6, 0x54, 0xd1, 0x46, 0xc1, 0x79, 0x51, - 0x12, 0x84, 0x05, 0x45, 0x98, 0x31, 0xae, 0xb1, 0xa6, 0x9c, 0x29, 0x9f, 0x9d, 0x83, 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38, 0x17, 0xac, 0x0c, 0xaf, 0x5d, 0x89, 0x7c, 0xeb, 0x37, 0x65, 0xc0, 0x4a, 0xb8, 0x0f, - 0x6e, 0x4e, 0xb0, 0x2c, 0x28, 0xcb, 0xa5, 0x19, 0x77, 0xb8, 0x74, 0x25, 0xe8, 0x8a, 0x63, 0x64, - 0x06, 0xb1, 0xf3, 0xa9, 0x0d, 0xae, 0xdb, 0xe6, 0x42, 0x06, 0x3a, 0x6e, 0xa6, 0x30, 0xf9, 0xbb, - 0x7d, 0x97, 0xd7, 0x26, 0x7a, 0xf0, 0x4f, 0x8d, 0x9b, 0x4c, 0xb2, 0xfe, 0xf1, 0xdb, 0xcf, 0xaf, - 0xed, 0xbb, 0xb0, 0x87, 0x9c, 0x18, 0xd9, 0xb5, 0x74, 0xbb, 0x02, 0x3f, 0x07, 0xa0, 0xdb, 0x9c, - 0x28, 0xdc, 0x5a, 0x08, 0x5d, 0xb8, 0x4c, 0xd1, 0x93, 0xff, 0xd2, 0x7a, 0x23, 0x0f, 0xad, 0x91, - 0x18, 0x6e, 0x34, 0x8c, 0xb8, 0xfd, 0xca, 0xeb, 0xe9, 0xf5, 0x77, 0x4f, 0xa7, 0x71, 0x70, 0x36, - 0x8d, 0x83, 0x1f, 0xd3, 0x38, 0xf8, 0x32, 0x8b, 0x5b, 0x67, 0xb3, 0xb8, 0xf5, 0x7d, 0x16, 0xb7, - 0xde, 0x6e, 0xfd, 0xd1, 0xda, 0x3d, 0x4b, 0x78, 0x71, 0x80, 0x29, 0xab, 0x69, 0xef, 0x3d, 0xcf, - 0xb4, 0x78, 0xd8, 0xb1, 0x5f, 0xdb, 0xb3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x18, 0x52, 0x93, - 0x1b, 0xdd, 0x03, 0x00, 0x00, + // 536 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x9b, 0x76, 0x2b, 0xcc, 0x83, 0xc1, 0xdc, 0x31, 0x45, 0xdd, 0xc8, 0x46, 0x40, 0x68, + 0x1a, 0x22, 0xd1, 0x06, 0x9f, 0xa0, 0xec, 0x82, 0x10, 0x55, 0x09, 0x70, 0x19, 0x48, 0x91, 0xdb, + 0x5a, 0x99, 0xd5, 0xc4, 0xce, 0x6c, 0x67, 0xda, 0x38, 0xf2, 0x01, 0x10, 0x12, 0x7c, 0xa8, 0x1d, + 0x27, 0x71, 0x41, 0x1c, 0x26, 0xd4, 0xee, 0x83, 0x20, 0xff, 0x69, 0x59, 0x58, 0x85, 0xa6, 0x9e, + 0xec, 0xbe, 0xef, 0xe3, 0x9f, 0x9f, 0xe6, 0x7d, 0x0c, 0x1a, 0x39, 0xe6, 0x79, 0x78, 0xb4, 0x13, + 0x1e, 0x16, 0x98, 0x9f, 0x04, 0x39, 0x67, 0x92, 0xc1, 0x25, 0x4a, 0xba, 0x84, 0x17, 0x81, 0xea, + 0x05, 0x47, 0x3b, 0xcd, 0x95, 0x84, 0x25, 0x4c, 0xb7, 0x42, 0xb5, 0x33, 0xaa, 0xe6, 0x7a, 0xc2, + 0x58, 0x92, 0xe2, 0x10, 0xe5, 0x24, 0x44, 0x94, 0x32, 0x89, 0x24, 0x61, 0x54, 0xd8, 0xee, 0x04, + 0x2c, 0x24, 0x92, 0xd8, 0x14, 0xfd, 0x15, 0x00, 0xdf, 0xa8, 0x7b, 0x3a, 0x88, 0xa3, 0x4c, 0x44, + 0xf8, 0xb0, 0xc0, 0x42, 0xfa, 0xaf, 0x40, 0xa3, 0x54, 0x15, 0x39, 0xa3, 0x02, 0xc3, 0xe7, 0xa0, + 0x9e, 0xeb, 0x8a, 0xeb, 0x6c, 0x3a, 0x5b, 0x8b, 0xbb, 0xab, 0x41, 0xd9, 0x56, 0x60, 0xf4, 0xad, + 0xb9, 0xd3, 0xf3, 0x8d, 0x4a, 0x64, 0xb5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xf0, 0x01, 0xb8, + 0xd5, 0x4d, 0x59, 0x6f, 0x10, 0xd3, 0x22, 0xeb, 0x62, 0xee, 0xde, 0xd8, 0x74, 0xb6, 0x6a, 0xd1, + 0xa2, 0xae, 0xb5, 0x75, 0x69, 0xf7, 0x4b, 0x15, 0xcc, 0xeb, 0x31, 0x43, 0x0a, 0xea, 0x26, 0x5d, + 0xd0, 0xff, 0x77, 0x90, 0x57, 0x03, 0xdc, 0x7c, 0xf8, 0x5f, 0x8d, 0xc9, 0x88, 0xbf, 0xf6, 0xf9, + 0xc7, 0xc5, 0xb7, 0xea, 0x3d, 0xd8, 0x08, 0x8d, 0x38, 0xd4, 0x0f, 0xc4, 0xa4, 0x16, 0x7e, 0x77, + 0xec, 0x1b, 0x28, 0x07, 0x0c, 0x6e, 0x4f, 0x25, 0x4f, 0xcd, 0x76, 0xf3, 0xc9, 0xb5, 0xb4, 0xd6, + 0xcd, 0x23, 0xed, 0xc6, 0x83, 0xeb, 0x25, 0x37, 0x26, 0xee, 0xf1, 0x38, 0x4c, 0xad, 0xbd, 0xd3, + 0xa1, 0xe7, 0x9c, 0x0d, 0x3d, 0xe7, 0xf7, 0xd0, 0x73, 0xbe, 0x8e, 0xbc, 0xca, 0xd9, 0xc8, 0xab, + 0xfc, 0x1c, 0x79, 0x95, 0xfd, 0xed, 0x4b, 0x73, 0x68, 0x6b, 0xc2, 0x8b, 0x03, 0x44, 0xe8, 0x98, + 0x76, 0x6c, 0x79, 0x6a, 0x1e, 0xdd, 0xba, 0x7e, 0xfc, 0xcf, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, + 0x83, 0xa0, 0xeb, 0xc3, 0x6c, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -276,7 +293,7 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the x/perp module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - TraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) + QueryTraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) } type queryClient struct { @@ -296,9 +313,9 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) TraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) { +func (c *queryClient) QueryTraderPosition(ctx context.Context, in *QueryTraderPositionRequest, opts ...grpc.CallOption) (*QueryTraderPositionResponse, error) { out := new(QueryTraderPositionResponse) - err := c.cc.Invoke(ctx, "/nibiru.perp.v1.Query/TraderPosition", in, out, opts...) + err := c.cc.Invoke(ctx, "/nibiru.perp.v1.Query/QueryTraderPosition", in, out, opts...) if err != nil { return nil, err } @@ -309,7 +326,7 @@ func (c *queryClient) TraderPosition(ctx context.Context, in *QueryTraderPositio type QueryServer interface { // Parameters queries the parameters of the x/perp module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - TraderPosition(context.Context, *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) + QueryTraderPosition(context.Context, *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -319,8 +336,8 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) TraderPosition(ctx context.Context, req *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method TraderPosition not implemented") +func (*UnimplementedQueryServer) QueryTraderPosition(ctx context.Context, req *QueryTraderPositionRequest) (*QueryTraderPositionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryTraderPosition not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -345,20 +362,20 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_TraderPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_QueryTraderPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryTraderPositionRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).TraderPosition(ctx, in) + return srv.(QueryServer).QueryTraderPosition(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/nibiru.perp.v1.Query/TraderPosition", + FullMethod: "/nibiru.perp.v1.Query/QueryTraderPosition", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).TraderPosition(ctx, req.(*QueryTraderPositionRequest)) + return srv.(QueryServer).QueryTraderPosition(ctx, req.(*QueryTraderPositionRequest)) } return interceptor(ctx, in, info, handler) } @@ -372,8 +389,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "TraderPosition", - Handler: _Query_TraderPosition_Handler, + MethodName: "QueryTraderPosition", + Handler: _Query_QueryTraderPosition_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -493,10 +510,25 @@ func (m *QueryTraderPositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if m.BlockNumber != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.BlockNumber)) + i-- + dAtA[i] = 0x38 + } + { + size := m.MarginRatioIndex.Size() + i -= size + if _, err := m.MarginRatioIndex.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a { - size := m.MarginRatio.Size() + size := m.MarginRatioMark.Size() i -= size - if _, err := m.MarginRatio.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.MarginRatioMark.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintQuery(dAtA, i, uint64(size)) @@ -600,8 +632,13 @@ func (m *QueryTraderPositionResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) l = m.UnrealizedPnl.Size() n += 1 + l + sovQuery(uint64(l)) - l = m.MarginRatio.Size() + l = m.MarginRatioMark.Size() + n += 1 + l + sovQuery(uint64(l)) + l = m.MarginRatioIndex.Size() n += 1 + l + sovQuery(uint64(l)) + if m.BlockNumber != 0 { + n += 1 + sovQuery(uint64(m.BlockNumber)) + } return n } @@ -993,7 +1030,7 @@ func (m *QueryTraderPositionResponse) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MarginRatio", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MarginRatioMark", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1021,10 +1058,63 @@ func (m *QueryTraderPositionResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.MarginRatio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.MarginRatioMark.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarginRatioIndex", 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 + } + if err := m.MarginRatioIndex.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockNumber", wireType) + } + m.BlockNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockNumber |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/perp/types/query.pb.gw.go b/x/perp/types/query.pb.gw.go index ec40a0e6a..0fd134914 100644 --- a/x/perp/types/query.pb.gw.go +++ b/x/perp/types/query.pb.gw.go @@ -50,37 +50,37 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } var ( - filter_Query_TraderPosition_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_Query_QueryTraderPosition_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Query_TraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_Query_QueryTraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryTraderPositionRequest 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_TraderPosition_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryTraderPosition_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.TraderPosition(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.QueryTraderPosition(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_TraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_QueryTraderPosition_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryTraderPositionRequest 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_TraderPosition_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryTraderPosition_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.TraderPosition(ctx, &protoReq) + msg, err := server.QueryTraderPosition(ctx, &protoReq) return msg, metadata, err } @@ -111,7 +111,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_TraderPosition_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_QueryTraderPosition_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) @@ -120,14 +120,14 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_TraderPosition_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_QueryTraderPosition_0(rctx, inboundMarshaler, server, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_TraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_QueryTraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -192,7 +192,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_TraderPosition_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_QueryTraderPosition_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) @@ -201,14 +201,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_TraderPosition_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_QueryTraderPosition_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_TraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_QueryTraderPosition_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -218,11 +218,11 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_TraderPosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "trader_position"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_QueryTraderPosition_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"nibiru", "perp", "trader_position"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_TraderPosition_0 = runtime.ForwardResponseMessage + forward_Query_QueryTraderPosition_0 = runtime.ForwardResponseMessage ) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index c16b03640..9ab34f45e 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/libs/log" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -28,6 +29,10 @@ type Keeper struct { pricefeedKeeper types.PricefeedKeeper } +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + /* Trades baseAssets in exchange for quoteAssets. The base asset is a crypto asset like BTC. diff --git a/x/vpool/keeper/pool_state.go b/x/vpool/keeper/pool_state.go index 76d3a76bb..61fc601e9 100644 --- a/x/vpool/keeper/pool_state.go +++ b/x/vpool/keeper/pool_state.go @@ -118,3 +118,24 @@ func (k Keeper) GetAllPools(ctx sdk.Context) []*types.Pool { return pools } + +// GetPoolPrices returns the mark price, twap (mark) price, and index price for a vpool. +func (k Keeper) GetPoolPrices(ctx sdk.Context, pool types.Pool) types.PoolPrices { + indexPrice, err := k.GetUnderlyingPrice(ctx, pool.Pair) + if err != nil { + // fail gracefully so that vpool queries run even if the oracle price feeds stop + k.Logger(ctx).Error(err.Error()) + } + twapMark, err := k.GetCurrentTWAP(ctx, pool.Pair) + if err != nil { + // fail gracefully so that vpool queries run even if the TWAP is undefined. + k.Logger(ctx).Error(err.Error()) + } + return types.PoolPrices{ + MarkPrice: pool.QuoteAssetReserve.Quo(pool.BaseAssetReserve), + IndexPrice: indexPrice, + TwapMark: twapMark.Price, + SwapInvariant: pool.BaseAssetReserve.Mul(pool.QuoteAssetReserve).RoundInt(), + BlockNumber: ctx.BlockHeight(), + } +} diff --git a/x/vpool/keeper/prices.go b/x/vpool/keeper/prices.go index 7550fd936..09ee7a3a8 100644 --- a/x/vpool/keeper/prices.go +++ b/x/vpool/keeper/prices.go @@ -271,8 +271,11 @@ func (k Keeper) calcTwap( return cumulativePrice.QuoInt64(cumulativePeriodMs), nil } -// GetCurrentTWAP fetches the current median price of all oracles for a specific market -func (k Keeper) GetCurrentTWAP(ctx sdk.Context, pair common.AssetPair) (types.CurrentTWAP, error) { +// GetCurrentTWAP fetches the instantaneous time-weighted average (mark) price +// for the given asset pair. +func (k Keeper) GetCurrentTWAP( + ctx sdk.Context, pair common.AssetPair, +) (types.CurrentTWAP, error) { // Ensure we still have valid prices _, err := k.GetSpotPrice(ctx, pair) if err != nil { diff --git a/x/vpool/keeper/query_server.go b/x/vpool/keeper/query_server.go index 4357f4e6b..fedf842e5 100644 --- a/x/vpool/keeper/query_server.go +++ b/x/vpool/keeper/query_server.go @@ -61,9 +61,14 @@ func (q queryServer) AllPools( if err != nil { return nil, err } + var pricesForPools []types.PoolPrices + for _, pool := range pools { + pricesForPools = append(pricesForPools, q.GetPoolPrices(ctx, *pool)) + } return &types.QueryAllPoolsResponse{ - Pools: pools, + Pools: pools, + Prices: pricesForPools, }, nil } diff --git a/x/vpool/types/query.pb.go b/x/vpool/types/query.pb.go index 7210207b1..7ed2764ba 100644 --- a/x/vpool/types/query.pb.go +++ b/x/vpool/types/query.pb.go @@ -152,7 +152,8 @@ func (m *QueryAllPoolsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryAllPoolsRequest proto.InternalMessageInfo type QueryAllPoolsResponse struct { - Pools []*Pool `protobuf:"bytes,1,rep,name=pools,proto3" json:"pools,omitempty"` + Pools []*Pool `protobuf:"bytes,1,rep,name=pools,proto3" json:"pools,omitempty"` + Prices []PoolPrices `protobuf:"bytes,2,rep,name=prices,proto3" json:"prices"` } func (m *QueryAllPoolsResponse) Reset() { *m = QueryAllPoolsResponse{} } @@ -195,6 +196,13 @@ func (m *QueryAllPoolsResponse) GetPools() []*Pool { return nil } +func (m *QueryAllPoolsResponse) GetPrices() []PoolPrices { + if m != nil { + return m.Prices + } + return nil +} + type QueryBaseAssetPriceRequest struct { Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` Direction Direction `protobuf:"varint,2,opt,name=direction,proto3,enum=nibiru.vpool.v1.Direction" json:"direction,omitempty"` @@ -298,42 +306,44 @@ func init() { func init() { proto.RegisterFile("vpool/v1/query.proto", fileDescriptor_e2294d8bbf3b156d) } var fileDescriptor_e2294d8bbf3b156d = []byte{ - // 556 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x86, 0xe3, 0x86, 0x22, 0xba, 0x88, 0x96, 0x2c, 0x29, 0xa4, 0xa6, 0x72, 0x22, 0x0b, 0xa2, - 0x8a, 0x80, 0x57, 0x0d, 0x17, 0xae, 0x09, 0xe1, 0xc0, 0x05, 0xb5, 0x3e, 0x56, 0x08, 0xcb, 0x49, - 0x56, 0xee, 0x0a, 0x67, 0xc7, 0xf1, 0xda, 0x11, 0xe5, 0xc0, 0x81, 0x07, 0x40, 0x48, 0x7d, 0x0b, - 0x1e, 0x04, 0xf5, 0x58, 0x89, 0x0b, 0xea, 0xa1, 0x42, 0x09, 0x0f, 0x82, 0x76, 0xd7, 0xa6, 0x49, - 0x9a, 0x42, 0x95, 0x53, 0xac, 0xd9, 0xdf, 0xdf, 0xce, 0xfc, 0xf3, 0xc7, 0xa8, 0x3c, 0x8a, 0x00, - 0x42, 0x32, 0xda, 0x25, 0xc3, 0x94, 0xc6, 0x47, 0x4e, 0x14, 0x43, 0x02, 0x78, 0x83, 0xb3, 0x2e, - 0x8b, 0x53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c, 0xa0, 0xf9, - 0xf4, 0x7a, 0xe2, 0xac, 0x9d, 0xba, 0x6a, 0xa7, 0x86, 0xad, 0xd9, 0x76, 0xa6, 0x42, 0xa7, 0x16, - 0xd7, 0x7e, 0x75, 0x32, 0xb6, 0x8c, 0xd3, 0xb1, 0x65, 0xfc, 0x1a, 0x5b, 0xc6, 0xd7, 0x89, 0x55, - 0x38, 0x9d, 0x58, 0x85, 0x9f, 0x13, 0xab, 0x70, 0xd0, 0x98, 0x4a, 0xc0, 0x1b, 0xc5, 0x78, 0x79, - 0xe8, 0x33, 0x9e, 0xf3, 0x3e, 0x64, 0x44, 0x15, 0x85, 0xee, 0x4d, 0xf5, 0xbd, 0x7a, 0xfe, 0x27, - 0x00, 0x00, 0xff, 0xff, 0x07, 0xfb, 0xab, 0x40, 0x22, 0x05, 0x00, 0x00, + // 577 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0x9b, 0x76, 0x9b, 0x98, 0x11, 0x1b, 0x35, 0x1d, 0x74, 0xd9, 0x94, 0x56, 0x11, 0x54, + 0x13, 0x85, 0x44, 0x2b, 0x17, 0x38, 0xb6, 0x94, 0x03, 0x17, 0xb4, 0xe5, 0x38, 0x21, 0xa2, 0xb4, + 0xb5, 0xba, 0x88, 0xd4, 0x4e, 0xe3, 0xa4, 0x62, 0x1c, 0x40, 0xe2, 0x01, 0x10, 0xd2, 0xde, 0x82, + 0x07, 0x41, 0x3b, 0x4e, 0xe2, 0x82, 0x76, 0x98, 0x50, 0xcb, 0x83, 0x20, 0x7f, 0x76, 0x58, 0xdb, + 0x65, 0x6c, 0xea, 0xa9, 0x91, 0xfd, 0xf7, 0xcf, 0xdf, 0xf7, 0xff, 0xfe, 0x2e, 0x2a, 0x8d, 0x42, + 0xc6, 0x02, 0x7b, 0xb4, 0x6b, 0x0f,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0xf8, 0x51, 0x36, 0x7e, 0x2e, 0x97, 0x7a, 0xed, 0x3a, 0x99, 0x2a, 0xa0, 0x02, 0x05, 0x6c, + 0xe2, 0x07, 0xb3, 0x05, 0x78, 0x41, 0xe0, 0xca, 0x68, 0x1e, 0x6b, 0x68, 0x6d, 0x76, 0x24, 0xf8, + 0x8a, 0x0e, 0x33, 0x03, 0xa8, 0x3f, 0xb9, 0x99, 0x58, 0x95, 0x53, 0x83, 0x72, 0xaa, 0xd8, 0x98, + 0x2d, 0x67, 0x2a, 0x74, 0x30, 0xb8, 0xd6, 0xab, 0x93, 0xb1, 0xa1, 0x9d, 0x8e, 0x0d, 0xed, 0xf7, + 0xd8, 0xd0, 0xbe, 0x4d, 0x8c, 0xdc, 0xe9, 0xc4, 0xc8, 0xfd, 0x9a, 0x18, 0xb9, 0x83, 0xfa, 0x54, + 0x02, 0xde, 0x00, 0xe3, 0xe5, 0xa1, 0xe7, 0xd3, 0x94, 0xf7, 0x41, 0x11, 0x21, 0x0a, 0x9d, 0x15, + 0xf8, 0xab, 0x7b, 0xf6, 0x37, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x18, 0xc3, 0x4e, 0x5d, 0x05, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -610,6 +620,20 @@ func (m *QueryAllPoolsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Prices) > 0 { + for iNdEx := len(m.Prices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Prices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } if len(m.Pools) > 0 { for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { { @@ -763,6 +787,12 @@ func (m *QueryAllPoolsResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if len(m.Prices) > 0 { + for _, e := range m.Prices { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -1114,6 +1144,40 @@ func (m *QueryAllPoolsResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Prices", 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.Prices = append(m.Prices, PoolPrices{}) + if err := m.Prices[len(m.Prices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/vpool/types/vpool.pb.go b/x/vpool/types/vpool.pb.go index d1f12c866..8080d80d5 100644 --- a/x/vpool/types/vpool.pb.go +++ b/x/vpool/types/vpool.pb.go @@ -207,56 +207,118 @@ func (m *Pool) GetPair() common.AssetPair { return common.AssetPair{} } +type PoolPrices struct { + // MarkPrice is the instantaneous price of the perp. + // Equivalent to quoteAssetReserve / baseAssetReserve. + MarkPrice github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=mark_price,json=markPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"mark_price"` + // IndexPrice is the price of the "underlying" for the perp + IndexPrice github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=index_price,json=indexPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"index_price"` + // TwapMark is the time-weighted average (mark) price. + TwapMark github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,12,opt,name=twap_mark,json=twapMark,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"twap_mark"` + // SwapInvariant is the product of the reserves, commonly referred to as "k". + SwapInvariant github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,13,opt,name=swap_invariant,json=swapInvariant,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"swap_invariant" yaml:"swap_invariant"` + // The block number corresponding to each price + BlockNumber int64 `protobuf:"varint,14,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` +} + +func (m *PoolPrices) Reset() { *m = PoolPrices{} } +func (m *PoolPrices) String() string { return proto.CompactTextString(m) } +func (*PoolPrices) ProtoMessage() {} +func (*PoolPrices) Descriptor() ([]byte, []int) { + return fileDescriptor_eb4ac691d1b54d04, []int{2} +} +func (m *PoolPrices) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PoolPrices) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PoolPrices.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 *PoolPrices) XXX_Merge(src proto.Message) { + xxx_messageInfo_PoolPrices.Merge(m, src) +} +func (m *PoolPrices) XXX_Size() int { + return m.Size() +} +func (m *PoolPrices) XXX_DiscardUnknown() { + xxx_messageInfo_PoolPrices.DiscardUnknown(m) +} + +var xxx_messageInfo_PoolPrices proto.InternalMessageInfo + +func (m *PoolPrices) GetBlockNumber() int64 { + if m != nil { + return m.BlockNumber + } + return 0 +} + func init() { proto.RegisterEnum("nibiru.vpool.v1.Direction", Direction_name, Direction_value) proto.RegisterEnum("nibiru.vpool.v1.TwapCalcOption", TwapCalcOption_name, TwapCalcOption_value) proto.RegisterType((*ReserveSnapshot)(nil), "nibiru.vpool.v1.ReserveSnapshot") proto.RegisterType((*Pool)(nil), "nibiru.vpool.v1.Pool") + proto.RegisterType((*PoolPrices)(nil), "nibiru.vpool.v1.PoolPrices") } func init() { proto.RegisterFile("vpool/v1/vpool.proto", fileDescriptor_eb4ac691d1b54d04) } var fileDescriptor_eb4ac691d1b54d04 = []byte{ - // 613 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xdf, 0x4e, 0xdb, 0x3c, - 0x1c, 0x86, 0xfb, 0x0f, 0x3e, 0x70, 0xd1, 0xd7, 0x12, 0xca, 0x28, 0x68, 0x2a, 0x8c, 0x83, 0x09, - 0x31, 0xad, 0x11, 0xec, 0x0a, 0xd2, 0x36, 0x48, 0x95, 0xda, 0x26, 0x24, 0x61, 0x48, 0x68, 0x9a, - 0xe5, 0x06, 0xd3, 0x5a, 0xc4, 0x71, 0x66, 0xbb, 0x5d, 0x77, 0x17, 0x3b, 0xd9, 0x3d, 0x71, 0xc8, - 0xe1, 0xb4, 0x03, 0x84, 0xe0, 0x46, 0xa6, 0xd8, 0xd1, 0x54, 0xa6, 0xed, 0x60, 0xd5, 0x76, 0x94, - 0xe4, 0xf5, 0x4f, 0xcf, 0x53, 0xbf, 0x95, 0x0d, 0x6a, 0xd3, 0x84, 0xb1, 0xc8, 0x9c, 0x1e, 0x99, - 0xea, 0xa5, 0x99, 0x70, 0x26, 0x99, 0x51, 0x89, 0xc9, 0x90, 0xf0, 0x49, 0x53, 0x67, 0xd3, 0xa3, - 0x9d, 0xed, 0x90, 0x09, 0xca, 0x04, 0x54, 0xcb, 0xa6, 0xfe, 0xd0, 0xb3, 0x3b, 0xb5, 0x11, 0x1b, - 0x31, 0x9d, 0xa7, 0x6f, 0x59, 0xba, 0x11, 0x32, 0x4a, 0x59, 0x6c, 0xea, 0x87, 0x0e, 0xf7, 0xbf, - 0x14, 0x40, 0xc5, 0xc3, 0x02, 0xf3, 0x29, 0xf6, 0x63, 0x94, 0x88, 0x31, 0x93, 0xc6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, 0x5d, 0x27, 0xd0, 0xcc, 0xd3, - 0x33, 0x27, 0xb0, 0xa1, 0xe5, 0xfb, 0x76, 0x00, 0xfd, 0x73, 0xcb, 0xad, 0x16, 0x8c, 0x0d, 0x50, - 0x69, 0x59, 0xfe, 0x93, 0xb0, 0xd8, 0xb2, 0x6f, 0x1e, 0x1a, 0xf9, 0xdb, 0x87, 0x46, 0xfe, 0xfe, - 0xa1, 0x91, 0xff, 0xfc, 0xd8, 0xc8, 0xdd, 0x3e, 0x36, 0x72, 0x5f, 0x1f, 0x1b, 0xb9, 0x8b, 0x57, - 0x73, 0x35, 0x0c, 0xd4, 0x39, 0x6d, 0x8f, 0x11, 0x89, 0x4d, 0x7d, 0x66, 0xcd, 0x99, 0xbe, 0x50, - 0x75, 0x1f, 0xc3, 0x65, 0x75, 0x01, 0xbe, 0xf9, 0x1e, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x93, 0xa8, - 0x1f, 0x6f, 0x05, 0x00, 0x00, + // 730 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0x4f, 0x6f, 0x23, 0x35, + 0x18, 0xc6, 0xf3, 0x6f, 0x97, 0xc6, 0xe9, 0x36, 0xd9, 0x69, 0xca, 0xce, 0xae, 0x50, 0x5a, 0x72, + 0x40, 0x55, 0x11, 0x89, 0x5a, 0x6e, 0xdc, 0xf2, 0x67, 0x8a, 0x22, 0x92, 0xcc, 0x74, 0x26, 0xa5, + 0x52, 0x85, 0xb0, 0x9c, 0x89, 0x9b, 0x58, 0x19, 0x8f, 0x07, 0x8f, 0x93, 0xa6, 0xdf, 0x81, 0x03, + 0x17, 0xbe, 0x53, 0x8f, 0x3d, 0x22, 0x0e, 0x55, 0xd5, 0x7e, 0x03, 0x3e, 0x01, 0xb2, 0x3d, 0xa0, + 0x84, 0xc2, 0xa1, 0x23, 0xf6, 0x34, 0x7e, 0x1f, 0xbf,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e, 0x63, 0x8f, + 0x34, 0xf3, 0xec, 0xdc, 0x1e, 0x59, 0xb0, 0xe5, 0x79, 0xd6, 0x08, 0x7a, 0x17, 0x2d, 0xa7, 0x92, + 0x33, 0x76, 0x41, 0xb9, 0xdd, 0xf2, 0x36, 0xc4, 0x7c, 0xdb, 0xba, 0x7d, 0xac, 0x65, 0xef, 0x1e, + 0x6b, 0xd9, 0x87, 0xc7, 0x5a, 0xf6, 0x97, 0xa7, 0x5a, 0xe6, 0xee, 0xa9, 0x96, 0xf9, 0xed, 0xa9, + 0x96, 0xb9, 0xfc, 0x72, 0x2d, 0xc4, 0xa1, 0x1a, 0x9b, 0x9d, 0x19, 0x22, 0x61, 0x53, 0x8f, 0xd0, + 0xe6, 0x4a, 0xbf, 0x6f, 0x3a, 0xcd, 0xf1, 0x6b, 0xf5, 0x1e, 0x7d, 0xfd, 0x67, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x92, 0xd9, 0xf0, 0x13, 0xfe, 0x06, 0x00, 0x00, } func (m *ReserveSnapshot) Marshal() (dAtA []byte, err error) { @@ -415,6 +477,74 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *PoolPrices) 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 *PoolPrices) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PoolPrices) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockNumber != 0 { + i = encodeVarintVpool(dAtA, i, uint64(m.BlockNumber)) + i-- + dAtA[i] = 0x70 + } + { + size := m.SwapInvariant.Size() + i -= size + if _, err := m.SwapInvariant.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintVpool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x6a + { + size := m.TwapMark.Size() + i -= size + if _, err := m.TwapMark.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintVpool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x62 + { + size := m.IndexPrice.Size() + i -= size + if _, err := m.IndexPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintVpool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + { + size := m.MarkPrice.Size() + i -= size + if _, err := m.MarkPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintVpool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + return len(dAtA) - i, nil +} + func encodeVarintVpool(dAtA []byte, offset int, v uint64) int { offset -= sovVpool(v) base := offset @@ -470,6 +600,26 @@ func (m *Pool) Size() (n int) { return n } +func (m *PoolPrices) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MarkPrice.Size() + n += 1 + l + sovVpool(uint64(l)) + l = m.IndexPrice.Size() + n += 1 + l + sovVpool(uint64(l)) + l = m.TwapMark.Size() + n += 1 + l + sovVpool(uint64(l)) + l = m.SwapInvariant.Size() + n += 1 + l + sovVpool(uint64(l)) + if m.BlockNumber != 0 { + n += 1 + sovVpool(uint64(m.BlockNumber)) + } + return n +} + func sovVpool(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -953,6 +1103,211 @@ func (m *Pool) Unmarshal(dAtA []byte) error { } return nil } +func (m *PoolPrices) 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 ErrIntOverflowVpool + } + 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: PoolPrices: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PoolPrices: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MarkPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVpool + } + 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 ErrInvalidLengthVpool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVpool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MarkPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IndexPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVpool + } + 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 ErrInvalidLengthVpool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVpool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.IndexPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TwapMark", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVpool + } + 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 ErrInvalidLengthVpool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVpool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TwapMark.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SwapInvariant", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVpool + } + 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 ErrInvalidLengthVpool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVpool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SwapInvariant.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockNumber", wireType) + } + m.BlockNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVpool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockNumber |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipVpool(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthVpool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipVpool(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0