Part 5 · Chapter 4

On-Chain vs Off-Chain Liquidity

AT A GLANCE

Liquidity can live on centralized order books or decentralized pools. You'll learn how depth, latency, and transparency differ — and how that affects your execution.

CEX Order BooksDEX AMM PoolsSlippageMEVTrade Routing

Who Is This For?

  • Traders deciding between CEX and DEX routes
  • DeFi users curious why prices differ across venues

Learning Objectives

  • 1.Distinguish on-chain AMM liquidity from off-chain order books
  • 2.Identify slippage, spreads, and MEV considerations
  • 3.Choose venues based on size, speed, and custody needs
Sections 1 & 2

CEX vs DEX Liquidity

🔍 Venue Deep Dive

🏦
Centralized Exchange (CEX)

Binance, Coinbase, Kraken, OKX, Bybit

Order books run on centralized servers. Market makers provide liquidity by placing buy and sell orders. A matching engine pairs orders in microseconds.

Speed
Milliseconds
Depth
Very deep for major pairs
Spreads
Tight (0.01-0.05%)
Fees
0.02-0.10% maker/taker
Gas Cost
None (off-chain)
Custody
Exchange holds your funds
Transparency
Limited — trust the exchange
MEV Risk
None
Availability
Can go down / freeze withdrawals
KYC Required
Yes (most jurisdictions)
✅ Advantages
  • +Best execution for large trades
  • +Deep liquidity on major pairs
  • +No gas fees on trades
  • +Advanced order types (stop, limit, OCO)
  • +Fast settlement within the exchange
❌ Disadvantages
  • Custodial — "not your keys"
  • Can freeze accounts or halt withdrawals
  • Opaque order matching
  • KYC required
  • Downtime during high volatility
  • Counterparty risk (FTX collapse)

🥪 MEV Sandwich Attack — Step by Step

MEV (Maximal Extractable Value) is a DEX-specific risk. Here's how a sandwich attack works:

Step 1: You Submit a Swap

You submit a transaction to swap 10 ETH → USDC on Uniswap. Your transaction enters the public mempool where it's visible to everyone before being included in a block.

👤 → 📡 Mempool

💡 Your transaction is PUBLIC before it executes.

Step 1 of 5

🛡️ MEV Protection Methods

Private RPCs / MEV Blockers
HighEasy

Send transactions through private mempools (Flashbots Protect, MEV Blocker) that hide your trade from searcher bots.

Examples: Flashbots Protect, MEV Blocker RPC, Blink by BloXroute

Aggregators with MEV Protection
Very HighEasy

DEX aggregators like CoW Swap batch orders off-chain and settle on-chain, preventing sandwich attacks entirely.

Examples: CoW Swap, 1inch Fusion, Hashflow

Limit Orders on DEX
HighModerate

Place limit orders instead of market swaps. Limit orders don't hit the mempool the same way — they fill at your price or not at all.

Examples: 1inch Limit, Uniswap X, Jupiter Limit

Tight Slippage Tolerance
ModerateEasy

Set slippage tolerance to 0.1-0.5%. Sandwich attacks become unprofitable if your allowed slippage is too tight for the bot to extract value.

Examples: Any DEX frontend settings

Smaller Trade Sizes
ModerateEasy

MEV bots target larger trades because the profit per sandwich is higher. Splitting into smaller swaps reduces attractiveness.

Examples: Manual splitting or TWAP on-chain

Section 3

Routing Trades Smartly

📊 DEX Slippage Estimator

See how trade size and pool depth affect your execution cost:

$5,000
$100$200,000
Price Impact
0.002%
Swap Fee
0.05%
Total Cost
0.05%
$ Lost to Slippage
$2.60

🧭 Trade Routing Advisor

Tell us your trade parameters and we'll recommend the best venue:

CEX Limit Orders (split if needed)
🏦 Confidence: High

At this size, CEX order books provide significantly better execution than DEX pools for most pairs. Use limit orders and consider splitting into 2-3 orders.

⏱️ Settlement Speed Comparison

1
Trade executes~ms

Matching engine pairs your order instantly

2
Balance updates~ms

Internal ledger credits your account

3
Withdraw to wallet1-60 min

On-chain transaction to your address

4
Deposit to DeFi1-15 min

Send from wallet to protocol

Total time to DeFi-ready:5-90 minutes

Funds are usable on the exchange immediately, but moving them on-chain requires withdrawal + confirmation time.

Watch Out

Common Mistakes & Gotchas

🥪
I swapped $50K of ETH on a DEX during a volatile selloff and got terrible execution
Large swaps during high volatility are MEV magnets. Use private RPCs (Flashbots Protect), MEV-protecting aggregators (CoW Swap), or trade on a CEX where MEV doesn't exist. Or split into smaller swaps over time.
💧
I market-sold into a pool with only $200K TVL — my $30K trade moved price 12%
Always check pool depth before trading. A $30K trade in a $200K pool has massive price impact. Either use a deeper pool, split the trade, use limit orders, or consider selling on a CEX where order book depth handles the size.
🏚️
I left $80K on FTX because CEX execution was so convenient — lost everything
CEX convenience is real, but never leave more on an exchange than you need for active trading. After executing, withdraw to your own wallet. CEX custody = counterparty risk. FTX, Mt. Gox, and many others proved this.
⚖️
The DEX shows ETH at $2,010 but Binance shows $2,000 — the DEX is overcharging me!
Price differences between venues are normal and temporary. Arbitrage bots continuously close these gaps, but it takes seconds to minutes. The DEX price includes pool mechanics and may reflect a momentary imbalance, not a permanent overcharge.

🔀 Golden Rule: The best venue depends on the trade, not the venue. Use CEXs for deep liquidity and fast execution; use DEXs for self-custody, transparency, and DeFi composability. For large trades, always check depth first — the cheapest route is the one with the least slippage.

Test Yourself

Knowledge Check

1

Why can DEX trades suffer from MEV (Maximal Extractable Value)?

2

What is a key benefit of CEX liquidity?

3

How can you reduce slippage on a DEX?

4

Why might you choose a DEX over a CEX?

5

What's the main risk of keeping large funds on a CEX?

Next Steps

Continue learning: "Fundamentals vs Narratives" to pair execution with thesis building
Hands-on practice: Compare quoted slippage for the same swap on an aggregator (1inch, Jupiter) vs a single DEX pool