Risk Warning: Beware of illegal fundraising in the name of 'virtual currency' and 'blockchain'. — Five departments including the Banking and Insurance Regulatory Commission
Information
Discover
Search
Login
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt
BTC
ETH
HTX
SOL
BNB
View Market
Uniswap Labs releases Uniswap v4 code draft, a peep into the main functions
秦晓峰
Odaily资深作者
@@QinXiaofeng888
2023-06-13 15:11
This article is about 2141 words, reading the full article takes about 4 minutes
Features: hooks+singleton+flash accounting.


Tonight, UniswapLabs released a Uniswap v4 code draft so that v4 can be built publicly, with public feedback and meaningful community contributions. The vision of Uniswap v4 is to allow anyone to make trade-off decisions by introducing "hooks". Hooks are contracts that run at various points in the lifecycle of pool operations. Pools can make the same tradeoffs as v3, or they can add entirely new functionality. For example, v4 will allow the pool itself to support dynamic fees, add on-chain cap orders, or act as a time-weighted average market maker (TWAMM) to spread out large orders over time. v4 pools will exist in a single contract, which will reduce the gas cost of pool creation by 99%.

The Uniswap v4 code will be released under Business Source License 1.1, which will limit the use of the v4 source code in a commercial or production environment to 4 years, at which time it will be permanently converted to a GPL license. The protocol fee mechanism will also be modeled after v3. Governance will be able to vote to add protocol fees to any pool, up to a capped amount.

The following are the founders of UniswapHayden AdamsWriting articles, compiled by Odaily.

Two years ago we released Uniswap v3, a turning point for on-chain liquidity and DeFi. Today, the Uniswap protocol is the largest decentralized exchange protocol, handling over $1.5 trillion in transaction volume. As a public infrastructure, it is an important part of the cryptocurrency ecosystem.

As technology and markets evolve, the Uniswap protocol must evolve too. We are very happy to introduce the vision of Uniswap v4 to you, and we believe it will open up infinite possibilities for the trading method of creating tokens with on-chain liquidity.

We're releasing code drafts now to create v4 with open feedback and meaningful community contributions. We expect this to be a months-long process. You can read an open-source early release of the Uniswap v4 core and surrounding libraries here, read the draft technical white paper here, and learn more about how to contribute here.

Uniswap v3 takes a strong, assertive approach to providing liquidity, balanced by an extremely complex trade-off space. New features come at the cost of higher expense and code complexity. For example, the V3 version includes oracles, allowing builders to integrate real-time on-chain pricing data, but at the expense of increased costs for traders.

Our vision for Uniswap v4 is to allow anyone to make trade-off decisions by introducing "hooks". Hooks are contracts that run at different points in the lifecycle of pool operations. Pools can make the same tradeoffs as v3, or add entirely new functionality. For example, v4 will allow mining pools to support dynamic fees themselves, add on-chain cap orders, or act as a time-weighted average market maker (TWAMM) to spread out large orders over time.

While doing this customization, Uniswap v4's architecture also reduces costs and ensures efficiency. it introduces a new"singleton"(singleton) contract, all mining pools are in one smart contract. We believe the combination of hooks and singleton architecture will create a very powerful platform with fast and safe pool customization and efficient routing across multiple pools. Uniswap v4 brings fast, expressive AMM innovation in a robust ecosystem.

secondary title

hooks and custom pools

Every Uniswap liquidity pool has a lifecycle. During the lifetime of a pool, several things happen: pools are created with default fee tiers; liquidity is added, removed, or realigned; and of course, users trade tokens. In Uniswap v3, these lifecycle events are tightly coupled and executed in a very strict order.

In order to create room for customizable liquidity in Uniswap v4, we want to create a way for pool deployers to introduce code that performs specified actions at key points in the pool's life cycle -- such as before or after a trade, Or before or after changing LP positions.

Enter hooks, which are plugins that customize how pools, swaps, fees, and LP positions interact. Developers can innovate based on the liquidity and security of the Uniswap protocol, and create custom AMM pools through hooks integrated with v4 smart contracts.

We're excited about some experiments, including:

  • Time Weighted Average Market Maker (TWAMM)

  • Dynamic fees based on volatility or other inputs

  • On-chain limit orders

  • Deposit out-of-scope liquidity into the lending agreement

  • Custom on-chain oracles, such as geomean oracles

  • Automatically compound LP fees back into LP positions

  • Internalized MEV profits are distributed back to LPs

The sea is as wide as the fish leap, the sky is as high as the birds fly, the imagination space of v4 is unlimited. Now each pool is not just defined by tokens and fee tiers, we will see pools of all colors, shapes and sizes. The core logic of Uniswap v4 is the same as that of v3, which is not upgradeable. While each pool can use its own hooks smart contract, hooks can be restricted to specific permissions determined at pool creation time.

secondary title

Improve architecture and save gas

In Uniswap v3, we deploy a new contract for each pool, which makes it more expensive to create pools and perform multi-pool swaps. In v4, we put all the pools in a singleton contract, which will provide effective gas saving, because transactions no longer need to transfer tokens between pools in different contracts. Early data shows that v4 reduces pool creation gas costs by 99%. Hooks introduce a world of endless choices, and singletons allow you to efficiently span 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 each trade in v3, the system only makes transfers based on net balances - meaning a more efficient system, providing additional gas savings in Uniswap v4.

We believe that the best design for flash accounting is to use the"Instantaneous storage", which will be implemented by EIP-1153. This EIP is being considered to be included as part of the Ethereum Cancun hard fork upgrade and will bring more Gas improvements and cleaner contract designs in various applications.

secondary title

Licensing and Administration

As always, we firmly 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 have governed previous versions.

The code will be released under the Business Source License 1.1, which limits the use of the v4 source code in commercial or production environments to four years, at which point it will permanently transition to the GPL license. As with v3, Uniswap Governance and Uniswap Labs can grant license exceptions.

The charging mechanism of the protocol will also be based on v3. Governance layers will be able to vote to increase protocol fees in any pool, subject to a cap. More details on the fee mechanism can be found in the white paper.


Uniswap
Welcome to Join Odaily Official Community