Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explains Uniswap by translating and expanding on its official documentation.
The official documentation is available below.
Uniswap overview
The Uniswap ecosystem consists of several components.
Uniswap Labs
The company that developed the Uniswap protocol and its web interface. Uniswap Labs develops the Uniswap protocol as a whole.
Uniswap protocol
The Uniswap protocol consists of persistent, non-upgradeable smart contracts. These contracts create automated market makers that allow users to exchange tokens and engage in market making. This takes place on the Ethereum blockchain.
Uniswap interface: The Uniswap interface is a web-based tool for interacting conveniently with the protocol. Through this interface, users can swap tokens and provide liquidity. However, it is only one way to interact with the Uniswap protocol. Other methods are also available.
Uniswap governance: A governance system for the Uniswap protocol enabled by the UNI token. Users can participate in governing the protocol using UNI tokens.
These components form part of the Uniswap ecosystem and play important roles in understanding and using the protocol. As engineers, understanding the Uniswap protocol and its related components can help us contribute to blockchain development and trading.
Uniswap protocol
Introduction
The Uniswap protocol provides a mechanism for exchanging cryptocurrencies (ERC20 tokens) on the Ethereum blockchain. It uses a peer-to-peer system designed to allow users to exchange tokens directly.
See the following resource for more about ERC20.
The protocol consists of persistent, non-upgradeable smart contracts. Once deployed, these contracts cannot be changed, a property that contributes to censorship resistance and security. The protocol also follows the principle of self-custody, allowing users to manage and trade their own tokens.
The protocol emphasizes operating without reliance on trusted intermediaries. This removes restrictions imposed by intermediaries that might limit access and provides an open trading environment.
At the time of writing, the Uniswap protocol has three versions. V1 and V2 are open source and distributed under the GPL. V3 is also open source, with some modifications. All versions remain functional for as long as the Ethereum blockchain continues to exist.
The protocol provides a means for users to exchange tokens directly while emphasizing important properties such as security and self-custody. The Uniswap protocol is widely used as a blockchain-based mechanism for secure and reliable token exchange.
Comparing the Uniswap protocol with traditional markets
Two perspectives help explain how the Uniswap protocol differs from traditional markets. The first is how the automated market maker (AMM) design differs from conventional centralized order-book exchanges. The second is how permissionless access differs from permissioned systems.
Order books versus AMMs
Traditional markets commonly use a centralized order-book model. Buyers and sellers submit orders at different prices, and trades proceed according to supply and demand. This resembles the order-book system used when trading stocks through a brokerage.
The Uniswap protocol uses an automated market maker (AMM) approach. It uses a liquidity pool containing two assets instead of an order book. Swapping one asset for the other changes their relative prices and establishes a new market price. Buyers and sellers trade directly against the pool rather than waiting for a matching order. Research continues into the differences, advantages, and disadvantages of AMMs and traditional order books.
Permissionless systems
The following sections examine the Uniswap protocol's permissionless and immutable design in more detail.
Permissionless design
Unlike traditional financial markets, the Uniswap protocol adopts a permissionless design. This means anyone can freely use the protocol's services. Access is not reserved for a limited group of people or organizations. For example, anyone can swap tokens, provide liquidity, or create new trading pairs. Traditional financial services often restrict access based on location, wealth, age, and other factors, whereas the Uniswap protocol offers an open environment in which anyone can participate.
Immutable design
The Uniswap protocol is designed to be immutable. Once deployed, the protocol cannot be upgraded. No one can pause the contracts, undo executed trades, or change the protocol's behavior. This design aims to ensure stability and reliability, allowing everyone to use the protocol under the same conditions without changing its operation.
Uniswap Governance has the authority to allocate a portion of swap fees to a specified address, but this power is known in advance to participants and the proportion is constrained to the range from 10% to 25%.
This establishes a mechanism for managing protocol changes appropriately and preventing abuse.
The permissionless and immutable design of the Uniswap protocol supports a future in which everyone can access financial services on equal terms.
Further reading
Finding more information
See Uniswap's research page for information about AMM economics, game theory, and optimization research. It provides research on a variety of topics. These resources help readers understand the theories and mechanisms underlying the Uniswap protocol.
New features in V3
V3 of the Uniswap protocol introduces features that extend and refine the AMM design. See the V3 concepts page for more details. It covers the concepts and features introduced in V3. These resources help deepen understanding of the protocol as described at the time of writing.
Through these sources, readers can learn about various aspects and concepts of the Uniswap protocol in depth. A better understanding of the protocol can support related development and trading.
Protocol concepts
Concentrated liquidity
Introduction
A notable idea introduced by Uniswap v3 is concentrated liquidity.
It allows liquidity to be concentrated within a specified price range.
In previous versions, liquidity was distributed uniformly along the price curve from 0 to infinity.
This uniform distribution enabled trading across the entire price range (0, ∞) without exhausting liquidity. However, much of the liquidity in many pools was rarely used.
For example, in a stablecoin pair, the relative prices of the two assets are nearly constant.
Liquidity outside the usual price range was rarely used.
In the v2 DAI/USDC pair, for instance, only about 0.50% of the total capital was used for trading within $0.99 to $1.01, the range with the most trading activity and fee-earning opportunities for LPs (liquidity providers).
In v3, liquidity providers can concentrate their capital within a price range narrower than (0, ∞).
For a stablecoin/stablecoin pair, for example, LPs can concentrate their capital between $0.99 and $1.01.
This provides traders with deeper liquidity around the midpoint price and allows LPs to use their capital to earn more trading fees.
Liquidity allocated to such a narrow price range is called a position.
An LP can hold multiple positions in a single pool, creating a distinct liquidity curve according to the LP's preferences.
Active liquidity
The following points help explain active liquidity.
1. Price ranges and positions
In Uniswap v3, liquidity providers (LPs) can concentrate liquidity within particular price ranges. In other words, an LP can specify a price range and allocate liquidity within it. This is called a position.
2. Price movements and active liquidity
Asset prices constantly fluctuate. If the price moves outside the range specified by the LP, the position's liquidity becomes inactive and no longer earns trading fees for trades outside that range.
3. Position adjustments and earning fees
When the asset price returns to a position's price range, its liquidity becomes active again. The LP can then resume earning trading fees within that range.
4. Flexible position creation
LPs can create multiple positions. Each position can specify a different price range. This allows liquidity to be adjusted according to market conditions and the LP's strategy.
Concentrated liquidity allows the market to allocate liquidity across price ranges and find an appropriate distribution organically. The mechanism allows LPs to earn fees more effectively while providing market participants with deep liquidity.
Ticks
Ticks are boundaries that partition the price space to enable the concentrated liquidity mechanism characteristic of Uniswap v3.
Ticks in price space mark discrete price boundaries.
The price space is divided into regular intervals, with a one-tick movement representing a 0.01% change in price.
The figures are reproduced from the original Japanese article; any Japanese labels are retained.

The bar-like elements shown above are ticks. They represent specific price points and appear as groups of bars.

The magnified view may make the concept clearer.
The figure shows a slight difference in price over the range from 435 to 440.
Ticks serve as boundaries for liquidity positions. When creating a position, the provider must select its upper and lower ticks.
When a swap occurs, the pool contract uses liquidity available for trading within the current tick interval. This exchanges the outgoing asset for the incoming asset. Specifically, the pool's liquidity is used to sell one token and acquire another.
When the next tick is reached, the pool contract moves to the new tick. This transition activates liquidity that was inactive at the previous tick, with the new tick acting as a position boundary. Liquidity is therefore used efficiently across price ranges, allowing swaps to proceed continuously.
Each pool has the same total number of ticks, but only some ticks are active. Because of the design of the Uniswap v3 smart contracts, tick spacing is directly related to the swap fee. Lower fee tiers have more closely spaced active ticks, while higher fee tiers have relatively wider spacing.
Inactive ticks do not affect transaction costs during a swap, but crossing an active tick increases transaction costs as liquidity in positions bounded by that tick is activated.
For pairs requiring efficient liquidity, particularly stablecoin pairs, tighter tick spacing can reduce price impact during swaps. This increases the possibility of executing stablecoin swaps at better prices.
See the whitepaper for details about the relationship between tick spacing and fee tiers.
Fees
Swap fees
When a token swap occurs, swap fees are distributed in proportion to liquidity within the price range in which the swap takes place. In other words, fees are distributed according to the amount of tokens provided to the liquidity pool and their price ranges.
If the spot price moves outside a position's price range, liquidity associated with that position becomes inactive, and the position does not earn fees from swaps outside that range. When the spot price returns to the range, the position becomes active again and resumes earning swap fees.
Swap fees were automatically reinvested in previous versions of Uniswap, but this changed in Uniswap v3. Swap fees accumulate separately from liquidity in the pool, and position owners need to collect them manually. This change allows liquidity providers more flexibility in deciding how to use their fees.
Pool fees
Uniswap v3 introduces multiple pools with different swap fees for each token pair.
Liquidity providers can initially create pools with three fee tiers (0.05%, 0.30%, and 1%).
Additional fee tiers may also be introduced through UNI governance.
A governance proposal in November 2021 introduced the 0.01% fee tier.
Previously, aligning incentives through different fee options was difficult, and splitting pairs into separate pools was not practical. Such a split fragmented liquidity, reducing liquidity per pair and increasing price impact during swaps.
In earlier Uniswap versions, aligning liquidity provider and trader incentives by offering different swap fees was difficult.
For example, liquidity providers selecting a 1% fee would earn more revenue, while traders would pay higher fees.
This made it difficult to balance the interests of liquidity providers and traders.
Uniswap v3 manages liquidity and designs liquidity pools differently from earlier versions.
The new approach makes it possible to create multiple pools with different fee tiers.
For example, pools can be created at fee tiers of 0.05%, 0.30%, and 1%.
This enables liquidity to be provided more appropriately for each asset. Previously, introducing different fee tiers into a pool was difficult, making it difficult to provide suitable liquidity across assets. Concentrated liquidity makes it possible to create multiple pools with different fee tiers, allowing trades to occur at different fees in each pool.
This approach enables pool designs that balance the interests of liquidity providers and traders. Liquidity providers can earn fees appropriate to their assets by selecting a suitable fee-tier pool, while traders can select different fee tiers to suit their trading needs.
This pool design addresses the earlier problem and provides a more flexible and efficient trading environment for both traders and liquidity providers.
Concentrated liquidity decouples total liquidity from price impact.
This makes splitting a token pair across multiple pools feasible.
It also offers more suitable pools for assets that were poorly served by the previous 0.30% swap fee.
Finding an appropriate pool fee
Different asset types, such as stablecoins and exotic assets, tend to converge on fee tiers suited to their characteristics and market conditions. Swappers and liquidity providers have different objectives and incentives, so selecting a suitable fee tier is important.
1. Fee tiers for low-volatility assets
Assets with low volatility, such as stablecoins, have lower price risk, so liquidity providers are likely to concentrate at the lowest fee tier. Swappers are also likely to select this tier to obtain an execution price as close to 1:1 as possible.
2. Fee tiers for exotic or infrequently traded assets
Conversely, liquidity providers for exotic or infrequently traded assets may prefer higher fee tiers to offset the costs and risks of holding them.
Different asset types therefore tend to converge on appropriate fee tiers depending on their characteristics and trading frequency. This creates balanced incentives for both swappers and liquidity providers and supports the operation of the pools.
Exotic assets The term refers to financial products or assets that trade relatively infrequently on conventional financial markets or exchanges and have characteristics or risks different from ordinary assets. These assets may behave differently from ordinary stocks, bonds, and currencies and may have low market liquidity. Exotic assets may offer investors and traders new opportunities and risks, but may also exhibit greater price volatility and risk.
Examples of exotic assets include the following.
- Derivatives
- Derivative products tied to underlying assets, such as options, futures, and swaps.
- Quantitative investment products
- Products designed using mathematical models or algorithms.
- Leveraged ETFs (exchange-traded funds)
- ETFs that use leverage to pursue returns exceeding the movements of an underlying index.
- Illiquid assets
- Highly illiquid assets that are difficult to trade or subject to trading restrictions.
Exotic assets may require specialized knowledge and risk management, so investors and traders should evaluate them carefully and conduct appropriate research.
Protocol fees
Uniswap v3 has a mechanism known as the protocol fee. This fee can be enabled through UNI governance. Compared with Uniswap v2, Uniswap v3 gives UNI governance more flexibility in selecting the share of swap fees allocated to the protocol. Specifically, governance can adjust the proportion of trading fees directed to the protocol. See the whitepaper for details.
Oracles
If you are unfamiliar with the concept of an oracle, start with the Ethereum Foundation's overview of oracles.
An oracle is a mechanism for providing real-world data and information to smart contracts executing on a blockchain. Because a blockchain operates within a closed environment, accessing external data directly is difficult. Oracles allow data from outside the blockchain to be incorporated. For example, an oracle is used to incorporate real-world data such as weather information or stock prices into a smart contract. Oracles play an important role that requires reliability and accurate data.
All Uniswap v3 pools can act as oracles, providing access to historical price and liquidity data. This enables a variety of onchain use cases.
Historical data is stored in an array of observations.
Initially, each pool records only one observation and updates that data as blocks progress.
Consequently, the period of historical data accessible to users is limited.
By paying transaction fees, however, users can increase the number of observations tracked, up to 65535.
This can extend the available data history to approximately nine days or more.
Storing historical price and liquidity data directly in pool contracts substantially reduces the likelihood of logic errors in calling contracts and lowers integration costs because those contracts do not need to maintain their own history. Because the maximum amount of data that can be recorded is sufficiently large, calling smart contracts can calculate weighted averages over arbitrary available time intervals at relatively low cost. This makes manipulating oracle prices more difficult.
Specifically, maintaining price and liquidity history directly within the pool makes it easy to calculate the average price for a particular period. The stored data is not simply a sequence of numbers; it is maintained in a form supporting time-weighted averages. Calling contracts can use this data within the pool to determine price changes over a particular time interval.
This capability makes oracle price manipulation more difficult. Because a calling contract can easily calculate an accurate weighted average, improper price manipulation or a lack of transparency in operations is more likely to be detected. This helps provide secure and reliable oracle data.
Observations
Observation has the following form.
struct Observation {
// the block timestamp of the observation
uint32 blockTimestamp;
// the tick accumulator, i.e. tick * time elapsed since the pool was first initialized
int56 tickCumulative;
// the seconds per liquidity, i.e. seconds elapsed / max(1, liquidity) since the pool was first initialized
uint160 secondsPerLiquidityCumulativeX128;
// whether or not the observation is initialized
bool initialized;
}Observation is a struct that stores information about a pool at a particular point in time.
blockTimestamp- The block timestamp of the observation.
- The timestamp of the block in which the observation was recorded.
tickCumulative- Also known as the tick accumulator, this value relates to ticks and elapsed time.
- A tick is an indicator of price; this field represents the accumulated tick value over the time elapsed since the pool was first initialized.
secondsPerLiquidityCumulativeX128- A value representing elapsed time per unit of liquidity.
- The elapsed time since the pool was first initialized is divided by a maximum value, and liquidity affects the result when it is at least
1. - The original explanation describes the representation as multiplying this value by 128.
initialized- A boolean indicating whether the observation has been initialized.
- It is set to
truewhen the observation is first created.
In v3 pools, observations can be retrieved using the observations method.
However, this is not the recommended way to use oracle data.
Use observe instead.
When calling observe, the caller must provide an array containing numbers of seconds in the past.
The array specifies how far back in time each requested observation should be.
Each specified time must be at or after the oldest stored observation.
If a specified time does not exactly match the block in which an observation was recorded, the method automatically adjusts the observation.
This eliminates the need for manual interpolation.
For this reason, observe is recommended over observations.
The oracle updates at most once per block, so calling observe with a seconds-ago value of 0 returns the most recently written observation.
This observation is from the beginning of the current block or an earlier time.
Tick accumulator
The tick accumulator records the cumulative total of active ticks at particular points in time. The original explanation describes this value as gradually increasing each second according to the current tick.
To calculate the average tick over a given period, the caller retrieves two observations, calculates the difference between their values, and divides it by the elapsed time between them.
The following example illustrates the steps for calculating an average tick over a given period.
Consider a Uniswap v3 pool tracking the price of a currency pair. Suppose we want to calculate the average tick over a 24-hour period.
-
Retrieve observations First, retrieve two observations: one from 24 hours ago and one from the present. This allows price movements over the specified period to be analyzed.
-
Calculate the difference Subtract the two observed values to calculate the change. For example, if the observation from 24 hours ago is
100and the current observation is120, the difference is20. -
Calculate the elapsed time Calculate the elapsed time within the 24-hour period. This makes it possible to evaluate the speed and rate of the change. For example, 24 hours equals
1,440minutes or86,400seconds. -
Calculate the average tick Divide the difference by the elapsed time to calculate the average tick over the period. For example, if the difference is
20and the elapsed time is86,400seconds, the average tick is20 / 86,400 ≈ 0.00023.
This is how the average tick over a particular period is calculated. Uniswap v3 uses this method to take advantage of the tick accumulator and evaluate price movements.
The whitepaper also describes how to calculate the TWAP (Time-Weighted Average Price) using the tick accumulator. Note that deriving a price from the arithmetic mean tick corresponds to a geometric mean price.
Geometric and arithmetic means are different methods for calculating averages in statistics and mathematics. They are used in particular to calculate prices and indices in financial markets and economics.
- Arithmetic mean The arithmetic mean is calculated by summing a set of numbers and dividing by the number of values. It is represented by the following formula.
Arithmetic mean = (value1 + value2 + ... + valueN) / nThe arithmetic mean averages the sum of individual values and is the familiar ordinary average. The geometric mean, on the other hand, is sometimes used for price data.
- Geometric mean The geometric mean is calculated by multiplying all values in a set and taking the nth root, where n is the number of values. It is represented by the following formula.
Geometric mean = (value1 * value2 * ... * valueN)^(1/n)The geometric mean is especially useful when considering ratios or multipliers. Financial markets sometimes use it to reflect changes in prices and indices accurately. Because price changes are calculated on an equivalent proportional basis, investors and traders can better understand actual market movements.
Uniswap v3 uses the tick accumulator to compute an average tick and the geometric mean when converting it into a price, providing a more appropriate representation of price data. This approach enables interpretation that accounts for price fluctuations and helps readers understand and forecast prices in financial markets.
See OracleLibrary for a concrete example of how to use the tick accumulator.
The tick accumulator is thus a key component of the Uniswap v3 oracle and a means of making effective use of price and liquidity data.
Liquidity accumulator
The liquidity accumulator tracks changes in liquidity within a Uniswap v3 pool.
Specifically, the liquidity accumulator records seconds divided by the amount of in-range liquidity at the observation time. This value reflects the amount of liquidity in the pool and its effective range. The liquidity accumulator increases monotonically over time, adding seconds divided by the amount of in-range liquidity each second.
To derive the harmonic mean liquidity over a given period, the caller retrieves two observations and calculates the difference between their values. The elapsed time is then divided by this difference to calculate the harmonic mean liquidity. This method enables evaluation of liquidity changes over a particular period. The whitepaper explains in detail how to calculate TWAL (Time-Weighted Average Liquidity) using this method.
This method helps evaluate changes in liquidity within a Uniswap v3 pool and assess suitable trading times and conditions.
Suppose, for example, the liquidity accumulator of a Uniswap v3 pool increases as follows (time in seconds).
- After 100 seconds:
5000 - After 200 seconds:
7000 - After 300 seconds:
10000
Suppose we want to calculate the harmonic mean liquidity over a specific period, such as from 100 to 300 seconds.
The increase in the liquidity accumulator over this period is 10000 - 5000 = 5000.
The elapsed time is 300 seconds - 100 seconds = 200 seconds.
The original worked example divides the increase (5000) by the elapsed time (200 seconds) to calculate the harmonic mean liquidity.
Harmonic mean liquidity = 5000 / 200 = 25The example presents this value as the harmonic mean liquidity over the specified period. The value can be used to evaluate changes in liquidity within a Uniswap v3 pool. This evaluation helps assess liquidity conditions and changes in demand during particular periods, and informs trading strategies.
In this way, the liquidity accumulator and harmonic mean liquidity allow changes in liquidity within a Uniswap v3 pool to be evaluated quantitatively.
A larger harmonic mean liquidity indicates higher average liquidity during the period. Specifically, the harmonic mean takes the mean of the reciprocals of individual values; the presence of large liquidity values increases the resulting mean.
The original explanation describes the harmonic mean as more sensitive to larger individual values. In other words, it claims that increases in values during periods of high liquidity have a substantial effect on the mean. On this basis, a large harmonic mean liquidity is described as suggesting relatively stable and high liquidity during the period.
Conversely, a low harmonic mean liquidity may indicate low liquidity or substantial fluctuations during the period. Harmonic mean liquidity is used as an indicator when evaluating liquidity changes within a pool.
In summary, the original explanation interprets larger harmonic mean liquidity as indicating higher average liquidity and relatively small changes in price or demand over the period. Smaller values may indicate low liquidity or greater fluctuations.
⚠️ Caution
The in-range liquidity accumulator must be used carefully.
The current tick and current in-range liquidity may be entirely uncorrelated, so taking a pool's arithmetic mean tick and harmonic mean liquidity over the same interval can misrepresent its characteristics relative to another pool.
For example, suppose pool A's current tick is 0 for 5 seconds and 100 for another 5 seconds. The original example describes the tick accumulator value as 50.
If in-range liquidity over these periods is 5000 and 50, the harmonic mean liquidity is approximately 99.
Now consider pool B containing the same assets, with a tick of 50 and in-range liquidity of approximately 99.
The accumulator values are equivalent, but the underlying behavior is very different.
In other words, the same accumulator values can represent pools with different characteristics. When changes in the current tick and in-range liquidity are uncorrelated, comparing pools solely through their accumulator values may be inaccurate.
Deriving a price from a tick
The active tick is the lower tick closest to the pool's current price. When a pool is created, each token is assigned as token0 or token1. This establishes a fixed token ordering for relative valuation and pool logic. Whether a token is token0 or token1 is unrelated to its value.
When deriving an asset price, it is important to determine how the price of token0 (e.g., WETH) is expressed in terms of token1 (e.g., USDC). A concrete method is to use the tick price derived from the tick.
Consider deriving a price for a WETH / USDC pool.
Suppose tickCumulative has the values [70,000, 1,070,000] and the elapsed time between observations is 10 seconds.
First, calculate the difference between accumulator values (1,070,000 - 70,000 = 1,000,000) and divide it by the elapsed time to obtain the average tick (1,000,000 / 10 = 100,000).
Use this tick value to convert between the price of token1 (USDC) and token0 (WETH).
Formula: p(i) = 1.0001**i(See section 6.1 of the whitepaper.) Use this formula for the calculation.
1.0001**100,000 ≅ 22015.5 USDC / WETHBecause ticks are signed integers, note that a negative tick can be returned when the relative value of token0 and token1 is reversed. This method can derive prices between different tokens within a pool.
However, when interpreting tick prices and the method used to derive them, consider the relationship between the active tick and in-range liquidity. As discussed above, comparisons between pools may otherwise be misleading.
Oracles on layer 2 rollups
Optimism
Optimism is an Ethereum scaling solution designed to process transactions quickly.
As described at the time of writing, each transaction on Optimism is treated as an individual block.
The important point is that the block.timestamp (block timestamp) of these blocks is based on the time at which the Sequencer last incorporated them into an L1 (Ethereum mainchain) block.
Because this can introduce a substantial delay, the timestamp of a block on Optimism may differ from the time when the transaction actually occurred.
Optimism is an Ethereum scaling solution designed to process transactions quickly.
As described at the time of writing, each transaction on Optimism is treated as an individual block.
The important point is that the block.timestamp (block timestamp) of these blocks is based on the time at which the Sequencer last incorporated them into an L1 (Ethereum mainchain) block.
Because this can introduce a substantial delay, the timestamp of a block on Optimism may differ from the time when the transaction actually occurred.
This timestamp delay may cause problems when providing oracle prices. Oracle prices must be accurate and reliable; deriving prices from delayed timestamps could make malicious price manipulation easier.
Future updates to Optimism block timestamps may provide greater precision and improve oracle pricing. Forced transaction inclusion may also improve oracle security. Under the conditions described at the time of writing, however, providing oracle prices on Optimism was considered unsuitable.
Range orders
In Uniswap V3, customizable liquidity positions and single-sided token deposits enable a new automated market maker (AMM) trading strategy known as range orders.
Single-sided liquidity provision
This refers to providing only one of the two tokens to a liquidity pool.
Conventional AMMs required users to supply both token A and token B to a liquidity pool. However, single-sided liquidity provision in Uniswap V3 allows users to supply only the token they already hold. As the price moves through the supplied token's price range, the position is automatically converted into the other token.
For example, a user who holds ETH can supply only ETH to a customizable liquidity position in Uniswap V3. The protocol converts the position into the corresponding token as the price moves through the configured range. This allows users to provide liquidity using only their existing tokens, enabling more flexible trading strategies.
In a conventional order-book market, anyone can easily place a limit order. It is an order to buy or sell an asset at a specified price, with the expectation that the order will execute at some future point.
In Uniswap V3, providing a single asset as liquidity within a specified price range produces behavior similar to a limit order. A range order is likewise placed with the expectation that it will execute at some point in the future. Once the spot price crosses the order's range, the target asset can be withdrawn.
Conventional markets may charge fees for limit orders, whereas Uniswap V3 range-order makers earn fees as their orders execute. This is because a range order is a form of liquidity provision rather than an ordinary swap.
Possible range-order strategies
The AMM design can reproduce some styles of limit orders, but not others. The following four examples illustrate range orders and their conventional order counterparts. The first two can be reproduced, whereas the latter two cannot.
One important difference is that, unlike a conventional limit order, a range order can become unfilled again if the spot price crosses the specified price range and then reverses, crossing back through it. During this period, the liquidity provider earns LP fees. However, if the goal is to exit entirely in a particular target asset, the position must be monitored and liquidity manually removed once the order fills, or a third-party position manager must withdraw it on the provider's behalf.
In short, a range order may become unfilled again when the price crosses the specified range and then moves in the opposite direction. The provider can earn LP fees during this period, but anyone seeking to exit entirely in the target asset needs to monitor the order, remove liquidity manually after it fills, or use a third-party position management service to withdraw it.
Understanding this distinction makes it possible to use different order types in automated market makers effectively.
Sell limit order
A take-profit order executes automatically when a specified price is reached. For example, suppose you hold ETH at a current price of 1,500 DAI / ETH but want to sell it automatically when the price reaches 1,600 DAI / ETH. You would place a take-profit order, specifically an order offering ETH at 1,600 DAI / ETH. The order is intended to execute automatically when ETH reaches 1,600 DAI / ETH, selling ETH at that price.
The advantage of a limit order is that it removes the need to monitor the market continuously. When the market price reaches the specified target, the order executes automatically. This allows trades to be made efficiently without missing market movements.
However, there is an important caveat. Even when the range order fills, the liquidity provider's tokens are not automatically withdrawn. The provider must monitor the order and withdraw the tokens when it fills. A range order can earn LP (liquidity provider) fees until it fills, but if the goal is to withdraw liquidity in a particular token, the provider must monitor the order and remove liquidity manually after it fills, or use a third-party position manager.

Source: https://docs.uniswap.org/concepts/protocol/range-orders

Source: https://docs.uniswap.org/concepts/protocol/range-orders
Buy limit order
The current price of a DAI / ETH pool is 1,500 DAI / ETH. You expect ETH to fall to 1,000 DAI / ETH during the next market downturn and then rebound. You therefore want to place a range order to swap DAI for ETH at 1,000 DAI / ETH. The goal of the order is to purchase ETH at a lower price.
Specifically, you place an order providing DAI at a price of 1,000 DAI / ETH. The order is designed to fill automatically if the price of ETH falls below 1,000 DAI / ETH. At that point, the supplied DAI is exchanged for ETH, and you acquire ETH at a price of 1,000 DAI / ETH.
The order fills when the price of ETH reaches the target of 1,000 DAI / ETH. When the market falls to the target price, the order automatically executes and ETH is purchased.
However, the timing of the fill matters. If ETH falls below 1,000 DAI / ETH and then rises again, the order may become unfilled again. The liquidity provider can earn LP fees while the order is pending, but must remove liquidity manually or use a third-party position manager to withdraw the position if necessary.
Uniswap V3 arranges a token pair, such as DAI and ETH, in a single pool. In the pool, the two tokens are arranged on opposite sides of the spot price. Specifically, the original explanation describes the higher-priced token (here, ETH) as positioned above the spot price and the lower-priced token (here, DAI) as positioned below it.
This property enables trading strategies resembling limit orders. Uniswap V3 enables limit-order-style strategies that can be difficult to implement in other AMM designs.
For example, if you want to purchase the higher-priced token (ETH) at a price below the spot price (e.g., 1,000 DAI / ETH), you can configure such an order in Uniswap V3. When the spot price reaches the configured price (1,000 DAI / ETH), the order automatically executes and ETH is acquired at the lower price.
This division of price space enables token trades within particular price ranges according to market movements and trading strategies. Uniswap V3 offers a flexible trading environment for traders and liquidity providers.
Buy stop order
This is an order to purchase an asset at a price higher than the current spot price when a particular level is reached. Suppose the token currently trades at 1,500 DAI / ETH and is expected to reach 2,000 DAI / ETH in the future. You expect ETH to rise rapidly after reaching 2,000 DAI / ETH and subsequently reach 3,000 DAI / ETH. You therefore want to place an order that automatically purchases ETH once the price reaches 2,000 DAI / ETH.
However, this type of buy stop order cannot be implemented using a Uniswap V3 range order. This is because Uniswap V3 separates assets across the price space, and the higher price range above the spot price is denominated in the other asset (ETH in this example). As a result, supplying DAI, the input token, cannot acquire ETH in the higher price range above the spot price in this manner.
To configure a buy stop order, it is therefore necessary to consider the price range in which the input token (here, DAI) can be supplied. Supplying the input token in a higher price range above the spot price does not create the desired trade.
Stop-loss order
The current price of a DAI / ETH pool is 1,500 DAI / ETH. You expect ETH to fall below 1,000 and then decline further to 200. You therefore want to place a range order that exchanges ETH for DAI at 1,000 DAI / ETH. However, this cannot be achieved. With the current price at 1,500 DAI / ETH, the price space below the spot price (below 1,000 DAI / ETH in the example) is denominated in DAI. In other words, exchanging ETH for DAI at 1,000 DAI / ETH would require providing ETH at that price. But this range is associated with DAI, so the required ETH cannot be supplied there.
When configuring a range order, pay attention to the price range in which the output token, DAI, can be supplied. It is important to understand the price ranges in which the token to be exchanged (ETH) can be exchanged for DAI relative to the current price. This helps in planning feasible swap strategies.
Fees
Providing liquidity in Uniswap V3 involves fees. When you provide liquidity to a particular pair, fees accrue in both tokens that constitute the pair. In the previous example, providing liquidity to the ETH and DAI pair can result in fees in both ETH and DAI.
Consider a concrete example. The original explanation describes a swap from ETH to DAI as involving fees paid in both ETH and DAI. It describes a swap from DAI to ETH in the same way.
When placing a range order, the liquidity provider can choose how wide the range should be. A wider range can earn more fees as prices fluctuate within it, but also increases the risk that the spot price reverses before the range is fully crossed and the order fails to fill completely.
Swaps
Introduction
Swaps are the most common way of interacting with the Uniswap protocol. For users, swapping is straightforward.
For example, select an ERC20 token you hold and another token for which you want to exchange it. Executing the swap automatically exchanges the token you currently own for a corresponding quantity of the desired token. The exchange involves a small fee. This fee is paid to liquidity providers.
Anyone can freely perform swaps using the Uniswap protocol. Users do not need to undergo complicated procedures or obtain permission before exchanging their tokens for other tokens.
⚠️ Caution Using a web interface to swap through the Uniswap protocol may introduce additional permission structures and behave differently from interacting directly with the protocol.
Swaps through the Uniswap protocol differ from conventional order-book trading. Whereas order-book trading processes individual orders in a particular order, swaps in Uniswap are performed against passive liquidity pools. These pools contain the assets supplied as liquidity.
Specifically, a user does not need to wait for a matching order when making a swap. Instead, the supplied tokens enter the liquidity pool, and the balance of its assets determines the exchange. This allows users to exchange tokens immediately.
Liquidity providers can earn fees corresponding to the capital they supply. Swap fees are distributed to liquidity providers as compensation.
Because swaps through the Uniswap protocol execute against pooled liquidity, they can occur quickly and efficiently without waiting for a particular order. This mechanism enables users to swap while liquidity providers earn fees.
Price impact
Price impact refers to the effect of a swap or trade on the price. It is an important concept when understanding the difference between conventional order-book markets and swaps through the Uniswap protocol.
In a conventional order-book market, a large market buy order can consume the liquidity of an existing limit sell order and subsequently execute against a higher-priced limit sell order. The final execution price of the order consequently lies between the prices of the two filled limit sell orders.
In a conventional order-book market, trades are executed based on a list called the order book. Investors register their orders in the list as buyers or sellers. Buyers submit orders to purchase tokens at specified prices, and sellers submit orders to sell tokens at specified prices.
A large market buy order increases demand entering the market and reduces available liquidity from existing sell orders. Once the first limit sell order is filled, sell orders at subsequent prices may also execute. As a large buy order consumes liquidity, prices can rise progressively, resulting in execution of subsequent limit sell orders at higher prices.
The overall execution price falls between the prices of the multiple limit sell orders filled in this process. In other words, the actual execution price is influenced by multiple prices within the order book rather than a single price.
By contrast, the relative value of tokens changes continuously during a swap through the Uniswap protocol because of its automated market maker (AMM) design. The price moves between the start and end of the swap, and these movements determine the overall execution price.
The exchange rate between the tokens may change between the price at which the swap starts and the price at which it finishes. This change arises from the balance between the supply of and demand for tokens in the liquidity pool. For example, even if you intend to exchange tokens at a certain price when the swap starts, their relative value may change as the swap proceeds.
The swap's final execution price reflects these continuous price changes. The original explanation describes the exchange as being based on the relative price at the point when the swap is completed. This property means that the final execution price is affected by price movements during the trade.
This price movement dynamic affects all swaps through the Uniswap protocol. The price impact of a given swap size varies according to the amount of liquidity available at different price points within the pool. When substantial liquidity is available at a price, the price impact for a given swap size is lower; when liquidity is scarce, the impact is higher.
Specifically, the extent to which a swap moves the price depends on the amount of liquidity available at particular price points in the pool. Price impact measures how much the price changes when a swap is executed.
At price points with deep liquidity, many tokens are available, so swaps are less likely to cause abrupt price movements. At price points with limited liquidity, fewer tokens are available, so a swap may have a large effect on the price.
For a given swap size, the extent of price impact depends on the liquidity available at each price point in the pool. Price impact tends to be lower where liquidity is abundant and higher where it is scarce.
Users should therefore account for price movements and price impact when executing swaps.
The Uniswap interface estimates price impact in real time and displays a warning when it is unusually high. This allows users to consider price impact before executing a swap.
Slippage
Slippage is an important concept when swapping through the Uniswap protocol. It refers to the possibility that prices change while a submitted transaction is pending, causing its actual execution price to differ from the expected price.
When transactions are submitted to Ethereum, the amount of the fee commonly associated with gas influences their execution order. Offering a higher gas fee can lead to quicker execution, whereas a lower gas fee may leave the transaction pending. Other swaps may occur while the transaction is pending, changing its eventual execution price.
Slippage tolerance is the amount of price movement the user is willing to accept.
If the execution price remains within the configured tolerance (for example, within 1%), the transaction can execute.
However, if the execution price falls outside that range, the transaction fails and the swap does not occur.
This concept also applies to conventional markets. For example, a market buy order executed after a delay may have a different actual execution price from the price expected at submission.
Slippage is important for executing swaps with appropriate safeguards because it accounts for price movements during the transaction process. Configuring a slippage tolerance protects against unexpected price movements and helps constrain swaps to the intended price range.
Safety checks
The Uniswap protocol provides safety checks related to price impact and slippage to support reliable transactions.
1. Expired
A safety check intended to prevent a pending swap from executing after its configured deadline. If some time passes between submitting a swap and executing it, the price may change. Once the deadline is reached, the pending swap can no longer execute successfully, protecting against a prolonged delay and the associated price movements.
2. Insufficient output amount (INSUFFICIENT_OUTPUT_AMOUNT)
When the user submits a swap, Uniswap estimates the amount of tokens the user expects to receive. The swap checks that the actual output amount stays within the specified tolerance (slippage tolerance). If the output is outside the permitted range, the swap fails. This protects users from unfavorable trades when the price changes rapidly while a transaction is pending.
These safety checks reduce the risk of users encountering unexpected conditions during swap execution. Considering these factors before executing swaps helps users maintain a safer and more predictable trading environment.
Token integration issues
In Uniswap v3, note that fee-on-transfer tokens and rebasing tokens behave differently from ordinary tokens.
Fee-on-transfer tokens
Fee-on-transfer tokens may not work correctly with Uniswap v3 router contracts. As alternatives, token issuers can create token wrappers or custom routers. At the time of writing, Uniswap does not plan to provide a new router supporting fee-on-transfer tokens.
Rebasing tokens
Although pools can be created and swaps can succeed with rebasing tokens, liquidity providers may incur losses when a negative rebase occurs and their position is active. These losses cannot be recovered, so caution is necessary.
Governance
Overview
This section of the documentation focuses mainly on code, so this article skips it. See the following resource for details.
Process
The following describes the process guidelines for developing and advancing Uniswap governance proposals as presented in the source documentation.
Process
Uniswap governance uses several tools for different purposes.
-
gov.uniswap.org This is a forum using Discourse where discussions about Uniswap governance take place. Community members must register an account before sharing or liking posts. Before creating their own posts, new members must spend ten minutes reading four topics and fifteen posts.
-
Snapshot: Snapshot is a simple offchain voting interface for expressing sentiment. Votes on Snapshot are weighted according to the number of UNI tokens delegated to the voting address.
-
Governance portal: The official governance portal can be accessed directly through the Uniswap application interface. Voting power is delegated and votes are cast through this portal.
These tools are used at different stages of governance. First, discussions take place on the gov.uniswap.org forum. Next, sentiment is expressed through Snapshot, and the final proposal is voted on through the governance portal.
These processes may change based on feedback from the Uniswap community.
The first phase of Uniswap governance, the Temperature Check, assesses whether there is sufficient interest in changing the status quo.
Phase 1: Temperature Check — Discourse/Snapshot
The procedure is as follows.
-
Post a question to the community Post a neutral question about a potential change on the gov.uniswap.org community forum. For example, Should Uniswap governance introduce liquidity mining for XYZ tokens? Label the forum post Temperature Check - [Title]. Include a link to the relevant Snapshot poll in the forum post.
-
Vote using Snapshot Community members use Snapshot to express interest in the proposal. Set the Snapshot voting period to two days.
This begins the process of gathering support for the proposal.
When the two-day voting period ends, the Temperature Check succeeds if the majority is in favor with at least 25,000 UNI voting in support.
If the Temperature Check does not recommend changing the status quo, the topic is closed on the governance portal. If it recommends a change, proceed to the Consensus Check in phase two.
In this way, the Temperature Check advances proposals by assessing community interest and willingness to support them.
Phase 2: Consensus Check — Forum/Snapshot
The purpose of the Consensus Check is to establish a formal discussion about a potential proposal.
Follow these steps to conduct a Consensus Check.
-
Use feedback from the Temperature Check Use feedback from the Temperature Check post to create a new Snapshot poll covering the options that received support. The poll may be binary or multiple-choice, but must include No change or an equivalent option. Set the voting period to five days.
-
Create a new topic Create a new topic titled Consensus Check — [Title] in the Proposal Discussion category on gov.uniswap.org. This tells the community that the topic has already passed the Temperature Check. Moderators promptly remove topics beginning with Consensus Check that have not passed the Temperature Check. Include links to the new Snapshot poll and the Temperature Check discussion thread.
-
Build support Engage the community to gather support for the proposal. Discuss the proposal and actively ask delegates to vote. Be prepared to answer questions in the Consensus Check topic while remaining neutral. Share your views, but maintain neutrality.
After the five-day voting period ends, the option receiving a majority of votes wins and can be included in the phase-three governance proposal.
Passing the Consensus Check requires 50,000 UNI voting in support.
If No change wins, moderators close the Consensus Check topic.
Phase 3: Governance Proposal — Governance Portal
The governance proposal is the third and final phase of the governance process. The proposal is based on the Consensus Check result and may consist of one to ten actions.
The procedure for making a governance proposal is as follows.
-
Write the proposal code Write the code for the proposal to be voted on through the governance portal. See this documentation for details. All code included in a proposal should be audited by professional auditors. This audit is funded by the community or covered through reimbursement.
-
Secure at least 2.5 million UNI To submit a proposal, ensure that at least 2.5 million UNI have been delegated to your address. Alternatively, find a delegate who holds enough voting power to meet the proposal threshold and can submit it on your behalf.
-
Create a topic in the Proposal Discussion category on gov.uniswap.org Create a topic titled Governance Proposal — [Title] in the Proposal Discussion category on gov.uniswap.org. Include links to relevant Snapshot polls, discussion threads, and code audit reports. Moderators remove topics beginning with Governance Proposal if they have not passed the Temperature Check and Consensus Check stages.
-
Call Governor Bravo's propose() function Call Governor Bravo's
propose()function to submit the proposal. -
Calling propose() starts a two-day voting delay: When
propose()is called, a two-day voting delay begins. Once the voting delay ends, a seven-day voting period begins. Discussion continues on the gov.uniswap.org forum. If the proposal succeeds, a two-day timelock follows before the proposed code executes.
Soft governance
Soft governance is an approach to governance that involves not only formal voting procedures for particular issues but also discussions about policy direction and implementation processes.
The specific procedures are described above. Before voting on a particular proposal, steps such as the Temperature Check and Consensus Check consolidate community preferences and guide the decision.
However, operating the system as a whole also requires discussing how policies should be advanced and implemented, not just the policies themselves. For example, community discussions take place when considering ways to improve proposal processes, new ideas, and strategies. These discussions are known as metagovernance.
The Governance-Meta category is where metagovernance discussions take place. Participants discuss ideas and changes relating to policy implementation and improvements to the proposal process. Discussions in this category do not require an onchain vote and are used when updating offchain processes.
Soft governance thus advances community governance through flexible discussions about policies and procedures as well as formal voting.
A beginner's guide to voting
The following resource provides an illustrated explanation.
Glossary
- UNI
- An ERC20 token representing the weight of a user's voting power.
- The more UNI a user holds in their wallet, the greater their potential voting weight when delegating or voting on proposals.
- Delegation
- UNI holders cannot vote or create proposals without delegating their voting power to an address.
- Delegation can be made to one address at a time, including the holder's own address.
- Delegation does not lock tokens; it assigns voting power to the selected delegate address.
- Proposal
- A proposal is executable code that changes the behavior of governance contracts or the treasury.
- To create a proposal, a user must have at least
0.25%of all UNI (2,500,000UNI) delegated to their address. - Proposals are stored in the governor smart contract's
proposalsmapping and have a seven-day voting period. - If the proposer fails to maintain the required voting-power balance during the voting period, another party can cancel the proposal.
- Quorum
- A successful vote requires
40,000,000UNI (4%of all UNI) voting in favor. - Quorum ensures sufficient participation and helps determine whether a proposal passes.
- A successful vote requires
- Voting
- Users can vote for or against a proposal when voting power has been delegated to their address.
- While the proposal is active, they can vote directly using
castVoteor submit a signed vote usingcastVoteBySig. - If a majority and the
4%UNI quorum vote in favor, the proposal can be queued in the timelock.
- Voting period
- When a proposal is submitted, Uniswap community members can vote during a seven-day voting period.
- Timelock
- All governance and other administrative actions are timelocked for at least two days before they can execute.
Future challenges
This document examines challenges that Uniswap governance may face in the future. Its goal is to help people interested in Uniswap governance understand the rationale and constraints behind its design and possible avenues for growth. It discusses the background to the governance design, its constraints, and possibilities for future growth.
Scenario 1
A well-intentioned proposal is submitted for voting but contains an exploitable edge case. A malicious actor uses DeFi leverage to rapidly acquire a large amount of UNI during the voting period and manipulate the vote in favor of the proposal. The proposal may consequently pass, allowing the vulnerability to be exploited.
Mitigation
UNI voting power must be fully delegated to a particular address before the proposal is submitted or during its proposal delay.
At the time described by the source, the proposal delay was one block (approximately 15 seconds).
This short delay leaves little time for a third party to find an exploitable edge case, hurriedly acquire UNI, self-delegate, and manipulate the vote.
Uniswap governance may increase the proposal delay in the future. Extending the delay has clear benefits, but potential negative effects, such as opportunistic exploitation of edge cases, must also be considered. The community may decide such changes through a vote.
Scenario 2
A malicious proposal is created and submitted for voting. The proposal is not in the best interests of Uniswap governance. Multiple parties coordinate in advance to manipulate the UNI market, force the proposal through, gain access to UNI reserves, and drain the funds.
Mitigation UNI is a freely tradable asset that anyone can acquire on the market. This makes an attempted governance takeover possible. However, forcing a malicious proposal through requires at least 40 million UNI. This is a substantial amount, and accounting for price movements, the cost of the attack would likely exceed the potential benefits.
If a malicious group successfully takes control, the timelock delay gives affected parties time to withdraw their assets from the protocol. This situation also creates an opportunity to fork the protocol. In that case, the remaining well-intentioned participants may continue operating a protocol with a new direction.
Scenario 3
A user may attempt to use a flash loan to advance proposals rapidly, flooding governance with numerous proposals in a short period and obstructing effective operation. This would effectively resemble a DDoS (distributed denial-of-service) attack.
Mitigation Submitting a proposal requires at least 2.5 million UNI delegated to a particular address, but the balance is checked at the preceding block. This prevents proposals from being created using flash loans. Flash loans must be completed atomically within a single transaction.
The proposer must also maintain a balance of at least 2.5 million UNI during the voting period; otherwise, anyone can cancel the proposal. This balance maintenance check is intended to prevent proposal strategies using sophisticated leverage spanning multiple blocks.
Scenario 4
A malicious proposal may be created with incentives intended to encourage voters to support it.
For example: The treasury is drained. Voters who support the proposal receive the treasury balance. Voters who oppose the proposal are excluded from the treasury funds.
Mitigation Although there is no explicit mechanism preventing this situation, market forces can serve as a deterrent.
Because the treasury described in the source consists solely of UNI tokens, the market would be expected to react if a governance proposal threatened Uniswap's economic sustainability or the UNI token. By the time the proposal passed, the UNI price would likely have fallen, leaving the attackers with little expected profit.
Holding UNI as the sole governance treasury asset is intended to deter this type of malicious voting. In the future, Uniswap governance may choose to diversify the assets held in the treasury. Although diversification has many benefits, it may also involve limited risks, including incentives for malicious voting.
Changelog
The following resource summarizes the changes.
Research
See the following resource.
Resources
See the following resource.
Conclusion
This article covered the Uniswap documentation.
I also publish articles about blockchain and AI on my blog and Qiita; you can find them below.


