Deployment
Architecture
Section titled “Architecture”Uniswap V2 is composed of Core and Periphery layers.
The Core consists of a singleton Factory and multiple Pair contracts, designed with a “brutalist” minimalism to ensure functional elegance and minimize the attack surface.
This architectural separation means the Core handles safety and the preservation of invariants, while the Periphery handles domain-specific logic like routing and WETH wrapping.
Contracts
Section titled “Contracts”- Liquidity Pool (Pair)
- holds balances of two unique ERC-20 tokens
- and enforces rules for swapping, depositing, and withdrawing them.
- native ETH is not supported; it must be wrapped into WETH to interact with the protocol
- Factory
- instantiates pairs
- uses the Ethereum
CREATE2opcode to generate a deterministic address for the pair contract - f(addresses of the two tokens)
- calculated off-chain without querying the blockchain state
Deployment
Section titled “Deployment”WETH9: is the canonical ETH ERC20 wrapper where you can exchange ETH to/from WETH (1:1)UniswapV2Factory: createsUniswapV2Pairpool pairsUniswapV2Router02- stateless, therefore, easily replaceable
- main user-facing contract
- extra helper functions
UniswapV2Router01: replaced byUniswapV2Router02because of a low-severity bug
// UniswapV2Workflows:deploy:25:54static async deploy(lensClient: LensClient<UniswapV2Artifacts>) { const feeToSetAccount = privateKeyToAccount(generatePrivateKey());
const factoryDeployResult = await lensClient.deploy( 'contracts/uniswap-v2/v2-core/contracts/UniswapV2Factory.sol:UniswapV2Factory', [feeToSetAccount.address] );
const wethDeployResult = await lensClient.deploy( 'contracts/uniswap-v2/v2-periphery/contracts/test/WETH9.sol:WETH9', [] );
const router2DeployResult = await lensClient.deploy( 'contracts/uniswap-v2/v2-periphery/contracts/UniswapV2Router02.sol:UniswapV2Router02', [factoryDeployResult.createdAddress!, wethDeployResult.createdAddress!] );
const factory = lensClient.getContract( factoryDeployResult.createdAddress!, 'contracts/uniswap-v2/v2-core/contracts/UniswapV2Factory.sol:UniswapV2Factory' );
const router2 = lensClient.getContract( router2DeployResult.createdAddress!, 'contracts/uniswap-v2/v2-periphery/contracts/UniswapV2Router02.sol:UniswapV2Router02' );
return { factory, router2 };}