Skip to content

Commit 2cfc4da

Browse files
committed
Don't update liquidity when next tick is not initialized
1 parent 2f29618 commit 2cfc4da

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/UniswapV3Pool.sol

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ contract UniswapV3Pool is IUniswapV3Pool {
420420

421421
step.sqrtPriceStartX96 = state.sqrtPriceX96;
422422

423-
(step.nextTick, ) = tickBitmap.nextInitializedTickWithinOneWord(
423+
(step.nextTick, step.initialized) = tickBitmap.nextInitializedTickWithinOneWord(
424424
state.tick,
425425
int24(tickSpacing),
426426
zeroForOne
@@ -459,28 +459,30 @@ contract UniswapV3Pool is IUniswapV3Pool {
459459
}
460460

461461
if (state.sqrtPriceX96 == step.sqrtPriceNextX96) {
462-
int128 liquidityDelta = ticks.cross(
463-
step.nextTick,
464-
(
465-
zeroForOne
466-
? state.feeGrowthGlobalX128
467-
: feeGrowthGlobal0X128
468-
),
469-
(
470-
zeroForOne
471-
? feeGrowthGlobal1X128
472-
: state.feeGrowthGlobalX128
473-
)
474-
);
475-
476-
if (zeroForOne) liquidityDelta = -liquidityDelta;
477-
478-
state.liquidity = LiquidityMath.addLiquidity(
479-
state.liquidity,
480-
liquidityDelta
481-
);
482-
483-
if (state.liquidity == 0) revert NotEnoughLiquidity();
462+
if (step.initialized) {
463+
int128 liquidityDelta = ticks.cross(
464+
step.nextTick,
465+
(
466+
zeroForOne
467+
? state.feeGrowthGlobalX128
468+
: feeGrowthGlobal0X128
469+
),
470+
(
471+
zeroForOne
472+
? feeGrowthGlobal1X128
473+
: state.feeGrowthGlobalX128
474+
)
475+
);
476+
477+
if (zeroForOne) liquidityDelta = -liquidityDelta;
478+
479+
state.liquidity = LiquidityMath.addLiquidity(
480+
state.liquidity,
481+
liquidityDelta
482+
);
483+
484+
if (state.liquidity == 0) revert NotEnoughLiquidity();
485+
}
484486

485487
state.tick = zeroForOne ? step.nextTick - 1 : step.nextTick;
486488
} else if (state.sqrtPriceX96 != step.sqrtPriceStartX96) {

0 commit comments

Comments
 (0)