diff --git a/contracts/PoolManager.sol b/contracts/PoolManager.sol index 7c888e0a1..4cfd6a591 100644 --- a/contracts/PoolManager.sol +++ b/contracts/PoolManager.sol @@ -20,11 +20,6 @@ contract PoolManager is IPoolManager, NoDelegateCall { mapping(bytes32 => Pool.State) public pools; - /// @dev For mocking in unit tests - function _blockTimestamp() internal view virtual returns (uint32) { - return uint32(block.timestamp); - } - function _getPool(IPoolManager.PoolKey memory key) private view returns (Pool.State storage) { return pools[keccak256(abi.encode(key))]; } @@ -35,23 +30,13 @@ contract PoolManager is IPoolManager, NoDelegateCall { key.hooks.beforeInitialize(msg.sender, key, sqrtPriceX96); } - tick = _getPool(key).initialize(_blockTimestamp(), sqrtPriceX96); + tick = _getPool(key).initialize(sqrtPriceX96); if (key.hooks.shouldCallAfterInitialize()) { key.hooks.afterInitialize(msg.sender, key, sqrtPriceX96, tick); } } - /// @notice Increase the maximum number of stored observations for the pool's oracle - function increaseObservationCardinalityNext(IPoolManager.PoolKey memory key, uint16 observationCardinalityNext) - external - override - returns (uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew) - { - (observationCardinalityNextOld, observationCardinalityNextNew) = _getPool(key) - .increaseObservationCardinalityNext(observationCardinalityNext); - } - /// @inheritdoc IPoolManager mapping(IERC20Minimal => uint256) public override reservesOf; @@ -175,7 +160,6 @@ contract PoolManager is IPoolManager, NoDelegateCall { tickLower: params.tickLower, tickUpper: params.tickUpper, liquidityDelta: params.liquidityDelta.toInt128(), - time: _blockTimestamp(), maxLiquidityPerTick: Tick.tickSpacingToMaxLiquidityPerTick(key.tickSpacing), tickSpacing: key.tickSpacing }) @@ -201,7 +185,6 @@ contract PoolManager is IPoolManager, NoDelegateCall { delta = _getPool(key).swap( Pool.SwapParams({ - time: _blockTimestamp(), fee: key.fee, tickSpacing: key.tickSpacing, zeroForOne: params.zeroForOne, @@ -237,23 +220,4 @@ contract PoolManager is IPoolManager, NoDelegateCall { // subtraction must be safe _accountDelta(token, -(paid.toInt256())); } - - /// @notice Observe a past state of a pool - function observe(IPoolManager.PoolKey calldata key, uint32[] calldata secondsAgos) - external - view - noDelegateCall - returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) - { - return _getPool(key).observe(_blockTimestamp(), secondsAgos); - } - - /// @notice Get the snapshot of the cumulative values of a tick range - function snapshotCumulativesInside( - IPoolManager.PoolKey calldata key, - int24 tickLower, - int24 tickUpper - ) external view override noDelegateCall returns (Pool.Snapshot memory) { - return _getPool(key).snapshotCumulativesInside(tickLower, tickUpper, _blockTimestamp()); - } } diff --git a/contracts/hooks/V3Oracle.sol b/contracts/hooks/V3Oracle.sol new file mode 100644 index 000000000..2a6e28266 --- /dev/null +++ b/contracts/hooks/V3Oracle.sol @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity =0.8.13; + +import {IHooks} from '../interfaces/IHooks.sol'; +import {IPoolManager} from '../interfaces/IPoolManager.sol'; +import {Hooks} from '../libraries/Hooks.sol'; + +/// @notice Includes the Oracle feature in a similar way to V3. This is now externalized +contract V3Oracle is IHooks { + constructor() { + Hooks.validateHookAddress( + this, + Hooks.Calls({ + beforeInitialize: false, + // to initialize the observations for the pool + afterInitialize: true, + // to record the tick at the start of the block for the pool + beforeModifyPosition: true, + afterModifyPosition: false, + // to record the tick at the start of the block for the pool + beforeSwap: true, + afterSwap: false + }) + ); + } + + function beforeInitialize( + address sender, + IPoolManager.PoolKey memory key, + uint160 sqrtPriceX96 + ) external override { + revert(); + } + + function afterInitialize( + address sender, + IPoolManager.PoolKey memory key, + uint160 sqrtPriceX96, + int24 tick + ) external override { + revert(); + } + + function beforeModifyPosition( + address sender, + IPoolManager.PoolKey calldata key, + IPoolManager.ModifyPositionParams calldata params + ) external override { + revert(); + } + + function afterModifyPosition( + address sender, + IPoolManager.PoolKey calldata key, + IPoolManager.ModifyPositionParams calldata params, + IPoolManager.BalanceDelta calldata delta + ) external override { + revert(); + } + + function beforeSwap( + address sender, + IPoolManager.PoolKey calldata key, + IPoolManager.SwapParams calldata params + ) external override { + revert(); + } + + function afterSwap( + address sender, + IPoolManager.PoolKey calldata key, + IPoolManager.SwapParams calldata params, + IPoolManager.BalanceDelta calldata delta + ) external override { + revert(); + } + + +// /// @notice Observe a past state of a pool +// function observe(PoolKey calldata key, uint32[] calldata secondsAgos) +// external +// view +// returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); +// +// /// @notice Get the snapshot of the cumulative values of a tick range +// function snapshotCumulativesInside( +// PoolKey calldata key, +// int24 tickLower, +// int24 tickUpper +// ) external view returns (Pool.Snapshot memory); + + /// @dev Increase the number of stored observations +// function observe( +// IPoolManager.PoolKey calldata key, +// uint32[] calldata secondsAgos +// ) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) { +// return observations[key].observe( +// time, +// secondsAgos, +// self.slot0.tick, +// self.slot0.observationIndex, +// self.liquidity, +// self.slot0.observationCardinality +// ); +// } +// +// /// @dev Increase the number of stored observations +// function increaseObservationCardinalityNext(State storage self, uint16 observationCardinalityNext) +// internal +// returns (uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew) +// { +// observationCardinalityNextOld = self.slot0.observationCardinalityNext; +// observationCardinalityNextNew = self.observations.grow( +// observationCardinalityNextOld, +// observationCardinalityNext +// ); +// self.slot0.observationCardinalityNext = observationCardinalityNextNew; +// } + +} diff --git a/contracts/interfaces/IPoolManager.sol b/contracts/interfaces/IPoolManager.sol index cec2d1215..5d32f72b7 100644 --- a/contracts/interfaces/IPoolManager.sol +++ b/contracts/interfaces/IPoolManager.sol @@ -45,11 +45,6 @@ interface IPoolManager { /// @notice Initialize the state for a given pool ID function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick); - /// @notice Increase the maximum number of stored observations for the pool's oracle - function increaseObservationCardinalityNext(PoolKey memory key, uint16 observationCardinalityNext) - external - returns (uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew); - /// @notice Represents the stack of addresses that have locked the pool. Each call to #lock pushes the address onto the stack /// @param index The index of the locker, also known as the id of the locker function lockedBy(uint256 index) external view returns (address); @@ -110,17 +105,4 @@ interface IPoolManager { /// @notice Called by the user to pay what is owed function settle(IERC20Minimal token) external returns (uint256 paid); - - /// @notice Observe a past state of a pool - function observe(PoolKey calldata key, uint32[] calldata secondsAgos) - external - view - returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); - - /// @notice Get the snapshot of the cumulative values of a tick range - function snapshotCumulativesInside( - PoolKey calldata key, - int24 tickLower, - int24 tickUpper - ) external view returns (Pool.Snapshot memory); } diff --git a/contracts/libraries/Pool.sol b/contracts/libraries/Pool.sol index b6a7a9d31..b86c89647 100644 --- a/contracts/libraries/Pool.sol +++ b/contracts/libraries/Pool.sol @@ -5,7 +5,6 @@ import {SafeCast} from './SafeCast.sol'; import {Tick} from './Tick.sol'; import {TickBitmap} from './TickBitmap.sol'; import {Position} from './Position.sol'; -import {Oracle} from './Oracle.sol'; import {FullMath} from './FullMath.sol'; import {FixedPoint128} from './FixedPoint128.sol'; import {TickMath} from './TickMath.sol'; @@ -19,7 +18,6 @@ library Pool { using TickBitmap for mapping(int16 => uint256); using Position for mapping(bytes32 => Position.Info); using Position for Position.Info; - using Oracle for Oracle.Observation[65535]; /// @notice Thrown when tickLower is not below tickUpper /// @param tickLower The invalid tickLower @@ -61,12 +59,6 @@ library Pool { uint160 sqrtPriceX96; // the current tick int24 tick; - // the most-recently updated index of the observations array - uint16 observationIndex; - // the current maximum number of observations that are being stored - uint16 observationCardinality; - // the next maximum number of observations to store, triggered in observations.write - uint16 observationCardinalityNext; } /// @dev The state of a pool @@ -78,7 +70,6 @@ library Pool { mapping(int24 => Tick.Info) ticks; mapping(int16 => uint256) tickBitmap; mapping(bytes32 => Position.Info) positions; - Oracle.Observation[65535] observations; } /// @dev Common checks for valid tick inputs. @@ -88,144 +79,12 @@ library Pool { if (tickUpper > TickMath.MAX_TICK) revert TickUpperOutOfBounds(tickUpper); } - struct SnapshotCumulativesInsideState { - int56 tickCumulativeLower; - int56 tickCumulativeUpper; - uint160 secondsPerLiquidityOutsideLowerX128; - uint160 secondsPerLiquidityOutsideUpperX128; - uint32 secondsOutsideLower; - uint32 secondsOutsideUpper; - } - - struct Snapshot { - int56 tickCumulativeInside; - uint160 secondsPerLiquidityInsideX128; - uint32 secondsInside; - } - - /// @dev Take a snapshot of the cumulative values inside a tick range, only consistent as long as a position has non-zero liquidity - function snapshotCumulativesInside( - State storage self, - int24 tickLower, - int24 tickUpper, - uint32 time - ) internal view returns (Snapshot memory result) { - checkTicks(tickLower, tickUpper); - - SnapshotCumulativesInsideState memory state; - { - Tick.Info storage lower = self.ticks[tickLower]; - Tick.Info storage upper = self.ticks[tickUpper]; - bool initializedLower; - ( - state.tickCumulativeLower, - state.secondsPerLiquidityOutsideLowerX128, - state.secondsOutsideLower, - initializedLower - ) = ( - lower.tickCumulativeOutside, - lower.secondsPerLiquidityOutsideX128, - lower.secondsOutside, - lower.initialized - ); - if (!initializedLower) revert TickNotInitialized(tickLower); - - bool initializedUpper; - ( - state.tickCumulativeUpper, - state.secondsPerLiquidityOutsideUpperX128, - state.secondsOutsideUpper, - initializedUpper - ) = ( - upper.tickCumulativeOutside, - upper.secondsPerLiquidityOutsideX128, - upper.secondsOutside, - upper.initialized - ); - if (!initializedUpper) revert TickNotInitialized(tickUpper); - } - - Slot0 memory _slot0 = self.slot0; - - unchecked { - if (_slot0.tick < tickLower) { - result.tickCumulativeInside = state.tickCumulativeLower - state.tickCumulativeUpper; - result.secondsPerLiquidityInsideX128 = - state.secondsPerLiquidityOutsideLowerX128 - - state.secondsPerLiquidityOutsideUpperX128; - result.secondsInside = state.secondsOutsideLower - state.secondsOutsideUpper; - } else if (_slot0.tick < tickUpper) { - (int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) = self.observations.observeSingle( - time, - 0, - _slot0.tick, - _slot0.observationIndex, - self.liquidity, - _slot0.observationCardinality - ); - result.tickCumulativeInside = tickCumulative - state.tickCumulativeLower - state.tickCumulativeUpper; - result.secondsPerLiquidityInsideX128 = - secondsPerLiquidityCumulativeX128 - - state.secondsPerLiquidityOutsideLowerX128 - - state.secondsPerLiquidityOutsideUpperX128; - result.secondsInside = time - state.secondsOutsideLower - state.secondsOutsideUpper; - } else { - result.tickCumulativeInside = state.tickCumulativeUpper - state.tickCumulativeLower; - result.secondsPerLiquidityInsideX128 = - state.secondsPerLiquidityOutsideUpperX128 - - state.secondsPerLiquidityOutsideLowerX128; - result.secondsInside = state.secondsOutsideUpper - state.secondsOutsideLower; - } - } - } - - function observe( - State storage self, - uint32 time, - uint32[] calldata secondsAgos - ) internal view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) { - return - self.observations.observe( - time, - secondsAgos, - self.slot0.tick, - self.slot0.observationIndex, - self.liquidity, - self.slot0.observationCardinality - ); - } - - function initialize( - State storage self, - uint32 time, - uint160 sqrtPriceX96 - ) internal returns (int24 tick) { + function initialize(State storage self, uint160 sqrtPriceX96) internal returns (int24 tick) { if (self.slot0.sqrtPriceX96 != 0) revert PoolAlreadyInitialized(); tick = TickMath.getTickAtSqrtRatio(sqrtPriceX96); - (uint16 cardinality, uint16 cardinalityNext) = self.observations.initialize(time); - - self.slot0 = Slot0({ - sqrtPriceX96: sqrtPriceX96, - tick: tick, - observationIndex: 0, - observationCardinality: cardinality, - observationCardinalityNext: cardinalityNext - }); - } - - /// @dev Increase the number of stored observations - function increaseObservationCardinalityNext(State storage self, uint16 observationCardinalityNext) - internal - returns (uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew) - { - observationCardinalityNextOld = self.slot0.observationCardinalityNext; - observationCardinalityNextNew = self.observations.grow( - observationCardinalityNextOld, - observationCardinalityNext - ); - self.slot0.observationCardinalityNext = observationCardinalityNextNew; + self.slot0 = Slot0({sqrtPriceX96: sqrtPriceX96, tick: tick}); } struct ModifyPositionParams { @@ -236,8 +95,6 @@ library Pool { int24 tickUpper; // any change in liquidity int128 liquidityDelta; - // current time - uint32 time; // the max liquidity per tick uint128 maxLiquidityPerTick; // the spacing between ticks @@ -268,24 +125,12 @@ library Pool { ModifyPositionState memory state; // if we need to update the ticks, do it if (params.liquidityDelta != 0) { - (state.tickCumulative, state.secondsPerLiquidityCumulativeX128) = self.observations.observeSingle( - params.time, - 0, - self.slot0.tick, - self.slot0.observationIndex, - self.liquidity, - self.slot0.observationCardinality - ); - state.flippedLower = self.ticks.update( params.tickLower, self.slot0.tick, params.liquidityDelta, self.feeGrowthGlobal0X128, self.feeGrowthGlobal1X128, - state.secondsPerLiquidityCumulativeX128, - state.tickCumulative, - params.time, false, params.maxLiquidityPerTick ); @@ -295,9 +140,6 @@ library Pool { params.liquidityDelta, self.feeGrowthGlobal0X128, self.feeGrowthGlobal1X128, - state.secondsPerLiquidityCumulativeX128, - state.tickCumulative, - params.time, true, params.maxLiquidityPerTick ); @@ -346,17 +188,6 @@ library Pool { params.liquidityDelta ); } else if (self.slot0.tick < params.tickUpper) { - // current tick is inside the passed range, must modify liquidity - // write an oracle entry - (self.slot0.observationIndex, self.slot0.observationCardinality) = self.observations.write( - self.slot0.observationIndex, - params.time, - self.slot0.tick, - self.liquidity, - self.slot0.observationCardinality, - self.slot0.observationCardinalityNext - ); - result.amount0 += SqrtPriceMath.getAmount0Delta( self.slot0.sqrtPriceX96, TickMath.getSqrtRatioAtTick(params.tickUpper), @@ -386,12 +217,6 @@ library Pool { struct SwapCache { // liquidity at the beginning of the swap uint128 liquidityStart; - // the current value of the tick accumulator, computed only if we cross an initialized tick - int56 tickCumulative; - // the current value of seconds per liquidity accumulator, computed only if we cross an initialized tick - uint160 secondsPerLiquidityCumulativeX128; - // whether we've computed and cached the above two accumulators - bool computedLatestObservation; } // the top level state of the swap, the results of which are recorded in storage at the end @@ -430,7 +255,6 @@ library Pool { struct SwapParams { uint24 fee; int24 tickSpacing; - uint32 time; bool zeroForOne; int256 amountSpecified; uint160 sqrtPriceLimitX96; @@ -457,12 +281,7 @@ library Pool { revert PriceLimitOutOfBounds(params.sqrtPriceLimitX96); } - SwapCache memory cache = SwapCache({ - liquidityStart: self.liquidity, - secondsPerLiquidityCumulativeX128: 0, - tickCumulative: 0, - computedLatestObservation: false - }); + SwapCache memory cache = SwapCache({liquidityStart: self.liquidity}); bool exactInput = params.amountSpecified > 0; @@ -536,29 +355,10 @@ library Pool { if (state.sqrtPriceX96 == step.sqrtPriceNextX96) { // if the tick is initialized, run the tick transition if (step.initialized) { - // check for the placeholder value, which we replace with the actual value the first time the swap - // crosses an initialized tick - if (!cache.computedLatestObservation) { - (cache.tickCumulative, cache.secondsPerLiquidityCumulativeX128) = self - .observations - .observeSingle( - params.time, - 0, - slot0Start.tick, - slot0Start.observationIndex, - cache.liquidityStart, - slot0Start.observationCardinality - ); - cache.computedLatestObservation = true; - } - int128 liquidityNet = self.ticks.cross( step.tickNext, (params.zeroForOne ? state.feeGrowthGlobalX128 : self.feeGrowthGlobal0X128), - (params.zeroForOne ? self.feeGrowthGlobal1X128 : state.feeGrowthGlobalX128), - cache.secondsPerLiquidityCumulativeX128, - cache.tickCumulative, - params.time + (params.zeroForOne ? self.feeGrowthGlobal1X128 : state.feeGrowthGlobalX128) ); // if we're moving leftward, we interpret liquidityNet as the opposite sign // safe because liquidityNet cannot be type(int128).min @@ -580,21 +380,7 @@ library Pool { } } - // update tick and write an oracle entry if the tick change - if (state.tick != slot0Start.tick) { - (self.slot0.observationIndex, self.slot0.observationCardinality) = self.observations.write( - slot0Start.observationIndex, - params.time, - slot0Start.tick, - cache.liquidityStart, - slot0Start.observationCardinality, - slot0Start.observationCardinalityNext - ); - (self.slot0.sqrtPriceX96, self.slot0.tick) = (state.sqrtPriceX96, state.tick); - } else { - // otherwise just update the price - self.slot0.sqrtPriceX96 = state.sqrtPriceX96; - } + (self.slot0.sqrtPriceX96, self.slot0.tick) = (state.sqrtPriceX96, state.tick); // update liquidity if it changed if (cache.liquidityStart != state.liquidity) self.liquidity = state.liquidity; diff --git a/contracts/libraries/Tick.sol b/contracts/libraries/Tick.sol index 37e32ba13..28578abe9 100644 --- a/contracts/libraries/Tick.sol +++ b/contracts/libraries/Tick.sol @@ -8,6 +8,8 @@ import {TickMath} from './TickMath.sol'; /// @title Tick /// @notice Contains functions for managing tick processes and relevant calculations library Tick { + error TickLiquidityOverflow(int24 tick); + using SafeCast for int256; // info stored for each initialized individual tick @@ -20,17 +22,6 @@ library Tick { // only has relative meaning, not absolute — the value depends on when the tick is initialized uint256 feeGrowthOutside0X128; uint256 feeGrowthOutside1X128; - // the cumulative tick value on the other side of the tick - int56 tickCumulativeOutside; - // the seconds per unit of liquidity on the _other_ side of this tick (relative to the current tick) - // only has relative meaning, not absolute — the value depends on when the tick is initialized - uint160 secondsPerLiquidityOutsideX128; - // the seconds spent on the other side of the tick (relative to the current tick) - // only has relative meaning, not absolute — the value depends on when the tick is initialized - uint32 secondsOutside; - // true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0 - // these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks - bool initialized; } /// @notice Derives max liquidity per tick from given tick spacing @@ -102,9 +93,6 @@ library Tick { /// @param liquidityDelta A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left) /// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0 /// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1 - /// @param secondsPerLiquidityCumulativeX128 The all-time seconds per max(1, liquidity) of the pool - /// @param tickCumulative The tick * time elapsed since the pool was first initialized - /// @param time The current block timestamp cast to a uint32 /// @param upper true for updating a position's upper tick, or false for updating a position's lower tick /// @param maxLiquidity The maximum liquidity allocation for a single tick /// @return flipped Whether the tick was flipped from initialized to uninitialized, or vice versa @@ -115,9 +103,6 @@ library Tick { int128 liquidityDelta, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128, - uint160 secondsPerLiquidityCumulativeX128, - int56 tickCumulative, - uint32 time, bool upper, uint128 maxLiquidity ) internal returns (bool flipped) { @@ -128,7 +113,7 @@ library Tick { ? liquidityGrossBefore - uint128(-liquidityDelta) : liquidityGrossBefore + uint128(liquidityDelta); - require(liquidityGrossAfter <= maxLiquidity, 'LO'); + if (liquidityGrossAfter > maxLiquidity) revert TickLiquidityOverflow(tick); flipped = (liquidityGrossAfter == 0) != (liquidityGrossBefore == 0); @@ -137,11 +122,7 @@ library Tick { if (tick <= tickCurrent) { info.feeGrowthOutside0X128 = feeGrowthGlobal0X128; info.feeGrowthOutside1X128 = feeGrowthGlobal1X128; - info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128; - info.tickCumulativeOutside = tickCumulative; - info.secondsOutside = time; } - info.initialized = true; } info.liquidityGross = liquidityGrossAfter; @@ -162,28 +143,17 @@ library Tick { /// @param tick The destination tick of the transition /// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0 /// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1 - /// @param secondsPerLiquidityCumulativeX128 The current seconds per liquidity - /// @param tickCumulative The tick * time elapsed since the pool was first initialized - /// @param time The current block.timestamp /// @return liquidityNet The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left) function cross( mapping(int24 => Tick.Info) storage self, int24 tick, uint256 feeGrowthGlobal0X128, - uint256 feeGrowthGlobal1X128, - uint160 secondsPerLiquidityCumulativeX128, - int56 tickCumulative, - uint32 time + uint256 feeGrowthGlobal1X128 ) internal returns (int128 liquidityNet) { unchecked { Tick.Info storage info = self[tick]; info.feeGrowthOutside0X128 = feeGrowthGlobal0X128 - info.feeGrowthOutside0X128; info.feeGrowthOutside1X128 = feeGrowthGlobal1X128 - info.feeGrowthOutside1X128; - info.secondsPerLiquidityOutsideX128 = - secondsPerLiquidityCumulativeX128 - - info.secondsPerLiquidityOutsideX128; - info.tickCumulativeOutside = tickCumulative - info.tickCumulativeOutside; - info.secondsOutside = time - info.secondsOutside; liquidityNet = info.liquidityNet; } } diff --git a/contracts/test/MockTimePoolManager.sol b/contracts/test/MockTimePoolManager.sol deleted file mode 100644 index e16d13663..000000000 --- a/contracts/test/MockTimePoolManager.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {PoolManager} from '../PoolManager.sol'; - -contract MockTimePoolManager is PoolManager { - uint32 public time; - - function _blockTimestamp() internal view override returns (uint32) { - return time; - } - - function advanceTime(uint32 by) external { - unchecked { - time += by; - } - } -} diff --git a/contracts/test/TickOverflowSafetyEchidnaTest.sol b/contracts/test/TickOverflowSafetyEchidnaTest.sol index 366335cbb..b9bce38f0 100644 --- a/contracts/test/TickOverflowSafetyEchidnaTest.sol +++ b/contracts/test/TickOverflowSafetyEchidnaTest.sol @@ -48,9 +48,6 @@ contract TickOverflowSafetyEchidnaTest { liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, - 0, - 0, - uint32(block.timestamp), false, MAX_LIQUIDITY ); @@ -60,9 +57,6 @@ contract TickOverflowSafetyEchidnaTest { liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, - 0, - 0, - uint32(block.timestamp), true, MAX_LIQUIDITY ); @@ -97,11 +91,10 @@ contract TickOverflowSafetyEchidnaTest { while (tick != target) { if (tick < target) { if (ticks[tick + 1].liquidityGross > 0) - ticks.cross(tick + 1, feeGrowthGlobal0X128, feeGrowthGlobal1X128, 0, 0, uint32(block.timestamp)); + ticks.cross(tick + 1, feeGrowthGlobal0X128, feeGrowthGlobal1X128); tick++; } else { - if (ticks[tick].liquidityGross > 0) - ticks.cross(tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128, 0, 0, uint32(block.timestamp)); + if (ticks[tick].liquidityGross > 0) ticks.cross(tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128); tick--; } } diff --git a/contracts/test/TickTest.sol b/contracts/test/TickTest.sol index c173a5a11..05f22bfc3 100644 --- a/contracts/test/TickTest.sol +++ b/contracts/test/TickTest.sol @@ -33,9 +33,6 @@ contract TickTest { int128 liquidityDelta, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128, - uint160 secondsPerLiquidityCumulativeX128, - int56 tickCumulative, - uint32 time, bool upper, uint128 maxLiquidity ) external returns (bool flipped) { @@ -46,9 +43,6 @@ contract TickTest { liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, - secondsPerLiquidityCumulativeX128, - tickCumulative, - time, upper, maxLiquidity ); @@ -61,19 +55,8 @@ contract TickTest { function cross( int24 tick, uint256 feeGrowthGlobal0X128, - uint256 feeGrowthGlobal1X128, - uint160 secondsPerLiquidityCumulativeX128, - int56 tickCumulative, - uint32 time + uint256 feeGrowthGlobal1X128 ) external returns (int128 liquidityNet) { - return - ticks.cross( - tick, - feeGrowthGlobal0X128, - feeGrowthGlobal1X128, - secondsPerLiquidityCumulativeX128, - tickCumulative, - time - ); + return ticks.cross(tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128); } } diff --git a/test/PoolManager.gas.spec.ts b/test/PoolManager.gas.spec.ts index f7f8184d9..b70f076fa 100644 --- a/test/PoolManager.gas.spec.ts +++ b/test/PoolManager.gas.spec.ts @@ -1,6 +1,6 @@ import { ethers, waffle } from 'hardhat' import { Wallet } from 'ethers' -import { MockTimePoolManager, PoolSwapTest, PoolModifyPositionTest } from '../typechain' +import { PoolManager, PoolSwapTest, PoolModifyPositionTest } from '../typechain' import { expect } from './shared/expect' import { tokensFixture } from './shared/fixtures' @@ -17,7 +17,6 @@ import { getMaxTick, MaxUint128, SwapToPriceFunction, - MAX_SQRT_RATIO, MIN_SQRT_RATIO, getPoolId, } from './shared/utilities' @@ -52,10 +51,10 @@ describe('PoolManager gas tests', () => { const gasTestFixture = async ([wallet]: Wallet[]) => { const { token0, token1 } = await tokensFixture() - const singletonPoolFactory = await ethers.getContractFactory('MockTimePoolManager') + const singletonPoolFactory = await ethers.getContractFactory('PoolManager') const swapTestFactory = await ethers.getContractFactory('PoolSwapTest') const mintTestFactory = await ethers.getContractFactory('PoolModifyPositionTest') - const manager = (await singletonPoolFactory.deploy()) as MockTimePoolManager + const manager = (await singletonPoolFactory.deploy()) as PoolManager const swapTest = (await swapTestFactory.deploy(manager.address)) as PoolSwapTest const modifyPositionTest = (await mintTestFactory.deploy(manager.address)) as PoolModifyPositionTest @@ -108,16 +107,11 @@ describe('PoolManager gas tests', () => { } await manager.initialize(poolKey, encodeSqrtPriceX96(1, 1)) - await manager.increaseObservationCardinalityNext(poolKey, 4) - - await manager.advanceTime(1) await modifyPosition(minTick, maxTick, expandTo18Decimals(2)) await swapExact0For1(expandTo18Decimals(1), wallet.address) - await manager.advanceTime(1) await swapToHigherPrice(startingPrice, wallet.address) - await manager.advanceTime(1) const { tick, sqrtPriceX96 } = await getSlot0() @@ -130,7 +124,7 @@ describe('PoolManager gas tests', () => { let swapExact0For1: SwapFunction let swapToHigherPrice: SwapToPriceFunction let swapToLowerPrice: SwapToPriceFunction - let manager: MockTimePoolManager + let manager: PoolManager let modifyPosition: ModifyPositionFunction let getSlot0: AsyncReturnType['getSlot0'] let poolKey: AsyncReturnType['poolKey'] @@ -200,25 +194,6 @@ describe('PoolManager gas tests', () => { await snapshotGasCost(swapExact0For1(expandTo18Decimals(1), wallet.address)) expect((await getSlot0()).tick).to.be.lt(startingTick - 2 * tickSpacing) // we crossed the last tick }) - - it('large swap crossing several initialized ticks after some time passes', async () => { - await modifyPosition(startingTick - 3 * tickSpacing, startingTick - tickSpacing, expandTo18Decimals(1)) - await modifyPosition(startingTick - 4 * tickSpacing, startingTick - 2 * tickSpacing, expandTo18Decimals(1)) - await swapExact0For1(2, wallet.address) - await manager.advanceTime(1) - await snapshotGasCost(swapExact0For1(expandTo18Decimals(1), wallet.address)) - expect((await getSlot0()).tick).to.be.lt(startingTick - 4 * tickSpacing) - }) - - it('large swap crossing several initialized ticks second time after some time passes', async () => { - await modifyPosition(startingTick - 3 * tickSpacing, startingTick - tickSpacing, expandTo18Decimals(1)) - await modifyPosition(startingTick - 4 * tickSpacing, startingTick - 2 * tickSpacing, expandTo18Decimals(1)) - await swapExact0For1(expandTo18Decimals(1), wallet.address) - await swapToHigherPrice(startingPrice, wallet.address) - await manager.advanceTime(1) - await snapshotGasCost(swapExact0For1(expandTo18Decimals(1), wallet.address)) - expect((await getSlot0()).tick).to.be.lt(tickSpacing * -4) - }) }) describe('#mint', () => { @@ -251,11 +226,6 @@ describe('PoolManager gas tests', () => { await modifyPosition(tickLower, tickUpper, expandTo18Decimals(1)) await snapshotGasCost(modifyPosition(tickLower, tickUpper, expandTo18Decimals(1))) }) - it('add to position after some time passes', async () => { - await modifyPosition(tickLower, tickUpper, expandTo18Decimals(1)) - await manager.advanceTime(1) - await snapshotGasCost(modifyPosition(tickLower, tickUpper, expandTo18Decimals(1))) - }) }) } }) @@ -314,27 +284,4 @@ describe('PoolManager gas tests', () => { // await snapshotGasCost(pool.burn(tickLower, tickUpper, 0)) // }) // }) - - describe('#increaseObservationCardinalityNext', () => { - it('grow by 1 slot', async () => { - await snapshotGasCost(manager.increaseObservationCardinalityNext(poolKey, 5)) - }) - it('no op', async () => { - await snapshotGasCost(manager.increaseObservationCardinalityNext(poolKey, 3)) - }) - }) - - describe('#snapshotCumulativesInside', () => { - it('tick inside', async () => { - await snapshotGasCost(manager.estimateGas.snapshotCumulativesInside(poolKey, minTick, maxTick)) - }) - it('tick above', async () => { - await swapToHigherPrice(MAX_SQRT_RATIO.sub(1), wallet.address) - await snapshotGasCost(manager.estimateGas.snapshotCumulativesInside(poolKey, minTick, maxTick)) - }) - it('tick below', async () => { - await swapToLowerPrice(MIN_SQRT_RATIO.add(1), wallet.address) - await snapshotGasCost(manager.estimateGas.snapshotCumulativesInside(poolKey, minTick, maxTick)) - }) - }) }) diff --git a/test/Tick.spec.ts b/test/Tick.spec.ts index f4b04dc28..17d45a232 100644 --- a/test/Tick.spec.ts +++ b/test/Tick.spec.ts @@ -67,10 +67,6 @@ describe('Tick', () => { feeGrowthOutside1X128: 3, liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) const { feeGrowthInside0X128, feeGrowthInside1X128 } = await tickTest.getFeeGrowthInside(-2, 2, 0, 15, 15) expect(feeGrowthInside0X128).to.eq(13) @@ -83,10 +79,6 @@ describe('Tick', () => { feeGrowthOutside1X128: 3, liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) const { feeGrowthInside0X128, feeGrowthInside1X128 } = await tickTest.getFeeGrowthInside(-2, 2, 0, 15, 15) expect(feeGrowthInside0X128).to.eq(13) @@ -99,20 +91,12 @@ describe('Tick', () => { feeGrowthOutside1X128: 3, liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) await tickTest.setTick(2, { feeGrowthOutside0X128: 4, feeGrowthOutside1X128: 1, liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) const { feeGrowthInside0X128, feeGrowthInside1X128 } = await tickTest.getFeeGrowthInside(-2, 2, 0, 15, 15) expect(feeGrowthInside0X128).to.eq(9) @@ -125,20 +109,12 @@ describe('Tick', () => { feeGrowthOutside1X128: constants.MaxUint256.sub(2), liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) await tickTest.setTick(2, { feeGrowthOutside0X128: 3, feeGrowthOutside1X128: 5, liquidityGross: 0, liquidityNet: 0, - secondsPerLiquidityOutsideX128: 0, - tickCumulativeOutside: 0, - secondsOutside: 0, - initialized: true, }) const { feeGrowthInside0X128, feeGrowthInside1X128 } = await tickTest.getFeeGrowthInside(-2, 2, 0, 15, 15) expect(feeGrowthInside0X128).to.eq(16) @@ -148,93 +124,60 @@ describe('Tick', () => { describe('#update', async () => { it('flips from zero to nonzero', async () => { - expect(await tickTest.callStatic.update(0, 0, 1, 0, 0, 0, 0, 0, false, 3)).to.eq(true) + expect(await tickTest.callStatic.update(0, 0, 1, 0, 0, false, 3)).to.eq(true) }) it('does not flip from nonzero to greater nonzero', async () => { - await tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, false, 3) - expect(await tickTest.callStatic.update(0, 0, 1, 0, 0, 0, 0, 0, false, 3)).to.eq(false) + await tickTest.update(0, 0, 1, 0, 0, false, 3) + expect(await tickTest.callStatic.update(0, 0, 1, 0, 0, false, 3)).to.eq(false) }) it('flips from nonzero to zero', async () => { - await tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, false, 3) - expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, 0, 0, 0, false, 3)).to.eq(true) + await tickTest.update(0, 0, 1, 0, 0, false, 3) + expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, false, 3)).to.eq(true) }) it('does not flip from nonzero to lesser nonzero', async () => { - await tickTest.update(0, 0, 2, 0, 0, 0, 0, 0, false, 3) - expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, 0, 0, 0, false, 3)).to.eq(false) + await tickTest.update(0, 0, 2, 0, 0, false, 3) + expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, false, 3)).to.eq(false) }) it('does not flip from nonzero to lesser nonzero', async () => { - await tickTest.update(0, 0, 2, 0, 0, 0, 0, 0, false, 3) - expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, 0, 0, 0, false, 3)).to.eq(false) + await tickTest.update(0, 0, 2, 0, 0, false, 3) + expect(await tickTest.callStatic.update(0, 0, -1, 0, 0, false, 3)).to.eq(false) }) it('reverts if total liquidity gross is greater than max', async () => { - await tickTest.update(0, 0, 2, 0, 0, 0, 0, 0, false, 3) - await tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, true, 3) - await expect(tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, false, 3)).to.be.revertedWith('LO') + await tickTest.update(0, 0, 2, 0, 0, false, 3) + await tickTest.update(0, 0, 1, 0, 0, true, 3) + await expect(tickTest.update(0, 0, 1, 0, 0, false, 3)).to.be.revertedWith('TickLiquidityOverflow(0)') }) it('nets the liquidity based on upper flag', async () => { - await tickTest.update(0, 0, 2, 0, 0, 0, 0, 0, false, 10) - await tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, true, 10) - await tickTest.update(0, 0, 3, 0, 0, 0, 0, 0, true, 10) - await tickTest.update(0, 0, 1, 0, 0, 0, 0, 0, false, 10) + await tickTest.update(0, 0, 2, 0, 0, false, 10) + await tickTest.update(0, 0, 1, 0, 0, true, 10) + await tickTest.update(0, 0, 3, 0, 0, true, 10) + await tickTest.update(0, 0, 1, 0, 0, false, 10) const { liquidityGross, liquidityNet } = await tickTest.ticks(0) expect(liquidityGross).to.eq(2 + 1 + 3 + 1) expect(liquidityNet).to.eq(2 - 1 - 3 + 1) }) it('reverts on overflow liquidity gross', async () => { - await tickTest.update(0, 0, MaxUint128.div(2).sub(1), 0, 0, 0, 0, 0, false, MaxUint128) - await expect(tickTest.update(0, 0, MaxUint128.div(2).sub(1), 0, 0, 0, 0, 0, false, MaxUint128)).to.be.reverted + await tickTest.update(0, 0, MaxUint128.div(2).sub(1), 0, 0, false, MaxUint128) + await expect(tickTest.update(0, 0, MaxUint128.div(2).sub(1), 0, 0, false, MaxUint128)).to.be.reverted }) it('assumes all growth happens below ticks lte current tick', async () => { - await tickTest.update(1, 1, 1, 1, 2, 3, 4, 5, false, MaxUint128) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - secondsPerLiquidityOutsideX128, - tickCumulativeOutside, - initialized, - } = await tickTest.ticks(1) + await tickTest.update(1, 1, 1, 1, 2, false, MaxUint128) + const { feeGrowthOutside0X128, feeGrowthOutside1X128 } = await tickTest.ticks(1) expect(feeGrowthOutside0X128).to.eq(1) expect(feeGrowthOutside1X128).to.eq(2) - expect(secondsPerLiquidityOutsideX128).to.eq(3) - expect(tickCumulativeOutside).to.eq(4) - expect(secondsOutside).to.eq(5) - expect(initialized).to.eq(true) }) it('does not set any growth fields if tick is already initialized', async () => { - await tickTest.update(1, 1, 1, 1, 2, 3, 4, 5, false, MaxUint128) - await tickTest.update(1, 1, 1, 6, 7, 8, 9, 10, false, MaxUint128) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - secondsPerLiquidityOutsideX128, - tickCumulativeOutside, - initialized, - } = await tickTest.ticks(1) + await tickTest.update(1, 1, 1, 1, 2, false, MaxUint128) + await tickTest.update(1, 1, 1, 6, 7, false, MaxUint128) + const { feeGrowthOutside0X128, feeGrowthOutside1X128 } = await tickTest.ticks(1) expect(feeGrowthOutside0X128).to.eq(1) expect(feeGrowthOutside1X128).to.eq(2) - expect(secondsPerLiquidityOutsideX128).to.eq(3) - expect(tickCumulativeOutside).to.eq(4) - expect(secondsOutside).to.eq(5) - expect(initialized).to.eq(true) }) it('does not set any growth fields for ticks gt current tick', async () => { - await tickTest.update(2, 1, 1, 1, 2, 3, 4, 5, false, MaxUint128) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - secondsPerLiquidityOutsideX128, - tickCumulativeOutside, - initialized, - } = await tickTest.ticks(2) + await tickTest.update(2, 1, 1, 1, 2, false, MaxUint128) + const { feeGrowthOutside0X128, feeGrowthOutside1X128 } = await tickTest.ticks(2) expect(feeGrowthOutside0X128).to.eq(0) expect(feeGrowthOutside1X128).to.eq(0) - expect(secondsPerLiquidityOutsideX128).to.eq(0) - expect(tickCumulativeOutside).to.eq(0) - expect(secondsOutside).to.eq(0) - expect(initialized).to.eq(true) }) }) @@ -246,30 +189,13 @@ describe('Tick', () => { feeGrowthOutside1X128: 2, liquidityGross: 3, liquidityNet: 4, - secondsPerLiquidityOutsideX128: 5, - tickCumulativeOutside: 6, - secondsOutside: 7, - initialized: true, }) await tickTest.clear(2) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - secondsPerLiquidityOutsideX128, - liquidityGross, - tickCumulativeOutside, - liquidityNet, - initialized, - } = await tickTest.ticks(2) + const { feeGrowthOutside0X128, feeGrowthOutside1X128, liquidityGross, liquidityNet } = await tickTest.ticks(2) expect(feeGrowthOutside0X128).to.eq(0) expect(feeGrowthOutside1X128).to.eq(0) - expect(secondsOutside).to.eq(0) - expect(secondsPerLiquidityOutsideX128).to.eq(0) - expect(tickCumulativeOutside).to.eq(0) expect(liquidityGross).to.eq(0) expect(liquidityNet).to.eq(0) - expect(initialized).to.eq(false) }) }) @@ -280,24 +206,11 @@ describe('Tick', () => { feeGrowthOutside1X128: 2, liquidityGross: 3, liquidityNet: 4, - secondsPerLiquidityOutsideX128: 5, - tickCumulativeOutside: 6, - secondsOutside: 7, - initialized: true, }) - await tickTest.cross(2, 7, 9, 8, 15, 10) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - tickCumulativeOutside, - secondsPerLiquidityOutsideX128, - } = await tickTest.ticks(2) + await tickTest.cross(2, 7, 9) + const { feeGrowthOutside0X128, feeGrowthOutside1X128 } = await tickTest.ticks(2) expect(feeGrowthOutside0X128).to.eq(6) expect(feeGrowthOutside1X128).to.eq(7) - expect(secondsPerLiquidityOutsideX128).to.eq(3) - expect(tickCumulativeOutside).to.eq(9) - expect(secondsOutside).to.eq(3) }) it('two flips are no op', async () => { await tickTest.setTick(2, { @@ -305,25 +218,12 @@ describe('Tick', () => { feeGrowthOutside1X128: 2, liquidityGross: 3, liquidityNet: 4, - secondsPerLiquidityOutsideX128: 5, - tickCumulativeOutside: 6, - secondsOutside: 7, - initialized: true, }) - await tickTest.cross(2, 7, 9, 8, 15, 10) - await tickTest.cross(2, 7, 9, 8, 15, 10) - const { - feeGrowthOutside0X128, - feeGrowthOutside1X128, - secondsOutside, - tickCumulativeOutside, - secondsPerLiquidityOutsideX128, - } = await tickTest.ticks(2) + await tickTest.cross(2, 7, 9) + await tickTest.cross(2, 7, 9) + const { feeGrowthOutside0X128, feeGrowthOutside1X128 } = await tickTest.ticks(2) expect(feeGrowthOutside0X128).to.eq(1) expect(feeGrowthOutside1X128).to.eq(2) - expect(secondsPerLiquidityOutsideX128).to.eq(5) - expect(tickCumulativeOutside).to.eq(6) - expect(secondsOutside).to.eq(7) }) }) }) diff --git a/test/__snapshots__/PoolManager.gas.spec.ts.snap b/test/__snapshots__/PoolManager.gas.spec.ts.snap index 20e99603f..f469223ad 100644 --- a/test/__snapshots__/PoolManager.gas.spec.ts.snap +++ b/test/__snapshots__/PoolManager.gas.spec.ts.snap @@ -1,182 +1,127 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PoolManager gas tests #increaseObservationCardinalityNext grow by 1 slot 1`] = ` -Object { - "calldataByteLength": 196, - "gasUsed": 51502, -} -`; - -exports[`PoolManager gas tests #increaseObservationCardinalityNext no op 1`] = ` -Object { - "calldataByteLength": 196, - "gasUsed": 26433, -} -`; - -exports[`PoolManager gas tests #mint above current price add to position after some time passes 1`] = ` -Object { - "calldataByteLength": 260, - "gasUsed": 187229, -} -`; - exports[`PoolManager gas tests #mint above current price add to position existing 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 187229, + "gasUsed": 180996, } `; exports[`PoolManager gas tests #mint above current price new position mint first in range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 282204, + "gasUsed": 240537, } `; exports[`PoolManager gas tests #mint above current price second position in same range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 187229, -} -`; - -exports[`PoolManager gas tests #mint around current price add to position after some time passes 1`] = ` -Object { - "calldataByteLength": 260, - "gasUsed": 261872, + "gasUsed": 180996, } `; exports[`PoolManager gas tests #mint around current price add to position existing 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 254578, + "gasUsed": 249478, } `; exports[`PoolManager gas tests #mint around current price new position mint first in range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 406793, + "gasUsed": 358723, } `; exports[`PoolManager gas tests #mint around current price second position in same range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 254578, -} -`; - -exports[`PoolManager gas tests #mint below current price add to position after some time passes 1`] = ` -Object { - "calldataByteLength": 260, - "gasUsed": 187909, + "gasUsed": 249478, } `; exports[`PoolManager gas tests #mint below current price add to position existing 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 187909, + "gasUsed": 181673, } `; exports[`PoolManager gas tests #mint below current price new position mint first in range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 347736, + "gasUsed": 305582, } `; exports[`PoolManager gas tests #mint below current price second position in same range 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 187909, + "gasUsed": 181673, } `; -exports[`PoolManager gas tests #snapshotCumulativesInside tick above 1`] = `34840`; - -exports[`PoolManager gas tests #snapshotCumulativesInside tick below 1`] = `34799`; - -exports[`PoolManager gas tests #snapshotCumulativesInside tick inside 1`] = `40079`; - exports[`PoolManager gas tests #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 237414, + "gasUsed": 228521, } `; exports[`PoolManager gas tests #swapExact0For1 first swap in block with no tick movement 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 224640, + "gasUsed": 222627, } `; exports[`PoolManager gas tests #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 261591, + "gasUsed": 247469, } `; exports[`PoolManager gas tests #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 316576, + "gasUsed": 289513, } `; exports[`PoolManager gas tests #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 249422, -} -`; - -exports[`PoolManager gas tests #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = ` -Object { - "calldataByteLength": 260, - "gasUsed": 316576, -} -`; - -exports[`PoolManager gas tests #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = ` -Object { - "calldataByteLength": 260, - "gasUsed": 316576, + "gasUsed": 240507, } `; exports[`PoolManager gas tests #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 237414, + "gasUsed": 228521, } `; exports[`PoolManager gas tests #swapExact0For1 second swap in block with no tick movement 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 224728, + "gasUsed": 222716, } `; exports[`PoolManager gas tests #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 250748, + "gasUsed": 241692, } `; exports[`PoolManager gas tests #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 305706, + "gasUsed": 283711, } `; diff --git a/test/__snapshots__/PoolManager.spec.ts.snap b/test/__snapshots__/PoolManager.spec.ts.snap index acf5b766d..b2734b12f 100644 --- a/test/__snapshots__/PoolManager.spec.ts.snap +++ b/test/__snapshots__/PoolManager.spec.ts.snap @@ -3,50 +3,50 @@ exports[`PoolManager #initialize gas cost 1`] = ` Object { "calldataByteLength": 196, - "gasUsed": 71245, + "gasUsed": 48954, } `; exports[`PoolManager #lock gas overhead of no-op lock 1`] = ` Object { "calldataByteLength": 36, - "gasUsed": 59684, + "gasUsed": 59649, } `; exports[`PoolManager #mint gas cost 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 329731, + "gasUsed": 287177, } `; exports[`PoolManager #mint gas cost with hooks 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 329740, + "gasUsed": 287187, } `; exports[`PoolManager #swap gas cost 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 89034, + "gasUsed": 83518, } `; exports[`PoolManager #swap gas cost for swap against liquidity 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 223290, + "gasUsed": 222990, } `; exports[`PoolManager #swap gas cost with hooks 1`] = ` Object { "calldataByteLength": 260, - "gasUsed": 93129, + "gasUsed": 87613, } `; -exports[`PoolManager bytecode size 1`] = `21425`; +exports[`PoolManager bytecode size 1`] = `15633`;