
A decentralized exchange lets users swap tokens through on-chain protocols. Learn how liquidity pools, AMM formulas, slippage and fees affect execution.
In brief
- A decentralized exchange (DEX) allows token trading through smart contracts instead of a traditional centralized order book operator.
- An automated market maker (AMM) calculates swap amounts using pool balances, liquidity and pricing rules.
- A quoted swap price can differ from execution because of price impact, slippage, fees and transaction ordering.
What happens on a decentralized exchange
A decentralized exchange, usually called a DEX, is a service for exchanging crypto assets using blockchain-based protocols.
Instead of requiring users to place assets in a centralized trading account, many DEX designs let them interact with smart contracts through a compatible wallet.
The contracts apply rules for exchanging tokens and settling transactions.
A website can provide the interface, but the underlying swap may be executed by contracts independently of that website.
Different DEX designs have different custody and operational arrangements.
DEX trading is not necessarily anonymous, free, or instant.
Public blockchains can record the wallet addresses, token movements and transaction details involved.
Users also pay network transaction fees according to the chain's rules, and execution depends on whether the transaction is included and succeeds.
A wallet confirmation authorizes an operation but does not guarantee a chosen price if market conditions change before settlement.
DEXs can also use routing services and other contracts to find available liquidity.
There are several kinds of decentralized trading venues.
Some use on-chain order books, some rely on off-chain order matching with on-chain settlement, and many use automated market makers, or AMMs.
The term DEX describes the broader trading arrangement; AMM describes one way of determining exchange amounts.
These concepts should not be treated as synonyms.
A single interface may route a user's order through several liquidity pools or protocols to obtain a quoted exchange amount.
How liquidity pools quote a swap
In a basic AMM, liquidity providers supply tokens to a shared pool.
Traders swap against these reserves rather than directly matching a particular buyer and seller at every moment.
The smart contract uses a defined rule to calculate how much of one token a trader receives for another.
A widely used simple model is the constant-product rule, often written x times y equals k.
Here x and y are the two token reserves, and k is the product the mechanism seeks to preserve before accounting for fees.
Suppose a pool contains equal dollar values of two assets at its starting market ratio.
When someone sends token A into the pool to receive token B, the reserve of A increases while the reserve of B decreases.
The pool's implied exchange rate changes as a result.
A larger swap shifts that ratio more than a smaller swap relative to the same reserves.
This is why a pool does not offer unlimited quantities at one fixed price, even when a swap quote displays a single headline rate.
AMMs also exist with pricing rules other than the simple constant-product formula.
Stablecoin-focused pools may use curves designed for assets expected to trade near a similar value.
Concentrated-liquidity models let providers place capital within selected price ranges rather than spread it uniformly across every possible price.
These designs change how depth, fees and liquidity respond to trading.
No single formula describes all DEX pools, and identical token pairs can have different execution quality across different venues.
Why execution prices move
Price impact is the change in the pool's implied price caused by the swap itself.
It typically becomes larger when the trade is large relative to available liquidity.
Slippage refers to a difference between an expected or quoted execution outcome and the amount actually received.
Price impact can be reflected in a quote in advance, while additional slippage may arise when other transactions move the pool before execution.
Interfaces often show a minimum amount to receive based on a specified tolerance.
Network transaction ordering can matter because swaps are submitted to a public or otherwise shared execution environment.
Other transactions may reach the pool before an intended trade.
Automated traders may also exploit opportunities between pools or markets, and some strategies can extract value from transaction ordering.
Arbitrage can help prices across venues converge, but it does not ensure every user receives the same price or eliminate adverse execution.
The precise risks depend on the blockchain and the protocol's design.
A swap fee is another part of the cost.
It may compensate liquidity providers, support protocol operations, or be split according to the pool's rules.
Network gas fees are separate and can be owed even when a submitted transaction fails, depending on the chain.
A quoted exchange rate and an effective all-in transaction cost are therefore different quantities.
Routing through multiple pools can further change the amount received because each hop can add fees and price impact.
What DEXs do and do not guarantee
Liquidity providers enable swaps by placing assets at risk in the pool.
Their returns may include a share of trading fees, but the value of their position can change with market prices and the pool's rebalancing mechanics.
A provider can experience impermanent loss relative to simply holding the assets, and can also face smart contract or token-related risks.
Thus, a DEX's trading liquidity is not costless infrastructure.
It is supplied by participants who bear financial and technical exposure.
Smart contracts reduce certain dependencies on centralized intermediaries, but they do not remove all trust assumptions.
Vulnerabilities, malicious token behavior, compromised interfaces, admin permissions and oracle dependencies can still create problems.
Some platforms also use upgradable contracts or governance-controlled parameters.
A non-custodial trading flow describes who controls the assets before and after the transaction; it does not establish that every component is decentralized to the same degree or immune to failure.
The main idea behind an AMM is that a pool and its pricing rules make a trade possible without finding a specific counterparty for each swap.
A DEX provides the broader route for that on-chain exchange, often through a wallet and smart contracts.
The swap outcome depends on reserves, pool design, fees and transaction conditions.
Understanding these pieces helps explain why a displayed price, the amount actually received and the market's reference price can differ without the blockchain itself making an arithmetic error.