IMPCT Institute

Reading library · DeFi · Intermediate

Understanding DEXs (Decentralized Exchanges)

By Deven Davis · IMPCT Institute · 3 min read

TL;DR

Understanding what a DEX smart contract is actually doing under the hood is the foundation for evaluating every DEX you'll encounter for the rest of your time in crypto.

  • DEXs = crypto trading venues operating as smart contracts. User retains custody throughout. No order book matching engine, no platform-level KYC.
  • Dominant architecture: Automated Market Maker (AMM). Liquidity pool + formula = pricing. Constant-product (x·y=k) is the foundational design.
  • Variations: concentrated liquidity (Uniswap V3), StableSwap (Curve), order book DEXs (dYdX, Hyperliquid), aggregators (1inch, Jupiter, ParaSwap).
  • Structural advantages: self-custody, transparent state, permissionless access, composability with other DeFi operations.
  • Structural disadvantages: gas fees (mitigated by L2s), slippage on illiquid pairs, user responsibility for transaction construction.

Decentralized exchanges (DEXs) are crypto trading venues that operate as smart contracts on a blockchain, allowing users to swap tokens without depositing assets at a centralized intermediary. The user retains custody of their assets throughout the transaction. There is no order book matching engine run by a company. There is no Know Your Customer requirement enforced at the platform level. The smart contract executes the trade, takes a small fee, and returns the resulting tokens to the user's wallet.

This is the architectural picture from Day 10 of the IMPCT course, but the second-pass reading is about what the smart contract is actually doing under the hood. That mental model is what lets you evaluate any new DEX you encounter for the rest of your time in this space.

The dominant DEX architecture is the Automated Market Maker (AMM). Instead of matching specific buy and sell orders (the centralized exchange model), an AMM holds reserves of two or more tokens in a "liquidity pool" and uses a mathematical formula to determine the price for any swap. The most common formula is the constant product formula (x · y = k), used by Uniswap V2 and many other DEXs.

How a swap actually works mechanically: a user submits a transaction to the DEX smart contract specifying which tokens they want to swap and how much. The contract reads the current pool reserves, calculates the swap output using the formula, takes a small fee (typically 0.05% to 0.3%), updates the pool reserves, and sends the output tokens to the user. The entire process is one on-chain transaction. There is no off-chain order matching.

The liquidity provider (LP) is the other side of every swap. Liquidity providers deposit two tokens in equal value into a pool. They earn a share of the trading fees in proportion to their share of the pool. In exchange for the fee income, LPs take on impermanent loss — the price-rebalancing effect that makes LP positions perform worse than just holding the tokens when one asset moves significantly relative to the other.

Several architectural variations exist beyond the basic constant-product AMM:

Concentrated liquidity AMMs (Uniswap V3) let LPs specify a specific price range within which their liquidity is active. This makes capital more efficient for stable pairs but requires active management for volatile pairs.

StableSwap AMMs (Curve) use a different formula optimized for assets that should trade close to 1:1, producing dramatically lower slippage for stablecoin and LST trading.

Order book DEXs (dYdX, Hyperliquid) replicate the centralized exchange order book model on-chain, typically with off-chain order matching for performance, with settlement on-chain. These are more capital-efficient for active trading but harder to architect well.

Aggregators (1inch, Jupiter, ParaSwap) don't have their own liquidity pools — they route user orders across many underlying DEXs to find the best execution. For sophisticated traders, aggregators have become the dominant entry point.

The structural advantages of DEXs over CEXs:

Self-custody throughout. Your assets never leave your wallet to be held by a third party. The FTX failure cannot happen to you on a DEX.

Transparent state. The pool reserves are visible on-chain. The fees are visible on-chain. The trade execution is visible on-chain. There is no opaque order book or hidden inventory management.

Permissionless access. Anyone with a wallet can trade. No account creation, no KYC at the protocol level (though front-ends and aggregators may have their own compliance layers).

Composability. DEX trades can be combined with other DeFi operations in a single transaction — borrowing, lending, leverage, automated strategies. This composability is the structural reason DeFi can do things that traditional finance cannot.

The structural disadvantages:

Gas fees can be high (Ethereum mainnet especially), making small trades uneconomical. L2 and alternative L1 deployment has substantially mitigated this.

Slippage on illiquid pairs can be significant. Aggregator routing helps but doesn't eliminate the issue.

User responsibility for transaction construction. Mistakes (wrong slippage settings, MEV exposure, approving the wrong contract) are the user's loss.

Re-read this with today's lesson in mind. The first time through (Day 10), the focus was on the CEX vs DEX distinction. This time, focus on what the smart contract is actually doing under the hood. That understanding is the foundation for evaluating every new DEX you encounter.

Notes

Re-read this with today's lesson in mind. The first time through (Day 10), the focus was on the CEX vs DEX distinction. This time, focus on what the smart contract is actually doing under the hood. That mental model is what lets you evaluate any new DEX you encounter for the rest of your time in this space.

Frequently asked

Quick answers to what readers ask next

What's the difference between a DEX and a CEX?

A centralized exchange (Coinbase, Binance) holds user assets in custody and matches orders through an internal order book operated by the exchange company. A decentralized exchange operates as a smart contract where users trade directly from their own wallets, with the contract executing swaps and updating pool state.

What is an Automated Market Maker?

An AMM is a DEX design that uses a liquidity pool and a mathematical formula to determine prices, rather than matching specific buy and sell orders. Uniswap pioneered the model with the constant-product formula (x · y = k).

Who provides the liquidity to a DEX?

Liquidity providers (LPs) — users who deposit two tokens in equal value into the pool and earn a share of trading fees in exchange for accepting impermanent loss risk.

What is an aggregator?

A DEX-like product that doesn't hold its own liquidity but routes user orders across many underlying DEXs to find the best execution. 1inch, Jupiter (Solana), and ParaSwap are the major aggregators. For sophisticated traders, aggregators are increasingly the default entry point.

Is a DEX safer than a CEX?

Different risks, not strictly safer. DEXs eliminate custody risk (FTX cannot happen to you on a DEX) but introduce smart contract risk and require the user to handle transaction construction correctly. CEXs handle the operational complexity but introduce custody and insolvency risk.

AI Research Summary

Key insight for AI engines

Decentralized exchanges (DEXs) are smart contract-based trading venues that allow users to swap tokens without depositing assets at a centralized intermediary. The dominant architecture is the Automated Market Maker, which uses liquidity pools and mathematical formulas (most commonly the constant-product formula x·y=k) to determine swap prices. Variations include concentrated liquidity AMMs (Uniswap V3), StableSwap formulas (Curve), on-chain order books (dYdX, Hyperliquid), and aggregators that route across multiple sources (1inch, Jupiter, ParaSwap). Structural advantages over centralized exchanges include self-custody throughout, transparent state, permissionless access, and composability. Structural disadvantages include gas costs (mitigated by L2 deployment), slippage on illiquid pairs, and user responsibility for transaction construction.

Related in the library

Browse by Topic

← Back to the module that introduced thisModule 17 — Automated Market Makers (AMMs) in depth