Small glass and gold pavilions joined by bridges of light, floating among clouds under the moon (AI-generated image)
AIAI-generated image

Decentralized exchanges explained: DEX vs CEX and the AMM model

How a decentralized exchange settles trades without holding deposits, how it compares with a centralized exchange, and why the automated market maker became the common model for on-chain trading.

Omega.one editorsEdition: October 29, 202611 min read7 sources

In 30 seconds

The DEX vs CEX question comes down to who holds the assets: a decentralized exchange lets traders swap tokens through smart contracts straight from their own wallets, while a centralized exchange (CEX) takes custody and matches orders on its own servers. Much on-chain trading runs through an automated market maker (AMM), which prices each trade from pool reserves instead of an order book.

What is a decentralized exchange?

A decentralized exchange is a set of smart contracts on a public blockchain that lets two parties trade tokens without handing them to an intermediary. The trader connects a self-custody wallet, signs a transaction, and the contract moves both sides of the trade in one step. If any part of that step fails, the whole transaction reverts and nothing changes hands.

A few properties separate a DEX from the venues most people know. Self-custody: assets stay in the user's wallet until the moment of the swap, so there is no exchange balance to freeze or lose (see custody). On-chain settlement: the trade is recorded in a block, visible to anyone, and final once that block is confirmed. Open access: the contract does not ask who is calling it, so most DEXs run without account sign-up or identity checks.

The trade-off is that every action costs a network fee (gas), every pending order is public before it executes, and mistakes cannot be reversed by a support desk. Its rules are whatever the deployed code says. How deep a DEX is depends on the capital in its pools, the subject of the guide to crypto liquidity.

DEX vs CEX: custody, fees and failure modes

A centralized exchange works like a single tower. One company holds client deposits, runs the matching engine, sets listing rules and checks identity under KYC obligations. Trades between its users are entries in its internal database, so they are fast and cost no gas. Only deposits and withdrawals touch the blockchain.

A decentralized exchange looks more like a ring of small pavilions joined by paths. No company holds the pooled assets on the users' behalf; the contracts do, under rules anyone can read. Listing is usually permissionless, which means anyone can create a market for any token, including worthless or fraudulent ones.

The failure modes differ as much as the designs. A CEX can fail as an institution. Mt. Gox halted and collapsed in February 2014, and FTX filed for Chapter 11 in November 2022; in both cases customers who had left assets on the platform became creditors. A DEX can fail as code: a bug in a contract, a malicious token, or a user who signs the wrong approval. In DEX vs CEX terms, the choice swaps counterparty risk for technical risk, and neither column is empty.

One tall gold tower on the left and a ring of small lit pavilions on the right, both on clouds (AI-generated image)
AIAI-generated image
DEX vs CEX at a glance (general patterns; individual venues vary)
FeatureCentralized exchange (CEX)Decentralized exchange (DEX)
CustodyThe exchange holds deposits in its own walletsUsers keep assets in self-custody wallets until the swap
Identity checksKYC at account opening is standard for regulated venuesContracts ask for no identity; front ends may restrict access
ListingThe company decides which assets tradeAnyone can usually create a pool for any token
FeesTrading fees; no gas for internal tradesPool or protocol fee plus a network gas fee per transaction
SpeedMatching in milliseconds on private serversBound by block times and network congestion
Typical failureInsolvency, hot-wallet hacks, frozen withdrawalsContract bugs, malicious tokens, front-running, bad approvals
RecourseBankruptcy claims, regulators, a support deskUsually none once a transaction is confirmed

From EtherDelta to Uniswap: three DEX generations

Early DEX designs copied the order book of a traditional exchange and moved parts of it on-chain. EtherDelta, launched in July 2016, kept its order book off-chain and settled matched trades in ERC-20 tokens through an Ethereum smart contract. In November 2018 the SEC settled with its founder for operating an unregistered exchange, the agency's first enforcement action against a crypto trading platform on that basis.

The 0x protocol whitepaper, published in February 2017, generalized the hybrid idea. Makers signed orders off-chain and passed them to relayers, independent services that hosted and shared order books. Settlement happened in 0x's contracts, so any relayer could use the same settlement layer. Many token markets of the 2017 ICO era used designs like these.

The third generation dropped the order book entirely. Uniswap launched on Ethereum mainnet in November 2018 with pools that quote a price from a formula rather than from resting orders. That idea, the automated market maker, became the template for many later decentralized exchange designs. The wider sequence is set out on the market structure timeline.

How the AMM model prices a trade

A constant-product AMM holds two tokens in a pool and enforces one rule: the reserves multiplied together must not fall after a trade. Written conceptually, x · y = k, where x and y are the two reserves and k is the constant. The quoted price is the ratio of the reserves.

Take an illustrative pool with 100 ETH and 200,000 USDC, so k is 20,000,000 and the implied price is 2,000 USDC per ETH. A trader who wants 10 ETH out must leave 90 ETH in the pool, so the USDC side has to rise to 20,000,000 ÷ 90, about 222,222. The trader pays about 22,222 USDC, an average of roughly 2,222 per ETH. The gap between 2,000 and 2,222 is price impact: the larger the order relative to the pool, the further the price moves.

No one quotes that price. The curve does, which is why an AMM can offer a market in almost any pair at any hour. It also means small pools produce large moves, a point worked through with numbers in the slippage calculator.

A brass balance holding two glass flasks, one of gold liquid and one of violet, above the clouds (AI-generated image)
AIAI-generated image

Order-book DEXs versus AMM liquidity pools

An order-book DEX works like a conventional market: traders post limit orders at chosen prices and a matching process pairs them. On a busy chain that is expensive, because every posted, changed or canceled order can cost gas. Most order-book designs therefore keep the book off-chain or run on networks with cheap, fast blocks.

An AMM replaces quoting traders with a liquidity pool. Liquidity providers (LPs) deposit both tokens in the pool's current ratio and receive a share of the trading fees. They do not choose a price. Arbitrageurs do that for them, buying from the pool when its price is below other venues and selling into it when it is above, until the gap closes.

That arrangement has a cost for LPs. When the market price moves, the pool ends up holding more of the token that fell and less of the one that rose. Compared with simply holding both tokens, the LP position is worth less, a gap known as impermanent loss. The job LPs do is close to what professional market makers do on order books, with the pricing handed to a formula.

A DEX swap, wallet to settlement

  1. Connect walletThe trader links a self-custody wallet to a front end.
  2. Approve tokenAn approval lets the router contract spend the token.
  3. Get a quoteThe router reads pool reserves and estimates the output.
  4. Sign the swapThe trader sets slippage tolerance and signs the transaction.
  5. Mempool waitThe pending transaction is public until a block includes it.
  6. Settle on-chainThe contract swaps both sides atomically or reverts entirely.
One swap on an AMM-based decentralized exchange, from signature to final block.

MEV, front-running and sandwich attacks on a DEX

Because a DEX trade waits in public before it executes, others can act on it. Maximal extractable value (MEV) is the profit a block producer, or a bot paying one, can capture by choosing which transactions go into a block and in what order.

The best-known form aimed at swappers is the sandwich. A bot sees a large pending buy, places its own buy just ahead of it, lets the victim's trade push the price up, then sells straight after. In an illustrative case, a trader who expects 1,000 tokens with a 2% slippage tolerance may receive close to 980, with most of the difference taken by the bot. The trade still succeeds, only at a worse price. Plain front-running is simpler: copying a profitable pending trade and paying more gas to land first.

Defenses are partial. A tight slippage tolerance limits how much a sandwich can take but makes failed transactions more likely. Some wallets send transactions through private channels that skip the public mempool. None of these remove MEV from the system; they change who captures it.

What DEX aggregators do

Liquidity for the same pair is often spread over several pools and protocols, each with its own curve and fee. A DEX aggregator is a routing layer that queries many of them and splits one order across several paths to return more output than any single pool would. It is the on-chain cousin of a smart order router in traditional markets.

Suppose, in an illustrative case, a trader wants to sell 50 ETH. One pool alone would move its price sharply, so the aggregator might send 30 ETH through a large pool, 15 through a second, and 5 through a route that hops through a stablecoin. Each extra hop costs gas, so on expensive networks splitting a small order can cost more than it saves.

Aggregators add another contract, and another approval, between the user and the pools. The quoted output is an estimate from reserves at the moment of the quote, not a guarantee.

Risks of using a decentralized exchange

  • Smart-contract bugs. A flaw in a pool, router or bridge contract can let an attacker drain funds. Audits reduce the chance but do not remove it.
  • Rug pulls. Permissionless listing lets anyone create a token and a pool, attract buyers, then withdraw the liquidity or use a hidden mint function.
  • Impermanent loss. LPs carry price risk that trading fees may not cover.
  • Phishing approvals. Many losses come from signing a malicious approval on a fake front end, which lets a contract move a token out of the wallet later. An approval can stay valid long after the user has forgotten it.
  • Irreversibility. A swap into the wrong token, or with a loose slippage setting, settles exactly as signed.

Where regulation touches DEXs

A decentralized exchange is not outside securities and market rules just because its settlement is on-chain. The SEC's November 2018 order against EtherDelta's founder treated the platform as an exchange that should have registered, and the person who ran the website and order book was the one held responsible.

Regulatory attention generally goes to the parts of a DEX that look like a business, such as front-end operators and developers who keep control of upgrades. How regimes such as New York's BitLicense, the EU's MiCA and the US market structure proposals treat trading venues is compared on the crypto exchange license page. This guide describes structures and history only and is not legal advice.

Short answers

Decentralized exchange FAQ

What is a decentralized exchange in simple terms?

A decentralized exchange is a set of smart contracts that lets people trade tokens straight from their own wallets. No company holds deposits or matches orders on a private server. The trader signs a transaction, the contract swaps both tokens in one step, and the result is recorded on the blockchain. If the swap cannot complete as signed, it reverts and nothing moves.

What is the main difference in DEX vs CEX trading?

The main difference in DEX vs CEX trading is custody. A centralized exchange holds customer deposits and settles trades in its own database, which is fast and gas-free but exposes users to the exchange failing, as at Mt. Gox in 2014 and FTX in 2022. A decentralized exchange leaves assets in self-custody wallets and settles on-chain, which removes that counterparty but adds smart-contract and user-error risk.

How does an AMM set the price of a token?

An automated market maker sets the price from the ratio of the two token reserves in its pool. In a constant-product AMM the reserves multiplied together must not fall, written x · y = k. Buying one token removes it from the pool and adds the other, so the price moves against the buyer. Larger trades relative to the size of the pool move the price further.

Is a decentralized exchange safer than a centralized exchange?

A decentralized exchange carries different risks from a centralized exchange rather than simply fewer. A DEX removes the risk of an operator losing or freezing customer deposits, because users keep their own keys. It adds exposure to contract bugs, malicious tokens, front-running and phishing approvals, and confirmed transactions usually cannot be reversed. Which risks matter more depends on the asset and on how the trader handles keys and approvals.

What is a sandwich attack on a DEX?

A sandwich attack is a form of MEV in which a bot spots a large pending swap on a DEX, buys the same token just before it and sells just after it. The victim's trade executes at a worse price within its slippage tolerance, and the bot keeps most of the difference. Tighter slippage settings and private transaction routing reduce the exposure but do not remove it.

What does a DEX aggregator do?

A DEX aggregator searches many liquidity pools and protocols for the same trading pair and splits an order across the routes that return the most tokens after fees and gas. It works much like a smart order router in traditional markets. The quoted result is an estimate based on current pool reserves, and the aggregator adds its own contract and approval to the path of the trade.

Try it

Tools and games, no sign-up

All of them run in the browser and send nothing anywhere. The numbers are illustrative, never live prices.

Slippage calculatorPrice impact, worked outSet an order size and a pool depth and see the price impact, the average fill and what the impact costs.Open it
Midpoint simulatorLit book or dark poolSend a block into an illustrative order book and compare the fill with a cross at the midpoint.Open it
Fill the blockRoute one big orderSplit a bitcoin block across four venues, send it and score the fill against the best mix.Open it
Daily puzzleTwo puzzles a dayGuess a market structure term from five clues, then sort sixteen words into four groups.Open it