Section 6 of 18
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.updateis a checkpoint-then-accrue machine: it computes fees earned since the last touch asmulDiv(feeGrowthInside - feeGrowthInsideLast, liquidity, Q128), adds them totokensOwed, and overwrites the checkpoint. Fees never auto-compound — they sit as atokensOweddebt untilcollectpays them out. The fee-delta subtraction lives inunchecked(the accumulators are relative and wrap by design, section 4), andtokensOwed += feesmay overflow by explicit design decision — Uniswap's own comment: withdraw before you hittype(uint128).maxfees. 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
Requirements
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 continueAlready have an account? Log in