
Uniswap V4 is a significant upgrade to the popular decentralized exchange (DEX) platform, offering improved scalability and performance.
At its core, Uniswap V4 is built on a modular architecture, allowing for greater flexibility and customization.
This modular design enables developers to swap out individual components, making it easier to adapt to changing market conditions.
One of the key innovations in Uniswap V4 is the introduction of a new liquidity pool architecture, which allows for more efficient liquidity management.
With this new architecture, liquidity providers can earn more rewards and enjoy better capital efficiency.
What Is Uniswap V4?
Uniswap V4 is a major update to the Uniswap decentralized exchange, which is set to revolutionize the DeFi sector by introducing new and improved features on the protocol.
The Uniswap community is building Uniswap V4, and it's slated for launch in the third quarter of 2024. Once launched, Uniswap will have exclusive access to their V4 innovations for four years, but all the code will be made open-source eventually.
Uniswap V4 aims to reduce gas costs and make liquidity pools more customizable. This is a significant improvement over previous versions, which had limitations that made the system less efficient.
The new feature called "hooks" in Uniswap V4 allows developers to customize how pools behave at different stages of a trade. This opens up many possibilities, including dynamic fees and on-chain limit orders.
Uniswap V4 also introduces a new setup, where all pools are now housed in a single smart contract, making the system more efficient and cheaper to use. This is a significant improvement over previous versions, which had limitations that made the system less efficient.
Key Features and Innovations
Uniswap V4 brings several key features and innovations that improve the protocol and automated market maker (AMM) system.
The new singleton architecture holds all pools in one contract, reducing pool creation gas costs by 99% and providing important gas savings. This is achieved by eliminating the need to transfer tokens between pools held in different contracts.
The flash accounting system is a crucial component of Uniswap V4, transferring only on net balances instead of assets in and out of pools at the end of every swap. This results in a far more efficient system that provides additional gas savings.
Key features of Uniswap V4 include:
- Hooks – external contracts designed 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).
The integration of Uniswap V4 swaps into the UniversalRouter enhances routing by allowing complex and optimized trade paths across Uniswap V2, V3, and V4 pools.
Key Benefits and Innovations
The Uniswap V4 brings several benefits and innovations to the Uniswap protocol and the automated market maker (AMM) system.
One of the key benefits is the improved architecture, which reduces pool creation gas costs by 99%. This is achieved by holding all pools in one singleton contract, making swaps more efficient.
The singleton architecture is complemented by a new "flash accounting" system, which transfers only on net balances, providing additional gas savings. This system is made possible by using "transient storage", which is enabled by EIP-1153.

Unlimited fee tiers are also a new feature, allowing pool creators to set fees at the level that makes them most competitive or customize them with a dynamic fee hook. This is made possible by the efficiency of singleton and flash accounting.
Native ETH support is another innovation, offering additional gas savings and direct trading pairs with native ETH, no need for WETH (Wrapped ETH).
Universal Router Integration
Universal Router Integration offers a seamless trading experience for users by accessing multiple pool types and routes, including Uniswap V2, V3, and V4 pools.
With the integration of Uniswap V4 swaps into the Universal Router, complex and optimized trade paths are now possible. This is made possible through the base Dispatcher contract.
The Universal Router also supports the migration of liquidity from V3 to V4 with the V3ToV4Migrator contract, allowing liquidity providers to seamlessly transfer their liquidity positions.
Nested actions enable this seamless transfer, utilizing flash accounting to ensure delta resolution without unnecessary token transfers. This is a game-changer for liquidity providers.
Singleton Contract
The Singleton contract is a game-changer for Uniswap V4. It consolidates all token pairs into a single smart contract, eliminating the need for multiple contracts for each liquidity pool.
This design reduces gas fees significantly, making it 99% cheaper to create new pools compared to Uniswap V3. With the Singleton contract, creating new pools is a breeze, and users can save a substantial amount of money.
The Singleton contract also enables Flash Accounting System, which allows users to perform multiple actions in a single transaction, minimizing the number of ERC20 transfers and reducing gas costs.
Singleton Contract
The Singleton contract is a game-changer for Uniswap V4, consolidating all token pairs into a single smart contract. This eliminates the need for a separate contract for every liquidity pool.
Creating new pools will become significantly cheaper, with gas fees reduced by up to 99% compared to Uniswap V3. The Singleton contract reduces unnecessary gas expenses tied to traditional pool creation.

The architecture of V4 protocol has been updated to a new Singleton contract, which reduces gas costs for both trading and pool creation. This is a huge cost savings, especially for frequent traders and pool creators.
The Singleton contract also enables Flash Accounting System, which allows users to perform multiple actions in one transaction. This optimizes the number of transfers in pool operations, minimizing associated costs.
With the Singleton contract, tokens no longer need to be transferred between multiple contracts, reducing the number of ERC20 transfers and associated gas costs. This makes trading and pool creation more efficient and cost-effective.
On-Chain Limit Orders
On-Chain Limit Orders enable more strategic trading without constant monitoring, simplifying decentralized trading for retail users.
This automated functionality allows users to set price conditions for trades, which are then executed on-chain when the market hits the target price.
With On-Chain Limit Orders, users can automate their trades, freeing up time to focus on other aspects of their trading strategy.
This automated functionality is made possible by the Singleton Contract, which enables the execution of trades on-chain when the market hits the target price.
Flash Accounting and Storage
Flash accounting is a system introduced in Uniswap V4 that allows users to chain multiple actions in one transaction, such as swapping and adding liquidity. This system tracks token balances throughout the transaction and ensures all debts are settled.
If not all debts are settled, the transaction is reversed, which cuts gas costs and boosts efficiency. This is a significant improvement over previous versions of Uniswap.
The flash accounting system also helps make routes between liquidity pools significantly more gas efficient. It tracks balance deltas throughout the lifetime of a single transaction and ensures all debts are settled at the end.
To settle unsettled positive deltas, users must deliberately call the clear() function. This serves as a protection mechanism against unknowingly leaving unsettled deltas and prevents accidental state changes.
The use of assembly-level transient storage for various operations, including lock/unlock states, currency deltas, delta counts, and currency reserves, enables flash accounting in Uniswap V4. This reduces gas costs by minimizing storage operations on both token transfers and internal state updates.
Here are the types of storage operations made possible by transient storage:
- Lock/unlock states
- Currency deltas
- Delta counts
- Currency reserves
Flash Accounting and Storage

Flash accounting is a game-changer in Uniswap V4, allowing users to chain multiple actions in one transaction, like swapping and adding liquidity.
It tracks token balances throughout the transaction and ensures all debts are settled, cutting gas costs and boosting efficiency. If not, the transaction is reversed.
This design enables chaining multiple actions into a single transaction and reduces unnecessary token transfers, significantly improving gas efficiency in complex operations.
Flash accounting is made possible in Uniswap V4 by the use of assembly-level transient storage for various operations, including:
- Lock/unlock states
- Currency deltas
- Delta counts
- Currency reserves
Combined, these optimizations reduce gas costs by minimizing storage operations on both token transfers and internal state updates.
Fee Accounting
Accrued fees can function as a credit when modifying liquidity, allowing you to convert fee revenue into additional liquidity within your position.
In Uniswap V4, liquidity pools have unlimited fee tiers, giving you greater flexibility to accommodate different assets and trading strategies.
Accrued fees can be a valuable resource, but reducing liquidity automatically triggers the withdrawal of any unclaimed fee revenue.

The salt parameter can be used when creating liquidity to differentiate positions with the same range in the same pool, simplifying fee accounting.
Customized fee structures allow each pool to have its own unique fee structure, meeting the specific needs of different users.
If two users share the same range and state in the PoolManager, integrating contracts must handle fee management carefully to avoid conflicts.
Native Ethereum Support
Native Ethereum support is a significant improvement in Uniswap V4, allowing for direct trading pairs with native ETH, eliminating the need for Wrapped ETH (WETH).
This simplification makes the trading process more straightforward and reduces transaction costs. Direct trading pairs with native ETH also eliminate the need for WETH.
The implementation of the Singleton Contract and flash accounting enables users to pair directly with native ETH. This change was made to address concerns over liquidity fragmentation and implementation complexity in V2.
The WETH pair will still be supported for users who prefer it. However, native ETH pairs offer a more efficient and cost-effective option.
Native Token Support and Custom Types
Native token support is a game-changer in Uniswap V4, allowing direct support for native tokens without the need for wrapped ERC-20 alternatives.
This is due in part to Uniswap V4's extensive use of custom types, which include the Currency representation. Currency unifies ERC-20 and native token handling through a common transfer API.
The Currency type includes a transfer API that can handle both ERC-20 and native tokens with ease.
One of the benefits of using custom types is gas efficiency, achieved through in-memory packing of the Slot0 struct.
This is particularly useful for handling large amounts of data, such as the 4096 bytes returned by some Curve v1 tokens.
Certain tokens, like CELO, have both native and ERC-20 representations, which can make token handling more complex.
To avoid security vulnerabilities, great care should be taken when implementing these types of tokens, as documented in the Open Zeppelin audit report.
Here are some examples of custom types used in Uniswap V4:
- BalanceDelta
- BeforeSwapDelta
- PoolId
- Slot0
Native Eth Support
Native ETH support is a significant improvement in Uniswap V4, allowing direct trading pairs with native ETH without the need for Wrapped ETH (WETH).
This simplification makes the trading process more straightforward and reduces transaction costs, as noted in Uniswap's documentation.
The implementation of the Singleton Contract and flash accounting enables users to directly pair with native ETH, eliminating the need for WETH.
However, the WETH pair will still be supported for users who prefer it.
Here are some key benefits of native ETH support in Uniswap V4:
- Eliminates the need for WETH, making transactions more straightforward
- Reduces transaction costs
- Directly pairs with native ETH using the Singleton Contract and flash accounting
It's worth noting that certain tokens, like CELO, have both native and ERC-20 representations, which can make token handling more complex.
Frequently Asked Questions
Is Uniswap V4 released?
No, Uniswap V4 has not been released yet, with a planned launch expected by the end of 2024. The upgrade promises significant improvements, including a 99% reduction in certain gas fees.
What is the difference between Uniswap V3 and V4?
Uniswap V4 introduces a unique salt parameter for each liquidity position, unlike V3, which shared pool state among similar deposits. This change improves customization and tracking, making V4 more tailored to individual users
How does Uniswap V4 work?
Uniswap V4 enables users to perform multiple actions in a single transaction, such as swapping and adding liquidity, with a built-in system that ensures accurate token balances and debt settlement. This "flash accounting" system boosts efficiency and reduces gas costs.
What is a V4 hook?
A V4 hook is a separate smart contract that adds custom logic to Uniswap pool operations, allowing developers to modify swap behavior and create complex strategies. This innovation enables developers to enhance Uniswap's functionality without altering the protocol itself.
Sources
- https://coinswitch.co/switch/crypto/uniswap-v4-upgrade/
- https://blog.uniswap.org/uniswap-v4
- https://empirica.io/blog/uniswap-v4-the-most-important-changes-compared-to-v3-when-creating-a-pool/
- https://www.cyfrin.io/blog/uniswap-v4-vs-v3-architectural-changes-and-technical-innovations-with-code-examples
- https://threesigma.xyz/blog/uniswap-v4-features-dynamic-fees-hooks-gas-saving
Featured Images: pexels.com