Decode Uniswap V3

Decode Uniswap V3

Tags
Web3
Defi
Published
June 8, 2024
Author
Senn

Overview

Uniswap V3 is the third iteration of Uniswap, built on the Ethereum blockchain. It represents a significant advancement over its predecessors, Uniswap V1 and V2, by introducing several new features aimed at improving capital efficiency, flexibility, and user experience.

Low Capital Efficiency of Uniswap V2

In Uniswap V2, liquidity is distributed uniformly along the entire price range from 0 to infinity. This means that much of the liquidity is not actively utilized unless the price of the tokens changes significantly.
Swapping stablecoins (such as USDC, DAI, USDT) is a common use case in decentralized finance. Normally, the exchange price between stable coins is close to 1:1. However, the liqudiity of Uniswap V2 is distributed along the entire price range from 0 to infinity, large volume swap can easily make the price deviate from 1:1 significantly. Large volume trader needs to split the trade, wait for arbitrager to rebalance of pool, which is quite inconvinent.
Consider a pool with USDC and DAI, each with $1 million worth of liquidity.
Initial State:
  • USDC reserve: 1,000,000 USDC
  • DAI reserve: 1,000,000 DAI
  • Initial price: 1 USDC = 1 DAI
Swap Scenario: A trader wants to swap 100,000 USDC for DAI.
Calculation:
  1. Constant Product Formula:
  1. Post-Swap Reserves:
      • New USDC reserve:
      • Let be the new DAI reserve:
  1. DAI Output:
      • DAI output:
  1. New Price:
      • New price of USDC in terms of DAI:
      • The new price of USDC is approximately 1.21 DAI, indicating a significant deviation from the initial 1:1 ratio.
From the above example, we can see that the swap changes the price significantly due to uniformly distributed liquidity.
What if the liquidity is concentrated in a smaller range, like [0.99,1.01]? So that the price impact of swap on the price is limited? This is in deed the problem Uniswap V3 aims to solve.
Uniswap V3 allows liquidity provider to add liquidity into a specified price range, which significantly improve capital efficiency.

Key Features

  1. Concentrated Liquidity
      • Unlike Uniswap V2, where liquidity is distributed uniformly across the entire price range, Uniswap V3 allows liquidity providers (LPs) to concentrate their capital within specific price ranges where they believe most trading will occur. This leads to higher capital efficiency, as more liquidity is available at the actual trading prices.
      • LPs can choose custom price ranges, meaning they no longer need to provide liquidity for the entire price range of an asset pair.
  1. Multiple Fee Tiers
      • Uniswap V3 introduces multiple fee tiers: 0.05%, 0.30%, and 1.00%. This flexibility allows LPs to select a fee tier based on their risk tolerance and the characteristics of the trading pair. Higher fees may be chosen for more volatile pairs to compensate for the higher risk of impermanent loss.
  1. Improved Price Oracles
      • Uniswap V3 enhances the functionality of its time-weighted average price (TWAP) oracles, which are used by other smart contracts to obtain reliable price data. These oracles are more precise and robust, providing better security for DeFi applications relying on them.
  1. Flexible Liquidity Provision
      • LPs can now add and remove liquidity more flexibly, without the need to interact with the entire pool. They can target specific price ranges and manage their positions more dynamically.
  1. Non-Fungible Liquidity Positions
      • In Uniswap V3, each liquidity position is represented by a non-fungible token (NFT). This differs from the fungible LP tokens in Uniswap V2. These NFTs capture the unique characteristics of each liquidity position, including the chosen price range and the amount of liquidity provided.

Advantages

  • Higher Capital Efficiency: By allowing LPs to concentrate liquidity within specific price ranges, Uniswap V3 achieves greater capital efficiency. This means that traders can experience lower slippage with the same amount of liquidity compared to previous versions.
  • More Flexibility for LPs: Liquidity providers have more control over how they allocate their capital and can optimize their strategies based on market conditions.
  • Better Trading Experience: With concentrated liquidity, traders benefit from deeper liquidity at specific price points, leading to reduced slippage and better execution prices.
  • Enhanced Oracles: The improved oracles provide more accurate and reliable price data, which is crucial for the stability and security of DeFi protocols relying on Uniswap’s price feeds.

Challenges

  • Increased Complexity: The introduction of features like concentrated liquidity and multiple fee tiers adds complexity to the protocol. LPs need to actively manage their positions and understand the nuances of providing liquidity in specific price ranges.
  • Impermanent Loss: While capital efficiency is improved, LPs are still exposed to impermanent loss. The risk management strategies may need to be more sophisticated to mitigate this risk.
  • Usability: For new users, the complexity of setting price ranges and understanding the implications of different fee tiers can be daunting. User interfaces need to simplify these processes to make the protocol more accessible.

Contract

Network
Name
Address
Ethereum
UniswapV3Factory
0x1F98431c8aD98523631AE4a59f267346ea31F984
Ethereum
NonfungiblePositionManager
0xC36442b4a4522E871399CD717aBDD847Ab11FE88
Ethereum
NonfungibleTokenPositionDescriptor
0x91ae842A5Ffd8d12023116943e72A606179294f3
Ethereum
SwapRouter
0xE592427A0AEce92De3Edee1F18E0157C05861564
Ethereum
SwapRouter02
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
Ethereum
UniversalRouter
0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD
Ethereum
Multicall
0x1F98415757620B543A52E61c46B32eB19261F984
Ethereum
Multicall2
0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696
Ethereum
ProxyAdmin
0xB753548F6E010e7e680BA186F9Ca1BdAB2E90cf2
Ethereum
TickLens
0xbfd8137f7d1516D3ea5cA83523914859ec47F573
Ethereum
Quoter
0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6
Ethereum
NFTDescriptor
0x42B24A95702b9986e82d421cC3568932790A48Ec
Ethereum
TransparentUpgradeableProxy
0xEe6A57eC80ea46401049E92587E52f5Ec1c24785
Ethereum
V3Migrator
0xA5644E29708357803b5A882D272c41cC0dF92B34
Ethereum
QuoterV2
0x61fFE014bA17989E743c5F6cB21bF9697530B21e
Ethereum
Permit2
0x000000000022D473030F116dDEE9F6B43aC78BA3
Ethereum
v3StakerAddress
0xe34139463bA50bD61336E0c446Bd8C0867c6fE65

Code Analysis

Deploy Pool

Add Liquidity

Remove Liquidity

Swap

 

Conclusion

Uniswap V3 is a groundbreaking update in the world of decentralized exchanges, offering significant improvements in capital efficiency and flexibility for liquidity providers. Its innovative features set a new standard for automated market makers (AMMs) and enhance the overall trading experience for users. However, the increased complexity requires a good understanding of the protocol’s mechanics

Reference