Rebuild active Uniswap v3 liquidity by crossing tick boundaries
Summing every position’s liquidity overstates the liquidity available at the current price. Each range contributes only while the price lies inside its lower-inclusive, upper-exclusive interval.
Apply the signed liquidity change in the swap direction
For an upward crossing add liquidityNet at the crossed initialized tick. For a downward crossing apply the opposite sign. The example position contributes positive net at 100 and negative net at 200, before combining with other positions at the same boundaries.
position range: [100, 200)
position liquidity: 500
upward crossings: 100 adds 500; 200 removes 500
An upward move through both boundaries first increases and then decreases active liquidity by 500. Its final contribution is zero even though the position still exists and can hold token balances.
Respect tick updates at an exact boundary
During a downward crossing the pool can record the current tick as the crossed tick minus one. Use the pool’s swap logic and slot0 tick when aligning snapshots, rather than blindly recomputing the current tick from a boundary square-root price. github.com UniswapV3Pool.sol