Section 2 of 18
The Coordinate System: Ticks and sqrtPriceX96
Key takeaway: V3 stores price as
sqrtPriceX96— the square root of price in Q64.96 fixed point — because swap math is linear insqrt(P)(Δy = L * Δ(sqrt(P))), and it indexes price space with ticks, where tickimeans price1.0001^i.TickMathconverts between the two with hardcoded magic constants (provided; you use it, you do not retype it). You implement the safety rails around the coordinate system:LiquidityMath.addDeltawith V3's terse'LS'/'LA'overflow checks inside anuncheckedblock,tickSpacingToMaxLiquidityPerTickwhich caps per-tick liquidity so the pool-wideuint128can never overflow, andcheckTickswith the'TLU'/'TLM'/'TUM'range validation every mint and burn passes through.
What You Are Building
Before you can build pools, you need V3's coordinate system: how price is stored, how price space is indexed, and the invariants that keep both inside safe bounds. In this section the heavy artillery — TickMath, with its 20 magic constants — is provided in full. Your job is the surrounding safety layer: LiquidityMath.addDelta, tickSpacingToMaxLiquidityPerTick, and tick-range validation. Small functions, but every mint, burn, and swap in the rest of the module runs through them.
Your Code
Requirements
Sign up free — keep reading + earn 10 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in