Decentralized Exchange

A decentralized exchange (DEX) is a marketplace for trading tokens that runs on-chain, without a central operator holding custody of user funds. Trades settle directly between the user’s wallet and a smart contract.

A centralized exchange (CEX) like Coinbase or Binance takes deposits into its own custody, matches orders on an order book it operates, and pays out on request. A DEX replaces all three with smart contracts, and the tokens stay in the trader’s wallet until the block that executes the swap. There is no account to create, no KYC gate, and no withdrawal queue, because there is nothing on deposit to withdraw.

DEX architectures#

Three main designs have emerged, each with different trade-offs around latency, gas cost, and liquidity depth.

AMM-based DEXs#

Automated market makers replaced order books with liquidity pools – smart contracts that hold reserves of two or more tokens and price trades using a deterministic formula. Traders swap against the pool rather than matching with a counterparty.

Uniswap popularized this model. Other notable AMM DEXs include Curve (optimized for stablecoin and like-kind swaps) and Balancer (multi-asset pools with custom weightings).

AMMs are simple and permissionless, but they impose slippage on large trades and expose liquidity providers to impermanent loss.

Order-book DEXs#

Some DEXs preserve the familiar order-book model but move settlement on-chain. In practice, most hybrid designs keep the order book off-chain for speed and only settle matched trades on-chain. dYdX and Loopring take this approach.

Pure on-chain order books exist but are expensive in gas and slow on L1 chains. They work better on high-throughput L2s or app-specific chains.

Intent-based DEXs#

A newer category where users sign an intent (“I want to sell 1 ETH for at least 2,500 USDC”) and off-chain solvers compete to fill it at the best price. UniswapX and CoW Swap are leading examples. This model can tap both on-chain and off-chain liquidity and can protect users from MEV extraction.

Properties that follow from the design#

Self-custody. Tokens move from the trader’s wallet into the pool and back in one transaction. An exchange hack, insolvency, or withdrawal freeze cannot strand them, because the exchange never held them.

Permissionlessness. Anyone can list a token by creating a liquidity pool, and anyone can trade it. There is no listing committee.

Composability. Because DEXs are smart contracts, other protocols can build on top of them – aggregators, yield farming strategies, and automated portfolio managers all compose with DEX liquidity.

Censorship resistance. No single operator can block an address or delist a token (though frontends can impose restrictions, the contracts remain accessible).

Trade-offs#

  • Liquidity depth. CEXs still dominate in raw liquidity for major pairs. DEXs rely on incentivized liquidity provision, which can dry up when rewards end.
  • Execution speed. On-chain settlement means trades are limited by block times. L2 DEXs largely close this gap.
  • Gas costs. Every swap is a transaction. On Ethereum L1 a swap costs dollars at ordinary gas prices and far more during congestion; L2s and alt-L1s bring it down to cents.
  • UX complexity. Managing wallets, signing transactions, and setting slippage tolerances is still harder than clicking “Buy” on a CEX.
  • MEV exposure. Public mempools let searchers front-run or sandwich trades. Intent-based DEXs and private mempools are the main mitigations.

DEX vs. CEX comparison#

DEX CEX
Custody User retains control Exchange holds funds
Listing Permissionless Curated by exchange
KYC Not required at contract level Typically required
Settlement On-chain, final Internal ledger, then on-chain withdrawal
Liquidity Pool-based or solver-based Order book with market makers
Regulatory risk Contract is immutable; frontends can be restricted Subject to jurisdiction-level regulation