Skip to content

Uniswap

Overview

Uniswap is a decentralized exchange protocol (DEX) built on the Ethereum blockchain that employs an Automated Market Maker (AMM) model, allowing users to trade ERC-20 tokens without the need for a centralized intermediary. As one of the cornerstone protocols in DeFi (Decentralized Finance), Uniswap addresses the issues of insufficient liquidity and high transaction costs that traditional order book exchanges face on blockchain due to performance limitations.

Uniswap was founded by Hayden Adams in 2018, deeply inspired by Ethereum founder Vitalik Buterin's article on on-chain automated market makers. It not only provides users with permissionless token swapping services but also allows anyone to earn trading fees by providing liquidity.

As of 2024, Uniswap has gone through multiple version iterations (V1, V2, V3, and the upcoming V4), with cumulative trading volume exceeding trillions of dollars, making it one of the largest and most liquid decentralized exchanges in the Ethereum ecosystem and the entire cryptocurrency market.

Core Mechanisms and Principles

Automated Market Maker (AMM)

Uniswap abandons the traditional financial market's buy/sell order book model in favor of Liquidity Pools and a constant product formula to determine prices.

The core formula is: \(x * y = k\)

Where: - \(x\) is the quantity of Token A in the liquidity pool - \(y\) is the quantity of Token B in the liquidity pool - \(k\) is a constant that remains unchanged when a trade occurs (ignoring fee effects)

When a user sells Token A for Token B, \(x\) in the pool increases, and \(y\) must decrease to keep \(k\) constant, thus pushing up the relative price of Token A against Token B. This mechanism ensures continuous liquidity -- as long as there are assets in the pool, trades can be executed.

Liquidity Provision

Anyone can deposit equal value of two tokens into a Uniswap liquidity pool and become a Liquidity Provider (LP). In return, LPs receive liquidity tokens (LP Tokens) representing their share in the pool and earn a proportional share of the trading fees generated by that pool.

Major Versions and Features

Uniswap V1 (November 2018)

  • Mechanism: The initial version, supporting only trades between ETH and ERC-20 tokens.
  • Limitation: To trade two ERC-20 tokens (e.g., DAI for USDC), one had to first swap DAI for ETH, then ETH for USDC, resulting in double slippage and high fees.

Uniswap V2 (May 2020)

  • ERC-20 to ERC-20 Trading: Allows creating direct liquidity pools between any two ERC-20 tokens, eliminating the dependency on ETH and reducing slippage.
  • Price *Oracle: Introduced a Time-Weighted Average Price (TWAP) mechanism, providing on-chain price data that is difficult to manipulate for other *DeFi** protocols.
  • Flash Swaps: Allows users to borrow tokens before paying, as long as they are returned with fees within the same transaction -- commonly used for arbitrage.

Uniswap V3 (May 2021)

  • Concentrated Liquidity: This is the core innovation of V3. LPs no longer need to provide liquidity across the entire price range from \(0\) to \(\infty\); instead, they can select specific price ranges (e.g., ETH/USDC between 1500-2500) to deploy capital. This greatly improves capital efficiency, allowing LPs to earn more fees with less capital, though it also increases impermanent loss risk and management complexity.
  • Multiple Fee Tiers: Offers different fee tiers such as 0.05%, 0.30%, and 1.00% to accommodate assets with different volatility levels (e.g., stablecoin pairs, major token pairs, long-tail assets).
  • NFT LP Tokens: Since each LP selects a different price range, liquidity positions are no longer homogeneous ERC-20 tokens but are represented as NFTs (ERC-721).

Uniswap V4

  • Hooks: Allows developers to insert custom logic at specific points in a liquidity pool's lifecycle (such as before a trade, after a trade, before adding liquidity, etc.). This enables features like limit orders, dynamic fees, and TWAMM (Time-Weighted Average Market Maker) to be implemented at the pool level.
  • Singleton Contract: All liquidity pools will exist within a single smart contract, rather than deploying a new contract for each pool as before. This will significantly reduce Gas costs for pool creation and multi-hop trades.

UniswapX

  • Aggregation and Dutch Auctions: An intent-based trading protocol that outsources routing complexity to third-party Fillers. Fillers compete with each other to provide the best price, covering liquidity from the Uniswap protocol as well as other DEX liquidity. It also enables gasless transactions (Fillers pay the Gas) and MEV protection.

Governance Token (UNI)

In September 2020, Uniswap launched its governance token UNI and airdropped it to early users. UNI holders have governance rights over the protocol and can vote to decide: - The Community Treasury fund allocation. - The Fee Switch: The community can vote on whether to enable protocol-level fees (e.g., taking 10%-25% from LP revenue for the protocol). - Management of the uniswap.eth domain name, etc.

  • AMM (Automated Market Maker): The trading model adopted by Uniswap.
  • Impermanent Loss: The potential value loss faced by LPs when providing liquidity compared to simply holding the assets, typically occurring when asset prices fluctuate significantly.
  • Slippage: The difference between the expected price and the actual execution price of a trade.
  • TWAP (Time-Weighted Average Price): The on-chain price oracle mechanism provided by Uniswap.