Automated Market Makers (AMMs) Explained
Automated Market Makers are the engine behind most decentralized exchanges. Instead of matching buyers and sellers through an order book, AMMs use mathematical formulas and liquidity pools to enable trading at any time. Understanding how they work is essential for anyone using DeFi.
Table of Contents
What Is an AMM?
An Automated Market Maker is a type of decentralized exchange protocol that uses algorithms to price assets instead of a traditional order book. In traditional finance and centralized crypto exchanges, market makers are entities that provide liquidity by placing buy and sell orders. AMMs automate this process using smart contracts and liquidity pools β collections of tokens locked in a contract that anyone can trade against. When you swap tokens on Uniswap, Jupiter, or PancakeSwap, you are trading against a liquidity pool, not another user directly. The smart contract calculates the price based on the current ratio of tokens in the pool and executes the trade instantly.
The Constant Product Formula
The most widely used AMM model is the constant product formula, popularized by Uniswap: x * y = k. In this formula, x represents the quantity of one token, y represents the quantity of the other token, and k is a constant. When a trader buys token x, they add token y to the pool and remove token x. The formula ensures that k remains constant, which means the price automatically adjusts based on supply and demand. As one token becomes scarcer in the pool, its price increases relative to the other. This creates a price curve where large trades cause more price impact (slippage) because they shift the ratio more dramatically. The beauty of this model is its simplicity β no order matching, no market makers needed, just math.
Liquidity Pools Explained
A liquidity pool is a smart contract holding reserves of two or more tokens that traders can swap between. Each pool represents a trading pair β for example, an ETH/USDC pool holds both ETH and USDC. The pool is funded by liquidity providers (LPs) who deposit tokens in exchange for LP tokens representing their share of the pool. Trading fees (typically 0.3% on Uniswap) are distributed proportionally to LP token holders. The size of a pool determines its depth β larger pools handle bigger trades with less price impact. Pool sizes can range from thousands to billions of dollars for major pairs like ETH/USDC on Ethereum mainnet.
Becoming a Liquidity Provider
Anyone can become a liquidity provider by depositing tokens into a pool. On standard AMMs like Uniswap v2, you deposit equal value of both tokens. If ETH is $3,000 and you deposit 1 ETH, you also deposit $3,000 in USDC. In return, you receive LP tokens that represent your share of the pool. You earn a proportional share of all trading fees generated by that pool. When you want to exit, you redeem your LP tokens for your share of the pool's current assets. The amounts you receive may differ from what you deposited due to price changes and the resulting impermanent loss. Uniswap v3 introduced concentrated liquidity, where LPs can specify price ranges for their liquidity, increasing capital efficiency but requiring more active management.
Types of AMMs
Different AMM designs optimize for different use cases. Constant product AMMs (Uniswap v2, PancakeSwap) work for general-purpose token swaps. Stable swap AMMs (Curve) use a modified formula optimized for assets that should trade near 1:1, like stablecoins or wrapped tokens β this dramatically reduces slippage for stable pairs. Concentrated liquidity AMMs (Uniswap v3, Orca Whirlpools) let LPs focus their capital within specific price ranges for greater efficiency. Weighted pool AMMs (Balancer) allow pools with unequal token ratios like 80/20 instead of 50/50. Virtual AMMs (used by some perpetual DEXs) simulate AMM mechanics without actual liquidity pools. Each design makes tradeoffs between simplicity, capital efficiency, and specific use case optimization.
AMM Limitations
AMMs have inherent limitations compared to order book exchanges. Capital efficiency is lower because liquidity is spread across the entire price curve in basic AMMs, though concentrated liquidity addresses this. Impermanent loss erodes LP returns when token prices diverge. AMMs are vulnerable to sandwich attacks and MEV extraction, where sophisticated actors profit at the expense of regular traders. Price discovery on AMMs typically lags behind centralized exchanges β AMM prices update only when arbitrageurs trade to correct the discrepancy. Large trades suffer significant slippage on smaller pools. Despite these limitations, AMMs have proven remarkably effective at enabling permissionless, decentralized trading at scale.
Frequently Asked Questions
How do AMMs determine prices?
AMMs use mathematical formulas based on the ratio of tokens in a liquidity pool. The most common is the constant product formula (x * y = k), where the price adjusts automatically as traders buy or sell tokens from the pool.
Can anyone create an AMM pool?
Yes. On permissionless DEXs like Uniswap, anyone can create a liquidity pool for any token pair by depositing equal value of both tokens. This is what makes DEXs permissionless.
What are the risks of providing liquidity to an AMM?
The primary risk is impermanent loss, which occurs when the price ratio of deposited tokens changes. Smart contract risk and rug pulls on new token pools are also concerns.