Section 18 of 18
Complete Protocol
Final Build
Submit your complete protocol and run the full test suite. Earn the "uniswap-v3-builder" badge on completion.
Key takeaway: This is the capstone of the Uniswap V3 reconstruction at Zealynx Academy. You wrote the math layer (LiquidityMath, SqrtPriceMath, Tick, TickBitmap, Position, SwapMath), the full pool (Slot0, mint/burn/collect, the swap loop, the oracle ring buffer, flash loans, protocol fees), the factory with its deployer-parameters CREATE2 pattern, and a single-hop SwapRouter with a verified callback. The final test suite runs against your aggregated code from every build section and re-checks the load-bearing line of each: rounding directions, the fees-outside trick, the bitmap XOR, Q128 fee accrual, the exact-in fee branch, tick-cross negation, balance-check payments, and verify-before-pay. Pass it and you have written the most-forked concentrated-liquidity engine in DeFi, line by line.
What You Built
Eighteen sections, fourteen of them code. This is the same machinery that has secured hundreds of billions of dollars in cumulative volume — and the same machinery that hundreds of forks copied, sometimes correctly.
Part 1: The Math of Concentrated Liquidity
| # | Section | What you wrote |
|---|---|---|
| 2 | Ticks and sqrtPriceX96 | LiquidityMath.addDelta with its 'LS'/'LA' overflow guards, tickSpacingToMaxLiquidityPerTick, tick-range validation — the Q96 coordinate system |
| 3 | SqrtPriceMath | getAmount0Delta / getAmount1Delta and the getNextSqrtPriceFrom* family — every rounding direction chosen in the pool's favor |
| 4 | Tick | update, cross, getFeeGrowthInside — the fees-outside trick that turns a global accumulator into per-range accounting with two subtractions |
| 5 | TickBitmap | flipTick's mask XOR and nextInitializedTickWithinOneWord — how the swap loop finds the next initialized tick in one word read |
| 6 | Position | Position keying by keccak256(owner, tickLower, tickUpper), fee accrual via Q128 mulDiv, the 'NP' poke guard |
Part 2: The Pool
| # | Section | What you wrote |
|---|---|---|
| 7 | Pool state | Slot0 packing, the immutable pool configuration (plain constructor args; the deployer-parameters pattern arrives in section 15), initialize ('AI'), checkTicks ('TLU'/'TLM'/'TUM'), the lock guard, raw balance readers |
| 8 | mint | _modifyPosition / _updatePosition — tick updates, bitmap flips, fee settlement — and the mint callback with 'M0'/'M1' balance checks |
| 9 | burn and collect | Burn as negative-liquidity modify accruing tokensOwed; collect as the only token exit; the burn-0 fee poke |
| 10 | SwapMath | computeSwapStep — target-vs-exhaustion, fee on input, the exact-in remainder branch |
| 11 | The swap loop | SwapCache/SwapState/StepComputations, the while loop over ticks, crossing with liquidityNet negation, feeGrowthGlobal, protocol fee split, the swap callback |
| 12 | Core checkpoint | The aggregated Part 1 + 2 test run |
Part 3: Oracle, Factory, and Periphery
| # | Section | What you wrote |
|---|---|---|
| 13 | Oracle | The observation ring buffer: transform, write, grow's slot-warming, binary-searched observeSingle, geometric-mean TWAP |
| 14 | Flash loans | Up-front fees via mulDivRoundingUp, 'F0'/'F1' balance verification, the packed feeProtocol nibbles, collectProtocol's one-wei residue |
| 15 | Factory | Fee-tier registry, createPool with double-direction getPool, the transient-parameters CREATE2 deploy, setOwner |
| 16 | Why the periphery changed | Callbacks as the payment protocol; why unverified callbacks are the #1 V3 integration bug |
| 17 | SwapRouter | exactInputSingle / exactOutputSingle, deadline and slippage enforcement, price-limit defaulting, and a callback that verifies before it pays |
Your Complete Protocol
Sign up free — keep reading + earn 100 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in