How Does Uniswap Work (Uniswap V2) — A Complete Guide (Part 1)

·

Introduction

At the heart of Uniswap lies the constant product formula (x*y=k), which powers its decentralized trading mechanism. This guide dives deep into Uniswap V2, breaking down its smart contract architecture, core functionalities, and how it manages billions in Total Value Locked (TVL).


How Uniswap Works Fundamentally

Uniswap enables trustless swaps between ERC20 tokens (e.g., DOT for ETH) via Automated Market Makers (AMMs), eliminating traditional order books. Key components:

  1. Liquidity Pools: Users deposit pairs of tokens (e.g., DOT/ETH) to facilitate trades.

    • Incentive: Liquidity providers earn 0.3% fees per trade.
  2. Constant Product Formula: Ensures pool balance via (DOT amount * ETH amount) = k.

👉 Learn how AMMs revolutionize DeFi


Uniswap Versions

| Version | Description |
|---------|------------------------------|
| V1 | Basic functionality |
| V2 | Enhanced features (focus of this guide) |
| V3 | Optimized & complex |


Uniswap Smart Contract Architecture

Core Contracts

  1. Pair: Handles swaps, minting/burning LP tokens.
  2. Factory: Deploys/tracks Pair contracts.
  3. ERC20: Manages LP token ownership.

Periphery Contract


Key Functionalities

  1. Fund Management: Secures pool reserves.
  2. Swapping: Executes token trades.
  3. LP Ownership: Tracks provider stakes via LP tokens.
  4. Withdrawals: Lets LPs claim rewards + principal.
  5. Price Oracle: Provides accurate market rates for other dApps.

👉 Explore Uniswap V2 contracts


FAQs

Q1: How does Uniswap ensure fair token prices?

A1: Arbitrageurs correct price deviations, aligning them with external markets.

Q2: What are LP tokens?

A2: ERC20 tokens representing a provider’s share in a pool.

Q3: Is Uniswap V2’s 0.3% fee model sustainable?

A3: Yes, it balances incentives for LPs and traders.


Conclusion

Uniswap V2’s decentralized design relies on robust smart contracts and the constant product formula. Stay tuned for Part 2, covering advanced topics like protocol fees and oracle mechanics.

🚀 Pro Tip: Use the Router contract for gas-efficient swaps!