Uniswap protocol
The Uniswap protocol is a peer-to-peer system designed for the exchange of cryptocurrencies. The protocol is implemented as a set of permanent, non-renewable smart contracts.
There are currently three versions of the Uniswap protocol. V1, V2, and V3. Each version of Uniswap, when deployed, will function indefinitely, with 100% uptime, provided the blockchain is always live.
Concentrated Liquidity
In Uniswap v3 a liquidity distributed within a given price range. In previous versions, liquidity was distributed evenly along the price curve from 0 to infinity.
This uniform distribution allowed trading in the entire price range (0, ∞) without losing liquidity. However, in many pools, most of the liquidity was never utilized.
Consider stable coin pairs, where the relative price of the two assets remains relatively constant. Liquidity outside the typical price range of a stablecoin pair is rarely touched. For example, the v2 DAI/USDC pair uses ~0.50% of total available capital to trade between $0.99 and $1.01, the price range where Liquidity providers (LPs) expect to see the most volume - and therefore earn the highest fee.
In v3, LPs can concentrate their capital at smaller price intervals than (0, ∞). For example, in a stablecoin/stablecoin pair, an LP can choose to allocate capital exclusively to the 0.99-1.01 range. As a result, traders are offered deeper liquidity around the average price, and LPs earn more trading fee on their capital. A liquidity concentrated in the finite interval is a position. LPs can have many different positions per pool, which creates individual price curves reflecting each LP's preferences.
Uniswap v3 LP token allows NFTs to be transmitted with pre-built liquidity, high trading ranges and no fees, which simplifies the process and also provides protection against vampire mining attacks. You can find more about Uniswap v3 LP-NFT in this article:
Active liquidity
As the price of an asset rises or falls, it may move outside the price limits set by LP for the position. When the price moves out of the position interval, the liquidity of the position is no longer active and no longer generates fees.
As price moves in one direction, LPs acquire more and more of one asset as swappers demand another until their entire liquidity consists of only one asset. If the price falls back into the interval, liquidity becomes active again and LPs in the interval start earning fees again.
Ticks
To achieve concentrated liquidity, the once continuous spectrum of price space has been divided by ticks.
Ticks are the boundaries between discrete areas in the price space.
Ticks are spaced so far apart that an increase or decrease of 1 tick means an increase or decrease of 0.01% in price at any point in the price space.
The ticks serve as boundaries for liquid positions. When creating a position, the provider must select lower and upper ticks to represent the boundaries of his position.
As the spot price changes during the swapping process, the pool contract will continuously swap the outgoing asset for the incoming asset, gradually utilizing all the liquidity available in the current tick interval until the next tick is reached. At that point, the contract switches to the new tick and activates any inactive liquidity in the position that has a boundary on the new active tick.
Although each pool has the same number of underlying ticks, in practice only a fraction of them can serve as active ticks. Due to the nature of v3 smart contracts, the distance between ticks is directly related to the size of the swap fee. At lower fee levels, potentially active ticks are closer together, while at higher fee levels the distance between potentially active ticks is relatively larger.
Swaps
When a swap is executed, tokens owned by the user are traded for a proportional number of desired tokens, less a swap fee paid to liquidity providers.
Swaps in Uniswap are executed against a passive liquidity pool.
Price impact
When using an automated market maker (AMM), the relative value of one asset to another is constantly changing during the swap execution process, resulting in a final execution price somewhere between the beginning and end of the relative price.
This dynamic affects every swap using the Uniswap protocol because it is an integral part of the AMM design.
Since the amount of liquidity available at different price points can vary, the price impact for a given swap size will vary depending on the amount of liquidity available at any point in the price space. The more liquidity available at a given price, the lower the price impact for a given swap size. The less liquidity available, the higher the price impact.
Approximate price impact is expected in real time via the Uniswap interface.
Slippage
Slippage is a term to describe the changes in a given price that can occur while a submitted transaction is pending.
When transactions are submitted to Ethereum, the order in which they are executed is determined by the amount of “gas” offered as a fee for each transaction. The higher the fee offered, the faster the transaction is executed. Transactions with lower gas fees remain pending for an indefinite period of time. During this time, the price situation in which the transaction is ultimately executed will change as other swaps occur.
Slippage tolerances set a user-acceptable limit on changes independent of price impact.
Fees
Swap fees are allocated proportionally to all liquid funds in the range at the time of the swap.
Swap fees are not automatically reinvested as they were in previous versions of Uniswap. Instead, they are collected separately from the pool and must be redeemed manually when the owner wants to receive their fees.
Pool fee tiers
Uniswap v3 introduces multiple pools for each token pair, each with a different swapping fee. Liquidity providers can initially create pools with three fee levels: 0.05%, 0.30%, and 1%.
Other fee levels can be added by UNI governance.
Finding the right pool fee
Assets with low volatility (stable coins) will likely end up in the lowest fee tier, as the price risk for the LPs holding these assets is very low and swapping participants will be interested in keeping the execution price as close to 1:1 as possible.
More exotic assets or those that trade infrequently will naturally gravitate toward higher fees - as liquidity providers will be incentivized to offset the cost risk of holding these assets over the life of the position.
Protocol fee
Uniswap v3 has a protocol fee that can be enabled by UNI governance.
Price oracle
All Uniswap v3 pools can act as oracles, providing access to historical price and liquidity data.
Historical data is stored as an array of observations. Initially, each pool tracks only one observation, overwriting it as blocks expire. This limits users' access to past data. However, any party willing to pay transaction fees can increase the number of observations tracked (up to a maximum of 65535), extending the period of data availability to ~9 days or more.
Storing price and liquidity history directly in the pool contract significantly reduces the likelihood of logical errors on the calling contract side, and reduces integration costs by not having to store historical values. In addition, the significant maximum length of the v3 oracle makes it much more difficult to manipulate oracle prices.
Liquidity accumulator stores the value of seconds / liquidity in the range at the time of observation. The value of the liquidity accumulator monotonically increases and grows by the value of seconds / liquidity in the range - per second.
Tick accumulator stores the cumulative sum of active ticks at the time of observation. The value of the tick accumulator monotonically increases and grows by the value of the current tick - per second.
Price From A Tick. "Active tick” or other to refer to the current pool tick, is referring to the lower tick boundary that is closest to the current price.
Uniswap NFT marketplace aggregator
Key features:
- More flexibility. With Universal Router, users can make multiple token swaps on Uniswap V2 and V3, as well as buy NFTs on multiple trading platforms in a single transaction. For example, envision a swap that
-- Uses three different input tokens
-- Swaps on Uniswap V2 and V3 using a split route
-- Performs an ETH to WETH wrap
-- Buys an NFT on OpenSea
- More listings at better prices. Aggregators provide better prices by combining listings from multiple marketplaces into one interface. At launch, Uniswap will support OpenSea, X2Y2, LooksRare, Sudoswap, Larva Labs, Foundation, NFT20 and NFTX.
- More gas savings. Thanks to the Universal Router contract, aggregator Uniswap can save up to 15% on the cost of gas compared to other NFT aggregators when purchasing at all retail sites.
- More payment options. You can buy NFTs with any ERC20 token. Universal Router combines token and NFT transactions into a flexible and gas-optimized swap router. Universal Router finds the most cost-effective route to exchange your entered ERC20 token for a purchase token, such as ETH, and then settles via Opensea's Seaport, the protocol for swapping ERC721 and ERC1155.