From 40f8e71373333f0c35767aeae6dd31b2c0ddb7d8 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Sat, 7 Oct 2023 20:55:52 -0500 Subject: [PATCH] fix(perp): emit MarketUpdatedEvents even in the absence of index price (#1606) --- CHANGELOG.md | 4 ++++ x/perp/v2/module/abci.go | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3590d742..7f3a17466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `bufbuild/buf-setup-action` from 1.26.1 to 1.27.0 ([#1624](https://github.com/NibiruChain/nibiru/pull/1624)) - Bump `stefanzweifel/git-auto-commit-action` from 4 to 5 ([#1625](https://github.com/NibiruChain/nibiru/pull/1625)) +### Bug Fixes + +* [#1606](https://github.com/NibiruChain/nibiru/pull/1606) - fix(perp): emit `MarketUpdatedEvent` in the absence of index price + ## [v0.21.10] ### Features diff --git a/x/perp/v2/module/abci.go b/x/perp/v2/module/abci.go index 8b9edb281..6326700dc 100644 --- a/x/perp/v2/module/abci.go +++ b/x/perp/v2/module/abci.go @@ -37,18 +37,19 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) []abci.ValidatorUpdate { continue } - indexTwap, err := k.OracleKeeper.GetExchangeRateTwap(ctx, amm.Pair) - if err != nil { - k.Logger(ctx).Error("failed to fetch twap index price", "market.Pair", market.Pair, "error", err) - continue - } - if markTwap.IsNil() || markTwap.IsZero() { k.Logger(ctx).Error("mark price is zero", "market.Pair", market.Pair) continue } - if indexTwap.IsNil() || indexTwap.IsZero() { + var indexTwap sdk.Dec + indexTwap, err = k.OracleKeeper.GetExchangeRateTwap(ctx, amm.Pair) + if err != nil { + k.Logger(ctx).Error("failed to fetch twap index price", "market.Pair", market.Pair, "error", err) + indexTwap = sdk.OneDec().Neg() + } + + if indexTwap.IsNil() { k.Logger(ctx).Error("index price is zero", "market.Pair", market.Pair) continue }