Module 9: DeFi Deep Dive
AMMs and DEXs in Depth
Chapter 2 of 14 · about 6 minutes
2.1 Beyond x × y = k
In Module 1, Chapter 8, Mint learned the basic AMM formula and saw how pool size affects slippage. Now Mint noticed that swaps between two stablecoins had almost no slippage at all, even in large amounts, and that some pools showed liquidity concentrated in narrow price ranges.
"Not every DEX uses the same formula?" Mint asked.
"Far from it," said Hash. "The simple formula was the first design. Since then, DEXs have evolved to make liquidity more efficient. Understanding the main designs helps you trade better and, if you provide liquidity, understand your risks."
2.2 The constant product AMM, revisited
The constant product formula, x × y = k, keeps the product of the two token balances fixed (Module 1, Chapter 8). It has useful properties: it always has a price, it never runs out of either token, and it's simple and robust.
Its weakness is capital efficiency. Liquidity is spread evenly across every possible price, from near zero to near infinity. For an ETH/USDC pool where ETH trades around $3,000, most of the liquidity sits at prices like $10 or $1,000,000, where trades almost never happen. Only a small portion is actually used near the current price.
2.3 Concentrated liquidity
Concentrated liquidity lets liquidity providers choose a price range where their liquidity is active. If ETH trades around $3,000, a provider might place liquidity only between $2,700 and $3,300.
Within that range, the same capital provides much deeper liquidity, so traders get less slippage and providers earn more fees per dollar deposited. Outside the range, the position stops earning fees and is fully converted into one token.
| Full-range liquidity | Concentrated liquidity ($2,700 to $3,300) | |
|---|---|---|
| Where liquidity is active | All prices | Only within the chosen range |
| Capital efficiency | Low | Much higher |
| Fees earned per dollar while in range | Lower | Higher |
| If price leaves the range | Still earning | Earns nothing; holds only one token |
| Management needed | Minimal | Active: ranges may need adjusting |
| Impermanent loss within range | Standard | Amplified (Chapter 4) |
"So it's like a shop that only opens during the busiest hours," said Mint. "More customers per hour, but closed the rest of the time."
"And if the busy hours shift, you need to move your opening times," said Hash.
Chapter 2 · Concentrated liquidity
One curve shows constant-product liquidity thinly spread across every price. The other shows liquidity concentrated into a chosen band, making the pool far deeper within that range. When price moves outside the range, the position stops earning fees and sits in a single token.
2.4 Stable swap curves
For assets expected to trade near the same price, such as two dollar stablecoins, or ETH and a liquid staking token (Chapter 8), DEXs use stable swap curves. These behave almost like a fixed exchange rate near the expected price, giving very low slippage, but curve more steeply if the pool becomes heavily unbalanced.
| Swap of $1,000,000 between two stablecoins | Constant product pool | Stable swap pool |
|---|---|---|
| Typical slippage, deep pool | Noticeable | Very small |
The trade-off: if one asset in a stable pool loses its peg, the pool fills up with the depegged asset as traders swap it for the healthy one. Liquidity providers end up holding mostly the failing asset. This is exactly the pool imbalance signal from Module 6, Chapter 8.
2.5 Fees and fee tiers
DEX pools charge a fee on each swap, paid to liquidity providers and sometimes partly to the protocol. Many DEXs offer fee tiers:
| Pair type | Typical fee tier (illustrative) | Reason |
|---|---|---|
| Stablecoin pairs | ~0.01% to 0.05% | Low volatility, low risk for providers |
| Major pairs, like ETH/USDC | ~0.05% to 0.30% | Moderate volatility |
| Volatile or small tokens | ~0.30% to 1.00% | Higher risk for providers |
Higher fees compensate liquidity providers for higher risk, but push traders toward cheaper venues.
2.6 DEX aggregators
DEX aggregators search many DEXs and pools to find the best price for a trade, sometimes splitting it across several routes.
Example. Swapping $500,000 of USDC for ETH:
| Route | Share of trade |
|---|---|
| Pool A, concentrated liquidity | 55% |
| Pool B, different fee tier | 30% |
| Pool C, another DEX | 15% |
By splitting the order, the aggregator reduces total price impact compared with sending it all through one pool. Most users now swap through aggregators or wallets with built-in routing, often without realising it.
2.7 Intent-based trading
A newer approach is intent-based trading. Instead of specifying exactly which pools to trade through, the user signs an intent: "I want to sell 10 ETH for at least 29,800 USDC within the next two minutes."
Independent solvers compete to fill that intent at the best price, using any source of liquidity: DEX pools, their own inventory, or other users' opposite orders. The winning solver delivers the result.
| Traditional DEX swap | Intent-based trade | |
|---|---|---|
| User specifies | The exact route | The desired outcome |
| Who finds the route | The user or an aggregator | Competing solvers |
| Gas | Usually paid by the user | Often included in the price or paid by solvers |
| MEV exposure | Can be sandwiched (Module 3, Chapter 11) | Generally reduced, since orders aren't exposed as normal swaps in the public mempool |
| Trust | The pools' smart contracts | The settlement contract and solver competition |
Intent-based designs also power some cross-chain bridges (Module 3, Chapter 10).
2.8 Order book DEXs
As Module 1, Chapter 8 and Module 7, Chapter 13 mentioned, some DEXs use on-chain order books instead of pools, usually on high-throughput chains. They work like centralised exchanges, with limit orders and market makers, but settle on-chain.
2.9 Choosing where to trade
| Trade | Typically best |
|---|---|
| Small swap of major tokens | Aggregator or intent-based swap |
| Large swap | Aggregator or intent-based swap, with careful slippage settings |
| Stablecoin to stablecoin | Stable swap pools, usually via an aggregator |
| New or small tokens | The specific pool where liquidity exists, with extra caution (Module 2, Chapter 11) |
2.10 Try it yourself
Get quotes for swapping $1,000 and $100,000 of ETH to USDC from two different aggregators and one intent-based swap interface, without executing. Compare the output amounts, routes, and any fees. Then find a concentrated liquidity pool for ETH/USDC and look at how its liquidity is distributed around the current price.
Key takeaways from this chapter
- Constant product AMMs are simple and robust but spread liquidity inefficiently across all prices.
- Concentrated liquidity lets providers focus capital in price ranges, increasing efficiency but requiring active management.
- Stable swap curves give low slippage between assets expected to trade at similar prices, but fill with the weaker asset in a depeg.
- Fee tiers compensate liquidity providers according to the pair's risk.
- Aggregators split trades across pools for better prices.
- Intent-based trading lets solvers compete to fill a desired outcome, often reducing MEV exposure.
- Choose venues based on trade size, token type, and liquidity.