From 39ccf6c7c18b0d9fad63120cda74ae06481c7f16 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 13 Nov 2023 20:42:03 +0100 Subject: [PATCH] chore(oracle)!: SetExchangeRateWithEvent --- x/oracle/abci.go | 2 +- x/oracle/keeper/keeper.go | 14 +++++--------- x/oracle/keeper/keeper_test.go | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/x/oracle/abci.go b/x/oracle/abci.go index 9f366a438a..ccd14f89a8 100644 --- a/x/oracle/abci.go +++ b/x/oracle/abci.go @@ -76,7 +76,7 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error { return err } // save the exchange rate to store with denom and timestamp - k.SetExchangeRateWithEvent(ctx, denom, exchangeRate) + k.SetExchangeRate(ctx, denom, exchangeRate) if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) { k.AddHistoricPrice(ctx, denom, exchangeRate) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 0c4b30cb5a..a32202f170 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -113,7 +113,8 @@ func (k Keeper) GetExchangeRateBase(ctx sdk.Context, denom string) (sdk.Dec, err } // SetExchangeRateWithTimestamp sets the consensus exchange rate of USD denominated in the -// denom asset to the store with a timestamp specified instead of using ctx +// denom asset to the store with a timestamp specified instead of using ctx. +// NOTE: must not be used outside of genesis import. func (k Keeper) SetExchangeRateWithTimestamp(ctx sdk.Context, denom string, rate sdk.Dec, t time.Time) { key := types.KeyExchangeRate(denom) val := types.ExchangeRate{Rate: rate, Timestamp: t} @@ -121,19 +122,14 @@ func (k Keeper) SetExchangeRateWithTimestamp(ctx sdk.Context, denom string, rate util.Panic(err) } -// SetExchangeRate sets the consensus exchange rate of USD denominated in the -// denom asset to the store using timestamp from ctx -func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec) { - k.SetExchangeRateWithTimestamp(ctx, denom, rate, ctx.BlockTime()) -} - -// SetExchangeRateWithEvent sets an consensus +// SetExchangeRate sets an consensus // exchange rate to the store with ABCI event -func (k Keeper) SetExchangeRateWithEvent(ctx sdk.Context, denom string, rate sdk.Dec) { +func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec) { k.SetExchangeRateWithTimestamp(ctx, denom, rate, ctx.BlockTime()) sdkutil.Emit(&ctx, &types.EventSetFxRate{ Denom: denom, Rate: rate, }) + } // IterateExchangeRates iterates over all USD rates in the store. diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index b788657c78..e8ce168892 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -206,9 +206,9 @@ func (s *IntegrationTestSuite) TestAggregateExchangeRateVoteError() { s.Require().Errorf(err, types.ErrNoAggregateVote.Error()) } -func (s *IntegrationTestSuite) TestSetExchangeRateWithEvent() { +func (s *IntegrationTestSuite) TestSetExchangeRate() { v := sdk.OneDec() - s.app.OracleKeeper.SetExchangeRateWithEvent(s.ctx, displayDenom, v) + s.app.OracleKeeper.SetExchangeRate(s.ctx, displayDenom, v) rate, err := s.app.OracleKeeper.GetExchangeRate(s.ctx, displayDenom) s.Require().NoError(err) s.Require().Equal(rate, types.ExchangeRate{Rate: v, Timestamp: s.ctx.BlockTime()})