Uniswap AMM Core Mechanics

Uniswap's Automated Market Maker (AMM) is the engine that powers decentralized token swaps. At its heart is the constant-product formula x*y=k — a deceptively simple equation that creates an elegant pricing curve without any order book or centralized matching. Understanding how it works is essential for any DeFi user, liquidity provider, or protocol developer.

? Swap Simulator

Configure a swap and see how price impact, fees, and output amount change with pool size and trade size.

Input (ETH)
10.00
Fee (ETH)
0.030
Output (USDC)
19,609
Price Impact
0.50%
Mid price (before swap): 2,000 USDC/ETH  |  Effective price: 1,961 USDC/ETH

The Constant Product Formula: x ? y = k

Uniswap's pricing mechanism is governed by one equation: the product of the two token reserves must remain constant after every swap. This single invariant creates the entire pricing curve without any external price feed or matching engine.

x · y = k
  • x = reserve of token0 (e.g., ETH)
  • y = reserve of token1 (e.g., USDC)
  • k = constant (never changes)
If k is constant, buying ETH (reducing x) must increase y proportionally — raising the ETH price.
Price from reserves
price = y / x
= USDC_reserve / ETH_reserve
With 1,000 ETH and 2,000,000 USDC in the pool:
price = 2,000,000 / 1,000 = 2,000 USDC/ETH
Key property: The AMM curve is unbounded — k never changes, so the curve never stops. This means you can always swap, but large swaps become exponentially expensive. The AMM can provide liquidity at any price, but the cost of doing so grows with the size of the trade.

? Visual: The AMM Price Curve

The constant-product curve is a hyperbola. Near the middle (1:1 ratio), the curve is relatively flat — small swaps have minimal price impact. As you move away from center, the curve steepens — each additional unit costs exponentially more.

Near center (0.8-1.2x)
Low price impact
Most liquidity concentrated here
Mid range (2-5x)
Moderate price impact
Reasonable for medium orders
Far out (10x+)
Exponential cost
Only for extreme scenarios

How Swaps Execute: Step by Step

When you execute a swap, the AMM follows a precise sequence of calculations. The fee is taken first, then the constant-product invariant is applied to compute output.

// Step 1: Take fee from input
inputWithFee = inputAmount (1 - feeTier)
// Step 2: Apply constant product
k = x_reserve y_reserve   // constant
y_out = y_reserve - k / (x_reserve + inputWithFee)
// Example: 10 ETH → USDC, 0.30% fee, 1000 ETH pool
inputWithFee = 10 0.997 = 9.97 ETH
k = 1000 2,000,000 = 2,000,000,000
y_out = 2,000,000 - 2B / (1000 + 9.97) = 19,609 USDC
Small Swap: 1 ETH
Fee: 0.003 ETH
Output: ~1,994 USDC
Price impact: ~0.10%
Near-perfect execution
Medium Swap: 50 ETH
Fee: 0.150 ETH
Output: ~97,561 USDC
Price impact: ~2.4%
Notable slippage
Large Swap: 200 ETH
Fee: 0.600 ETH
Output: ~363,636 USDC
Price impact: ~9.1%
Severe slippage

Fee Tiers: Why They Exist

Uniswap supports three fee tiers (0.05%, 0.30%, 1.00%) — each optimized for different volatility profiles. The fee tier is set when the pool is created and cannot be changed without deploying a new pool.

Fee Tier Best For LP Annualized Revenue IL Risk Typical Pairs
0.05% Stablecoin pairs (1:1 ratio) Low per trade, high volume Minimal (correlated assets) USDC/USDT, DAI/USDC
0.30% General ETH/major tokens Moderate per trade Moderate ETH/USDC, BTC/USDC
1.00% Volatile/meme/exotic tokens High per trade, lower volume High MEME/ETH, PEPE/USDC
Fee tier decision: If you provide liquidity to a 1% fee tier on a stablecoin pair, your fees will be too high and traders will go elsewhere. If you provide liquidity to a 0.05% fee tier on a volatile MEME/ETH pair, a single 10% price move will cost you more in impermanent loss than you'd earn in fees for months. Match the fee tier to the pair's volatility profile.

Liquidity Provision: How to Earn Fees

Liquidity providers (LPs) deposit token pairs into pools and earn a share of the trading fees. In return for providing liquidity, you receive LP tokens that represent your proportional share of the pool.

Providing Liquidity Steps

  1. Select pool — Choose token pair + fee tier
  2. Deposit both tokens — In proportion to current ratio (e.g., 50% ETH + 50% USDC by value)
  3. Receive LP tokens — Proportional to your share of the pool
  4. Fees accumulate — Every swap distributes 0.30% to all LPs
  5. Claim fees — Redeem accrued fees via LP token
  6. Withdraw — Burn LP tokens to get back tokens + fees

LP Token Mechanics

  • ERC-20 tokens — Standard fungible tokens
  • 1:1 value backing — Each LP token = fractional pool share
  • Fee accumulation — Pool grows in value, LP tokens appreciate
  • No lockup — Withdraw anytime (but you lose accumulated fees if you exit early)
  • Composable — Can be used in other DeFi (LP tokens as collateral, etc.)
Fee Revenue Calculation
12.4%
Pool APY (annual)
0.034%
Daily fee yield
2.0%
Your share of pool
Example: $10,000 LP position at 2.0% pool share earns ~$24.80/day in fees at 12.4% APY.

Virtual Reserves & V3 Concentrated Positions

In Uniswap V3, positions use virtual reserves — the token amounts in a hypothetical full-range V2 pool that would produce the same swap behavior as the concentrated position. The swap formula xy=k still applies, but to virtual reserves.

// V3 position with liquidity L in price range [Pa, Pb]
virtual_x = L / ?Pb
virtual_y = L ?Pa
// Real token amounts (what you deposit):
real_x = L (1/?Pa - 1/?Pb)
real_y = L (Pb - Pa)
// Capital efficiency: real / virtual
efficiency = range_width (e.g., 2% width → 50x efficiency)
Full Range (V2 equivalent)
Range: [0, ?]
Capital deployed: $10,000
Virtual reserves: $10,000
Fee revenue: 0.30% of trade value
IL risk: distributed across all prices
Concentrated (V3, 2% width)
Range: [$1,960 - $2,040]
Capital deployed: $200
Virtual reserves: $10,000
Fee revenue: Same as V2 full-range!
IL risk: Amplified 50x within the range

? Price Impact Curve

As you increase trade size, price impact grows non-linearly. This chart shows how price impact compounds for the same ETH/USDC pool at different trade sizes.

Pool size: 1,000 ETH Mid price: 2,000 USDC/ETH Fee tier: 0.30%

How the AMM Actually Works

Uniswap's AMM is built on a single invariant: x * y = k. When you deposit liquidity into a pool, you're committing tokens to a shared reserve. The AMM uses these reserves to facilitate trades, charging a fee on every swap and distributing that fee proportionally to all LP token holders.

The beauty of the constant-product formula is that it creates a self-regulating market without any external control. If someone buys a lot of ETH, the ETH reserve decreases and the USDC reserve increases. The new price (USDC/ETH) is automatically higher — because the pool now has less ETH relative to USDC, each unit of ETH costs more USDC. This is the market's way of discouraging further buys and encouraging sells.

The 0.30% fee (in V2 and standard V3 pools) is taken at the input side — before the swap math is applied. So when you swap 10 ETH, only 9.97 ETH goes into the constant-product calculation, and the remaining 0.03 ETH becomes the first piece of LP fee revenue. This fee is taken upfront so that the pool's k is computed correctly with the net input amount.

Liquidity Provision Math

When you provide liquidity, you deposit both tokens in the proportion that matches the current pool ratio. If the pool has 1,000 ETH and 2,000,000 USDC, the ratio is 2,000 USDC per ETH. If you want to add $5,000 of liquidity, you'd deposit 2.5 ETH and 5,000 USDC — maintaining the ratio.

You receive LP tokens proportional to your share. If the total pool is worth $2,000,000 and you deposit $10,000, you own 0.5% of the pool and receive LP tokens representing that 0.5% share. Every time someone trades, 0.30% of the trade value goes to the pool, increasing the value of all LP tokens proportionally.

To withdraw, you burn your LP tokens and receive your proportional share of the current pool — which now includes accumulated fees. If the pool grew from $2,000,000 to $2,100,000 due to trading fees, your 0.5% share is worth $10,500, and you receive that plus your initial principal back in the form of the token pair.

Impermanent Loss: The Hidden Cost

Impermanent loss (IL) is the difference between holding tokens in the AMM vs holding them in a wallet. It occurs because the AMM automatically sells your appreciating asset as the price rises — leaving you with less of it than if you'd just held. IL is "impermanent" in the sense that it becomes real only when you withdraw; if prices return to the original ratio, the loss disappears.

The IL formula for a price ratio change of r (where r = new_price / old_price) is: IL = 2*?r / (1+r) - 1. For a 2x price increase (r=2), IL = 2*?2/3 - 1 = -5.72%. For a 5x increase (r=5), IL = -25.5%. This means even if the pool earns 20% in fees, a 5x price move would leave the LP underwater compared to just holding.

V3 concentrated positions amplify IL geometrically. A 2% width position experiences ~50x the IL of a full-range V2 position for the same price move — because the same capital is concentrated into a tighter price window where each price step has a proportionally larger effect.

Multi-Hop Swaps

Uniswap's router can find paths through multiple pools. If you want to swap USDC for WBTC but there's no direct WBTC/USDC pool, the router might find: USDC → ETH (ETH/USDC pool) → WBTC (WBTC/ETH pool). Each hop adds a fee, so multi-hop swaps are more expensive than direct swaps.

The router uses a "split search" algorithm — it checks all possible paths up to a maximum number of hops (typically 3), computes the output for each path, and returns the best one. For same-chain swaps, paths with more hops are generally worse due to compounding fees, but they may be necessary for illiquid pairs.

Key Concepts

Constant product invariant (x*y=k)
The mathematical foundation of Uniswap's pricing. The product of the two token reserves must remain constant after every swap. This creates a hyperbolic price curve where buying one token increases its price exponentially as you consume more liquidity.
Trading fee (0.30% standard)
Charged on the input amount of every swap. For a 10 ETH swap at 0.30% tier, 0.03 ETH goes to LPs and 9.97 ETH goes into the constant-product calculation. The fee is built into the swap math, not added afterward.
LP tokens
ERC-20 tokens issued when you provide liquidity. They represent your proportional share of a pool's reserves plus accumulated fees. Each pool has its own LP token (e.g., ETH/USDC LP token is different from ETH/WBTC LP token).
Price impact
The difference between the mid price before your swap and your actual average fill price. It's caused by walking up the AMM curve — each unit of the asset you buy costs more than the previous unit. Price impact grows with swap size relative to pool liquidity.
Virtual reserves
In V3 concentrated positions, the token amounts in a hypothetical full-range V2 pool that would produce the same swap behavior. The constant product formula applies to virtual reserves, enabling the same depth with a fraction of the capital.
Slippage tolerance
Your specified maximum acceptable price deviation from the quoted price. If the execution price moves beyond your slippage tolerance, the transaction reverts. Setting a higher tolerance protects against failed transactions but increases MEV exposure.
Minimum output
The minimum amount of output token you'll accept from a swap. Calculated by the router based on the quoted price minus your slippage tolerance. If the swap would produce less than this, it reverts and you pay no gas.