Section 6 of 18

Build
+15 Lynx

Position: Ownership and Fee Accounting

Key takeaway: A V3 position is keyed by keccak256(owner, tickLower, tickUpper) — same owner, same range, same position; there is no LP token in the core. Position.update is a checkpoint-then-accrue machine: it computes fees earned since the last touch as mulDiv(feeGrowthInside - feeGrowthInsideLast, liquidity, Q128), adds them to tokensOwed, and overwrites the checkpoint. Fees never auto-compound — they sit as a tokensOwed debt until collect pays them out. The fee-delta subtraction lives in unchecked (the accumulators are relative and wrap by design, section 4), and tokensOwed += fees may overflow by explicit design decision — Uniswap's own comment: withdraw before you hit type(uint128).max fees. The 'NP' require blocks pokes on empty positions.

What You Are Building

The Position library — the last piece of Part 1's math stack. Two functions: get (the mapping key) and update (liquidity changes plus fee accrual). Provided: FullMath, FixedPoint128, and your LiquidityMath from section 2. Short section, but it's where the fee machinery you built in section 4 finally pays a user.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 15 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in