UNISWAP V4
What is Uniswap v4?
HOOKS & CUSTOM POOLS:
Each Uniswap liquidity pool has a lifecycle. During a pool’s lifecycle, several things happen. A pool is created with a default fee tier. Liquidity is added, removed, or readjusted. And, of course, users swap tokens. In Uniswap v3, these lifecycle events are tightly coupled and executed in a very strict sequence.
To create room for customizable liquidity in Uniswap v4, we want to create a way for pool deployers to introduce code that performs a designated action at key points throughout the pool’s lifecycle – like before or after a swap, or before or after an LP position is changed.
Enter hooks, which are plugins to customize how pools, swaps, fees, and LP positions interact. Developers can innovate on top of the Uniswap Protocol’s liquidity and security to create customized AMM pools through hooks that integrate with v4’s smart contracts.
Some experiments we’re excited about include:
- A time-weighted average market maker (TWAMM)
Dynamic fees based on volatility or other inputs
Onchain limit orders
Depositing out-of-range liquidity into lending protocols - Customized onchain oracles, such as geomean oracles
Autocompounded LP fees back into the LP positions
Internalized MEV profits are distributed back to LPs
But really, the sky’s the limit. Because each pool is now defined by more than just the tokens and fee tier, we’ll see pools of all colors, shapes, and sizes. Uniswap v4’s core logic, like v3, is non-upgradeable. While each pool can use its own hook smart contract, hooks can be limited to only specific permissions determined at pool creation.
We’ve created sample hook contracts to start to understand the current framework here. We expect developers to think of new and interesting ways to build features we haven’t even thought of yet.
313
Improved architecture and gas savings
In Uniswap v3, we deploy a new contract for every pool, making creating pools and performing multi-pool swaps more expensive. In v4, we hold all the pools in one singleton contract, which will provide important gas savings because swaps will no longer need to transfer tokens between pools held in different contracts. Early estimates show that v4 reduces pool creation gas costs by 99%. Hooks introduce a world with endless options and singleton allows you to efficiently route across all of them.
This singleton architecture is complemented by a new "flash accounting" system. Instead of transferring assets in and out of pools at the end of every swap in v3, this system transfers only on net balances -- meaning a far more efficient system that provides additional gas savings in Uniswap v4.
We believe the best design for flash accounting uses "transient storage," which would be enabled by EIP-1153. This EIP is being considered as part of the Ethereum Cancun hardfork and will bring even bigger gas improvements and cleaner contract designs across a wide variety of applications.
With the efficiency of singleton and flash accounting, fee tiers no longer need to be limited. Pool creators can set them at the level that makes them most competitive or customize them with a dynamic fee hook. v4 also brings back support for native ETH, which offers additional gas savings.