Section 11 of 16

Build
+15 Lynx

Library: Helpers and Math

Key takeaway: UniswapV2Library is the stateless math layer the Router depends on. It enforces canonical token ordering (token0 < token1) so every token pair maps to exactly one CREATE2-deployed Pair address, computes that address off-chain via the same keccak256 formula the Factory uses, and provides getAmountOut and getAmountIn with the 0.30% fee baked in (multiply by 997, divide by 1000) plus quote() for proportional reserve math. Every Router function calls into this library; getting any helper wrong cascades through the entire periphery.

What You Are Building

UniswapV2Library is a stateless library that provides the mathematical foundation the Router depends on. Every swap amount calculation, every pair address lookup, every reserve fetch goes through this library. It is pure math and address computation. No state, no storage, no external calls except one reserve fetch. Eight functions, each building on the previous ones.

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