Section 8 of 16
The Factory (UniswapV2Factory)
Key takeaway: UniswapV2Factory is the only contract that deploys pairs, using CREATE2 with the sorted token-pair as salt to give every pair a deterministic, off-chain-computable address. The Router and any integrating contract can derive pair addresses from
keccak256(0xff, factory, salt, keccak256(creationCode))[12:]without an on-chain query, saving the SLOAD on everygetPairlookup. The factory also owns governance setters forfeeTo(toggles the 1/6 protocol fee) andfeeToSetter(rotates that role).
What You Are Building
UniswapV2Factory is the contract that deploys and registers trading pairs. It is the entry point for creating new markets. Every pair on Uniswap V2 was deployed by this single factory contract.
The factory is simpler than the pair. It has one core function (createPair), two governance setters, and a registry. But it introduces one of the most important concepts in the protocol: deterministic deployment with CREATE2. Understanding why the factory is designed this way reveals how Uniswap V2 achieves gas efficiency, composability, and a clean separation between pair logic and deployment logic.
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