Section 12 of 16

Build
+15 Lynx

Router: Adding Liquidity

Key takeaway: The Router's addLiquidity adds the safety layer absent from raw pair.mint() calls: deadline enforcement, slippage protection via amountAMin and amountBMin, and optimal-amount calculation using UniswapV2Library.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 both Desired amounts fall short of their Min thresholds. WETH wrapping (the addLiquidityETH variant) 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

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