Loading...
Uniswap doesn't have an order book. It has a math curve. Understand the curve and you understand 90% of DeFi.
A Uniswap V2 pool holds reserves of two tokens: x (e.g., ETH) and y (e.g., USDC). Its invariant:
x × y = kWhere k is constant across trades (it only grows from fees). When someone swaps dx of X for dy of Y:
(x + dx) × (y − dy) = k = x × y
solve for dy:
dy = y × dx / (x + dx)Pool: 100 ETH, 300,000 USDC (price = 3000 USDC/ETH). You swap 1 ETH for USDC.
dy = 300,000 × 1 / (100 + 1) ≈ 2970.30 USDC
effective price = 2970.30 USDC/ETH (worse than 3000 — slippage)
new pool = 101 ETH, 297,029.70 USDC
new mid price = 297,029.70 / 101 ≈ 2941.88 USDC/ETHOne trade:
Compute the dy for a given pool + swap using the formula.