From fba6dec41984a5413abeb3b05b9e6315aa09e3f2 Mon Sep 17 00:00:00 2001 From: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:41:32 -0800 Subject: [PATCH] fix: metoken medians (#2346) * fix: metoken medians * Update abci.go Co-authored-by: Robert Zaremba * add a log & changelog entry * actually, remove this log and use the err scope fix --------- Co-authored-by: Robert Zaremba --- CHANGELOG.md | 1 + x/oracle/abci.go | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb4598132c..2721cb65b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes - [2315](https://github.com/umee-network/umee/pull/2215) Improve reliability of MaxBorrow, MaxWithdraw when special asset pairs present. +- [2346](https://github.com/umee-network/umee/pull/2346) Fix an issue where metokens were not included in historic data. ### Improvements diff --git a/x/oracle/abci.go b/x/oracle/abci.go index ccd14f89a8..f0becd24b8 100644 --- a/x/oracle/abci.go +++ b/x/oracle/abci.go @@ -77,16 +77,23 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error { } // save the exchange rate to store with denom and timestamp k.SetExchangeRate(ctx, denom, exchangeRate) + } - if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) { - k.AddHistoricPrice(ctx, denom, exchangeRate) - } - - // Calculate and stamp median/median deviation if median stamp period has passed - if k.IsPeriodLastBlock(ctx, params.MedianStampPeriod) { - if err = k.CalcAndSetHistoricMedian(ctx, denom); err != nil { - return err - } + if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) { + k.IterateExchangeRates(ctx, func(denom string, exgRate sdk.Dec, _ time.Time) (stop bool) { + k.AddHistoricPrice(ctx, denom, exgRate) + return false + }) + } + // Calculate and stamp median/median deviation if median stamp period has passed + if k.IsPeriodLastBlock(ctx, params.MedianStampPeriod) { + var err error + k.IterateExchangeRates(ctx, func(denom string, _ sdk.Dec, _ time.Time) (stop bool) { + err = k.CalcAndSetHistoricMedian(ctx, denom) + return err != nil + }) + if err != nil { + return err } }