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:

x×y=kx \times y = k

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)

  • y=k/x=200,000/9=22,222.22y = k / x = 200,000 / 9 = 22,222.22

  • 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:

  1. The smart contract calculates new balances using x*y=k.

  2. It takes input tokens and returns output tokens accordingly.

  3. The difference in pool ratio automatically sets the new price.

  4. 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:

  1. Trading fees (e.g., 0.3% per trade)

  2. Incentive tokens (like UNI, CAKE, CRV)

  3. 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.

x×y=kx \times y = k

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 = y/xy / x.

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 y=k/xy = k/x).

  • When x is large → y small (cheap price).

  • When x is small → y large (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:

ActionETH in PoolUSDT in PoolETH Price (y/x)Comment
Start1020,0002000initial state
Buy 1 ETH922,2222469price increases
Sell 1 ETH1118,1811652price 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

FeatureOrder Book (CEX)Liquidity Pool (DEX)
MatchingBuyers & sellersSmart contract formula
Price DiscoveryMarket ordersAMM formula
LiquidityProvided by tradersProvided by LPs
ControlCentralized exchangeDecentralized contract
FeesExchange decidesShared among LPs
TransparencyOpaque100% on-chain

🧩 12. Types of Liquidity Pools

TypeUse CaseExample
Constant Product (x*y=k)General token swapsUniswap v2
StableSwap (low slippage)Stablecoin swapsCurve Finance
Constant Sum (x+y=k)Pegged assetsBalancer Pools
Weighted PoolsCustom ratios (e.g., 80/20)Balancer
Hybrid PoolsMix of the aboveCurve’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

ConceptExplanationExample
Liquidity PoolSmart contract holding tokens to enable tradingETH-USDT on Uniswap
AMMAlgorithm that sets prices automaticallyx*y=k
LP TokenProof of share in the poolUNI-V2 token
SlippagePrice change due to large tradesMore noticeable in small pools
Impermanent LossLoss due to price ratio changeETH rises, LP value drops
Trading FeePaid by traders, earned by LPs0.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

Popular posts from this blog