Description
_oraclePriceAdjuster1D scales the oracle price to 1e18 precision but compares it to currentPrice computed directly from raw token amounts (which include token-specific decimals). When token0 and token1 have different decimals, currentPrice is off by a constant factor (e.g., 1e12 for 18/6 pairs), causing the comparison oraclePrice > currentPrice to be unreliable. This suppresses or flips the adjustment condition, leading to incorrect or no adjustments.
// Oracle price scaled to 1e18
uint256 oraclePrice = answer.toUint256();
if (oracleDecimals < 18) {
oraclePrice = oraclePrice * 10**(18 - oracleDecimals);
} else if (oracleDecimals > 18) {
oraclePrice = oraclePrice / 10**(oracleDecimals - 18);
}
// Current price from raw amounts (token0 per token1)
uint256 currentPrice = (ctx.swap.amountOut * 1e18) / ctx.swap.amountIn;
if (oraclePrice > currentPrice) {
// adjust amounts ...
}
Example: token1=USDC(6), token0=WETH(18), amountOut≈1e18 (1 WETH), amountIn≈3000e6 (3000 USDC). currentPrice (1e18*1e18)/3000e6≈3.33e26, whereas an oracle scaled to 1e18 might yield ≈3.33e14 (WETH per USDC) or 3000e18 (USDC per WETH) depending on feed orientation. Because currentPrice is computed using raw decimals, the comparison against a 1e18-scaled oracle price becomes meaningless, causing the adjustment to fail or behave incorrectly even when market price differs materially