EVMTools

What is a DEX?

Learn what decentralized exchanges are, how AMMs work, DEX vs CEX comparison, liquidity pools, slippage, price impact, and MEV.

A DEX (Decentralized Exchange) is a peer-to-peer marketplace where users can trade cryptocurrency directly from their wallets without an intermediary. Unlike centralized exchanges like Coinbase or Binance, DEXs use smart contracts to facilitate trades automatically. This guide explains how DEXs work, the different types (AMMs, order books, aggregators), major platforms, and important concepts like slippage, price impact, and MEV.

What is a Decentralized Exchange?

A Decentralized Exchange (DEX) is a cryptocurrency exchange that operates without a central authority. Instead of a company matching orders and holding your funds, DEXs use smart contracts deployed on a blockchain to execute trades. The key advantages are:

  • Non-custodial: You maintain control of your assets at all times. Tokens move directly from your wallet to the smart contract and back. No need to deposit funds on an exchange.
  • Permissionless: Anyone can trade without creating an account, providing ID, or waiting for approval. Connect your wallet and trade immediately.
  • Permissionless listing: Anyone can create a trading pair for any ERC-20 token. No listing fees or approval process required.
  • Transparent: All trades, liquidity, and smart contract code are publicly verifiable on the blockchain.
  • Composable: DEXs can be integrated into other DeFi protocols, enabling complex strategies like flash loan arbitrage and automated yield farming.

DEX vs CEX: A Comparison

Understanding the differences between decentralized and centralized exchanges is essential for choosing the right platform:

FeatureCEX (Centralized)DEX (Decentralized)
CustodyExchange holds your fundsYou hold your funds (wallet)
KYC requiredYes (ID verification)No (just connect wallet)
Trading mechanismOrder book matchingAMM or on-chain order book
SpeedInstant (off-chain matching)Block confirmation time (~12s on ETH)
FeesTrading fee (0.1–0.5%)Swap fee (0.01–1%) + gas fee
Available tokensCurated listings (hundreds)Any token with a pool (thousands)
Fiat supportYes (bank transfers, cards)Limited (via on-ramp integrations)
Counterparty riskHigh (exchange can fail, e.g., FTX)Low (smart contract risk only)
PrivacyLow (full identity required)High (pseudonymous, wallet only)

How Automated Market Makers (AMMs) Work

Most DEXs use Automated Market Makers (AMMs) instead of traditional order books. An AMM replaces buyers and sellers with liquidity pools — smart contracts that hold reserves of two tokens and use a mathematical formula to determine the price.

The Constant Product Formula

Uniswap V2 pioneered the constant product formula, the simplest and most widely used AMM model:

x * y = k

Where:
  x = reserve of Token A in the pool
  y = reserve of Token B in the pool
  k = constant product (must remain equal after every trade)

Example: ETH/USDC pool with 100 ETH and 200,000 USDC
  k = 100 * 200,000 = 20,000,000
  Price of 1 ETH = 200,000 / 100 = $2,000

Buying 1 ETH:
  New ETH reserve = 99
  New USDC reserve = 20,000,000 / 99 = 202,020.20
  Cost = 202,020.20 - 200,000 = $2,020.20 per ETH
  Price impact = ($2,020.20 - $2,000) / $2,000 = 1.01%

Buying 10 ETH:
  New ETH reserve = 90
  New USDC reserve = 20,000,000 / 90 = 222,222.22
  Cost = 222,222.22 - 200,000 = $22,222.22 total ($2,222 per ETH)
  Price impact = ($2,222 - $2,000) / $2,000 = 11.1%

This illustrates a critical property of AMMs: larger trades have exponentially more price impact. This is why DEXs work best for pools with deep liquidity.

Concentrated Liquidity (Uniswap V3)

Uniswap V3 introduced concentrated liquidity, allowing liquidity providers to allocate capital to specific price ranges instead of across the entire price spectrum. A liquidity provider who believes ETH will stay between $1,800 and $2,200 can concentrate all their capital in that range, providing up to 4,000x more capital efficiency than V2. However, if the price moves outside the range, the position earns zero fees and suffers maximum impermanent loss.

StableSwap (Curve)

Curve Finance uses a modified AMM formula optimized for tokens that should trade near parity (stablecoins like USDC/USDT/DAI, or pegged assets like stETH/ETH). The StableSwap invariant concentrates liquidity around the 1:1 price, enabling very low slippage for same-peg trades. Swapping $1M USDC to USDT on Curve might cost only 0.01% in slippage, compared to several percent on a constant product AMM.

Types of Decentralized Exchanges

AMM-Based DEXs

The most common type. Liquidity pools with algorithmic pricing replace order books. Examples include:

  • Uniswap: The largest DEX by volume. Pioneered the constant product AMM. Operates on Ethereum, Arbitrum, Polygon, Optimism, and Base.
  • Curve Finance: Optimized for stablecoin and pegged-asset swaps with minimal slippage. Dominates the stablecoin trading market.
  • SushiSwap: Fork of Uniswap with additional features like yield farming and a broader multi-chain presence.
  • Balancer: Supports multi-token pools (up to 8 tokens) with custom weights, enabling portfolio-like liquidity pools.
  • PancakeSwap: The largest DEX on BNB Smart Chain, with lower fees than Ethereum-based DEXs.

Order Book DEXs

These DEXs use traditional order book models but execute on-chain or in a hybrid manner:

  • dYdX: Leading perpetual futures DEX. Uses an off-chain order book with on-chain settlement. Moved to its own Cosmos appchain for better performance.
  • Hyperliquid: High-performance perpetuals exchange running on its own L1 blockchain. Sub-second finality with fully on-chain order book.

DEX Aggregators

Aggregators route trades across multiple DEXs to find the best price. Instead of checking each DEX manually, an aggregator splits your trade across sources for optimal execution:

  • 1inch: The largest DEX aggregator. Routes across 400+ liquidity sources across multiple chains.
  • ParaSwap: Multi-chain aggregator with MEV protection and limit order features.
  • CowSwap: Uses batch auctions and Coincidence of Wants (CoW) to provide MEV protection and potentially better prices.

Slippage, Price Impact, and MEV

Slippage

Slippage is the difference between the quoted price at the time you submit a trade and the actual execution price. It happens because the pool state can change between when you sign the transaction and when it is confirmed on-chain. You set a slippage tolerance (e.g., 0.5%) to define the maximum acceptable price deviation. If the actual price moves beyond your tolerance, the transaction reverts.

Price Impact

Price impact is the effect your trade has on the pool price. It is deterministic and depends on your trade size relative to the pool liquidity. A $1,000 swap in a $100M pool has negligible impact; the same swap in a $10,000 pool would move the price dramatically. DEX interfaces show the expected price impact before you confirm a swap.

MEV (Maximal Extractable Value)

MEV is a significant concern for DEX traders. Because pending transactions are visible in the mempool before confirmation, bots can exploit this information:

  • Sandwich attacks: A bot places a buy order before your trade (frontrunning) and a sell order after (backrunning), profiting from the price movement your trade causes.
  • Frontrunning: A bot sees your profitable trade and submits the same trade with higher gas, taking the profit before you.
  • Just-in-time (JIT) liquidity: LPs add concentrated liquidity right before a large trade and remove it immediately after, capturing fees without long-term capital commitment.

To protect against MEV, use private RPC endpoints (Flashbots Protect, MEV Blocker), aggregators with built-in protection (CowSwap), or keep slippage tolerance low.

Providing Liquidity on a DEX

Anyone can become a liquidity provider (LP) by depositing tokens into a pool. In return, you earn a share of the trading fees proportional to your share of the pool:

Providing Liquidity Example (Uniswap V2):

Deposit: 1 ETH ($2,000) + 2,000 USDC → Total: $4,000
Pool total: 100 ETH + 200,000 USDC = $400,000
Your share: 1%

Fee tier: 0.3% of every swap goes to LPs
Daily volume: $2,000,000
Daily fees: $2,000,000 * 0.3% = $6,000
Your daily earnings: $6,000 * 1% = $60

Annual yield (if volume stays constant):
$60 * 365 = $21,900 on $4,000 = 547.5% APR

BUT: You must also account for impermanent loss
If ETH doubles to $4,000:
  Impermanent loss ≈ 5.7% of position value
  = $4,000 * 1.057 * 5.7% ≈ $240 loss
  Fees must exceed this to be profitable

Warning: Providing liquidity carries risk. You are exposed to impermanent loss when token prices diverge. The trading fees you earn may or may not offset the impermanent loss. Start with stablecoin pairs (USDC/USDT) to minimize risk while learning.

How to Swap Tokens Safely on a DEX

  1. Verify the token contract: Always check the token's contract address on Etherscan or the project's official website. Scam tokens with similar names are extremely common.
  2. Check liquidity: Ensure the pool has sufficient liquidity. Low liquidity means high price impact and potential manipulation.
  3. Review the price impact: The DEX UI shows expected price impact. If it exceeds 1–2% for a major token, the pool may have insufficient liquidity.
  4. Set appropriate slippage: Use 0.5% for major tokens, 1–3% for smaller tokens. Never use extremely high slippage (10%+) unless you understand why.
  5. Use an aggregator: Route through 1inch or CowSwap for better prices across multiple DEXs.
  6. Consider MEV protection: Use Flashbots Protect RPC or CowSwap to avoid sandwich attacks.

Frequently Asked Questions

Is it safe to use a DEX?

Established DEXs like Uniswap, Curve, and SushiSwap have been battle-tested with billions of dollars and are generally considered safe. However, risks include interacting with malicious tokens (scam tokens, honeypots), setting slippage too high, and MEV attacks (sandwich attacks). Always verify token contract addresses, use reasonable slippage settings, and consider using MEV-protected RPC endpoints.

Why are DEX prices sometimes different from centralized exchanges?

DEX prices are determined by the ratio of tokens in liquidity pools, not by a central order book. Price differences (arbitrage opportunities) naturally occur but are quickly corrected by arbitrage bots. For large-cap tokens, the difference is usually less than 0.1%. For smaller tokens, differences can be larger due to lower liquidity.

What is slippage and how do I set it?

Slippage is the difference between the expected price and the actual execution price. For major tokens (ETH, USDC), 0.5% is usually sufficient. For smaller tokens with less liquidity, you may need 1–3%. Setting slippage too low causes transactions to fail; setting it too high makes you vulnerable to sandwich attacks.

What is impermanent loss for liquidity providers?

Impermanent loss occurs when you provide liquidity to an AMM pool and the price ratio of the tokens changes. The pool rebalances automatically, selling the appreciating token and buying the depreciating one. The loss is "impermanent" because it reverses if prices return to the original ratio. Trading fees can offset the loss, but for volatile pairs, it can be significant.

Should I use a DEX or a centralized exchange?

It depends on your needs. Use a DEX for tokens not listed on centralized exchanges, to maintain self-custody, or to interact with DeFi. Use a CEX for fiat on/off ramps, lower fees on high-volume trades, advanced order types, or simpler UX. Many users use both depending on the situation.

Explore DEX Tools

Analyze DEX transactions with our developer tools. Use the Calldata Decoder to inspect swap transaction data, the Gas Fee Calculator to estimate swap costs, or learn how to read DEX transactions on Etherscan.

Related Guides