Section 17 of 18
Periphery: The SwapRouter
Key takeaway: The router is the user-facing shell around the pool's raw
swap:checkDeadlinerejects stale transactions,exactInputSingle/exactOutputSinglederivezeroForOnefrom token ordering, default a missingsqrtPriceLimitX96toMIN_SQRT_RATIO + 1/MAX_SQRT_RATIO - 1, and enforceamountOutMinimum/amountInMaximumslippage bounds after the pool returns. Payment happens inuniswapV3SwapCallback— and its first real statement is the security boundary of the entire periphery: recompute the legitimate pool for(tokenIn, tokenOut, fee)andrequire(msg.sender == pool)before trusting one byte of callback data or moving one wei of user funds. Skip that require and anyone can drain every allowance ever granted to your router.
What You Are Building
A single-hop SwapRouter: the checkDeadline modifier, a getPool lookup, exactInputSingle, exactOutputSingle, and the swap callback. Interfaces, TickMath bounds, SafeCast, and TransferHelper are provided.
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