What is Uniswap v4

Uniswap is a protocol that allows the exchange of tokens on the Ethereum network. They recently announced the release of Uniswap v4, which will allow anyone to make these compensation decisions by introducing “hooks.” Uniswap v4 architecture reduces costs and ensures efficiency. It introduces a new “singleton” contract, where all pools live within a single smart contract. Let's see what new version 4 of Uniswap brings us. 

What is Uniswap?

Uniswap is a protocol that allows the exchange of tokens on the Ethereum network. Typically, exchanges operate using an order book in which market makers set the price at which they are willing to buy and sell an asset. The difference between these prices is how they are paid for this work. Uniswap dispenses with the order book entirely, instead opting for market makers to deposit assets into a pool that traders can trade with. The price is determined algorithmically based on the ratio of the two assets being traded.

diagram

Schematic of how a Uniswap liquidity pool works. Source: Uniswap Docs.

What's new Uniswap v4 brings

Along with customization features, Uniswap v4 architecture reduces costs and ensures efficiency. It introduces a new “singleton” contract, where all pools live within a single smart contract. The combination of hooks and singleton architecture creates an incredibly powerful, fast, secure pool customization and efficient routing platform across many pools. Uniswap v4 brings fast and expressive AMM innovation within a powerful ecosystem. We can highlight these three new features incorporated into v4 of Uniswap: 

Customizable hooks and pools

To create room for customizable liquidity in Uniswap v4, we have created a way for pool implementers to enter code that performs a designated action at key points throughout the pool lifecycle, such as before or after a swap, or before or after an LP position is changed. Hooks are add-ons that allow you to customize how pools, swaps, commissions, and LP positions interact. Developers can innovate on the liquidity and security of the Uniswap protocol to create custom AMM pools through hooks that integrate with v4 smart contracts. Among others, these are the most notable new additions:

  • A time-weighted average market maker (TWAMM)
  • Dynamic fees based on volatility or other variables
  • Onchain Limit Orders
  • Liquidity deposit out of range in lending protocols
  • Custom onchain oracles, such as geomean oracles
  • Self-Compounded LP Commissions on LP Positions
  • The internalized profits of MEV are distributed to the LPs.

Although each pool can use its own smart contract hook, hooks can be limited to only specific permissions determined at the time of pool creation.

diagram

Evolution of Uniswap pools from v3 to v4. Source: Uniswap Blog.

Improved architecture and gas savings

In version 4, we will keep all pools in a single contract, which will be a significant gas savings because swaps will no longer have to transfer tokens between pools held in different contracts. Early estimates show that v4 reduces pool creation gas costs by 99%. Hooks introduces a world with infinite options and singleton allows you to cycle through them all efficiently. This singleton architecture is complemented by a new “flash accounting” system. Instead of transferring assets in and out of pools at the end of each swap in v3, this system transfers only on net balances – meaning a much more efficient system that provides additional gas savings on Uniswap v4. With EIP-1153, considered as part of the Ethereum Cancun hardfork, it will bring even greater gas improvements and cleaner contract designs across a wide variety of applications. With the efficiency of singleton and flash accounting, there is no longer a need to limit commission levels. Pool creators can set their pools to the level that makes them most competitive or customize them with a dynamic commission hook. v4 also brings back support for native ETH, offering additional gas savings.

diagram

Structure of EIP-1153. Source: Ethereum Magicians.

License and governance

The code will be released under a Business Source License 1.1, which limits use of the v4 source code in a commercial or production environment for up to four years, at which time it will be converted to a GPL in perpetuity. Like v3, Uniswap Governance and Uniswap Labs may grant exceptions to the license. The Protocol's fee mechanism will also follow the v3 model. Governing bodies may vote to add a Protocol fee to any pool, up to a maximum amount.

code

Uniswap v3 code example. Source: Trapdoor-Tech.