Section 7 of 18
Pool: State, Slot0, and Initialization
Key takeaway: UniswapV3Pool packs every value the swap hot path reads — price, tick, oracle indices, protocol fee, and the reentrancy flag — into a single storage slot called
Slot0, so one SLOAD serves the whole swap preamble. The reentrancy lock lives inside that slot and is mandatory, not defensive decoration: V3 verifies payment with balance checks, and a reentrant call between "compute owed" and "check balance" would let one deposit satisfy two debts.initializeconverts a startingsqrtPriceX96into a tick viaTickMath.getTickAtSqrtRatio, may run exactly once ('AI'), and is the only door into an otherwise-locked contract.
What You Are Building
Part 1 gave you the math libraries. Now you assemble the machine that uses them. This section builds the UniswapV3Pool skeleton: the immutable configuration, the packed Slot0 struct, fee-growth globals, the tick/bitmap/position mappings, the lock modifier, tick validation, raw balance reads, and initialize. Everything you write in sections 8 through 11 lives inside this contract.
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