DEX Trading
AMMs, on-chain order books, aggregators, slippage management, MEV protection, and trading efficiently on-chain.
From Thrive on YouTube
Watch the matching Thrive video
The True Cost of Trading: Fees, Spread, Slippage and Funding
Part of Funding Rates, Liquidations and Open Interest. Education only. Not financial advice.
How Automated Market Makers Work
An Automated Market Maker (AMM) is a smart contract that holds two (or more) tokens in a liquidity pool and uses a mathematical formula to determine the price. The foundational formula is the constant product equation: x × y = k, where x is the amount of Token A in the pool, y is the amount of Token B, and k is a constant. When someone buys Token A, they deposit Token B into the pool, increasing y and decreasing x. The formula ensures that as one token becomes scarcer in the pool, its price increases.
Unlike a centralized exchange order book where you trade against another person's limit order, an AMM trade is against the pool itself. The pool is always willing to trade at the price dictated by the formula. There is no order matching, no bid-ask spread in the traditional sense, and no counterparty, just math. The "liquidity providers" who deposit tokens into the pool earn a fee on every swap (typically 0.3% on Uniswap v2 pools).
A pool is created
A trader swaps USDC for ETH
Price impact scales with trade size
Arbitrageurs maintain the price
Concentrated Liquidity (Uniswap v3)
Uniswap v3 introduced concentrated liquidity: a major evolution of the AMM model. Instead of spreading your liquidity across the entire price range from zero to infinity (which means most of your capital is sitting idle at prices far from the current price), v3 lets you specify a price range for your liquidity. If you believe ETH will trade between $2,800 and $3,200 this week, you can concentrate all your liquidity in that range.
The advantage is capital efficiency: concentrated liquidity earns much higher fees per dollar deployed because all your capital is active in the trading range. The disadvantage is management overhead and increased impermanent loss if the price moves outside your range. When price exits your range, your position becomes 100% the less valuable token and earns zero fees until price re-enters.
Active vs. passive liquidity
On-Chain Order Books
Not all DEXs use AMMs. A newer generation of decentralized exchanges uses on-chain or hybrid order books: closer to the CEX model but running on a blockchain. dYdX (on its own Cosmos chain) and Hyperliquid operate central limit order books with full limit order support, cross-margin, and sub-second execution. These platforms bridge the gap between DeFi's permissionless access and CEX-grade execution quality.
| dYdX | Perpetual futures DEX on a dedicated Cosmos appchain. Full order book, cross-margin, up to 20x leverage. Off-chain matching, on-chain settlement. |
| Hyperliquid | High-performance perps DEX with its own L1. Sub-second execution, deep liquidity, CEX-like UX with self-custody. |
| Jupiter | Solana DEX aggregator that routes across AMMs and order books. Best execution for Solana token swaps with limit orders and DCA. |
| CoW Swap | Ethereum batch auction DEX. Matches trades peer-to-peer first (CoW = Coincidence of Wants), then routes remainder to AMMs. MEV protection built in. |
DEX Aggregators
A DEX aggregator searches across multiple liquidity sources (Uniswap, Curve, Balancer, SushiSwap, etc.) to find the best execution price for your trade. Instead of manually checking each DEX, the aggregator splits your order across multiple pools and routes to minimize price impact. For any trade above a few hundred dollars, using an aggregator almost always gets you a better price than trading directly on a single DEX.
The most established Ethereum DEX aggregator. Searches 100+ liquidity sources. Offers limit orders and fusion swaps for gas savings.
The dominant Solana aggregator. Routes across all Solana AMMs and CLOBs. Includes limit orders, DCA, and perpetuals.
Batch auction model with built-in MEV protection. Matches trades off-chain, settles on-chain. Often achieves better prices than 1inch.
Multi-chain aggregator with a focus on gas optimization. Integrates with many DeFi protocols beyond swaps.
Slippage and Price Impact
Slippage is the difference between the price you expect and the price you actually receive. On a DEX, slippage comes from two sources: price impact (the mathematical cost of your trade moving the AMM formula) and market movement (price changing between when you submit the transaction and when it executes on-chain).
Price impact is deterministic: a $10,000 swap on a pool with $1 million TVL will always cause roughly 1% price impact. You can calculate it before you trade. Market movement slippage is stochastic. You cannot predict whether the price will move 0.5% in the 15 seconds between your click and on-chain confirmation.
Minimize slippage
MEV: Maximal Extractable Value
MEV (Maximal Extractable Value) is profit that can be extracted by reordering, inserting, or censoring transactions within a block. When you submit a swap on Ethereum, your transaction sits in a public mempool before being included in a block. Sophisticated actors (MEV bots) can see your pending transaction and exploit it.
Sandwich Attacks
The most common MEV attack against retail traders. A sandwich bot sees your pending swap in the mempool, front-runs you with a buy (pushing the price up), lets your transaction execute at the inflated price, then back-runs you with a sell (pushing the price back down and pocketing the difference). You get worse execution; the bot profits from your slippage.
MEV Protection
Submit transactions directly to block builders instead of the public mempool. Bots cannot see your pending transaction.
Trades are matched off-chain in batches, then settled on-chain. No mempool exposure means no sandwich attacks.
Setting tight slippage (0.5%) makes sandwich attacks unprofitable because the bot cannot extract enough value.
Some wallets (like Rabby and newer MetaMask versions) route transactions through MEV-protected RPCs by default.
Trading Efficiently On-Chain
Time your transactions
Use limit orders when available
Batch your approvals
Trade on L2s for small sizes
Check before you swap
Put this lesson to work
Free on Thrive, no account needed.