LLMs.txt: agent-readable Markdown index of this site at /llms.txt
This page documents Uniswap v3. See Uniswap v4 for the current version.

Uniswap v3 Architecture

Understand Uniswap v3 architecture, including core contracts, factory design, and pool interaction patterns.

Uniswap v3 is a binary smart contract system comprised of many libraries, which together make the Core and Periphery.

Core contracts provide fundamental safety guarantees for all parties interacting with Uniswap. They define the logic of pool generation, the pools themselves, and the interactions involving the respective assets therein.

Periphery contracts interact with one or more Core contracts but are not part of the core. They are designed to provide methods of interacting with the core that increase clarity and user safety.

External calls will primarily call the periphery interfaces. Externally available functions are all viewable in the reference documentation. Internal functions are viewable on the Uniswap v3 GitHub repo.

Core

The core consists of a single factory, a pool deployer, and the many pools the factory will create.

A significant amount of care and attention has been given to gas optimization in the core contracts. The result is a substantial reduction in gas costs for all protocol interactions compared to v2, at the cost of a reduction in code clarity.

Source Code

Factory

The factory defines the logic for generating pools. A pool is defined by two tokens, which make up the asset pair, and a fee. There can be multiple pools of the same asset pair, distinguished only by their swap fee.

Source code: UniswapV3Factory.sol

Pools

Pools primarily serve as automated market makers for the paired assets. Additionally, they expose price oracle data and may be used as an asset source for flash transactions.

Source code: UniswapV3Pool.sol

Core libraries

The pool contract delegates most of its arithmetic to a set of libraries. They are the contracts a v3 integration reads most often when reasoning about ticks, prices and liquidity, and each one is small enough to read end to end.

LibraryWhat it does
TickMathComputes sqrt prices from ticks and vice versa, for ticks of size 1.0001
SqrtPriceMathPrice and amount functions based on Q64.96 sqrt price and liquidity
SwapMathComputes the result of a swap within a single tick
FullMath512-bit multiply and divide without loss of precision
LiquidityMathAdds a signed liquidity delta to liquidity
TickBitmapPacked record of which ticks are initialized
TickPer-tick state, including liquidity and fee growth
PositionPer-position state, keyed by owner and tick range

Alongside these sit the numeric helpers the pool uses internally: BitMath, FixedPoint96, FixedPoint128, LowGasSafeMath, SafeCast, UnsafeMath and TransferHelper.

Every library carries natspec on each function, so the source is the reference.

Source code: libraries/

Periphery

The periphery is a constellation of smart contracts designed to support domain-specific interactions with the core. As the Uniswap protocol is a permissionless system, the contracts described below have no special privileges and are only a small subset of possible periphery-like contracts.

SwapRouter

The swap router supports all the basic requirements of a front-end offering trading. It natively supports single trades (x to y) and multihop trades (e.g. x to y to z).

Source code: SwapRouter.sol

Nonfungible Position Manager

The position manager handles the logic transactions involving the creation, adjustment, or exiting of positions.

Oracle

The oracle provides price and liquidity data useful for a wide variety of system designs, and is available in every deployed pool.

Source code: Oracle.sol

Periphery libraries

The libraries provide a variety of helper functions developers may need, like calculating pool addresses, safe transfer functions, and more.

Source code: libraries/