Skip to content

Commit

Permalink
fix: metoken medians (#2346)
Browse files Browse the repository at this point in the history
* fix: metoken medians

* Update abci.go

Co-authored-by: Robert Zaremba <robert@zaremba.ch>

* add a log & changelog entry

* actually, remove this log and use the err scope fix

---------

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
adamewozniak and robert-zaremba authored Dec 1, 2023
1 parent 7a8cdfa commit fba6dec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 16 additions & 9 deletions x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit fba6dec

Please sign in to comment.