Uniswap

On this page 7

Uniswap is a decentralized exchange protocol that lets anyone swap tokens directly from a wallet through smart contracts on Ethereum and compatible networks, without an order book, a broker or a custodian. In DeFi, it is the best-known implementation of the automated market maker model, where prices come from a formula applied to pooled reserves rather than from matched buy and sell orders.

The protocol has no account registration and no listing approval: any pair of tokens can receive a pool, and any participant can supply liquidity and earn trading fees. This permissionless design made Uniswap a core building block of decentralized finance, but it also exposes traders and liquidity providers to risks that differ sharply from those of a centralized exchange.

How Uniswap prices a swap

Uniswap prices a swap by applying a pricing invariant to the token reserves held in a pool. In the classic design, the pool keeps the product of its two reserves constant, expressed as x · y = k. When a trader adds token A to the pool and withdraws token B, the ratio of reserves shifts and the price of token B rises for the next trade.

Because each trade moves the reserves, a larger order relative to pool depth receives a worse average price. This effect is called price impact, and the difference between the quoted and the executed price is slippage. Traders set a slippage tolerance, and the contract reverts the transaction if the final price falls outside it.

Every swap pays a trading fee that stays in the pool and accrues to liquidity providers. Arbitrageurs keep pool prices aligned with external markets: when a pool price drifts, they trade against it until the gap is closed, which is the main price discovery mechanism of the protocol.

The table below summarizes the components that participate in a single swap.

ComponentRoleWho controls it
Pool contractHolds reserves and enforces the invariantImmutable code
Router contractFinds a path across pools and checks limitsImmutable code
Trader walletSigns the transaction and pays gasThe trader
Liquidity providerSupplies reserves and earns feesAny participant
ArbitrageurAligns pool prices with other marketsIndependent bots and traders
Components involved in a Uniswap swap

Protocol versions and their design choices

Uniswap has evolved through several versions, each deployed as separate, non-upgradeable contracts, so older versions continue to operate alongside newer ones. Each version changed how liquidity is represented and how efficiently capital is used.

The most significant shift came with concentrated liquidity in version 3, which lets providers place capital within a chosen price range. Within that range, the same capital supports far deeper trading than a full-range position, but it stops earning fees once the price leaves the range.

VersionKey innovationLiquidity positionPractical effect
Version 1Pools paired only with ETHFungible shareSimple but required two hops for most pairs
Version 2Direct token-to-token pools and price oraclesFungible ERC-20 shareBroad pair coverage, uniform liquidity
Version 3Concentrated liquidity and multiple fee tiersNon-fungible positionHigher capital efficiency, active management
Version 4Single contract for all pools and custom hooksPosition within a shared contractLower gas costs and programmable pool logic
Main Uniswap versions compared

Version 3 introduced fee tiers, commonly 0.01%, 0.05%, 0.30% and 1.00%, so that stable pairs can trade cheaply while volatile pairs compensate providers for higher risk. Version 4 adds hooks, which are external contracts that run custom logic at defined points of a pool’s lifecycle, such as dynamic fees or on-chain limit orders.

Uniswap compared with other trading venues

Uniswap differs from a centralized exchange mainly in custody, settlement and price formation. A user keeps control of funds until the moment of the swap, and settlement is atomic on-chain, meaning the transaction either completes fully or not at all.

FeatureUniswapCentralized exchangeOrder-book DEX
CustodyUser walletExchange holds fundsUser wallet
Price formationPool formula and arbitrageMatched limit ordersMatched limit orders on-chain
ListingPermissionlessExchange approvalUsually permissionless
Identity checksNone at protocol levelTypically requiredNone at protocol level
Main costPool fee plus gasTrading feeFee plus gas or relayer cost
Uniswap versus other venues

Other automated market makers apply different curves. Some specialize in stablecoin swaps with a flatter curve near parity, while others support weighted pools with more than two assets. Uniswap remains the reference design against which most of these variants are measured.

Providing liquidity and governance

A liquidity provider deposits both tokens of a pair and receives a claim on a proportional share of the reserves and fees. The provider earns income from trading volume but carries impermanent loss, the shortfall compared with simply holding the tokens when their relative price changes.

Concentrated positions magnify both outcomes. A narrow range earns more fees per unit of capital while the price stays inside it, but suffers larger relative loss and needs frequent rebalancing. The decision table below shows typical strategies.

SituationTypical range choiceReason
Stablecoin pair near parityVery narrow rangePrice rarely moves, so capital stays productive
Major volatile pairModerate range with monitoringBalances fee income against rebalancing
Passive providerFull or wide rangeAvoids leaving the range and manual work
New or illiquid tokenWide range or avoidHigh volatility and potential manipulation
Choosing a liquidity strategy

Protocol governance runs through the UNI governance token. Holders, or the delegates they choose, vote on proposals affecting treasury funds, deployments to new networks and the protocol fee switch, which can redirect a portion of pool fees away from providers. Governance cannot alter deployed pool contracts, which limits its power over existing liquidity.

Risks, limitations and common mistakes

Uniswap removes counterparty custody risk but introduces smart contract, market and user-interface risks. Public transactions wait in a visible mempool before inclusion, which enables maximal extractable value strategies such as sandwich attacks that worsen a trader’s price.

ProblemCauseMitigation
Buying a counterfeit tokenAnyone can create a pool for any contractVerify the token contract address
Sandwich attackHigh slippage tolerance in a public mempoolUse a tight tolerance or private routing
Large price impactOrder too big for pool depthSplit the order or use an aggregator
Unexpected loss as a providerImpermanent loss exceeds fee incomeModel scenarios before depositing
Lingering token approvalsUnlimited allowances granted to contractsGrant limited approvals and revoke unused ones
Frequent problems and how to address them

A common misconception is that open-source code means safe tokens. The protocol itself has a strong security record, yet it does not vet the assets traded through it. Regulatory treatment of the interface, of token listings and of liquidity income also varies by jurisdiction and remains an unsettled legal area.

Understanding it simply

Imagine a currency exchange booth with no staff. Instead of a clerk, there is a large jar of two currencies and a fixed rule that sets the rate. When you put one currency in and take the other out, the jar becomes lopsided, so the rule automatically makes the next exchange a little more expensive in the same direction.

People who fill the jar earn a small fee from every exchange. Uniswap is that booth built from software on a blockchain. The rule sets the price, not a person, and anyone can use it or help fill it, which is both its main strength and its main source of risk.

Applied in practice

A small online retailer that accepts stablecoin payments wants to convert part of its weekly receipts into ETH to cover network fees. The finance manager connects a company wallet to the Uniswap interface on a lower-cost Ethereum layer-2 network and swaps about 5,000 units of a dollar stablecoin through a 0.05% fee pool.

Before signing, the manager checks the quoted price impact, which is below 0.1% because the pool is deep, and sets a slippage tolerance of 0.5%. The swap settles in a single transaction within seconds, and the network fee costs a few cents. Total cost, including the pool fee, is about 2.5 units of stablecoin.

The outcome is a fast, self-custodied conversion with no exchange account and no withdrawal delay. The company records the transaction hash for accounting and revokes the token approval afterward, a simple habit that limits exposure if the interface or a contract is ever compromised.