amm-that-defined-defi">Uniswap V2/V3: The AMM That Defined DeFi
Before Uniswap, decentralized exchanges operated like traditional order books. Buyers and sellers posted limit orders, and trades executed when orders matched. The model worked, but it had a fundamental problem in the context of blockchains: maintaining an order book requires constant updates, and every update on Ethereum costs gas. Market makers — the professionals who keep order books liquid — found on-chain markets uneconomical to operate.
Uniswap solved this with a radically simple idea: replace the order book with a mathematical formula. The result became the foundational primitive of decentralized finance, and the two whitepaper upgrades — V2 and V3 — added layers of sophistication that transformed it into a mature financial infrastructure.
The Constant Product Formula
The Uniswap V1 and V2 core rests on a single equation: x * y = k. In a liquidity pool containing two tokens, the product of their quantities must remain constant after any trade. When a trader buys token Y with token X, they add X to the pool and remove Y. The formula forces the ratio of X to Y — and therefore the price — to shift automatically.
This elegance has a direct consequence: Uniswap never runs out of liquidity. No matter how large a trade, the pool will execute it (though at an increasingly unfavorable price as the trade size grows relative to pool depth). There is no order book to exhaust, no counterparty to find. The formula is always willing to trade.
The price at any moment is simply the ratio of the two token reserves: if the pool holds 1,000 ETH and 2,000,000 USDC, the implied price is 2,000 USDC per ETH. When a trader buys ETH, the ETH reserve shrinks and the USDC reserve grows, pushing the price up automatically. Arbitrageurs then close the gap between Uniswap's price and external market prices, keeping the pool calibrated.
fee-mechanism">Liquidity Providers and the Fee Mechanism
Anyone can deposit tokens into a Uniswap pool and become a liquidity provider (LP). In exchange, they receive pool shares proportional to their contribution and earn a fraction of every trading fee paid by users. In V2, this fee is a flat 0.3% on every trade, shared pro-rata among all LPs.
The mechanism is passive income for LPs, but it comes with a well-documented risk: impermanent loss. When the price of one token in the pair moves significantly relative to the other, LPs end up holding more of the depreciating token and less of the appreciating one. The loss is "impermanent" because it reverses if prices return to their original ratio, but in practice many LPs realize losses when they withdraw during volatile periods. The 0.3% fee must more than offset impermanent loss for providing liquidity to be profitable.
oracle">The V2 Whitepaper: Pair Tokens and the TWAP Oracle
The Uniswap V2 whitepaper, published in March 2020, introduced several important improvements beyond V1's design.
Direct ERC-20 to ERC-20 Pairs
V1 required all trades to route through ETH as an intermediary token. Swapping DAI for USDC meant selling DAI for ETH and then selling ETH for USDC — two hops, two fees, more slippage. V2 enabled direct ERC-20 to ERC-20 pools, allowing DAI/USDC trades in a single transaction.
The Price Oracle
Perhaps the most underappreciated innovation in V2 is the on-chain price oracle. The whitepaper introduces a time-weighted average price (TWAP) mechanism that makes Uniswap's price data manipulation-resistant.
The oracle accumulates price data by tracking the cumulative sum of prices at each block. To compute the average price over any historical period, an observer records the cumulative price at the start and end of the window and divides by the elapsed time. This TWAP is expensive to manipulate: an attacker would need to hold a distorted price across multiple blocks, paying gas and facing arbitrage the entire time.
This oracle became the backbone of much of DeFi. Lending protocols, derivatives platforms, and stablecoins all rely on Uniswap TWAP feeds because they are decentralized, permissionless, and deeply integrated into the system.
Flash Swaps
V2 also introduced flash swaps, which allow a contract to withdraw tokens from a pool, use them in arbitrary on-chain operations, and return them within the same transaction. If the tokens are returned with the fee, the pool is unaffected. If not, the entire transaction reverts.
Flash swaps enabled new classes of arbitrage and liquidation strategies that were previously impossible, and they demonstrated the composability of DeFi: because everything runs on the same blockchain, transactions can interact with multiple protocols atomically.
The V3 Whitepaper: Concentrated Liquidity
The Uniswap V3 whitepaper, published in March 2021, introduced the most significant redesign of the AMM model since its invention. The central innovation is concentrated liquidity: LPs no longer spread their capital uniformly across all possible prices but instead specify a price range within which their liquidity is active.
Why Uniform Liquidity Is Inefficient
Consider a USDC/ETH pool. If ETH trades between $1,500 and $2,500 for a given month, liquidity deployed outside that range earns zero fees. In V2, LPs must spread capital across every price from zero to infinity, meaning most of their capital sits idle at prices where no trades occur. The pool looks large, but its effective depth near the current price is far thinner than the total value locked would suggest.
V3 allows LPs to concentrate their capital in narrow bands around the current price. An LP who believes ETH will trade between $1,800 and $2,200 can deploy liquidity exclusively in that range, providing much greater depth per dollar of capital deployed and earning proportionally more fees.
Fee Tiers
V3 introduced multiple fee tiers — 0.05%, 0.3%, and 1% — to reflect different levels of volatility and risk. Stable pairs like USDC/DAI suit the 0.05% tier because their prices rarely diverge significantly, so LPs need thin margins to compete. Exotic pairs with high volatility suit the 1% tier, compensating LPs for higher impermanent loss risk.
This market structure pushed Uniswap beyond a one-size-fits-all model into a system that efficiently prices liquidity provision for different asset types.
Non-Fungible Liquidity Positions
Because V3 positions are defined by specific price ranges, no two LP positions are necessarily identical. V2 pool shares were fungible ERC-20 tokens; V3 positions are non-fungible tokens (NFTs). This created a new ecosystem of LP management protocols that automatically rebalance positions as prices move — an otherwise manual and gas-intensive process.
The TWAP Oracle in V3
V3 improved the oracle by storing a history of cumulative prices directly in the contract, making it cheaper to access historical data without relying on external indexers. It also introduced geometric mean TWAPs in addition to arithmetic mean TWAPs, enabling more sophisticated financial applications.
Uniswap's Place in the DeFi Stack
Uniswap has processed hundreds of billions of dollars in trading volume across its versions. Its whitepaper designs have been forked hundreds of times — SushiSwap, PancakeSwap, Trader Joe, and dozens of others all trace their architecture to the constant product formula.
More importantly, the protocol demonstrated that financial infrastructure can be governed by mathematics rather than institutions. Anyone with a web3 wallet can trade on Uniswap, anyone with tokens can provide liquidity, and no account can be frozen or censored at the protocol level. The whitepaper's simple equation became the intellectual foundation of an entirely new financial system.