Deep diveLearn the foundationsLeaves: Go deeper

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.

CoinBeaver TeamPublished Jul 21, 2026Updated Jul 21, 2026
A mascot beaver guide inspecting a constant product formula x times y equals k balance wheel on a smart contract pool
On this page

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.

Post-Trade ETH9.00
Post-Trade USDC33,333
Avg Price Paid$3,333
Price Impact+11.1%
State 1 (10 ETH, $3,000)State 2 (9.0 ETH, $3,704)Pool ETH Reserves (x)Pool USDC Reserves (y)
Figure 1: Interactive Constant Product (x × y = k) bonding curve showing state movement from State 1 to State 2.

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:

  1. 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).
  2. 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).
  3. 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.

0.5 ETH1.0 ETH2.0 ETH3.0 ETHTrade Size (ETH Purchased)Price Impact (%)
Figure 2: Non-linear escalation of price impact percentage relative to trade size in a $300,000 AMM pool.
  • 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:

  1. Constant Sum (x + y = C): Zero slippage, but risks pool depletion if one token drops in value.
  2. 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.

Min Range Price$2,500
Max Range Price$3,500
Current Spot Price$3,000
Capital EfficiencyUp to 4,000x
Min: $2,500Max: $3,500Spot: $3,000Price Spectrum ($ USDC / ETH)
Figure 3: Uniswap v3 discrete tick-bar concentrated liquidity density centered around spot price ($3,000).

AMM Architecture Comparison

Comparison of AMM mathematical models and liquidity structures
AMM ModelKey ProtocolPrimary Use CaseCapital Efficiency
Constant Product (x × y = k)Uniswap v2, SushiSwapGeneral volatile token pairsStandard (Liquidity spread 0 to ∞)
Stableswap InvariantCurve FinancePegged assets (USDC/USDT, ETH/stETH)Extremely High near 1:1 parity
Concentrated LiquidityUniswap v3, AerodromeCustom LP price range targetingUltra-High (Up to 4,000x vs v2)
On-Chain Order BookHyperliquid, dYdXPerpetual futures & active tradingHigh (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


Sources and further reading

Primary whitepapers for automated market maker models:

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.