Uniswap Labs releases draft code for 'entirely new' version of Uniswap

Quick Take

  • Uniswap Labs CEO Hayden Adams laid out his vision for the next version of the protocol, called V4.
  • Uniswap V4’s draft code has been released, and it will be assessed over the following months.

Uniswap Labs released draft code for V4, a brand new version of the protocol with architecture that will allow for much more customization.

The new design will be more efficient, with initial results suggesting it will reduce the cost of creating pools by 99%. It will also let developers choose their own tradeoffs, allowing them to build minimalistic pools that are cheaper to use. But the biggest change is that it creates a much broader playing ground for developers to build their own pools with their rules — potentially leading to much more experimentation.

“As technology and markets evolve, so must the Uniswap Protocol,” Uniswap Labs CEO Hayden Adams said in a blog post. “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.”

Uniswap V4 is an “entirely new protocol,” Uniswap Labs smart contract engineer Sara Reynolds said in an interview. But developers will still be able to choose which one they want to use, as it will coexist alongside V3, which is immutably written to the Ethereum blockchain.

The code has been open sourced and will be audited and tested in public over the next few months before an eventual release under a Business Source License 1.1, which will transition to a GPL license. The exchange will be governed by the Uniswap community, made up of those who hold UNI tokens. Uniswap Labs also released a draft technical whitepaper alongside the code for V4.

“I think the biggest change with V3 was with regards to capital efficiency,” said Reynolds. “I think with V4, we expand this and bring this idea of expressiveness to a whole new level by introducing what we're calling hooks.”

Two key changes

The new version will bring two main benefits: customization through the use of “hooks” and efficiency through a new architecture with a single smart contract.

First, Uniswap V4 comes with creator customization through plugins that are called hooks. These can be set up to work just how V3 works, or developers can use them to add new functionality. This is where greater customization can be applied to pools, with developers able to set dynamic fees and add functions like on-chain limit orders. 

“I think there's a lot of things that we haven't considered and haven't thought of yet, and I'm excited to see how the community takes that and runs with it,” said Reynolds.

Uniswap Labs has even been experimenting with building a hook that supports the ability to act as a time-weighted average market maker (TWAMM) to spread out orders over a period of time. In this case, the blockchain transaction fee would be paid once to create the order but it wouldn’t have to be paid by the originator each time a trade is made. Other ideas include a hook that distributes profits created by maximal extractable value back to those providing liquidity to the pool.

“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,” said Adams. He noted that V4 will also bring back support for native ether, rather than just wrapped ether.

Second, the new architecture puts all Uniswap pools in a single smart contract, rather than deploying a smart contract for every new pool (which is how Uniswap V3 works). This means token swaps no longer have to transfer tokens between different smart contracts, resulting in cheaper token swaps. Plus this is why new pools are far cheaper to create.

“We believe the combination of hooks and singleton architecture creates an incredibly powerful platform — fast, safe pool customization and efficient routing across many pools,” said Adams.

Bringing in flash accounting

The new version of Uniswap will also introduce a flash accounting system. 

Under V3, when you make a swap, the protocol might route the trade through a number of different pools. At each point, the protocol would transfer the tokens in and out of pools when making swaps along the way.

Under the new design, all the pools will be within one contract. Therefore the protocol only needs to transfer the net balances back to the user. This saves on blockchain transaction fees and opens up more flexibility. 

“It’s essentially just a new cool way of doing balance accounting and it ensures that the pool's balance is safe and the user's balance is safe,” said Reynolds.

Uniswap Labs is hoping to make use of Ethereum Improvement Proposal 1153, which is currently being considered for the Cancun hard fork. If this is enabled, it will result in simpler smart contract designs and reduce transaction fees even further.

© 2023 The Block. All Rights Reserved. This article is provided for informational purposes only. It is not offered or intended to be used as legal, tax, investment, financial, or other advice.