Skip to content

Commit f6cc075

Browse files
committed
fix(x/oracle): overflow when calculating twap block range
Signed-off-by: Artur Troian <troian@users.noreply.github.com>
1 parent 44f8ece commit f6cc075

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

x/oracle/keeper/keeper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ func (k *keeper) calculateAggregatedPrices(ctx sdk.Context, latestData []types.P
554554
// calculateTWABySource calculates TWAP for a specific source over the window
555555
func (k *keeper) calculateTWAPBySource(ctx sdk.Context, source uint32, denom string, windowBlocks int64) (sdkmath.LegacyDec, error) {
556556
currentHeight := ctx.BlockHeight()
557-
startHeight := currentHeight - windowBlocks
557+
var startHeight int64
558+
if windowBlocks <= currentHeight {
559+
startHeight = currentHeight - windowBlocks
560+
}
558561

559562
// Get historical data points for this source within the window
560563
dataPoints := k.getTWAPHistory(ctx, source, denom, startHeight, currentHeight)

0 commit comments

Comments
 (0)