Section 10 of 16
Why the Router Exists
Key takeaway: Uniswap V2 deliberately separates the immutable, security-critical core (Pair, Factory) from the user-facing periphery (Router, Library). Calling
pair.swap()directly forces users to compute fee-adjusted output amounts, sort token addresses, transfer tokens to the pair before the call, and accept whatever price the pool gives them. The Router solves all of these: slippage protection viaamountOutMin, deadline enforcement against stale execution, multi-hop path routing, and WETH wrapping for ETH paths. Periphery can be replaced; core cannot.
The Problem with Raw Pair Calls
You have built the core protocol. UniswapV2Pair exposes mint(), burn(), and swap(). These functions work. But they are dangerously low level.
If a user called pair.swap() directly, they would need to:
- Calculate the exact output amount themselves, including the 0.3% fee math.
- Transfer the input tokens to the pair address before calling swap.
- Sort the two token addresses to figure out which is token0 and which is token1.
- Set the correct amount0Out/amount1Out based on the swap direction.
- Hope that no one front-runs their transaction and moves the price.
One mistake in any of these steps means lost funds. No safety net. No refund.
Knowledge Check
Answer correctly to earn lynx
What is the primary safety mechanism the Router provides to protect users from price manipulation between transaction submission and execution?
Two words. Think about what limits how much value a user can lose on a swap.
Sign up free — keep reading + earn 5 Lynx
Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.
Sign up free to continueAlready have an account? Log in