DeFi Basics
This section explains the basics of DeFi with a focus on Uniswap v2/v3 mechanics. Many DeFi protocols run on the EVM; Uniswap pioneered the AMM model, which later inspired forks such as PancakeSwap and SushiSwap.

AMM (Automated Market Maker)
An AMM sets prices automatically based on a liquidity pool rather than an order book. A canonical implementation is Uniswap v2, whose price is determined by the constant‑product model:
This formula expresses the constant‑product model where the product of the two token reserves (x, y) in the pool remains constant (k). When a user swaps one token for the other, the reserves change and the price adjusts automatically.
Here, x and y are the token reserves and k is a constant. The design is simple and gas‑efficient, but is susceptible to large swaps and frontrun‑driven price manipulation.
ref: What is an Automated Market Maker? by Uniswap
Liquidity Pools
Liquidity pools are the foundation of trading in AMMs. A pool is created by depositing two tokens (e.g., WETH/USDC) at a given ratio, enabling peer‑to‑peer swaps via the pool.
Who provides liquidity?
- Anyone can become a liquidity provider (LP).
- No special approval is needed; deposit the two tokens at the specified ratio.
- Your share of the pool is proportional to your contribution.
How it differs from CEX
- CEX (centralized exchanges)
- Maintain an order book of bids and asks.
- Match orders against each other to execute trades.
- AMM (decentralized exchanges)
- Users trade directly against the pool without finding a counterparty.
- Price is determined automatically by reserve changes.
- No order book; you’re less likely to “not fill because the book is thin.”
Incentives
- LPs receive a share of the trading fees generated by the pool.
- Uniswap v2 typically charges a 0.3% fee.
- Example: an LP with a 10% pool share earns 10% of fees accrued.
- LPs are thus compensated for providing liquidity to the exchange.
Notes
- Anyone can be an LP, but changing pool ratios introduce impermanent loss (IL) risk.
- Fee revenue compensates this risk; participation is a risk/reward decision.
Uniswap v2 swap examples
1. Initial pool state
Consider the following pool:
- x = 100 WETH
- y = 300,000 USDC
- The constant product is
The price is then
2. User swaps
Case A: Sell 10 WETH for USDC
The user adds 10 WETH to the pool and withdraws USDC.
- New x reserve:
- With k constant:
- USDC received by the user:
- New price:
So the price moves from 3,000 → ~2,479 USDC/WETH after the trade (slippage).
Case B: Add 30,000 USDC to buy WETH
Conversely, the user adds 30,000 USDC to buy WETH.
- New y reserve:
- With k constant:
- WETH received by the user:
- New price:
Thus the price moves from 3,000 → ~3,628 USDC/WETH after the trade.
3. Takeaways
- Larger orders move the price more, creating slippage.
- This is a byproduct of enforcing x × y = k.
- Large traders often split orders to reduce slippage.
Uniswap v3 improves on v2’s shortcomings
Uniswap v2 (May 2020) revolutionized DeFi with the simple constant‑product model, but placing liquidity uniformly across all price ranges is inefficient and leads to large slippage on big trades.
Uniswap v3 (May 2021) introduced concentrated liquidity. LPs can concentrate liquidity within chosen price ranges, so more liquidity sits where trades actually occur, reducing slippage.
Example (WETH/USDC)
-
v2
- 200 WETH and 600,000 USDC are spread uniformly.
- With 1 WETH ≈ 3,000 USDC, liquidity is thin at any specific range.
- Selling 10 WETH drops price from 3,000 → ~2,739 USDC/WETH (large slippage).
-
v3
- LPs concentrate liquidity in, say, the 2,500–3,500 USDC/WETH range.
- Effective liquidity is multiple times deeper in that band than in v2.
- Selling the same 10 WETH only moves price from 3,000 → ~2,950 USDC/WETH (smaller slippage).
Takeaways
- v3 lets LPs choose price ranges for liquidity, improving capital efficiency.
- Concentrating assets where trades occur reduces slippage for a given liquidity amount.
- If price exits the chosen range, an LP’s position may convert entirely to one token and provide zero liquidity.
Order‑book model (CEX and Hyperliquid)
Basics
In an order‑book exchange, traders submit price‑and‑size orders which are matched to execute trades.
- Bid: willing to buy at or below this price
- Ask: willing to sell at or above this price
The exchange sorts orders by price; trades occur where best bid meets best ask.
Example: WETH/USDC order book
Asks
3,010 USDC - 50 WETH
3,005 USDC - 30 WETH
3,000 USDC - 20 WETH ← Best ask
Bids
2,995 USDC - 25 WETH ← Best bid
2,990 USDC - 40 WETH
2,985 USDC - 60 WETH
Current market (spread) is 3,000–2,995 USDC.
- A market sell of 10 WETH matches at ~3,000 USDC/WETH.
- A market sell of 100 WETH walks the book (3,000 → 2,990 → 2,985), averaging ~2,990 USDC/WETH.
👉 With deep liquidity, even large orders have limited slippage.
Differences vs AMM
- AMM (e.g., Uniswap v2)
- Price is set by the constant‑product curve.
- Trades slide along the curve (slippage is inherent).
- Simple; anyone can supply liquidity.
- Order book (e.g., CEX, Hyperliquid)
- Price is set by the book.
- With a deep book, large orders have stable execution.
- Thin books can move violently (flash‑crash risk).
Pros and cons
Pros
- Less slippage (when liquidity is deep)
- Price control via limit orders
- Suited for high‑throughput systems (CEX or some L2 DEXs)
Cons
- Tends toward centralization (CEX controls the book)
- High infra requirements for decentralized implementations (off‑chain engines/L2)
- Sometimes less transparent than AMMs (spoofing, manipulation)
Hyperliquid highlights
- Runs on its own high‑performance chain (not EVM‑compatible)
- Aims for CEX‑like speed even while remaining on‑chain
- With speed and deep books, MEV risks like sandwiching are lower than AMMs