5/5
## Unlocking the Next Generation of DeFi: Uniswap V3 vs. V4 Uniswap v4 represents a significant evolution from its predecessor, V3, introducing a suite of powerful features designed to enhance customizability, reduce gas costs, and improve capital efficiency. This upgrade moves beyond incremental improvements to fundamentally reshape how developers and users interact with the protocol. Let's explore the five key innovations that define this upgrade: Hooks, Dynamic Fees, the Singleton Design, Flash Accounting, and the ERC6909 token standard. ## Introducing Hooks: The Future of AMM Customization The most transformative feature in Uniswap v4 is the introduction of "hooks." Hooks are external smart contracts that allow developers to execute custom logic at specific points within a liquidity pool's lifecycle. The core Uniswap v4 `PoolManager` contract makes calls to these hook contracts either immediately before or after a major pool operation. This creates a powerful plugin system directly at the protocol level. Hooks can be triggered by a variety of actions, including: - Initial pool creation - Adding or removing liquidity - Executing a swap - Donating to a pool The possibilities enabled by hooks are vast, allowing developers to build entirely new types of automated market makers (AMMs) and integrated features. For example, a developer could implement a hook that functions as a time-weighted average market maker (TWAMM), or one that executes a swap only when a specific on-chain price is reached, effectively creating native limit orders. Other powerful use cases include hooks for dynamic fee adjustments, automated rebalancing of concentrated liquidity, and the creation of custom on-chain oracles. ## From Static to Dynamic Fees Uniswap V3 operates on a static fee model. When a liquidity pool is created, the fee is set to a fixed tier (e.g., 0.05%, 0.30%, or 1.00%) and cannot be changed for the lifetime of that pool's contract. This model is simple but lacks the flexibility to adapt to changing market conditions. Uniswap v4 introduces dynamic fees, a more responsive and flexible system. Enabled by hooks, pool creators can implement custom logic to adjust swap fees based on any on-chain variable, such as market volatility or trading volume. A developer could design a hook that raises fees during periods of high volatility to better compensate liquidity providers for impermanent loss, and lowers them when the market is stable to attract more trading volume. This functionality can be triggered on every swap, on a set schedule, or by any other condition defined in the hook's code. ## The Singleton Architecture: A Paradigm Shift for Gas Efficiency A core architectural change in Uniswap v4 is the move to a "Singleton" design, which dramatically reduces gas costs, especially for creating new pools and executing multi-hop swaps. In Uniswap V3, a "factory" contract is used to deploy a new, separate smart contract for every single token pair (e.g., a unique contract for ETH-USDC, another for USDC-DAI, and so on). This fragments liquidity across thousands of contracts and makes creating a new pool an expensive transaction. Uniswap v4 consolidates all pools into a single, master smart contract. This eliminates the need to deploy new contract code for each new pair, reducing the gas cost of pool creation by an estimated 99%. This design also makes multi-hop swaps significantly more efficient. Consider a swap from ETH to DAI, routed through USDC. - **On V3:** The user's ETH is sent to the `ETH-USDC` pool contract for the first swap. The resulting USDC is then transferred from the `ETH-USDC` contract to the separate `USDC-DAI` pool contract—an expensive token transfer between contracts. The second swap occurs, and the final DAI is sent to the user. - **On V4:** The user interacts with the single Uniswap contract. The swap is routed internally from the ETH-USDC pair to the USDC-DAI pair. Because all tokens and pool logic reside within the same contract, there are no costly external token transfers between pools. The contract simply updates its internal accounting of token balances, resulting in major gas savings. ## Flash Accounting: Optimizing Transactions with Transient Storage The Singleton design enables another powerful optimization called Flash Accounting. This system leverages EIP-1153 (transient storage) to further reduce gas costs by minimizing actual token transfers during a transaction. With Flash Accounting, token transfers only happen at the very beginning (for input tokens) and the very end (for output tokens) of a complex transaction, like a multi-hop swap. In the intermediate steps, the system only tracks the net balance changes. This eliminates the gas-intensive process of sending tokens back and forth between different pools or contracts. This system has two major benefits beyond swap efficiency: 1. **Fee-Free Flash Loans:** Users can borrow any amount of a token from a V4 pool and use it anywhere on-chain, as long as the loan is repaid by the end of the same transaction. Unlike in V3, these flash loans carry no fee. 2. **Enhanced Flash Loan Power:** In V3, a flash loan is limited to the liquidity available in a single pool. Because all liquidity in V4 is held in one contract, a user can borrow the _entire balance_ of a token across _all pools_, making flash loans significantly more powerful for arbitrage and other complex DeFi strategies. ## The ERC6909 Standard: A New Vault for Your Tokens To complement the Singleton and Flash Accounting systems, Uniswap v4 helps introduce ERC6909, a new token standard designed for ultimate gas efficiency. ERC6909 functions as a multi-asset "vault" or a container contract that can manage multiple underlying tokens (like WETH, DAI, and USDC) on behalf of a user. The primary use case is to minimize token transfer operations for active users and liquidity providers. In V3, every time a user adds liquidity, removes it, or claims fees, they initiate an ERC20 token transfer, which costs gas. With an ERC6909-compliant contract, a user deposits their tokens into their personal vault once. From there, they can add and remove liquidity, swap, and manage positions within the Uniswap v4 ecosystem without executing a new `transfer` or `transferFrom` call for each action. The Singleton contract simply updates the user's internal balances within the vault. An actual token transfer is only required when the user wants to move their assets out of the Uniswap v4 system entirely. This dramatically reduces the cumulative gas costs for frequent traders and liquidity providers.
Uniswap v4 represents a significant evolution from its predecessor, V3, introducing a suite of powerful features designed to enhance customizability, reduce gas costs, and improve capital efficiency. This upgrade moves beyond incremental improvements to fundamentally reshape how developers and users interact with the protocol. Let's explore the five key innovations that define this upgrade: Hooks, Dynamic Fees, the Singleton Design, Flash Accounting, and the ERC6909 token standard.
The most transformative feature in Uniswap v4 is the introduction of "hooks." Hooks are external smart contracts that allow developers to execute custom logic at specific points within a liquidity pool's lifecycle. The core Uniswap v4 PoolManager
contract makes calls to these hook contracts either immediately before or after a major pool operation.
This creates a powerful plugin system directly at the protocol level. Hooks can be triggered by a variety of actions, including:
Initial pool creation
Adding or removing liquidity
Executing a swap
Donating to a pool
The possibilities enabled by hooks are vast, allowing developers to build entirely new types of automated market makers (AMMs) and integrated features. For example, a developer could implement a hook that functions as a time-weighted average market maker (TWAMM), or one that executes a swap only when a specific on-chain price is reached, effectively creating native limit orders. Other powerful use cases include hooks for dynamic fee adjustments, automated rebalancing of concentrated liquidity, and the creation of custom on-chain oracles.
Uniswap V3 operates on a static fee model. When a liquidity pool is created, the fee is set to a fixed tier (e.g., 0.05%, 0.30%, or 1.00%) and cannot be changed for the lifetime of that pool's contract. This model is simple but lacks the flexibility to adapt to changing market conditions.
Uniswap v4 introduces dynamic fees, a more responsive and flexible system. Enabled by hooks, pool creators can implement custom logic to adjust swap fees based on any on-chain variable, such as market volatility or trading volume. A developer could design a hook that raises fees during periods of high volatility to better compensate liquidity providers for impermanent loss, and lowers them when the market is stable to attract more trading volume. This functionality can be triggered on every swap, on a set schedule, or by any other condition defined in the hook's code.
A core architectural change in Uniswap v4 is the move to a "Singleton" design, which dramatically reduces gas costs, especially for creating new pools and executing multi-hop swaps.
In Uniswap V3, a "factory" contract is used to deploy a new, separate smart contract for every single token pair (e.g., a unique contract for ETH-USDC, another for USDC-DAI, and so on). This fragments liquidity across thousands of contracts and makes creating a new pool an expensive transaction.
Uniswap v4 consolidates all pools into a single, master smart contract. This eliminates the need to deploy new contract code for each new pair, reducing the gas cost of pool creation by an estimated 99%. This design also makes multi-hop swaps significantly more efficient.
Consider a swap from ETH to DAI, routed through USDC.
On V3: The user's ETH is sent to the ETH-USDC
pool contract for the first swap. The resulting USDC is then transferred from the ETH-USDC
contract to the separate USDC-DAI
pool contract—an expensive token transfer between contracts. The second swap occurs, and the final DAI is sent to the user.
On V4: The user interacts with the single Uniswap contract. The swap is routed internally from the ETH-USDC pair to the USDC-DAI pair. Because all tokens and pool logic reside within the same contract, there are no costly external token transfers between pools. The contract simply updates its internal accounting of token balances, resulting in major gas savings.
The Singleton design enables another powerful optimization called Flash Accounting. This system leverages EIP-1153 (transient storage) to further reduce gas costs by minimizing actual token transfers during a transaction.
With Flash Accounting, token transfers only happen at the very beginning (for input tokens) and the very end (for output tokens) of a complex transaction, like a multi-hop swap. In the intermediate steps, the system only tracks the net balance changes. This eliminates the gas-intensive process of sending tokens back and forth between different pools or contracts.
This system has two major benefits beyond swap efficiency:
Fee-Free Flash Loans: Users can borrow any amount of a token from a V4 pool and use it anywhere on-chain, as long as the loan is repaid by the end of the same transaction. Unlike in V3, these flash loans carry no fee.
Enhanced Flash Loan Power: In V3, a flash loan is limited to the liquidity available in a single pool. Because all liquidity in V4 is held in one contract, a user can borrow the entire balance of a token across all pools, making flash loans significantly more powerful for arbitrage and other complex DeFi strategies.
To complement the Singleton and Flash Accounting systems, Uniswap v4 helps introduce ERC6909, a new token standard designed for ultimate gas efficiency. ERC6909 functions as a multi-asset "vault" or a container contract that can manage multiple underlying tokens (like WETH, DAI, and USDC) on behalf of a user.
The primary use case is to minimize token transfer operations for active users and liquidity providers. In V3, every time a user adds liquidity, removes it, or claims fees, they initiate an ERC20 token transfer, which costs gas.
With an ERC6909-compliant contract, a user deposits their tokens into their personal vault once. From there, they can add and remove liquidity, swap, and manage positions within the Uniswap v4 ecosystem without executing a new transfer
or transferFrom
call for each action. The Singleton contract simply updates the user's internal balances within the vault. An actual token transfer is only required when the user wants to move their assets out of the Uniswap v4 system entirely. This dramatically reduces the cumulative gas costs for frequent traders and liquidity providers.
A comparative breakdown of Uniswap V3 vs. V4 - Explore the five core architectural upgrades that define the V4 protocol, from the custom logic of Hooks to the gas-saving Singleton design. Learn how these features enable a new era of AMM efficiency and flexibility.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Things to Note:
Last updated on September 18, 2025
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 Singleton architecture
Uniswap v4 flash accounting
Uniswap v4 operations
Uniswap v4 lifecycle
How to build a Uniswap v4 swap router
Last updated on September 22, 2025
Duration: 5min
Duration: 7min
Duration: 39min
Duration: 35min
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 Singleton architecture
Uniswap v4 flash accounting
Uniswap v4 operations
Uniswap v4 lifecycle
How to build a Uniswap v4 swap router
Last updated on September 22, 2025