Loading live crypto data...
Education15 min read

Inside a DEX Swap: AMMs, Slippage, MEV, and Why Your Price Moves

You click swap on Uniswap, expecting to get 2,500 USDC for your 1 ETH. But you only get 2,480. What happened? Let's break down exactly what goes on under the hood when you swap on a DEX.

TLDR

  • DEXs use Automated Market Makers (AMMs) with liquidity pools instead of order books
  • Slippage happens because your trade changes the pool's price, and other trades might execute first
  • MEV bots can front-run, back-run, or sandwich your trades to extract value
  • Price impact depends on trade size relative to pool size - bigger trades = worse prices
  • Understanding these mechanics helps you get better prices and avoid MEV

By William S. · Published November 16, 2025

The Basics: How DEXs Are Different

Traditional exchanges (like Coinbase) use order books. Buyers and sellers post orders, and trades happen when orders match. Simple.

DEXs are different. They use Automated Market Makers (AMMs) with liquidity pools. Instead of matching buyers and sellers, you trade against a pool of tokens. The pool's price changes based on supply and demand.

This is why prices move when you swap. You're not just taking the current price - you're changing it by trading against the pool.

How AMMs Work: The Constant Product Formula

Most DEXs (Uniswap V2, SushiSwap) use the constant product formula: x * y = k

This means: the amount of token X times the amount of token Y always equals a constant (k). When you trade, the pool adjusts to maintain this constant.

Example: A pool has 1,000 ETH and 2,500,000 USDC. k = 2,500,000,000.

You want to swap 1 ETH for USDC. The pool calculates: after removing 1 ETH, it needs to maintain k. So it gives you USDC, and the new pool balance maintains x * y = k.

The formula determines exactly how much USDC you get. Larger trades get worse prices because they move the pool more.

Why Prices Change

When you swap ETH for USDC:

  1. You add ETH to the pool (ETH supply increases)
  2. You remove USDC from the pool (USDC supply decreases)
  3. The pool's ETH/USDC ratio changes
  4. The new ratio becomes the new price

This is why bigger trades get worse prices. A 1 ETH trade might move the price 0.1%. A 100 ETH trade might move it 10%. The pool charges you for moving the price.

Slippage: Why You Don't Get the Price You See

Slippage is the difference between the expected price and the actual execution price. It happens for several reasons:

1. Price Impact

Your trade itself moves the price. If the pool shows "1 ETH = 2,500 USDC" but you're swapping 10 ETH, you'll get less than 25,000 USDC because your trade moves the price.

How to minimize: Use larger pools, split large trades, or use limit orders (if available).

2. Other Trades Execute First

Between when you submit your transaction and when it executes, other trades might happen first. If someone buys ETH before you, the price goes up, and you get a worse price.

This is why DEXs let you set a slippage tolerance. If the price moves too much, your trade fails instead of executing at a bad price.

3. MEV Extraction

MEV (Maximal Extractable Value) bots can see your transaction in the mempool and front-run it. They buy before you (pushing price up), then your trade executes at the higher price, then they sell (back-running) to profit.

This is called a "sandwich attack" and it makes your price worse.

MEV: The Hidden Cost

MEV stands for Maximal Extractable Value. It's profit that can be extracted by reordering, inserting, or censoring transactions. In practice, it means bots profit from your trades.

Types of MEV

Front-Running

A bot sees your large buy order in the mempool, submits their own buy with higher gas to execute first, pushes the price up, then your trade executes at the higher price. The bot profits.

Back-Running

A bot sees your trade will move the price, waits for it to execute, then immediately trades in the same direction to capture the price movement.

Sandwich Attacks

A bot front-runs your trade (buying before you), lets your trade execute (at worse price), then back-runs (selling after you). They profit from both sides.

Arbitrage

Bots find price differences between DEXs and profit by buying low on one, selling high on another. This is legitimate and helps keep prices aligned.

How MEV Affects You

MEV extraction makes your trades worse. You pay more for buys, get less for sells. Estimates suggest MEV costs traders billions annually.

How to reduce MEV:

  • Use private transaction pools (Flashbots, private RPCs)
  • Split large trades into smaller ones
  • Use DEXs with MEV protection
  • Set lower slippage tolerance (trades fail instead of executing at bad prices)

The Complete Swap Process

Here's what actually happens when you swap:

Step 1: You Initiate the Swap

You're on Uniswap, want to swap 1 ETH for USDC. You see the estimated price: 2,500 USDC. You click swap.

Step 2: Your Wallet Creates a Transaction

Your wallet (MetaMask) creates a transaction that calls Uniswap's router contract. The transaction includes:

  • Amount in: 1 ETH
  • Amount out (minimum): 2,475 USDC (with 1% slippage tolerance)
  • Deadline: transaction must execute within 20 minutes
  • Gas price: how much you're willing to pay

Step 3: Transaction Enters Mempool

Your transaction is broadcast to the network and enters the mempool (pending transactions). MEV bots can see it here.

If your trade is large or profitable to front-run, bots might submit their own transactions with higher gas to execute first.

Step 4: Block Production

A validator (or miner, on PoW) selects transactions from the mempool to include in the next block. They usually prioritize higher gas fees.

If a bot front-ran you, their transaction executes first, then yours, then their back-run.

Step 5: Execution

Your transaction executes. The Uniswap router:

  1. Checks current pool reserves
  2. Calculates output using AMM formula
  3. Checks if output meets your minimum (slippage check)
  4. Transfers your ETH to the pool
  5. Transfers USDC from the pool to you
  6. Updates pool reserves

Step 6: Price Update

After your trade, the pool's price is updated. The next trade will use this new price. If you got 2,480 USDC instead of 2,500, it's because the pool's price moved (from other trades, MEV, or your own trade's impact).

Understanding Price Impact

Price impact is how much your trade moves the pool's price. It depends on:

Trade Size vs Pool Size

The bigger your trade relative to the pool, the more price impact. A 1 ETH trade in a 10,000 ETH pool has minimal impact. A 1 ETH trade in a 10 ETH pool has huge impact.

Rule of thumb: Keep trades under 1% of pool size for minimal impact.

Pool Depth

Deeper pools (more liquidity) have less price impact. This is why major pairs (ETH/USDC) have better prices than obscure pairs.

Multiple Pools

Some DEXs (Uniswap V3) have multiple pools for the same pair with different fee tiers. Higher fee pools often have more liquidity and better prices for large trades.

How to Get Better Prices

1. Use Larger Pools

Trade on pools with more liquidity. Major pairs on major DEXs usually have the best prices.

2. Split Large Trades

Instead of one 10 ETH trade, do ten 1 ETH trades. Reduces price impact and MEV exposure.

3. Use Aggregators

Aggregators (1inch, Matcha, Paraswap) split your trade across multiple DEXs to get better prices. They find the best routes automatically.

4. Set Appropriate Slippage

Don't set slippage too high (you'll accept bad prices) or too low (trades will fail). For stable pairs, 0.1-0.5% is usually fine. For volatile pairs, 1-3% might be needed.

5. Use Private Pools

Private transaction pools (Flashbots) hide your transaction from MEV bots until it's included in a block. Reduces front-running.

6. Time Your Trades

Trade during low activity periods to reduce competition from other traders. But this isn't always practical.

Advanced: Uniswap V3 vs V2

Uniswap V2 uses the constant product formula across the entire price range. Simple but capital inefficient.

Uniswap V3 lets liquidity providers concentrate liquidity in specific price ranges. This means:

  • Better prices (more liquidity where it matters)
  • More complex (LPs need to manage positions)
  • Potential for worse prices if liquidity runs out

For traders, V3 usually offers better prices, but V2 is simpler and more predictable.

Common Mistakes

  • Setting slippage too high: Accepts bad prices to ensure execution
  • Large trades in small pools: Massive price impact
  • Not checking multiple DEXs: Prices vary, aggregators help
  • Ignoring gas costs: Small trades might cost more in gas than savings
  • Trading during high volatility: Prices move fast, slippage increases

Final Thoughts

DEX swaps are more complex than they appear. Understanding AMMs, slippage, and MEV helps you get better prices and avoid getting rekt.

The key takeaways: bigger trades get worse prices, MEV bots extract value from your trades, and pool size matters. Use aggregators, set appropriate slippage, and understand that the price you see isn't always the price you get.

DEXs are powerful - permissionless, global, transparent. But they're not magic. Prices move, bots profit, and you need to understand the mechanics to use them effectively.

Frequently Asked Questions

Why did I get less tokens than expected?

Likely due to slippage: price moved between when you saw the quote and when your trade executed, or your trade itself moved the price. Check your slippage tolerance and trade size relative to pool size.

What's a good slippage tolerance?

For stablecoin pairs: 0.1-0.5%. For volatile pairs: 1-3%. For very volatile or illiquid pairs: 5%+. Start low and increase if trades fail. Don't set it too high or you'll accept bad prices.

Can I avoid MEV?

Partially. Use private transaction pools (Flashbots), split large trades, use DEXs with MEV protection. But MEV is inherent to public mempools - complete avoidance is difficult.

Why do prices differ between DEXs?

Each DEX has separate liquidity pools. Prices align through arbitrage, but temporary differences exist. Use aggregators to find the best price across DEXs automatically.

Should I use Uniswap V2 or V3?

V3 usually offers better prices due to concentrated liquidity, but V2 is simpler and more predictable. For most traders, V3 is better. Use aggregators to automatically find the best option.

How does pool size affect my trade?

Larger pools have less price impact. A 1 ETH trade in a 10,000 ETH pool moves price minimally. The same trade in a 10 ETH pool moves price significantly. Always check pool size before large trades.

By William S. · Published November 16, 2025

William was among the first to recognize Bitcoin's potential in its earliest days. That early conviction has grown into over a decade of hands-on experience with smart contracts, DeFi protocols, and blockchain technology. Today, he writes plain-English guides to help others navigate crypto safely and confidently.

Educational content only. This is not financial, legal, or tax advice.

Questions or corrections? Contact [email protected].

Join the Discussion

Have questions or thoughts? Share them below. All comments are moderated to prevent spam. Read our comment policy.