Merkl | Blog

What is Uniswap v4? Comparison between Uniswap v4 and Uniswap v3

Written by Noe | 12/16/24 11:50 AM

Overview of Uniswap

What Is Uniswap?

Uniswap is a decentralized exchange (DEX) platform that allows users to buy, sell, and trade cryptocurrencies directly with one another, without the need for a central authority.

Built on the Ethereum blockchain, Uniswap uses an automated protocol called "Automated Market Maker" (AMM). Unlike traditional exchanges that rely on order books, Uniswap relies on "liquidity pools", where users deposit funds to facilitate trades.

With Uniswap, anyone can become a liquidity provider and earn fees in return for their investment. This approach enables fast and unrestricted transactions, removing geographic limitations. The platform is also known for its transparency, as it relies on smart contracts, which are self-executing programs on the blockchain that operate autonomously and immutably.

Uniswap plays a crucial role in the decentralized finance (DeFi) ecosystem, offering both investment opportunities and greater accessibility to cryptocurrency trading. It also strengthens the principles of decentralization and autonomy that define the crypto world, empowering users through peer-to-peer interactions and smart contract technology.

Want to leverage Uniswap v4 to drive your token growth?

 

Evolution of Uniswap

Introduction to Uniswap v1

Uniswap v1, launched in November 2018, introduced the concept of an "Automated Market Maker" (AMM) to decentralized exchanges. This first version enabled peer-to-peer trading through liquidity pools, where users would deposit funds to facilitate transactions. Uniswap v1 laid the foundation for decentralized finance (DeFi) by removing the need for centralized platforms and ensuring transparent, trustless exchanges. However, it faced challenges such as high fees and liquidity issues that limited its scalability and efficiency on a larger scale.

Introduction to Uniswap v2

Uniswap v2, launched in May 2020, brought significant enhancements to the platform. It introduced features like direct token swaps, integration with external oracles, and more efficient conversion mechanisms. One of the major upgrades was the improvement of liquidity pools, which enabled faster and cheaper transactions. Uniswap v2 also facilitated greater interoperability with other DeFi projects, solidifying its role as a critical infrastructure component in the Ethereum ecosystem.

Introduction to Uniswap v3

Uniswap v3, deployed in May 2021, introduced the concept of "concentrated liquidity", a game-changing feature that allowed liquidity providers to specify price ranges where their capital would be most actively deployed. This resulted in higher capital efficiency and reduced risks associated with impermanent loss. Uniswap v3 further optimized fees and improved overall profitability for liquidity providers. By consolidating these advanced functionalities, Uniswap v3 solidified its status as a leading decentralized exchange platform, offering better capital efficiency, greater accessibility, and robust profitability opportunities for users and investors alike.

Introduction to Uniswap v4

Uniswap v4 Core brings major improvements with customizable "hooks", allowing developers to add specific actions during swaps and liquidity changes. The introduction of a singleton contract model consolidates all pools into a single contract, drastically reducing gas costs. The Flash Accounting System further optimizes transactions by transferring tokens only once at the end of swaps. These upgrades aim to enhance efficiency, flexibility, and cost savings across the DeFi ecosystem while maintaining an open-source, community-driven development approach.

 

Learn how Merkl helped Uniswap launch on new chains

 

What is Uniswap v4?

Innovations of Uniswap v4

Hooks and Custom Pools

Uniswap v4 Core introduces "hooks", a powerful feature that enables developers to customize actions at different stages of a pool's lifecycle, such as before or after swaps or liquidity adjustments. These Uniswap v4 hooks allow the creation of tailored functionalities like dynamic fees, time-based liquidity incentives, and on-chain risk management strategies. Developers can build unique, custom pools with specialized logic, unlocking new opportunities for automated strategies and enhanced DeFi interactions.

Singleton Contract

The singleton contract model in Uniswap v4 consolidates all liquidity pools into a single, unified contract. This design drastically reduces gas fees by eliminating the need to transfer tokens across separate contracts. By having all pools reside within one contract, swap routing becomes more efficient, transactions faster, and overall costs minimized, which significantly benefits traders and liquidity providers alike.

Flash Accounting

Uniswap v4 introduces a new Flash Accounting System, which optimizes asset transfers by consolidating swaps into a single net balance transfer at the end of transactions. Unlike previous versions, which required multiple token transfers during swaps, this system minimizes redundant operations, reducing gas fees and streamlining performance. This enhancement enables more efficient high-frequency trading and reduces costs across the network.

Native ETH Trading Pairs

Another notable improvement in Uniswap v4 Core is the support for native ETH trading pairs. By directly supporting ETH without wrapping it into WETH, Uniswap offers additional gas savings and a smoother user experience. This eliminates unnecessary conversion steps, making trades more cost-effective and faster while enhancing overall transaction efficiency.

Governance

Uniswap v4 continues to uphold its commitment to community-driven governance, ensuring that protocol updates and changes remain open and transparent. The code is released under a Business Source License, with a commitment to convert to a GPL license after four years. This open-source approach invites developers and the community to contribute hooks and customize functionalities, fostering innovation and adaptability across DeFi projects. Governance remains a collective effort, empowering the Uniswap community to shape the platform's development and future enhancements.

 

Discover how Uniswap v4 can boost your business

Benefits and Limitations of Uniswap v4

What are the benefits of Uniswap v4?

Customization

Uniswap v4 offers unparalleled customization through its innovative "hooks". Developers can create tailored functionalities at various stages of swaps and liquidity operations, such as adding automated yield strategies, custom fees, or risk management logic. This flexibility enables more specialized interactions within the protocol, empowering projects to create unique DeFi solutions that suit specific goals and strategies

Efficiency

Uniswap v4 prioritizes efficiency with upgrades that enhance the speed and reliability of swaps. The introduction of the singleton contract model ensures that swap routing and pool interactions are faster and smoother since all liquidity pools are managed within a single, consolidated contract. This ensures quicker trades and a more seamless experience for both traders and liquidity providers.

Gas Reduction

One of the standout benefits of Uniswap v4 is its significant gas reduction. The singleton contract model and Flash Accounting System minimize unnecessary token transfers, consolidating swaps into a single net transfer at the end of transactions. These upgrades drastically reduce gas fees, making trades cheaper and more accessible to a broader range of users.

Potential for Increased Earnings for LPs

Liquidity providers (LPs) benefit significantly from Uniswap v4's upgrades. With the use of custom Uniswap v4 hooks, LPs can implement strategies to optimize returns, such as deploying liquidity in highly profitable price ranges or automating yield adjustments. Additionally, new protocols like Bunni address previous issues with concentrated liquidity, offering tools to automate liquidity management and maximize asset efficiency.

Advanced Trading Strategies

Uniswap v4 opens the door to advanced trading strategies, thanks to the integration of hooks and customizable liquidity pools. Traders can implement sophisticated, automated strategies directly on-chain, such as dynamic fee adjustments or complex liquidity placement logic. This level of customization allows traders to take advantage of market conditions, reduce impermanent loss risks, and enhance overall trading profitability.

These enhancements position Uniswap v4 as a more cost-effective, efficient, and flexible platform for DeFi trading and liquidity management, offering a competitive edge to developers, traders, and liquidity providers alike.

What are the limitations of Uniswap v4?

Fee Collection

Uniswap v4 whitepaper introduces two distinct fee mechanisms: swap fees and withdrawal fees. While the swap fee system remains similar to Uniswap v3, governance—comprising Uniswap DAO members and UNI token holders—can decide to collect a capped portion of swap fees from specific pools. Additionally, in Uniswap v4, governance has the authority to take a capped percentage of withdrawal fees if "hooks" enable these fees within a pool. These mechanisms add flexibility but also add complexity in fee distribution and governance decisions.

License Restricting Usage

Uniswap v4 is set to be deployed under the Business Source License 1.1, which restricts commercial and production use of the source code for a period of four years. After this term, the code will transition to a General Public License (GPL), ensuring long-term openness. However, this licensing model has sparked criticism within the community, as it limits the true open-source nature of the latest Uniswap iteration and hinders innovation in commercial or production environments during this initial timeframe.

v4 Code Format Controversy

The adoption of Uniswap v4’s code format, as outlined on the Uniswap v4 GitHub, has stirred developer controversy, primarily due to the constraints imposed by the licensing model. Many developers are dissatisfied with the current limitations, as these constraints prevent them from fully leveraging the protocol’s potential in commercial and production settings. This tension has slowed down some development initiatives and discouraged experimentation until the code is fully open-sourced under the GPL.

Heightened Protocol Vulnerability

Uniswap v4, as detailed in the Uniswap v4 GitHub, consolidates all liquidity pools into a single contract, a design choice that raises significant security risks. Historically, DeFi protocols have been targets of high-profile hacks due to vulnerabilities in smart contracts, despite thorough audits. In this setup, a single exploit could compromise the security of the entire Uniswap protocol. Addressing this risk requires the Uniswap team to implement robust, security-focused solutions to ensure that all pools remain safeguarded against potential attacks and protocol breaches.

What is the difference between Uniswap v4 and Uniswap v3?

Comparison of Uniswap v4 vs v3 features

FEATURE UNISWAP v3 UNISWAP v4
POOL CREATION More costly and limited, with choices restricted to fee tiers and price ranges. More affordable with greater flexibility, offering custom logic and functionality through Uniswap v4 hooks at various stages.
POOL ARCHITECTURE Each token pair is managed through a separate smart contract (Factory-pool). All pools are unified into a single contract (Singleton).
FEE STRUCTURE Fees are fixed with predefined tiers (0.05%, 0.30%, and 1%). Fees are dynamic and customizable via Uniswap v4 hooks, allowing each pool to have unique fee structures.
LIQUIDITY PROVISION Liquidity providers (LPs) can only select specific price ranges. Concentrated liquidity is maintained with customizability through Uniswap v4 hooks.
GAS COSTS Higher, due to the need for individual contracts for each token pair. Lower, thanks to the consolidated Singleton contract approach.
LIQUIDITY MANAGEMENT Utilizes Automated Market Maker (AMM). Utilizes Time-Weighted Average Market Maker (TWAMM) through Uniswap v4 hooks, which spreads large orders over time.
ORDER TYPES CUSTOMIZATION Not supported. Supported through Uniswap v4 hooks, allowing custom on-chain order types, such as limit and stop-loss orders.
NATIVE ETH Uses Wrapped ETH (WETH). Uses native ETH directly.
ACCOUNTING ERC20 standard. Flash accounting method supported.


Want to distribute incentives on Uniswap v4?

Examples of Uniswap v4 vs v3 code changes

Singleton pattern & ERC-6909

Uniswap v4 introduces in its whitepaper a singleton architecture, where a single PoolManager contract stores and manages all assets. In contrast, Uniswap v3 uses separate contracts for each pool, which means higher gas costs and more complex interactions. The singleton setup in v4 reduces gas costs and boosts capital efficiency by combining all token pairs into one contract, eliminating the need to route swaps through multiple individual pools. However, this design increases security risks, as a single exploit could compromise the entire system, unlike the more compartmentalized but still vulnerable pools in v3.

Flash accounting and transient storage

Uniswap v4’s flash accounting system optimizes gas efficiency by tracking balance changes throughout a transaction and only settling them at the end. In Uniswap v3, token transfers occur multiple times during swaps, resulting in higher gas costs. v4 consolidates these operations into a single net transfer, saving costs and ensuring accurate state updates. Additionally, v4 uses assembly-level transient storage, optimizing operations like lock/unlock states, currency reserves, and delta counts, which significantly reduce gas fees compared to the more fragmented operations seen in v3.

Hooks and custom accounting

Uniswap v4 hooks allow developers to inject custom logic at various stages of swap and liquidity operations without needing a protocol fork. In Uniswap v3, modifying AMM mechanics typically requires a fork or custom pool implementation, which is risky and less flexible. v4’s 14 permissions across 8 hook types optimize gas costs by embedding permissions directly into addresses. This customization enables features like dynamic fees, stable swap curves, and Time-Weighted Average Market Maker (TWAMM), offering more advanced and efficient solutions than v3's concentrated liquidity approach.

Fee flexibility

Uniswap v4 removes the fee tier limitations of Uniswap v3 (0.05%, 0.30%, 1.00%), allowing pools to set any custom fee value, even dynamically adjusting fees based on market conditions. v3’s rigid fee tiers can limit profitability and flexibility. v4’s singleton architecture consolidates tokens, reducing fragmentation across pools, while market dynamics drive liquidity aggregation, ensuring providers naturally form profitable and efficient pools. Additionally, v4 replaces v3's on-chain enumeration of pools with event indexing, such as tracking the Initialize event, to manage pool creation and interactions.

Native token support and custom types

Uniswap v4 directly supports native tokens (like ETH) without needing wrapped ERC-20 tokens, which was a necessity in Uniswap v3. v4 introduces custom types, including Currency, BalanceDelta, PoolId, and Slot0, which streamline token handling with a common transfer API. These custom types improve gas efficiency, such as packing the Slot0 struct in memory, and address compatibility issues like Curve v1 tokens returning non-standard data sizes. However, caution is necessary for tokens like CELO, which exist in both native and ERC-20 forms, as handling these representations through v4's custom Currency type requires careful implementation to avoid security vulnerabilities not as prominently seen in v3’s simpler token representations.

Should you use Uniswap v3 or v4?

If you prioritize customization, efficiency, and gas savings, Uniswap v4 is the superior choice. Its hooks enable tailored functionalities for swaps and liquidity operations, while the singleton contract model boosts speed and reduces gas costs by consolidating pools. Liquidity providers can also optimize returns with tools like Bunni, enhancing asset management and profitability. However, Uniswap v4 comes with trade-offs: fee collection adds governance complexities, the licensing model restricts commercial use for four years, and the consolidated architecture increases protocol vulnerability, requiring extra security measures.

If you prefer a more stable, battle-tested solution with a mature ecosystem, Uniswap v3 remains a solid choice, offering well-established features with widespread community support and proven reliability. Choose v4 for cutting-edge customization and efficiency, but consider v3 if you want a safer and more conventional DeFi experience.

For more details and to explore, audit the code, visit the Uniswap v4 GitHub repository or Uniswap v4 whitepaper docs.

Conclusion

Uniswap v4 builds on the foundation of v3 with significant advancements in customization, efficiency, and gas savings, thanks to features like hooks, the singleton contract model, and Flash Accounting. These updates offer developers and liquidity providers greater flexibility, cost-efficiency, and innovative opportunities.

However, Uniswap v4 introduces complexities with its fee collection mechanisms, licensing restrictions, and a consolidated architecture that heightens security risks. Choosing between v3 and v4 ultimately depends on your priorities: stick with v3 for a well-established, battle-tested experience, or move to v4 for cutting-edge flexibility and cost optimization, while carefully navigating its trade-offs.

FAQs about Uniswap v4

Is Uniswap v4 released?

No, Uniswap v4 has not yet been released. It is currently in development and expected to be available by late January 2024. The Uniswap team is actively working on finalizing updates and enhancements to bring new features and optimizations to the DeFi ecosystem.

When Uniswap v4 has been launched?

Uniswap v4 is scheduled to launch at the end of January 2024. The development team is focused on ensuring that all updates and customizations, such as the singleton architecture, hooks, and Flash Accounting, are thoroughly tested and optimized before the release.

Is Uniswap v3 still used?

Yes, Uniswap v3 remains widely in use and continues to be a popular choice for traders and liquidity providers. It introduced features like concentrated liquidity, which significantly improved capital efficiency. Even with the upcoming Uniswap v4 release, v3 will remain an important part of the Uniswap ecosystem, offering stability and a mature, battle-tested environment for DeFi interactions.