Uniswap Labs Blog

Our Vision for Uniswap v4
June 13, 2023

By Hayden Adams

Two years ago, we released Uniswap v3, a watershed moment for onchain liquidity and DeFi. Today, the Uniswap Protocol is the largest decentralized exchange protocol, processing over $1.5 trillion in trading volume. As public infrastructure, it's a vital part of the crypto ecosystem.

As technology and markets evolve, so must the Uniswap Protocol. That's why we're thrilled to introduce our vision for Uniswap v4, which we believe will open up a world of possibilities for how liquidity is created and how tokens are traded onchain.

We are releasing the draft code now so that v4 can be built in public, with open feedback and meaningful community contribution. We expect this will be a months-long process. You can read the open-sourced, early version of the Uniswap v4 core and periphery repositories, read the draft technical whitepaper here, and learn more about how to contribute here.

Uniswap v3 took a powerful, opinionated approach to liquidity provision, balancing an incredibly complex tradeoff space. New features come at the expense of higher fees and code complexity.  For example, v3 enshrined oracles, allowing builders to integrate real-time, onchain pricing data, but at the expense of some increased costs for swappers.

Our vision with Uniswap v4 is to allow anyone to make these tradeoff decisions through the introduction of "hooks." Hooks are contracts that run at various points of a pool action's lifecycle. Pools can make the same tradeoffs as v3, or they can add totally new functionality. For example, v4 will allow pools that natively support dynamic fees, add onchain limit orders, or act as a time-weighted average market maker (TWAMM) to spread out large orders over time.

Along with this customization, Uniswap v4's architecture reduces costs and ensures efficiency. It introduces a new "singleton" contract, where all pools live within a single smart contract. We believe the combination of hooks and singleton architecture creates an incredibly powerful platform ⸺ fast, safe pool customization and efficient routing across many pools. Uniswap v4 brings fast, expressive AMM innovation within one powerful ecosystem.

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.

Chart (1)

License and Governance

As always, we strongly believe that core financial infrastructure should be open and transparent. We also believe that the Uniswap community — the people and teams that support, use, and build on the Protocol — should govern v4 of the Protocol, just as they govern prior versions.

The code will be released under a Business Source License 1.1, which limits the use of the v4 source code in a commercial or production setting for up to four years, at which point it will convert to a GPL license into perpetuity. Like v3, Uniswap Governance and Uniswap Labs can grant exceptions to the license.

The Protocol fee mechanism will also be modeled after v3. Governance will be able to vote to add a Protocol fee to any pool, up to a capped amount. More details on the fee mechanism can be found in the whitepaper.

Related posts