Skip to content

Commit

Permalink
only update price when currenct timestamp is newer than existing one (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha authored Apr 23, 2024
1 parent 8d958e7 commit d02cd19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x/opchild/l2slinky/aggregator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package l2slinky

import (
"errors"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -48,6 +49,11 @@ func WritePrices(ctx sdk.Context, ok types.OracleKeeper, updatedTime time.Time,
continue
}

qp, err := ok.GetPriceForCurrencyPair(ctx, cp)
if err == nil && !qp.BlockTimestamp.After(updatedTime) {
return errors.New("try to update the past price")
}

// Convert the price to a quote price and write it to state.
quotePrice := oracletypes.QuotePrice{
Price: math.NewIntFromBigInt(price),
Expand Down
1 change: 1 addition & 0 deletions x/opchild/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type BankKeeper interface {

type OracleKeeper interface {
GetAllCurrencyPairs(ctx sdk.Context) []slinkytypes.CurrencyPair
GetPriceForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (oracletypes.QuotePrice, error)
SetPriceForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair, qp oracletypes.QuotePrice) error
}

Expand Down

0 comments on commit d02cd19

Please sign in to comment.