{"repo":"tomwangcn/UniswapV2","free":true,"listed":false,"github":"https://github.com/tomwangcn/UniswapV2","clone":"git clone https://github.com/tomwangcn/UniswapV2.git","description":"This project aims to break down and reimplement the core logic of Uniswap V2, providing a simplified version of an Automated Market Maker (AMM) for educational and experimental purposes. The main contract demonstrates how liquidity pools, pricing formulas, and token swaps work in a decentralized exchange.","language":"Solidity","stars":81,"topics":["smart-contracts","solidity","uniswapv2"],"license":null,"category":"blockchain-web3","readme_excerpt":"🦄 Uniswap V2 Mini Exchange (Simplified) This project is a minimal AMM (Automated Market Maker) , inspired by Uniswap V2 . It supports adding liquidity , quoting prices , and swapping ETH ↔ Token . Deploy address https://sepolia.etherscan.io/address/0x4e6037b6613dba5aba761e3b14c7954f114947b7 Structure - src/UniswapV2.sol : Main contract implementing the AMM logic - lib/openzeppelin-contracts/ : ERC20 standard contract dependency - test/ : Test scripts and cases - script/ : Deployment scripts Main Contract Flow Core invariant: - x = ETH reserve - y = Token reserve - k = Constant (liquidity invariant) --- 🔑 Core Components 1. Storage - token : ERC20 token contract - reserveEth : ETH liquidity stored - reserveToken : Token liquidity stored 👉 These reserves are always synced with the actual contract balances. --- 2. Add Liquidity - User sends ETH + Tokens - Both are deposited into the pool - Internal reserves are updated via sync() 📌 Check : Zero liquidity is rejected. --- 3. Quote Function (Pricing Formula) Formula (with 0.3% fee): - Preserves x y = k - Larger trades = higher slippage --- 4. Swap ETH → Token Steps: 1. User sends ETH ( msg.value ) 2. Contract calculates tokenOut = quote(ethIn, true) 3. Transfer Tokens to user 4. Sync reserves --- 5. Swap Token → ETH Steps: 1. User sends Tokens via transferFrom 2. Contract calculates ETH out using quote 3. Contract sends ETH ( .call{value: ethOut} ) 4. Sync reserves --- 📊 AMM Curve The constant product formula produces a hyper","default_branch":null,"files":null,"tree":[],"storefront":"/r/tomwangcn","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/tomwangcn/UniswapV2/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}