Section 8 of 18
Pool: Adding Liquidity (mint)
Key takeaway:
mintis a thin shell around two private workhorses._updatePositiondoes the bookkeeping — updates both boundary ticks, flips bitmap bits when a tick's liquidity appears or disappears, settles accumulated fees into the position viagetFeeGrowthInside, and clears dead ticks._modifyPositiondoes the economics — the current price sits below, inside, or above the range, and that alone decides whether the depositor owes token0, both tokens, or token1, with the pool's activeliquidityupdated only in the inside case. Payment is V3's signature move: compute what is owed first, calluniswapV3MintCallbackon the sender, then verify the pool's balances actually grew ('M0'/'M1'). The pool never callstransferFrom.
What You Are Building
Three functions that together let anyone deposit liquidity into a tick range: _updatePosition (state bookkeeping), _modifyPosition (amount computation), and mint (the external entry point with the callback payment flow). burn in section 9 reuses the first two with a negated sign — write them well once and removal comes almost free.
Your Code
Requirements
Sign up free — keep reading + earn 20 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in