Decentralized Exchanges: How Automated Market Makers Work

When you buy a stock through a traditional exchange, somewhere behind the interface is an order book — a ledger of buy orders and sell orders, ranked by price, waiting to be matched. Market makers stand in the middle, providing liquidity by quoting both a buy price and a sell price, earning the spre

When you buy a stock through a traditional exchange, somewhere behind the interface is an order book — a ledger of buy orders and sell orders, ranked by price, waiting to be matched. Market makers stand in the middle, providing liquidity by quoting both a buy price and a sell price, earning the spread between them. This system works well in traditional finance because the matching engines are fast, the market makers are well-capitalized, and the regulatory framework keeps the whole apparatus mostly honest. It also requires a central operator, significant infrastructure, and trust in every layer of the stack.

Decentralized exchanges had to solve a different problem. Running a traditional order book on a blockchain is prohibitively expensive. Every order placement, every cancellation, every modification would require a transaction — and transactions cost gas. Early attempts at on-chain order books were slow, costly, and thin on liquidity. The breakthrough came not from replicating the order book but from replacing it entirely with a different mechanism: the automated market maker.

The Uniswap whitepaper, published in 2018, described a system that now processes billions of dollars in trading volume. It is, in essence, a mathematical formula that replaces the human market maker. Understanding how it works is not optional if you intend to use decentralized finance with any sophistication. The mechanism is elegant, but it has costs that are not always visible.

The Constant Product Formula

The core of an AMM is a liquidity pool — a smart contract holding two tokens in reserve. Imagine a pool containing ETH and USDC. The pool maintains a relationship between these two reserves described by a simple equation: x multiplied by y equals k, where x is the quantity of one token, y is the quantity of the other, and k is a constant.

When someone wants to trade ETH for USDC, they deposit ETH into the pool and withdraw USDC. This changes the ratio of the two tokens. The pool now has more ETH and less USDC, which means the price of ETH — expressed as the ratio of USDC to ETH in the pool — has decreased. The next buyer of ETH gets a slightly better price; the next seller gets a slightly worse one. Price discovery happens through the ratio, not through an order book.

This is counterintuitive if you are accustomed to traditional markets. There is no bid and ask. There is no spread in the traditional sense. There is a curve — the bonding curve — and every trade moves along it. The price at any moment is the slope of the curve at the current reserve ratio. Large trades move the price more than small ones, because they shift the ratio more dramatically.

The beauty of this system is its simplicity. The contract does not need to know anything about the outside world. It does not need an oracle to determine the price. The price is the ratio. If the price in the pool diverges from the price on centralized exchanges, arbitrageurs step in to trade the pool back to equilibrium, profiting from the difference. The pool does not set the price; the market does, through the mechanical interaction of traders and arbitrageurs with the constant product formula.

Liquidity Providers

The pools do not fill themselves. Someone has to deposit the initial tokens and maintain the reserves that make trading possible. These participants are called liquidity providers, and their role is the decentralized equivalent of the market maker.

Anyone can become a liquidity provider. There is no application, no minimum net worth requirement, no licensing. You deposit a pair of tokens into the pool in equal value — say, $5,000 worth of ETH and $5,000 worth of USDC — and receive LP tokens representing your share of the pool. Every time someone trades through the pool, they pay a fee (typically 0.3% on Uniswap v2). That fee is added to the pool’s reserves, increasing the value of every LP’s share proportionally.

This is a genuine innovation. In traditional finance, market-making is the domain of specialized firms with proprietary algorithms, dedicated capital, and regulatory licenses. DeFi makes it permissionless. A college student with $500 can provide liquidity alongside a fund with $50 million. They earn the same proportional fees, face the same proportional risks, and need no one’s permission to participate.

The income from providing liquidity is real. It derives from trading activity — from the fees that traders pay to swap tokens. This is productive yield in the clearest sense: there is an economic service being provided (liquidity), and the provider is compensated for it. But there is a cost that is not immediately apparent, and understanding it is essential before you deposit a single token.

Impermanent Loss

The term “impermanent loss” is misleading, because it sounds temporary and minor. In practice, it can be permanent and significant. It is the hidden cost of providing liquidity, and it is the reason most casual liquidity providers underperform simply holding their tokens.

Here is how it works. When you deposit ETH and USDC into a pool at a 50/50 ratio, you are committing to the pool maintaining a balanced exposure to both tokens. If the price of ETH doubles relative to USDC, the pool rebalances — arbitrageurs buy the now-cheap ETH from the pool and sell USDC into it until the pool’s price matches the market price. Your share of the pool now contains less ETH and more USDC than when you started. If you had simply held your original tokens in a wallet, you would have more total value than your LP position is now worth. The difference is impermanent loss.

The word “impermanent” refers to the fact that if prices return to their original ratio, the loss disappears. But prices rarely cooperate with your entry point. In practice, impermanent loss is a drag on returns that compounds with price divergence. A 2x price divergence between the two tokens in a pool results in roughly 5.7% impermanent loss. A 5x divergence: approximately 25.5%. These are not edge cases in crypto markets where tokens routinely move 2-5x in a quarter.

The fees earned from providing liquidity offset impermanent loss — sometimes fully, sometimes not. Whether a particular LP position is profitable depends on the volume of trades flowing through the pool relative to the magnitude of price movement. High-volume, low-volatility pairs (like stablecoin pairs) tend to be profitable. Volatile pairs with modest trading volume tend to destroy value for LPs. This is the core calculus that every liquidity provider must understand.

Concentrated Liquidity: Uniswap v3

Uniswap v2 distributed liquidity uniformly across the entire price range, from zero to infinity. This meant that most of the capital in a pool was sitting idle, allocated to price ranges where trading would never occur. A pool for ETH/USDC had liquidity available at $0.01 per ETH and at $1,000,000 per ETH — prices that are functionally impossible — while the actual trading range might be $2,000 to $4,000.

Uniswap v3, launched in 2021, introduced concentrated liquidity. LPs now choose a specific price range for their capital. If you believe ETH will trade between $2,500 and $3,500, you can concentrate your liquidity in that range. This dramatically increases capital efficiency — your $10,000 does the work of $100,000 or more in a v2 pool, within that range. But if the price moves outside your range, your liquidity earns nothing. It sits idle until the price returns, or you manually reposition it.

Concentrated liquidity turned LP provision from a passive activity into an active one. It rewards precision and punishes inattention. Professional LPs with sophisticated rebalancing strategies tend to outperform. Casual LPs who set a range and forget about it tend to get caught out of range or suffer amplified impermanent loss within a tight range. The capital efficiency gain is real, but so is the management burden.

The DEX Landscape

Uniswap remains the largest decentralized exchange by volume, but it is not the only model. The landscape has diversified to serve different trading needs.

Curve Finance is optimized for stablecoin swaps — trading USDC for DAI, or USDT for USDC. Its bonding curve is flatter near the 1:1 ratio, meaning stablecoin trades experience minimal slippage. For anyone who uses stablecoins regularly, Curve provides a service that centralized exchanges cannot match for pure stablecoin-to-stablecoin conversion.

Balancer allows pools with more than two tokens and customizable weighting. Instead of a 50/50 pool, you can create an 80/20 pool or a pool with five different tokens at varying ratios. This enables index-fund-like structures on-chain, where the pool itself becomes a self-rebalancing portfolio.

DEX aggregators like 1inch and CoW Swap route trades across multiple DEXs to find the best execution price. Rather than trading directly on Uniswap and accepting whatever the pool ratio offers, an aggregator splits your trade across several pools on several protocols to minimize slippage and maximize the tokens you receive. For any trade above a few thousand dollars, using an aggregator rather than a single DEX is straightforward good practice.

Slippage and Execution

One honest limitation of AMMs: they provide worse execution for large orders than centralized exchanges with deep order books. This is a direct consequence of the constant product formula. Every trade moves the price. A $100 swap barely shifts the ratio. A $1 million swap can move it substantially, meaning you receive a worse average price than the quoted price at the moment you initiated the trade.

This difference is called slippage, and it is the practical cost of trading on an AMM rather than a centralized exchange. For small trades — under a few thousand dollars on a liquid pool — slippage is negligible. For large trades, it can be significant enough to make centralized exchanges the better venue purely on execution terms.

The trade-off is sovereignty versus execution quality. A centralized exchange offers tighter spreads, deeper liquidity, and better execution for large orders. It also requires identity verification, holds custody of your assets while they are on the platform, and can freeze your account, restrict withdrawals, or halt trading at its discretion — as several exchanges demonstrated during the market turmoil of 2022. A DEX offers inferior execution but absolute control: you trade from your own wallet, the contract executes or it does not, and no entity stands between you and your assets.

When to Use Which

The proportional approach is not to choose one and reject the other. It is to understand what each does well and use them accordingly.

Use a centralized exchange when you need to convert fiat currency to cryptocurrency — the on-ramp function that DEXs cannot perform. Use a centralized exchange when you are trading large amounts and execution price matters more than custody risk. Use a centralized exchange when the assets you want to trade are not available on decentralized venues.

Use a DEX when you want to trade without surrendering custody of your assets. Use a DEX for tokens that are not listed on centralized exchanges. Use a DEX when you want to provide liquidity and earn trading fees. Use a DEX when sovereignty matters more than saving a fraction of a percent on execution.

Most sovereignty-minded individuals will use both, transferring assets to centralized exchanges only when necessary and keeping the majority of their holdings in self-custody wallets that interact directly with decentralized protocols. The goal is not to avoid centralized services entirely — it is to avoid depending on them. The difference between using a tool and needing a tool is the difference between a cabin with a road to town and an apartment with no alternative.

The AMM replaced the exchange’s permission with a mathematical formula. You trade with a contract, not a counterparty. Whether that trade-off suits you depends on what you value more: the last basis point of execution quality, or the certainty that no one can close the exchange while your money is in it.


This article is part of the DeFi series at SovereignCML.

Related reading: What DeFi Actually Is (And What It Replaces), Lending and Borrowing Without a Bank, Stablecoins: The Dollar on Sovereign Rails

Read more