Skip to content
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

chore(oracle)!: SetExchangeRateWithEvent #2320

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,23 @@ 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}
err := store.SetValue[*types.ExchangeRate](ctx.KVStore(k.storeKey), key, &val, "exchange_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.
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand Down
Loading