Automated market maker

Uniswap

Short answer Uniswap is an automated market maker. A swap moves the reserves of a pool and the pool’s invariant sets the price. v2 spreads fungible liquidity across every price. v3 and v4 concentrate it between ticks. v4 keeps that pricing and changes the contracts around it: one PoolManager, flash settlement, and optional hooks.

Written by
Published
Updated
What changed
Last verified
What this date means
Reading time
About 9 min
Version context
v2, v3, and v4 are all part of the protocol the current Uniswap docs describe. v4 launched on 31 January 2025. Core pools are documented as non-upgradeable.

Uniswap replaces an order book with a pool. The pool holds two assets. A trader swaps against those reserves, and the price is the result of a formula rather than a matched bid. Liquidity providers commit assets and receive the pool’s fee. They also take the inventory risk: a swap leaves them with more of the asset traders are selling.

The current docs treat v2, v3, and v4 as one protocol family with different pool contracts. This page follows a swap and an LP position through that family. The version guide is the place for the contract-level differences. Uniswap’s own overview says the core contracts are not upgradeable. That is a different trust model from Aave’s proxy-based pool.

The v2 invariant

A v2 pool is a pair of ERC-20 reserves. The protocol overview states the pricing rule as x * y = k. After a swap, the product of the reserves must not fall once the fee is taken into account. The spot price is the ratio of the reserves. A trade that is large relative to the pool moves that ratio more. That movement is price impact, and it is part of the invariant, not a separate fee.

The v2 flash-swap guide documents the pool fee as 0.30 percent, implemented as a 997/1000 factor on the input. The production quote lives in the v2 periphery library. The function below is an educational sketch of that arithmetic, not the deployed pair. It ignores the pair’s balance check, which is how v2 actually enforces the invariant: tokens are sent to the pair first, and the pair compares its balances with the stored reserves.

// Educational sketch of the documented v2 quote. Not Uniswap source.
// Not compiled here, and not a contract to hold assets.
pragma solidity 0.8.26;

contract ConstantProductSketch {
    uint256 public reserveIn;
    uint256 public reserveOut;

    function quote(uint256 amountIn) external view returns (uint256 amountOut) {
        uint256 amountInWithFee = amountIn * 997;
        amountOut = (amountInWithFee * reserveOut) / (reserveIn * 1000 + amountInWithFee);
    }
}

Integer division rounds down. A real pair also requires the product check to pass after transfers, supports flash swaps that return tokens inside a callback, and mints a fungible LP token for a pro-rata claim on both reserves. The LP token is not a claim to withdraw the same quantities that were deposited. Swaps change the mix.

Simplified model A routed swap
  1. TraderChooses an input token, an output token, and a limit such as a minimum amount out.
  2. Router or interfaceSelects one or more pools. This step can include off-chain routing and is not itself the invariant.
  3. PoolApplies the pool’s pricing rule to its reserves or in-range liquidity, charges the pool fee, and updates state.
  4. SettlementThe input token is taken from the trader and the output token is sent on. A callback, a prior transfer, or flash settlement can be the payment method, depending on the version.

This is not a literal call trace. v2, v3, and v4 settle tokens differently, and a router may split one trade across several pools.

The swap documentation separates three protections that routers add and that the invariant does not provide by itself: a minimum amount out, a maximum amount in, and a deadline. Those revert the transaction if the pool has moved, or if the transaction waits too long. They are user limits. They do not change k.

Concentrated liquidity

v2 liquidity is active at every price from zero to infinity. The concentrated-liquidity docs use a stablecoin pair as the motivating case: most trading happens near one price, so the rest of the curve is idle capital. v3 lets a provider choose a lower and upper price. The position earns fees only while the pool’s price is inside that range. Outside it, the position has been converted entirely into one of the two tokens and is no longer active.

The v3 whitepaper divides price into ticks. Tick i is the price 1.0001^i, so adjacent ticks are one basis point apart. The contracts store the square root of price as a Q64.96 fixed-point number. TickMath in v3-core states the bounds and the conversion:

int24 internal constant MIN_TICK = -887272;
int24 internal constant MAX_TICK = -MIN_TICK;
// getSqrtRatioAtTick returns sqrt(1.0001^tick) * 2^96

That excerpt is from contracts/libraries/TickMath.sol at commit d8b1c635c275d2a9450bd6a78f3fa2484fef73eb. Not every tick can be initialized. The pool has a tickSpacing, and only multiples of that spacing are valid boundaries. The whitepaper ties tighter spacing to lower fee tiers. Crossing an initialized tick during a swap costs gas, so a finer grid is more precise and more expensive to trade across.

Inside one range, the active liquidity L behaves like a constant-product curve that has been shifted so the real reserves run out at the range boundaries. The concentrated liquidity article writes that relationship without pretending a single NFT is a v2 LP token.

v3 positions are not fungible ERC-20 shares. The docs describe v3 positions as NFTs, and the v3 liquidity-management guide shows them handled as ERC-721 tokens through the NonfungiblePositionManager contract. Two positions in the same pool at different ranges are different claims. Fees accrue to the position and are collected; they are not continuously rebasing the NFT balance.

A v3 swap walks the current tick range, then crosses into the next initialized tick if the price limit allows it. The swap docs say the pool collects payment through uniswapV3SwapCallback, and that the swap enforces a price limit sqrtPriceLimitX96. This is the opposite order from a naive “transfer, then call” mental model: the pool tells the caller how much input to pay during the callback.

v4: same curve, different shell

The v4 architecture page says v4 keeps v3’s capital efficiency and adds hooks, a singleton, and flash accounting. All pools live in PoolManager. Creating a pool writes state instead of deploying a new pair contract. A multi-pool swap does not have to transfer the intermediate token; the manager records deltas and settles at the end. The docs call that flash accounting.

Hooks are optional. The hooks documentation says a pool with no hook uses the same concentrated-liquidity behavior as v3. If a hook is set, it is part of the pool key passed to initialize and cannot be added or swapped later. The hooks documentation lists callbacks around initialize, liquidity changes, swaps, and donate. The hook declares which of those it implements by flags in its address. The architecture page also describes custom accounting: a hook can charge a fee or opt out of the concentrated-liquidity curve. A hooked pool follows that curve only when its hook leaves the curve in place. The pool will call whatever code was hashed into the pool key. Balancer V3 takes a similar route with hooks on a shared Vault, and Euler attaches hooks to lending vaults.

The launch post dated 31 January 2025 says v4 was live on Ethereum, Polygon, Arbitrum, OP Mainnet, Base, BNB Chain, Blast, World Chain, Avalanche, and Zora. The Uniswap Foundation’s announcement of the same day lists twelve chains, adding Ink and Soneium to that list. Treat the chain list as time-specific. The architectural claims above are about the contract design, not about which deployment an interface routes through today.

v4 liquidity positions are still NFTs. PositionManager in v4-periphery inherits ERC721Permit_v4 and names the collection “Uniswap v4 Positions NFT”. The file comment says it mints and manages ERC-721 tokens associated with each position. That was the source on main as read on 26 November 2026. main can move. The how-it-works overview says instead that PositionManager uses ERC-6909 for internal accounting; the contract source is what this page follows for the position token. The v3 position contract is a different address, NonfungiblePositionManager, so a transfer of a v3 token id does not move a v4 position.

ERC-6909 is a different object on PoolManager. The ERC-6909 page says a caller can leave the underlying ERC-20 in the manager and receive a claim token, then burn that claim instead of transferring the ERC-20 on a later call. Liquidity managers can opt to receive capital as a claim. The claim is not the position NFT, and a mint of claim tokens is not proof that a tick range was opened.

What stays outside the pool

Routing and the interface are not the invariant. The launch post says the Uniswap Labs interface can route across UniswapX, v2, v3, and v4. A user-level swap can therefore touch several pool types, and an intent-based filler, in one trade. The pool that executes still checks its own accounting. The router’s split is a separate choice.

Protocol fees and the TokenJar

For most of Uniswap’s history the protocol fee was a switch that governance could turn on and had not. That changed with the UNIfication proposal, published by Uniswap Labs on 10 November 2025 and passed by governance in December 2025.

As proposed, fees roll out in stages. On v2 the LP fee drops from 0.30 percent to 0.25 percent and the 0.05 percent difference becomes a protocol fee. On v3 the protocol fee starts at one quarter of the LP fee for the 0.01 percent and 0.05 percent pools and one sixth for the 0.30 percent and 1 percent pools. Fees from each source go through an adapter into an immutable contract called the TokenJar. The only way to withdraw from it is another contract, the Firepit, and it requires UNI to be burned. The proposal also burned 100 million UNI from the treasury as a retroactive adjustment, set Uniswap Labs’ interface, wallet and API fees to zero, and approved a 20 million UNI annual growth budget.

Rollout then continued through separate votes. A February 2026 temp check described fees as running on v2 and a curated set of v3 pools on Ethereum mainnet and proposed extending them to eight more chains and to all v3 pools through a tier-based adapter. A proposal to activate v4 fees, Part 1 of 2, was executed on 27 July 2026 on the governance dashboard. The proposal text says protocol fees were by then live across all v2 and v3 pools on 11 chains, so the curated v3 list above no longer describes the rollout. It sets a fee adapter as the protocol fee controller on each chain’s pool manager, with fees applied to three pool families: pools with a static fee and no hooks, pools launched after a continuous clearing auction, and aggregator hook pools. Its stated examples map a 5 basis point LP fee to a 1.25 basis point protocol fee and a 25 basis point LP fee to 4. The first vote covered Ethereum, Arbitrum, Base, BNB Chain, Polygon, Optimism and Robinhood Chain, and left five further chains for a later proposal. The dashboard lists an expansion to Arc as executed on 5 October 2026.

Two consequences for a reader. The pool’s fee is no longer one number: an LP earns the pool fee minus the protocol share, and the share differs by version, tier and chain. And “does this pool pay a protocol fee?” is a question about the adapter and the chain, so read it from the pool or the governance record, not from a page like this one.

UniswapX and the router

UniswapX is not a pool. The swapper signs an order, which authorizes a token transfer through Permit2 as long as the amounts received match a price that decays over time, and fillers compete to execute it. Because the filler pays the gas, the order is gasless for the swapper. The auction types page describes the same model on every supported chain, a quote round followed by an exclusive Dutch auction. The best quoter gets a short exclusive window, about 24 seconds on Ethereum and a few seconds on the chains that count in blocks, and if that filler backs out the order falls into an open Dutch auction that anyone can fill. The realized price depends on when the first successful filler settles. A filler can route through Uniswap pools or any other liquidity.

The consequence for analysis is that a swap through the Uniswap interface can be settled by a pool, by several pools, or by a filler’s own inventory, and the on-chain pool never sees the order when a filler uses other liquidity. A pool’s volume is therefore not all of Uniswap’s trading.

Failure modes that are actually about the design

  • Divergence loss. A constant-product LP is left holding more of the asset that fell in price. Concentrating liquidity increases fee income when the price stays in range and increases inventory loss when it does not.
  • Out-of-range positions. A v3 or v4 position outside its ticks earns no fees until the price re-enters. The position is not “stuck” in both tokens; it is entirely one token.
  • Hook risk. A v4 pool’s custom code runs inside the swap path. The singleton does not make an arbitrary hook safe.
  • Price impact and stale transactions. The invariant will execute at the pool’s current price. Minimum-output checks exist so the user can refuse that price. They have to be set.

Uniswap does not price collateral or liquidate borrowers. A lending protocol that uses a pool price as an oracle is importing this spot price, which a trade can move. That dependency is discussed under oracles, not as a feature of the pair.

Versions in this overview

  • v2 (active) ERC-20 pairs with fungible LP tokens and a 0.30 percent pool fee. Still part of documented routing.
  • v3 (active) Concentrated liquidity between ticks, fee tiers, and NFT positions through NonfungiblePositionManager.
  • v4 (active) Singleton PoolManager, flash accounting, and optional hooks. Launched 31 January 2025. PositionManager mints an ERC-721. ERC-6909 claims are a separate settlement balance.

Common questions

What pricing rule does a Uniswap v2 pool use?

The protocol overview states it as x * y = k. After a swap, the product of the two reserves must not fall once the fee is taken into account. The spot price is the ratio of the reserves, and a trade that is large relative to the pool moves that ratio more. That movement is price impact, and it is part of the invariant, not a separate fee.

What happens to a Uniswap v3 or v4 position when the price leaves its range?

It earns no fees until the price re-enters. The position is not stuck in both tokens. It has been converted entirely into one of the two tokens and is inactive, not liquidated.

What does Uniswap v4 change compared with v3?

The architecture page says v4 keeps v3’s capital efficiency and adds hooks, a singleton, and flash accounting. All pools live in PoolManager, creating a pool writes state instead of deploying a pair contract, and a multi-pool swap records deltas and settles at the end instead of moving the intermediate token.

Are Uniswap’s core contracts upgradeable?

Uniswap’s own overview says the core contracts are not upgradeable. That is a different trust model from Aave’s proxy-based pool. A v4 hook is separate code that runs inside the swap path, and the singleton does not make an arbitrary hook safe.

Sources

Check the claims yourself: each group below is a different kind of evidence. Code and specifications show what the contracts do. Documentation shows what the protocol says they do.

Source code

Documentation

Whitepaper

Governance

Changes

  • : Cited the Arc fee proposal, noted that UniswapX uses one auction model across chains, and flagged a docs disagreement about v4 position tokens.
  • : Noted that protocol fees now cover all v2 and v3 pools on 11 chains, and added the UniswapX auction-types page to back the Ethereum exclusivity window.
  • : Replaced the vague protocol-fee note with the UNIfication fee switch, the TokenJar and Firepit, and the v4 fee activation, and added how UniswapX orders are filled.
  • : Moved the cited documentation to its new developers.uniswap.org pages, sourced the v3 position NFT claim to the v3 liquidity-management guide, and sourced the twelve-chain v4 launch list to the Uniswap Foundation.

Every change to the publication is listed on What changed.

Keep reading

See something wrong or missing? Propose a change via pull request (src/content/protocols/uniswap.md) or report a correction. See how to contribute.