@@ -339,8 +339,9 @@ func (u *PriceUpdater) updateBalanceMetrics(ctx context.Context) error {
339339}
340340
341341// shouldUpdatePrice checks if the price change exceeds the threshold
342- // Formula: |newPrice - lastPrice| / lastPrice * 100 >= threshold
343- // Example: if threshold is 5, price must change by at least 5% to trigger update
342+ // Formula: |newPrice - lastPrice| / lastPrice * 10000 >= threshold
343+ // Threshold is in basis points (bps): 1 bps = 0.01%, 100 bps = 1%, 10000 bps = 100%
344+ // Example: if threshold is 100 (bps), price must change by at least 1% to trigger update
344345func (u * PriceUpdater ) shouldUpdatePrice (lastPrice , newPrice * big.Int ) bool {
345346 // Validate inputs
346347 if lastPrice == nil || newPrice == nil {
@@ -352,27 +353,37 @@ func (u *PriceUpdater) shouldUpdatePrice(lastPrice, newPrice *big.Int) bool {
352353 return true // Always update if no previous price
353354 }
354355
355- // Validate threshold is reasonable (should be < 100 for percentage )
356- // If threshold is unreasonably large, log warning and use default
356+ // Validate threshold is reasonable (should be <= 10000 for basis points )
357+ // If threshold is unreasonably large, log warning and cap at 100% (10000 bps)
357358 threshold := u .priceThreshold
358- if threshold > 100 {
359- log .Warn ("Price threshold is unusually large, capping at 100%" ,
360- "configured_threshold" , threshold )
361- threshold = 100
359+ if threshold > 10000 {
360+ log .Warn ("Price threshold is unusually large, capping at 100% (10000 bps)" ,
361+ "configured_threshold" , threshold ,
362+ "capped_threshold" , 10000 )
363+ threshold = 10000
362364 }
363365
364366 // Calculate absolute difference: |newPrice - lastPrice|
365367 diff := new (big.Int ).Sub (newPrice , lastPrice )
366368 diff .Abs (diff )
367369
368- // Calculate percentage change: diff * 100 / lastPrice
369- // This gives us the percentage as an integer (e.g., 5 for 5 %)
370- percentage := new (big.Int ).Mul (diff , big .NewInt (100 ))
371- percentage .Div (percentage , lastPrice )
370+ // Calculate change in basis points : diff * 10000 / lastPrice
371+ // This gives us the change in bps (e.g., 100 for 1%, 10 for 0.1%, 1 for 0.01 %)
372+ bps := new (big.Int ).Mul (diff , big .NewInt (10000 ))
373+ bps .Div (bps , lastPrice )
372374
373- // Compare with threshold (both are percentages )
375+ // Compare with threshold (both are in basis points )
374376 thresholdBig := big .NewInt (int64 (threshold ))
375- return percentage .Cmp (thresholdBig ) >= 0
377+ shouldUpdate := bps .Cmp (thresholdBig ) >= 0
378+
379+ log .Debug ("Price change check" ,
380+ "last_price" , lastPrice .String (),
381+ "new_price" , newPrice .String (),
382+ "change_bps" , bps .String (),
383+ "threshold_bps" , threshold ,
384+ "should_update" , shouldUpdate )
385+
386+ return shouldUpdate
376387}
377388
378389// fetchTokenIDsFromContract fetches supported token IDs from L2TokenRegistry contract
0 commit comments