Section 12 of 16
Router: Adding Liquidity
Key takeaway: The Router's
addLiquidityadds the safety layer absent from rawpair.mint()calls: deadline enforcement, slippage protection viaamountAMinandamountBMin, and optimal-amount calculation usingUniswapV2Library.quote()to determine how much tokenB to deposit for a given tokenA at the pool's current ratio. Brand-new pairs let the user's desired amounts set the initial price; existing pairs match the current ratio and revert if bothDesiredamounts fall short of theirMinthresholds. WETH wrapping (theaddLiquidityETHvariant) lets ETH-paired pools accept native ETH without forcing users to wrap manually.
What You Are Building
The Router's liquidity functions are the safe entry point for adding tokens to a Uniswap V2 pair. Users never interact with the pair contract directly. They call addLiquidity() or addLiquidityETH() on the Router, which handles optimal amount calculation, pair creation, token transfers, and LP minting. Getting these functions right means understanding why each step exists, what breaks without it, and how the Router protects users from common pitfalls.
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