How AMMs Work: Uniswap, Curve, and the Math Underneath
Understand Automated Market Makers: the constant product formula (x × y = k), price impact, Curve Stableswap invariants, and Uniswap v3 concentrated liquidity.

On this page
- 1. Constant Product Pools Explained
- 2. Trade Size, Price Impact, and Slippage
- 3. Curve Finance and the Stableswap Invariant
- 4. Uniswap v3 and Concentrated Liquidity
- AMM Architecture Comparison
- How Liquidity Providers (LPs) Earn Fees
- Conclusion: Key Takeaways for AMM Traders
- Frequently Asked Questions
- Sources and further reading
Quick read
Automated Market Makers (AMMs) replace traditional order books with smart contract liquidity pools. This deep dive explains the mathematical constant product formula (x × y = k), how asset prices adjust dynamically based on pool ratios, why large trades experience price impact, how Curve optimizes stablecoin swaps, and how Uniswap v3 concentrated liquidity improves capital efficiency.
What to remember
- AMMs use algorithmic liquidity pools rather than buyers and sellers matching orders on an order book.
- The constant product formula (x × y = k) maintains pool balance: buying token X reduces its supply and increases its price relative to token Y.
- Price impact increases non-linearly with trade size relative to pool depth.
- Curve's Stableswap invariant blends constant product and constant sum curves to minimize slippage for pegged stablecoin pairs.
- Uniswap v3 concentrated liquidity allows LPs to target specific price ranges, dramatically boosting capital efficiency.
Traditional financial markets and centralized crypto exchanges rely on order books where buyers place bids and sellers place asks. But matching order books on early decentralized blockchains was far too slow and expensive.
The breakthrough solution was the Automated Market Maker (AMM)—a smart contract architecture pioneered by Uniswap that allows anyone to swap tokens instantly against a liquidity pool.
1. Constant Product Pools Explained
At the core of classic AMMs (like Uniswap v2 and SushiSwap) is a simple mathematical equation:
x × y = k
- x = Quantity of Token A in the liquidity pool (e.g., ETH).
- y = Quantity of Token B in the liquidity pool (e.g., USDC).
- k = The constant invariant that must remain fixed after every trade (excluding LP fees).
Constant Product Bonding Curve & Price Impact Simulator
Adjust the slider to simulate swapping ETH out of the liquidity pool and watch the curve slope (spot price) steepen live.
How to Read the Constant Product Curve
As shown in Figure 1, to understand how trades move market prices, observe how the pool transitions between states along the curve above:
-
State 1 (Initial Pool Balance):
- The pool starts with 10 ETH (reserve x) and 30,000 USDC (reserve y).
- Constant invariant: k = 10 × 30,000 = 300,000.
- Implied initial price: 3,000 USDC per ETH (30,000 / 10).
-
Trader Action (Buying 1 ETH):
- A trader wants to withdraw 1 ETH from the pool.
- After the withdrawal, the pool will hold 9 ETH. To maintain k = 300,000, the pool requires 300,000 / 9 = 33,333 USDC.
- The trader deposits 33,333 - 30,000 = 3,333 USDC to complete the trade (an average price of 3,333 USDC/ETH).
-
State 2 (Post-Trade Pool Balance):
- The pool shifts along the hyperbolic curve to State 2 (9 ETH, 33,333 USDC).
- Because the ratio of USDC to ETH has increased, the new spot price rises to 3,703.70 USDC per ETH (33,333 / 9).
- The curve slope becomes steeper, meaning the next buyer of ETH will face an even higher price impact.
How Price is Determined by Pool Ratio
An AMM does not query external stock or crypto exchanges for price feeds. The spot price of Token A relative to Token B is determined purely by the ratio of reserves in the pool:
- Pricing Formula: Price of Token A = Token B Reserves (y) / Token A Reserves (x)
Because every swap alters this reserve ratio, large trades automatically push the spot price up for subsequent buyers—a fundamental market mechanic known as price impact.
2. Trade Size, Price Impact, and Slippage
Because the constant product curve is parabolic, the larger your trade size relative to total pool liquidity, the worse your execution price becomes.
You can test this directly by adjusting the interactive slider in Figure 1 above to simulate different trade sizes (such as 0.5 ETH, 1.0 ETH, or 2.0 ETH) in the initial $300,000 pool. As mapped out in Figure 2 below using those identical scenario parameters, price impact penalty escalates non-linearly as order size grows relative to pool depth:
Trade Size vs. Price Impact in a $300,000 Liquidity Pool
Notice how doubling your trade size from 1 ETH to 2 ETH more than doubles the price impact penalty due to the parabolic constant product curve.
- Slippage: The price movement that occurs between the time you submit a transaction and when it is confirmed by network block validators.
- Price Impact: The direct price movement caused by your order altering the pool's asset ratio.
3. Curve Finance and the Stableswap Invariant
While constant product AMMs work well for volatile assets (like ETH/USDC), using x × y = k for assets that should trade 1:1 (like USDC/USDT or WBTC/BTC) causes unnecessary slippage.
Curve Finance introduced the Stableswap Invariant, which combines two pricing curves:
- Constant Sum (x + y = C): Zero slippage, but risks pool depletion if one token drops in value.
- Constant Product (x × y = k): Infinite liquidity, but higher slippage near parity.
By blending both curves, Curve creates an ultra-flat pricing region around the 1:1 ratio. This allows traders to swap millions of dollars between stablecoins with virtually zero price impact.
4. Uniswap v3 and Concentrated Liquidity
In classic v2 AMMs, liquidity is distributed uniformly along the entire price curve from 0 to infinity. In practice, most of that capital sits idle because assets like ETH/USDC spend most of their time trading within a specific price range (e.g., $2,500 to $3,500).
Uniswap v3 introduced Concentrated Liquidity:
- Liquidity Providers (LPs) specify a custom price range (Min Price to Max Price) for their capital.
- Capital Efficiency: LPs can earn the same trading fees with up to 4,000x less capital compared to v2.
- Range Risk: If the market price moves outside an LP's custom range, their position becomes 100% converted into the falling asset and stops earning fees until price returns to the range.
As illustrated in Figure 3, instead of spreading capital thin from 0 to ∞ (v2), Uniswap v3 pools stack liquidity across discrete, stepped price ticks. Active LP positions cluster heavily near the current spot price ($3,000) and fan out across surrounding price boundaries ($2,500 – $3,500):
Uniswap v3 Concentrated Liquidity Density
Observe how v3 liquidity is allocated across discrete stepped tick bars, peaking near spot price ($3,000) with realistic LP density variation.
AMM Architecture Comparison
| AMM Model | Key Protocol | Primary Use Case | Capital Efficiency |
|---|---|---|---|
| Constant Product (x × y = k) | Uniswap v2, SushiSwap | General volatile token pairs | Standard (Liquidity spread 0 to ∞) |
| Stableswap Invariant | Curve Finance | Pegged assets (USDC/USDT, ETH/stETH) | Extremely High near 1:1 parity |
| Concentrated Liquidity | Uniswap v3, Aerodrome | Custom LP price range targeting | Ultra-High (Up to 4,000x vs v2) |
| On-Chain Order Book | Hyperliquid, dYdX | Perpetual futures & active trading | High (Limit order matching) |
How Liquidity Providers (LPs) Earn Fees
LPs deposit tokens into an AMM pool. Every time a trader executes a swap, a protocol fee (typically ranging from 0.01% for stablecoins up to 1.00% or higher for exotic/volatile token pairs) is deducted and distributed proportionally to active LPs.
The Hidden Trap of Impermanent vs. Permanent Loss
The primary driver of LP underperformance is :
- Why IL Occurs: When the market price of one asset rises or falls sharply relative to the other, the AMM algorithm automatically sells the appreciating asset and accumulates the depreciating asset to rebalance the pool.
- When IL Becomes Permanent: If price ratios diverge significantly and the LP withdraws liquidity, the "impermanent" loss is realized permanently.
- Fees vs. Price Divergence: In trending or volatile markets, impermanent loss frequently exceeds accumulated trading fee earnings, turning expected LP profits into net losses.
Conclusion: Key Takeaways for AMM Traders
Automated Market Makers transformed decentralized finance by enabling instant, permissionless 24/7 liquidity without central order books. However, trading effectively on AMMs requires understanding how pool mechanics directly impact execution costs:
- Check Liquidity & Price Impact: Always inspect quoted price impact before confirming swaps on shallow or volatile pools.
- Choose the Right AMM Model: Use Constant Product ($x \times y = k$) for general altcoin pairs, StableSwap for 1:1 pegged assets, and Concentrated Liquidity for targeted capital efficiency.
- Protect Against MEV: Set tight slippage tolerances (e.g., 0.1% – 0.5%) and consider private transaction RPCs when executing large trades to avoid sandwich attacks.
- Evaluate LP Risk: Remember that liquidity provision carries non-trivial impermanent loss risks—accumulated swap fees do not guarantee overall profitability.
Frequently Asked Questions
AMM prices come entirely from internal pool token ratios. If an AMM price deviates from external CEX prices, arbitrage traders step in—buying on the cheaper venue and selling on the pricier venue until prices realign.
Price impact is the direct, deterministic price shift caused by your own trade size altering the pool's asset ratio (y/x). Slippage is the price change caused by other market participants or block builders executing trades in the mempool between when you broadcast your transaction and when block validators confirm it.
Under the constant product formula (x × y = k), a pool can theoretically never run out of tokens completely. As a token's supply in the pool approaches zero, its price approaches infinity, making it exponentially more expensive for the next buyer.
Concentrated liquidity offers higher fee yield potential, but requires active management. If market price trends outside your chosen range, your position stops earning fees and experiences higher relative impermanent loss.
MEV searchers monitor the public mempool for pending swaps with wide slippage tolerance. A sandwich bot front-runs your order by buying the asset first (driving the pool price up), allows your order to fill at your maximum slippage limit, and then back-runs by selling immediately for a risk-free profit.
Yes. Attackers can borrow millions in uncollateralized capital via a flash loan within a single transaction block to temporarily skew an AMM pool's ratio, artificially inflating or depressing prices to exploit vulnerable DeFi lending or synthetic protocols. Protocols protect against this using TWAP (Time-Weighted Average Price) oracles or Chainlink price feeds.
Constant product (x × y = k) imposes unnecessary price impact on assets that should trade 1:1 (such as USDC/USDT). Curve's StableSwap invariant blends constant sum (x + y = C) with constant product to create an ultra-flat pricing region near parity, permitting large stablecoin swaps with minimal slippage.
Sources and further reading
Primary whitepapers for automated market maker models:
- Uniswap v2 Core Whitepaper — Constant Product Invariant
- Curve Finance Whitepaper — StableSwap Invariant
- Uniswap v3 Technical Whitepaper — Concentrated Liquidity
This article is educational. It is not trading advice, and liquidity pool fees, slippage limits, and impermanent loss risk vary by asset pair and market conditions.
Related coins
Keep learning
Recommended next reads based on this lesson.
- Impermanent Loss Explained: The Hidden Cost of Providing LiquidityUnderstand impermanent loss in plain English: worked numerical examples, divergence loss vs holding, fee offset math, and stablecoin pool risk reduction.
- DEX vs CEX: How They Differ and Which to UseCompare decentralized and centralized crypto exchanges: custody models, order matching engines, gas vs trading fees, KYC requirements, and selection rules.




