diff --git a/src/ammCalculator.ts b/src/ammCalculator.ts index 4ae3d42..a91c9ec 100644 --- a/src/ammCalculator.ts +++ b/src/ammCalculator.ts @@ -435,16 +435,23 @@ function computePriceImpact(spotPrice: string, effectivePrice: string): string { const spot = parseDecimal(spotPrice); const effective = parseDecimal(effectivePrice); - + const spotScaled = spot.int * spot.scale + spot.frac; const effectiveScaled = effective.int * effective.scale + effective.frac; - if (spotScaled === 0n) return "0.00"; + // Issue #1011 — normalize both values to their common scale before + // comparing, so that an integer spot price ("1") and a fractional + // effective price ("0.91") are not compared at different scales. + const commonScale = spot.scale > effective.scale ? spot.scale : effective.scale; + const spotCommon = spotScaled * (commonScale / spot.scale); + const effectiveCommon = effectiveScaled * (commonScale / effective.scale); + + if (spotCommon === 0n) return "0.00"; // (spot - effective) / spot * 100 with 4 decimal places of precision const SCALE = 10000n; - const numerator = (spotScaled - effectiveScaled) * SCALE * 100n; - const denominator = spotScaled; + const numerator = (spotCommon - effectiveCommon) * SCALE * 100n; + const denominator = spotCommon; if (numerator <= 0n) return "0.00";