Uniswap v2 Core

Authors Adams, Noah; Zinsmeister, Noah; Salem, Moody; Keefer, River; Robinson, Dan
Year 2020
Project Uniswap
License GPL-3.0
Official Source https://uniswap.org/whitepaper.pdf

This page is an educational summary and analysis of an official whitepaper or technical paper, written for reference purposes. It is not a verbatim reproduction. CryptoGloss does not claim authorship of the original work. All intellectual property rights remain with the original author(s). The official document is linked above.

“Uniswap v2 Core” is the whitepaper by the Uniswap team (Noah Adams, Noah Zinsmeister, Moody Salem, River Keefer, and Dan Robinson) published in March 2020. It describes the second major version of Uniswap — the automated market maker that defined decentralized trading on Ethereum.

The original Uniswap v1 (November 2018, by Hayden Adams) introduced the constant-product AMM for Ethereum and established the model for DEX trading. Uniswap v2 added critical infrastructure: direct ERC-20/ERC-20 pairs, a time-weighted average price (TWAP) oracle resistant to flash loan manipulation, and flash swaps.

> PDF hosting: The Uniswap v2 whitepaper is at uniswap.org/whitepaper.pdf. Uniswap v1 was undocumented academically; Uniswap v3 has a separate whitepaper.


Publication and Context

Hayden Adams built Uniswap v1 after being inspired by a Vitalik Buterin ethresear.ch post describing automated market makers. V1 only supported ETH-ERC20 pairs — every token trade routed through ETH as an intermediary.

V2 was designed by the Uniswap team to address V1’s limitations:

  1. ETH-as-intermediary inefficiency: Trading BAT for DAI required two transactions (BAT→ETH→DAI)
  2. Oracle manipulation vulnerability: Short-duration price reads were manipulable via flash loans
  3. Flash swaps: V1 had no uncollateralized loan mechanism

Uniswap v2 became the backbone of DeFi summer 2020 and remains active years later, with hundreds of billions in lifetime volume.


Core Design: Constant Product AMM

Uniswap uses the constant product formula:

$$x cdot y = k$$

Where $x$ and $y$ are the reserves of the two tokens, and $k$ is a constant. Any trade must keep $k$ constant (adjusting for fees):

  • Buy $Delta y$ tokens: the trader must provide $Delta x’ = frac{x cdot Delta y}{y – Delta y}$ tokens (plus the 0.3% fee)
  • Trade size determines slippage: larger trades move the price more

ERC-20/ERC-20 Pairs:

V2 supports direct pairs between any two ERC-20 tokens. Instead of BAT→ETH→DAI, users can trade BAT/DAI directly in a single pool. This reduces slippage and gas costs for cross-token trades.


TWAP Price Oracle

One of V2’s most important contributions is the Time-Weighted Average Price (TWAP) oracle — designed to be resistant to flash loan manipulation.

The V1 oracle problem: Reading pool price at a single block is trivially manipulable. An attacker can use a flash loan to buy/sell a large amount in the same block, artificially moving the price, and any protocol reading V1 price in the same block would read the manipulated value.

V2’s TWAP solution:

  • Each block accumulates: price0CumulativeLast += reserve1/reserve0 × time_elapsed
  • The cumulative price accumulates over time; to get the TWAP over a period, external contracts record the cumulative value at the start and end and divide by elapsed time
  • Flash loan manipulation within a single block affects only that block’s end-of-block snapshot (a negligible fraction of a long TWAP)
  • A 30-minute TWAP requires an attacker to control 50%+ of blocks for 30 minutes to meaningfully manipulate the price — practically infeasible

TWAP oracles became the standard on-chain price reference for DeFi protocols.


Flash Swaps

V2 introduced flash swaps: anyone can withdraw any amount of any pool asset, use it in the same transaction, and return it (with the 0.3% fee) before the transaction ends.

Similar to Aave’s flash loans but native to the AMM pool itself. Flash swaps enabled:

  • Arbitrage between pools without initial capital
  • Liquidations without pre-holding the repayment asset
  • Collateral swaps in lending protocols

Protocol Fee Switch

V2 includes an optional protocol fee (0.05% of the 0.3% trading fee) that can be turned on by the Uniswap governance/factory. This fee would go to the Uniswap treasury rather than LPs.

As of publication, the fee switch remains off on most deployments — Uniswap governance has debated activating it for years. The fee switch debates became a recurring governance drama.


Liquidity Provision and LP Tokens

Liquidity providers (LPs) receive UNI-V2 LP tokens proportional to their share of the pool. LP tokens:

  • Represent fractional ownership of the pool’s reserves
  • Accumulate 0.3% of all trading fees over time
  • Can be burned to redeem the underlying assets

Impermanent loss: If the price ratio changes significantly, LPs end up holding more of the depreciated asset than they started with — the “impermanent loss” relative to simply holding the tokens. The 0.3% fee compensates LPs for this risk, but only partially in high-volatility pairs.


Reality Check

Uniswap v2 is one of the most battle-tested smart contract systems in Ethereum history. Its simplicity is a security strength. The system has handled over $1 trillion in cumulative volume without a protocol-level hack.

Limitations:

  • Capital efficiency: 50/50 equal weight means much liquidity is idle far from market price
  • No concentrated liquidity: V3 (2021) addressed this with tick-based ranges
  • 0.3% fee is fixed: Cannot be adjusted per pool to optimize for different asset volatility

Legacy

Uniswap v2’s architecture is the foundation for hundreds of AMM forks (SushiSwap, PancakeSwap, QuickSwap, Trader Joe, and more). The TWAP oracle concept became an industry standard referenced by Chainlink, Compound, Aave, and virtually every DeFi money market. Flash swaps, alongside Aave’s flash loans, proved uncollateralized DeFi primitives viable.


Related Terms


Research

  • Adams, N., Zinsmeister, N., Salem, M., Keefer, R., & Robinson, D. (2020). Uniswap v2 Core. uniswap.org.

— Primary source. Section 2 (TWAP oracle) and Section 3 (flash swaps) are the key innovations.

  • Angeris, G., et al. (2020). An Analysis of Uniswap Markets. arXiv:1911.03380.

— Formal analysis of Uniswap’s invariant, price impact, and LP economics.

  • Wang, Y., et al. (2021). Cyclic Arbitrage in Decentralized Exchanges. arXiv:2105.02784.

— Studies cross-pool arbitrage dynamics that depend on Uniswap TWAP oracle accuracy.