Uniswap V4 – the most important changes compared to V3 when creating a pool
July 18, 2024
Uniswap holds a dominant position in the decentralized exchange (DEX) market. As of mid-2023, Uniswap accounts for approximately 66-70% of the total spot trading volume among DEXs (CryptoNews). This market share reflects Uniswap’s huge influence in the decentralized finance (DeFi) ecosystem. V4 is the latest version of Uniswap, which provides customizable pools with unlimited fees and automated strategies.
Uniswap V4 – what’s new?
Core concepts of Uniswap V4 include:
- Hooks – external contracts designed and created by community developers to customize pools and execute specific actions.
- Singleton contract – all pools consolidated within a single smart contract
- Flash accounting system – multiple actions in a single transaction
- Unlimited fee tiers – dynamic fee structure that can adjust based on market conditions
- Native ETH support – direct trading pairs with native ETH, no need for WETH (Wrapped ETH)
When setting up pools on Uniswap V4, hooks are crucial. So we’ll start by explaining what they are and how they work. Let’s break it down.
Hooks – V4’s essentials
Hooks are completely new to Uniswap. They allow developers to customize liquidity pools’ behavior by implementing additional features. Developers can modify how pools operate at different points (before or after swaps) and make changes in liquidity. For example, hooks can adjust fees dynamically, enable new order types (i.e. on-chain limit order), execute large orders over time using TWAMM, create custom-tailored oracles, or custom AMM curves.
You can find example hooks in the Open Source Directory for Uniswap V4 – a community-curated collection of open-source hooks. At the moment of writing this article, there are 114 hooks in this base.
Initializing a pool in V4
In V4, pools are initialized and managed by a single contract, the PoolManager. Pool creation is defined by 5 main arguments:
- Trading pair
- Fee tier
- Tick spacing
- Hook
- Starting Price
Uniswap V4 allows a single trading pair to exist in an unlimited number of pools, unlike V3, which restricted fee tiers to 1%, 0.30%, or 0.05%. A trading pair can exist in many pools. Each pool in V4 has one hook contract. Developers can assign a hook when setting up a liquidity pool. A pool may be initialized with a hook contract. This hook can perform various actions through callbacks before and after the core functionalities of the Uniswap liquidity pool: Initialize, AddLiquidity, RemoveLiquidity, Swap, Donate.
The callbacks executed on a pool cannot change after the pool is initialized. Hooks can be called back by the PoolManager, and they can also initiate transactions with the PoolManager. You can find the example hooks implementations and use cases here -> https://www.v4-by-example.org/
Hooks are not mandatory, you can create a pool without a hook.
Lower pool creation’s and trading costs. Singleton contract and flash accounting.
The architecture of V4 protocol has been updated to a new Singleton contract. All V4 pools are consolidated within a single smart contract reducing gas costs (up to 99% as reported by Uniswap Labs) for both trading and pool creation. Tokens do not need to be transferred between multiple contracts.
Additionally, Flash Accounting System allows users to perform multiple actions, like swapping tokens and adding liquidity, all in one transaction. FAS optimizes the number of transfers in pool operations to minimize the associated costs. For example, as a result of executing an operation (e.g., closing a position), funds can be used to pay for a swap. This reduces the number of ERC20 transfers and reduces gas costs.
This system is similar to flash loans in concept. FAS tracks the total amounts of tokens being moved in and out. At the end of the transaction, it checks to make sure all balances are correct. If there are any unpaid balances, the whole transaction reverts.
Swapping on Uniswap V4 compared to V3 (source: Uniswap Labs)
Creating a pool on Uniswap V4 – why you should consider
Before making a decision, let’s summarize the main differences of the new Uniswap V4 compared to the previous V3 version.
Feature: | Uniswap V3 | Uniswap V4 |
---|---|---|
Pool creation | More expensive and limited to the choice of fee tiers and price ranges. | Cheaper with a high degree of customization through hooks, enabling custom logic and specific functionalities at different points in a pool’s lifecycle. |
Pool architecture | Each token pair requires a separate smart contract (Factory-pool). | Consolidating all pools into a single contract (Singleton). |
Fee structure | Fixed with multiple fee tiers (0.05%, 0.30%, and 1%). | Dynamic fees supported through hooks. Each pool can have its own unique fee tiers. |
Liquidity provision | Allowing liquidity providers (LPs) only to specify price ranges. | Maintains concentrated liquidity with customization via hooks. |
Gas costs | Higher due to separate contracts for each pair. | Lower due to the Singleton contract model. |
Liquidity management | Automated Market Maker (AMM) | Time-Weighted Average Market Maker (TWAMM) allowing large orders to be spread over time (provided via hooks). |
Order types customization | Not supported. | Supported via hooks, e.g. on-chain limit orders or stop-loss orders |
Native ETH | Wrapped ETH (WETH) | ETH |
Accounting | ERC20 | Flash accounting |
Let’s consider whether V4, which promises minimum trading costs and increased earnings, could cause an influx of investors from V3 pools.
LPs will positively welcome advanced order types, including limit orders and stop-loss orders, which can be implemented via hooks. This gives users more control over their trades, akin to traditional centralized exchanges, but within a decentralized framework. Dynamic fees, also implemented via hooks, allow liquidity providers to adapt to market conditions. Multi-hop trades can be more efficient since tokens do not need to be transferred between multiple contracts. Architectural change reduces gas costs. Hooks like TWAMM enables large orders to be executed over time, reducing the impact on market prices and improving liquidity distribution. Sounds interesting, but there are also some limitations of V4’s version:
- Hooks are made by community developers, which means that you need to verify and trust the source. These hooks can potentially execute harmful code. It’s important to conduct testing before deploying them.
- Two separate governance fee mechanisms: swap fees and withdrawal fees. Uniswap governance, which involves the Uniswap DAO and UNI token holders, can elect to take a capped percentage of the swap fee on a particular pool. The same was in the V3 version. In Uniswap V4, if a pool has “hooks” that activate a withdrawal fee, the governance has the ability to take a small, capped portion of it.
- Business Source License which limits the use of the Uniswap V4 source code in a commercial or production setting for up to 4 years. Previously, Uniswap as an open source project, could be copied and modified freely which happened multiple times in history. These copies (called forks) include other DEX systems such as SushiSwap, PancakeSwap, QuickSwap and others. This has led to liquidity fragmentation because some of the Uniswap’s liquidity providers migrated to other systems anticipating higher returns. Uniswap has famously lost roughly 55% of its total liquidity to its competitor – SushiSwap. The 4 years BSL license on its source secures that no forks can be commercially deployed in this time period. This has been met with criticism from the community, who accuse Uniswap of no longer being a really open-source.
Empirica – your guide and liquidity provider on Uniswap V4
Empirica has long invested in developing tools for effective liquidity maintenance on DEXes, including Uniswap. We provide analytics and insights, helping new projects make informed decisions about their liquidity management and trading strategies. If you consider listing your token on Uniswap V4 we can help you create the pool for your trading pair or upgrade from lower versions (V1, V2, V3).
Thanks for reading! If you found this interesting, please share the article on Twitter and let your friends know about the new Uniswap V4. See you in the next article!
Anna Waszak
Crypto Researcher at Empirica
With over 20 years of experience researching and writing about IT technologies, I value simplicity and aim to explain complex concepts in a way that sparks the imagination. I craft my crypto articles to be easy to understand while preserving their substantive content.