diff --git a/x/gmp/types/payment.go b/x/gmp/types/payment.go index b1651d60..e594b028 100644 --- a/x/gmp/types/payment.go +++ b/x/gmp/types/payment.go @@ -5,11 +5,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +// TriggerUpdate checks if the payment should be updated based on the current rate and the last update block. func (p Payment) TriggerUpdate(rate math.LegacyDec, ctx sdk.Context) bool { - // Calculate the percentage difference + if p.LastBlock == 0 || p.LastPrice.IsZero() { + return true + } priceDiff := p.LastPrice.Sub(rate).Abs() - percentageDiff := priceDiff.Quo(p.LastPrice).MulInt64(100) + deviationExceeded := priceDiff.Quo(p.LastPrice).MulInt64(100).GT(p.Deviation) - return percentageDiff.GT(p.Deviation) || - p.LastBlock < ctx.BlockHeight()-p.Heartbeat + return deviationExceeded || p.LastBlock < ctx.BlockHeight()-p.Heartbeat }