-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(vpool): expose markPrice, markTwap, indexPrice, (and blockHeight?) on the all-pools query #789 #813
Conversation
…ice, and swap inv. for a pool
]; | ||
|
||
// SwapInvariant is the product of the reserves, commonly referred to as "k". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed like it might be useful to know k
mixed in with the prices for the pool, especially if k
is going to be dynamic. Seeing a price of $1000 has completely different implications if the scale of k
changes 3x, 10x, etc.
@@ -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)) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this Tendermint log.Logger
object in perp, and it seemed useful enoough to add to x/vpool
.
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()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vied for the route of gracefully failing here rather than erroring out the query. I think people should still be able to query the mark price even if the TWAP and oracle aren't valid. Invalid fields in the query will just have a blank/nil sdk.Dec
.
// 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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls GetSpotPrice
, which is retrieving the ratio quoteReserves / baseReserves
, so it has nothing to do with oracle prices.
commit b496438338d5cd136661e6cf79a694e47a8198b9 Author: Unique-Divine <realuniquedivine@gmail.com> Date: Fri Aug 12 18:03:02 2022 -0500 remove deperecated docs from x/perp/README commit fc260a5 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 8ec477a 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 208a102 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 75e8f03 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 <agentsmith@matrixsystems.co> commit 674da1b 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 c6ad354 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](cosmos/ibc-go@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] <support@github.com> * 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>
* docs(perp): events #wip * docs(perp): Added events specification for the perp module. * Squashed commit of the following: commit b496438338d5cd136661e6cf79a694e47a8198b9 Author: Unique-Divine <realuniquedivine@gmail.com> Date: Fri Aug 12 18:03:02 2022 -0500 remove deperecated docs from x/perp/README commit fc260a5 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 8ec477a 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 208a102 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 75e8f03 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 <agentsmith@matrixsystems.co> commit 674da1b 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 c6ad354 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](cosmos/ibc-go@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] <support@github.com> * 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> Co-authored-by: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com>
Reference: This PR was spawned by #789
q vpool all-prices
query, exposemarkPrice
,twapMark
,indexPrice
, andblockHeight
#808