diff --git a/onchain/src/abstracts/PriceOracle.sol b/onchain/src/abstracts/PriceOracle.sol index 3a91b13..2645d29 100644 --- a/onchain/src/abstracts/PriceOracle.sol +++ b/onchain/src/abstracts/PriceOracle.sol @@ -43,9 +43,15 @@ abstract contract PriceOracle { // Fallback to longer timeframe if recent data unavailable uint32 fallbackInterval = PRICE_STABILITY_INTERVAL * 200; // 6,000 seconds secondsAgo[0] = fallbackInterval; - (int56[] memory tickCumulatives,) = pool.observe(secondsAgo); - int56 tickCumulativeDiff = tickCumulatives[1] - tickCumulatives[0]; - averageTick = int24(tickCumulativeDiff / int56(int32(fallbackInterval))); + try pool.observe(secondsAgo) returns (int56[] memory fallbackCumulatives, uint160[] memory) { + int56 tickCumulativeDiff = fallbackCumulatives[1] - fallbackCumulatives[0]; + averageTick = int24(tickCumulativeDiff / int56(int32(fallbackInterval))); + } catch { + // Pool has insufficient observation history for both intervals. + // Treat price as unstable (safe default) — prevents recenter() from + // reverting with an opaque Uniswap error on pools with very short history. + return false; + } } isStable = (currentTick >= averageTick - MAX_TICK_DEVIATION && currentTick <= averageTick + MAX_TICK_DEVIATION); diff --git a/onchain/test/abstracts/PriceOracle.t.sol b/onchain/test/abstracts/PriceOracle.t.sol index 5882127..a0d9460 100644 --- a/onchain/test/abstracts/PriceOracle.t.sol +++ b/onchain/test/abstracts/PriceOracle.t.sol @@ -228,6 +228,15 @@ contract PriceOracleTest is Test { assertTrue(isStable, "Price stability should work with negative ticks"); } + function testDoubleFailureReturnsFalse() public { + // When pool has < 6000 seconds of history, both observe() calls fail. + // _isPriceStable should return false (safe default) instead of reverting. + mockPool.setShouldRevert(true); + + bool isStable = priceOracle.isPriceStable(1000); + assertFalse(isStable, "Double observe failure should return false, not revert"); + } + // ======================================== // PRICE MOVEMENT VALIDATION TESTS // ========================================