Decentralized exchange DEX: the essential five-minute primer
: the essential five-minute primer…

A Uniswap swap on Ethereum Mainnet consumes 184,523 gas units before the protocol's 0.30% fee enters the calculation. A DEX trade exposes the user to three variable cost layers — protocol fee, network gas, and price impact — and offers zero custodial recourse once the transaction is mined. The data indicates that "decentralized exchange" is a category, not a product. The architecture defines the cost stack, the risk profile, and the operational responsibility.
This is the minimal framework required before interacting with one.
Beyond the order book: how onchain trading systems function
A DEX has no central counterparty holding user balances. Trades execute against smart contracts on a public blockchain. The user signs the transaction from a self-custodial wallet; settlement and custody remain with the user until the swap completes onchain. Settlement is asynchronous — the transaction enters the mempool, is selected by a builder, included in a block, and only then is the swap final. That lag is part of the cost stack even if it is rarely priced in.
The architecture is distributed across separate components:
- The protocol: the onchain smart contracts that define pools, fees, and routing.
- The interface: the web front end or aggregator that builds transactions; the interface is not the protocol.
- The wallet: the user's signing tool; the wallet is neither the protocol nor the interface.
The distinction matters. A compromised interface does not necessarily compromise the underlying contracts, but a user who signs a malicious transaction from a compromised interface can drain their own wallet. Self-custody moves the security burden onto the user.
The most deployed DEX architecture is the automated market maker (AMM). Uniswap is the benchmark implementation. The U.S. Federal Trade Commission has stated explicitly that after cryptocurrency is sent to the wrong address or a compromised wallet, there may be no party able to recover the funds. That is the operational baseline.
The structural differences between a centralized exchange and a DEX are direct:
| Parameter | Centralized exchange (CEX) | Decentralized exchange (DEX) |
|---|---|---|
| Custody of funds | Exchange holds user balances | User retains custody via wallet |
| Trade execution | Internal order book | Smart contract / pooled liquidity |
| KYC requirement | Standard | Typically none |
| Settlement reversibility | Operator can reverse or freeze | Final once mined onchain |
| Single point of failure | Custodial database | Smart-contract or interface risk |
| Listing process | Operator decision | Permissionless pool creation |
The trade-off is direct: removing the custodian removes the recourse.
The mechanics of liquidity pools and constant-product AMMs
The constant-product AMM is the most deployed onchain pricing mechanism. Its core logic is the formula x × y = k. A pool holds reserves of two tokens, x and y; k is the constant. When a trader swaps one token for the other, the reserves shift to keep k unchanged before fees. The new ratio defines the execution price.
The mechanics are deterministic:
- The first liquidity provider seeds both tokens and establishes the initial price. If 10 ETH and 20,000 USDC are deposited, the implied ETH price is 2,000 USDC.
- Subsequent providers must deposit in proportion to the current reserves. Depositing off-ratio creates an arbitrage opportunity that trades against the new provider's deposit until the ratio is restored.
- A trade that is large relative to pool depth produces greater price impact than a smaller trade. Slippage is a function of trade size over pool size, not a transaction fee.
The shape of the curve is what makes these dynamics non-linear. A constant-product pool does not quote a flat price band; the marginal price worsens continuously as reserves shift. A trade that moves the pool 1% consumes a fraction of depth; a trade that moves the pool 10% costs far more than ten times the depth of the 1% trade. That convexity is the source of slippage, and it is why order size dominates execution quality for thinly-traded pools. External prices converge toward the pool's internal price through arbitrageurs — when the wider market moves and the pool does not, an arbitrageur closes the gap by trading against whichever side is mispriced.
x × y = k. The constant is the contract. The price is the ratio.
Navigating fee structures and the cost of onchain execution
Onchain execution costs are layered, not single. There is no universal "DEX fee." A swap on a Uniswap v2 pool charges 0.30% per trade, allocated pro rata to liquidity providers. That figure is protocol-specific. Other protocols charge different rates; some pools charge less.
Fee tiers on Uniswap v3 are documented at 0.05%, 0.30%, and 1%, with additional tiers enabled through UNI governance. Uniswap v4 extends this further: pool creators can set fees from 0% to 100% in increments of 0.0001%, and pools can use dynamic fees through hooks. The protocol's fee schedule is not the trader's total cost.
Onchain, a swap executes only after the user pays gas. Ethereum.org lists a Uniswap swap at 184,523 gas units in its illustrative transaction table. The actual fee paid equals:
total gas cost = gas units × (base fee + priority fee)
When the base fee is 30 gwei and ETH is at $3,000, a 184,523-unit swap costs roughly $16.60 at base fee alone — before priority fee, before the protocol's 0.30%. A $500 swap in a deep pool can pay more in gas than in slippage on a high-fee day. Trading through aggregators adds complexity: each hop through a different pool compounds the gas cost.
The practical consequence is that gas acts as a fixed denominator on trade size. A $16 gas bill is absorbed cleanly on a $10,000 swap and dominates a $100 swap. Liquidity migrates to lower-cost execution environments — Layer 2 rollups, app-chains, alternative L1s — for the same reason. The protocol's headline fee scales linearly with the trade; gas does not.
The actual cost stack for any DEX swap:
1. Protocol fee — varies by pool and version.
2. Price impact — function of trade size relative to pool depth.
3. Network gas — function of base fee × gas units consumed.
4. Priority fee — function of urgency and congestion.
Minimizing one variable is not minimizing the total. The misconception is treating the protocol's headline fee as the final cost.
Liquidity provider dynamics: range-bound fees and impermanent loss
Liquidity providers earn the protocol's swap fees. The terms differ across protocol versions.
On Uniswap v2, every swap charges 0.30%, allocated pro rata to all LPs in the pool. The position is full-range: the LP earns fees regardless of price, but capital is spread across an infinite price band.
On Uniswap v3, LPs select a price range. Fees accumulate only when the market price sits inside the selected range. The position stops earning fees the moment the price exits either side. Range-tightness concentrates capital and increases fee-per-dollar when the price is in range, but the position earns zero when the price is out of range.
Fee tier selection is itself a market call. Tighter ranges and lower fee tiers suit stable pairs where price stays inside a narrow band; wider ranges and higher fee tiers suit volatile pairs where the LP is compensated for deeper impermanent loss exposure. Picking the wrong tier for the regime is the same error as picking the wrong range: fees underperform IL because the parameters assumed a different volatility profile than the one delivered.
The Uniswap documentation defines impermanent loss as the loss in value experienced by a liquidity provider when the prices of pooled tokens change from the prices at which liquidity was deposited. It may become permanent if the price does not return to the entry level before withdrawal.
A practical comparison:
| Parameter | Uniswap v2 LP | Uniswap v3 LP |
|---|---|---|
| Capital efficiency | Low (full range) | High (concentrated) |
| Fee capture | Continuous | Only when in range |
| Impermanent loss exposure | Spread across full range | Magnified within range |
| Management cost | Passive | Active rebalancing |
The data indicates that LPs do not earn "yield." They earn fees — and fees may or may not exceed impermanent loss, depending on the asset pair, the volatility regime, and the duration of the position. A volatile asset that trends sharply against the entry price produces IL larger than the cumulative fees earned. The U.S. Federal Trade Commission has confirmed that guaranteed crypto profits or returns are a scam signal. The same logic applies to the assumption that LP positions are passively profitable.
Fees are earnings. Impermanent loss is a cost. The spread between them is the actual return.
The reality of self-custody and irreversible transaction risks
Self-custody is the operational feature of a DEX. It is also the largest source of user-side risk.
Once a transaction is mined onchain, the funds are settled. A token sent to the wrong address cannot be recalled by an operator. The FTC has stated that there may be no party able to recover the funds after such transfers. This is the baseline, not an edge case.
The non-custodial architecture places the following responsibilities on the user:
- Wallet security — seed phrase storage, device hygiene, phishing exposure.
- Transaction verification — inspecting the contract address, the swap route, the approval limits.
- Token legitimacy — distinguishing a legitimate token from a homoglyph or scam contract.
- Approval hygiene — revoking token allowances that are no longer needed.
Approval hygiene deserves its own framing. Many DEX interfaces request token allowances larger than the trade being made — historically, unlimited approvals were a default pattern. An open allowance is a standing grant to move that token; if the approved contract or interface is later compromised, the allowance can be drained at any moment. Periodic revocation, exact-amount approvals where the interface supports them, and isolation of high-value balances onto a separate wallet are the working defenses.
A DEX interface can be compromised. A phishing clone can replicate a legitimate front end. A malicious token can grant approvals that drain the user's wallet. None of these are protocol-level failures; they are user-execution risks. The protocol's code can be formally verified, and the user can still lose funds by signing the wrong transaction. The non-custodial benefit is the non-custodial liability: the user is the operator.
The bottom line
A DEX is onchain trading infrastructure. Its mechanics are deterministic — a constant-product formula, a fee schedule, a gas cost. Its costs are layered, not single. Its returns to liquidity providers are not guaranteed, and its self-custody model places the operational risk on the user.
The data indicates that a DEX is a tool, not a return. Anyone using one should know the formula, the fee tier, the gas cost, and the irreversibility of settlement before signing the first transaction.