Skip to main content

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

Watch the series
The True Cost of Trading: Fees, Spread, Slippage and Funding

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

1

A pool is created

Someone deploys a liquidity pool with an initial deposit: for example, 10 ETH and 30,000 USDC. The initial ratio sets the starting price: 30,000 / 10 = $3,000 per ETH. The constant k = 10 × 30,000 = 300,000.
2

A trader swaps USDC for ETH

A trader wants to buy 1 ETH. They send USDC to the pool. After the swap, the pool has 9 ETH and 33,333 USDC (because 9 × 33,333 ≈ 300,000). The trader received 1 ETH for 3,333 USDC: a price of $3,333 per ETH. Notice the price increased because the pool has less ETH.
3

Price impact scales with trade size

A small trade barely moves the price. A large trade (relative to pool liquidity) moves the price significantly. This price movement is called "price impact" and it is the AMM equivalent of "slippage" on a centralized exchange. The deeper the pool (higher TVL), the less price impact per trade.
4

Arbitrageurs maintain the price

If the pool price diverges from centralized exchange prices, arbitrageurs buy from the cheaper venue and sell on the more expensive one, pocketing the difference and pushing prices back into alignment. This arbitrage mechanism is what keeps AMM prices accurate.

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

Uniswap v2 (full-range liquidity) is "set and forget". Your liquidity works at every price. Uniswap v3 (concentrated liquidity) requires active management. You must monitor your range and rebalance if price moves. Professional LPs use automated vault managers to handle rebalancing, but individual providers often underperform because they rebalance at the wrong times.

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.

dYdXPerpetual futures DEX on a dedicated Cosmos appchain. Full order book, cross-margin, up to 20x leverage. Off-chain matching, on-chain settlement.
HyperliquidHigh-performance perps DEX with its own L1. Sub-second execution, deep liquidity, CEX-like UX with self-custody.
JupiterSolana DEX aggregator that routes across AMMs and order books. Best execution for Solana token swaps with limit orders and DCA.
CoW SwapEthereum 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.

1inch

The most established Ethereum DEX aggregator. Searches 100+ liquidity sources. Offers limit orders and fusion swaps for gas savings.

Jupiter

The dominant Solana aggregator. Routes across all Solana AMMs and CLOBs. Includes limit orders, DCA, and perpetuals.

CoW Swap

Batch auction model with built-in MEV protection. Matches trades off-chain, settles on-chain. Often achieves better prices than 1inch.

Paraswap

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

Set your slippage tolerance tight (0.5–1% for major tokens) and use DEX aggregators. For large trades ($50K+), split across multiple blocks or use TWAP (time-weighted average price) execution through protocols like CoW Swap. Never leave slippage tolerance at the default high settings. This invites sandwich attacks.

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

Private RPCs (Flashbots Protect)

Submit transactions directly to block builders instead of the public mempool. Bots cannot see your pending transaction.

CoW Swap batch auctions

Trades are matched off-chain in batches, then settled on-chain. No mempool exposure means no sandwich attacks.

Low slippage tolerance

Setting tight slippage (0.5%) makes sandwich attacks unprofitable because the bot cannot extract enough value.

MEV-aware wallets

Some wallets (like Rabby and newer MetaMask versions) route transactions through MEV-protected RPCs by default.

Trading Efficiently On-Chain

1

Time your transactions

Gas fees fluctuate dramatically by time of day and network congestion. On Ethereum, weekday early mornings (UTC) tend to have lower gas. On L2s and Solana, gas is negligible but network congestion during high-volatility events can still cause failed transactions.
2

Use limit orders when available

Many DEXs and aggregators now support on-chain limit orders. Instead of swapping at whatever the current price is, set a limit order at your target price. This avoids slippage entirely: the trade only executes at your price or better.
3

Batch your approvals

Every ERC-20 token requires an "approve" transaction before you can trade it. Approving for the maximum amount (common but risky) saves gas on future trades. Using Permit2 or batch approval protocols reduces the number of transactions.
4

Trade on L2s for small sizes

For trades under $10,000, Layer 2 networks (Arbitrum, Base, Optimism) offer the same protocol access with 10–100x lower gas fees than Ethereum mainnet. The liquidity may be thinner, but for reasonable trade sizes the savings far outweigh any additional price impact.

Check before you swap

Always verify the token contract address before swapping. On DEXs, anyone can create a token with any name or ticker. Scam tokens impersonating legitimate projects are common. Verify the contract address through the project's official website or a trusted token list. A wrong address means you buy a worthless token with no recourse.

Put this lesson to work

Free on Thrive, no account needed.