Liquidity Pools
🧩 1. The Core Problem — Why Do We Need Liquidity Pools?
Let’s first ask “why” liquidity pools exist at all.
Traditionally, in centralized exchanges (CEX) like Binance or stock markets, trades happen using an Order Book system:
-
Buyers place buy orders at a certain price.
-
Sellers place sell orders.
-
The exchange matches them.
But DeFi is decentralized — there’s no central entity to match buyers and sellers.
So how can we still make trading possible on the blockchain?
We need a system that:
-
Doesn’t rely on middlemen,
-
Always has liquidity (someone ready to trade),
-
Works automatically through code.
→ That’s why Liquidity Pools were invented.
They replace the order book with smart contract-based liquidity.
🧠 2. What is a Liquidity Pool (Simple Definition)
A liquidity pool is a smart contract that holds two (or more) tokens and allows users to trade between them using a mathematical formula, instead of matching buy/sell orders.
It’s like a bucket that holds two assets — say, ETH and USDT — and automatically sets the price based on supply and demand.
🧱 3. How Does It Work? (Let’s Take Uniswap as Example)
Uniswap uses a simple yet powerful formula:
Where:
-
x= amount of Token A (e.g., ETH) -
y= amount of Token B (e.g., USDT) -
k= constant value (doesn’t change)
This is called the Constant Product Market Maker (CPMM) formula.
Let’s walk through it with an example 👇
Example: ETH-USDT Pool
Imagine:
-
10 ETH and 20,000 USDT are in the pool.
-
So, each ETH = 2000 USDT.
-
Constant
k = 10 × 20,000 = 200,000.
Now, suppose a trader wants to buy 1 ETH using USDT.
He adds USDT to the pool. Let’s find out what happens.
After trade:
-
New ETH = 9 (since 1 ETH is taken)
-
-
So pool now has 22,222 USDT.
That means the trader had to deposit:
→ 22,222 − 20,000 = 2,222 USDT for 1 ETH.
So the new price ≈ 2,222 USDT/ETH.
💡 Price increases because ETH became scarcer in the pool.
This self-adjusting mechanism is called an automated market maker (AMM).
🔁 4. How Do Trades Happen Technically?
When a user swaps tokens:
-
The smart contract calculates new balances using
x*y=k. -
It takes input tokens and returns output tokens accordingly.
-
The difference in pool ratio automatically sets the new price.
-
A small trading fee (e.g., 0.3%) is distributed to liquidity providers.
No humans, no order books — pure math.
👥 5. Who Provides the Liquidity?
Liquidity providers (LPs) are people who deposit equal value of both tokens into the pool.
Example:
-
You deposit 1 ETH + 2000 USDT → you own a share of the pool.
-
The pool gives you LP tokens (like receipt slips) representing your contribution.
If you own 10% of the pool, you earn 10% of the fees from all trades.
When you withdraw:
-
You burn your LP tokens.
-
You receive your share of tokens (which may have changed in amount due to price movement).
💰 6. Rewards for LPs
LPs earn:
-
Trading fees (e.g., 0.3% per trade)
-
Incentive tokens (like UNI, CAKE, CRV)
-
Sometimes farming rewards (if staking LP tokens elsewhere)
This is the yield farmers’ playground.
⚖️ 7. Key Formula Behind Liquidity Pools — Constant Product AMM
Let’s understand it with precision.
This means:
-
The product of both token reserves stays constant.
-
If one token decreases (because it’s bought), the other increases.
The price of Token A in terms of Token B = .
So, as trades happen:
-
Buying Token A → its price increases.
-
Selling Token A → its price decreases.
This keeps prices balanced via supply-demand automatically.
📈 8. Visualizing It — The Curve
The price relationship forms a hyperbola (since ).
-
When
xis large →ysmall (cheap price). -
When
xis small →ylarge (expensive price).
So pools discourage draining — the more you buy one asset, the more expensive it gets.
That’s why large trades cause slippage (price impact).
🧮 9. Real Numbers Example (Hands-On)
Let’s simulate small trades:
| Action | ETH in Pool | USDT in Pool | ETH Price (y/x) | Comment |
|---|---|---|---|---|
| Start | 10 | 20,000 | 2000 | initial state |
| Buy 1 ETH | 9 | 22,222 | 2469 | price increases |
| Sell 1 ETH | 11 | 18,181 | 1652 | price decreases |
✅ Automatically maintains balance.
No human needed.
⚠️ 10. Impermanent Loss (Brief Intro)
When LPs withdraw, they might find:
-
The token ratio has changed (ETH ↑, USDT ↓ or vice versa),
-
The total value they get is less than if they had just held the tokens.
That’s called impermanent loss — we’ll decode this fully in the next topic if you wish.
🧠 11. Liquidity Pool vs Order Book — Comparison
| Feature | Order Book (CEX) | Liquidity Pool (DEX) |
|---|---|---|
| Matching | Buyers & sellers | Smart contract formula |
| Price Discovery | Market orders | AMM formula |
| Liquidity | Provided by traders | Provided by LPs |
| Control | Centralized exchange | Decentralized contract |
| Fees | Exchange decides | Shared among LPs |
| Transparency | Opaque | 100% on-chain |
🧩 12. Types of Liquidity Pools
| Type | Use Case | Example |
|---|---|---|
| Constant Product (x*y=k) | General token swaps | Uniswap v2 |
| StableSwap (low slippage) | Stablecoin swaps | Curve Finance |
| Constant Sum (x+y=k) | Pegged assets | Balancer Pools |
| Weighted Pools | Custom ratios (e.g., 80/20) | Balancer |
| Hybrid Pools | Mix of the above | Curve’s TriCrypto |
⚙️ 13. What’s Inside a Liquidity Pool Smart Contract
A liquidity pool smart contract usually has:
-
Reserves of both tokens
-
Function to add/remove liquidity
-
Swap function (calculates output)
-
Fee logic
-
LP token mint/burn logic
It’s like a mini bank vault with built-in math and accounting.
🌍 14. Real-World Analogy
Think of a money exchange counter:
-
You drop in dollars, you get rupees.
-
The counter maintains balance between the two.
-
If too many people buy rupees, they become more “expensive”.
Liquidity pools automate that exact process — but using code instead of humans.
✅ 15. Summary Table
| Concept | Explanation | Example |
|---|---|---|
| Liquidity Pool | Smart contract holding tokens to enable trading | ETH-USDT on Uniswap |
| AMM | Algorithm that sets prices automatically | x*y=k |
| LP Token | Proof of share in the pool | UNI-V2 token |
| Slippage | Price change due to large trades | More noticeable in small pools |
| Impermanent Loss | Loss due to price ratio change | ETH rises, LP value drops |
| Trading Fee | Paid by traders, earned by LPs | 0.3% per swap |
🎯 16. One-Line Summary
A Liquidity Pool is a decentralized vault of token pairs that uses mathematical rules (like x*y=k) to enable automated trading, without relying on order books or intermediaries — the foundation of all AMM-based DeFi.
Comments
Post a Comment