🎉 Gate xStocks Trading is Now Live! Spot, Futures, and Alpha Zone – All Open!
📝 Share your trading experience or screenshots on Gate Square to unlock $1,000 rewards!
🎁 5 top Square creators * $100 Futures Voucher
🎉 Share your post on X – Top 10 posts by views * extra $50
How to Participate:
1️⃣ Follow Gate_Square
2️⃣ Make an original post (at least 20 words) with #Gate xStocks Trading Share#
3️⃣ If you share on Twitter, submit post link here: https://www.gate.com/questionnaire/6854
Note: You may submit the form multiple times. More posts, higher chances to win!
📅 July 3, 7:00 – July 9,
Farewell to Fork Swap Uniswap V4 is entering the era of "Wan hook romance"?
Author: YBB Capital
Summary
Compared with the V3 version, which was released two years later in May 21, V4 has more free and flexible asset composability and greatly reduces the Gas fee required to provide liquidity and transactions. With the blessing of the new function Hooks (hooks), developers do not need to develop xxSwap, they only need to customize the liquidity in Hooks and add front-end pages and elements that meet their own needs, and then they can open "customized places". Worried about the problem of insufficient liquidity in the "designated place". Let's find out how Uni V4 leads DeFi from the "Lego Era" to the "Wangou Romance" era.
Uniswap V4—one of the few real innovations in the bear market
The iterative upgrade of Uniswap has allowed us to see the infinite potential of the DeFi world. It has not violated the original intention and rules of X*Y=K from the beginning to the end. The innovation of Uniswap V4 mainly focuses on providing more customized transaction logic, improving Gas efficiency and developer experience, and improving transaction convenience and efficiency. Compared with using V3, both developers and users can obtain more open, free and efficient automated market maker services. The following will fully introduce the upgrade of V4 and the two most important changes: Hooks and Singleton.
The introduction that changes everything: Hooks (hooks)
The core function of the Uniswap V4 version - Hooks, which allows every developer to create a customized DEX that meets the needs of the scene and build their own "Lego building blocks". Hooks are an important concept introduced by Uniswap V4. They are plug-ins for customizing the interaction of liquidity pools, exchanges, fees, and liquidity provider (LP) locations. Through the Hooks mechanism, developers can perform specific operations at key moments in the life cycle of the liquidity pool, such as before/after the exchange, or before/after the LP position changes.
At the same time, Hooks are also smart contracts, they interact with the core contract of Uniswap V4, and can be executed at different "key points" in the liquidity pool (key points refer to: operations before/after the exchange, or when LP deposits/withdrawals, etc. ), allowing developers to define and execute custom logic in a flexible manner. Hooks can be bound to a specific liquidity pool to control the behavior and interaction of the pool. For example, a developer could create a Hook that validates certain conditions before each swap, or perform some additional operations when the LP position changes.
Through Hooks, mining pool creators can adjust mining pool parameters and introduce new features to AMM, and even allow various DeFi strategies to be built on Uniswap, ultimately benefiting LPs / swappers more. It is not hard to imagine that the introduction of Hooks will bring developers greater flexibility and innovation space, and they can create unique liquidity pools according to their own needs and strategies to provide more innovative and personalized trading experiences, such as:
● Time-weighted average market maker (TWAMM): Developers can use the Hooks mechanism to create a liquidity pool that supports the TWAMM strategy to evenly disperse transactions of large orders over a period of time.
● Dynamic fees: Through Hooks, liquidity pools can dynamically adjust fees according to market volatility or other input parameters to better adapt to market conditions.
● Onchain limit orders: Hooks can create and execute limit orders on the chain, enabling users to trade at specified prices.
● Interaction with the lending agreement: developers can automatically deposit funds beyond the liquidity range into the lending agreement through Hooks, thereby maximizing the utility of funds.
At the same time, Uniswap V4 currently supports eight Hooks callbacks as shown in the figure below. These Hooks can be executed before the transaction starts and after the transaction ends, thereby realizing the function of chain price limit orders. In actual operation, a limit price can be set before the transaction starts, and then after the transaction is completed, it can be checked whether the limit price is satisfied. If it is satisfied, the transaction will be executed, and if it is not satisfied, the transaction will be cancelled.
Another Hooks of V4 - "Action Hooks"
In addition to Hooks, there is another "Action Hooks" in the Uniswap V4 version. It can trigger the contract to run only when the Flag condition is met, so it can invoke logic during contract execution. Refer to the flow chart below to explain. Before our asset exchange, the contract needs to check the Flag to evaluate the volatility of the liquidity pool. If the liquidity is high, the Flag will become True and execute our Hooks. If the liquidity Insufficient, the Flag will become False to reject the Hooks and keep the interaction unchanged. Executing the operation "Action Hooks" as shown below enables a more gas-saving method to execute the Hooks we need. Next, we will introduce the Singleton structure And Flash accounting will achieve a cheaper asset exchange and contract deployment experience in V4.
New singleton structure: Singleton
In the previous versions of Uniswap, Factory-Pool is the contract structure that has been used since V1, and it is also the most commonly used contract structure for many DEXs and derivatives in the DeFi world. However, in the V4 version, it abandoned Factory-Pool and replaced it with Singleton contract "Singleton" structure. In V3, every time a liquidity pool is created, a new contract needs to be redeployed, so the cost of deployment is very expensive, but in V4, the singleton structure saves all liquidity pools in In a contract, this can minimize the creation of liquidity and the Gas consumption in the cross-chain pool (contract), so that token transactions do not need to be transferred between different contracts, and can even reduce 99% from V3. Gas fees.
This singleton architecture is also equipped with a new "Flash Accounting" system. In V3, when each interaction ends, assets need to be transferred between liquidity pools, while in V4 version, the system only transfers assets on the "net balance", and each operation (exchange/deployment) will only result in Changes in internal balances, asset balances are expressed in units of "delta", at the end of the swap, it only swaps out the net "delta" balance after a series of calculations, which means a more efficient system is able to provide Uniswap V4 with additional Gas savings.
With "Singleton" and "Flash Accounting", Uniswap V4 supports Native ETH. Users can directly use Ethereum (ETH) for transactions without additional conversion operations, thereby improving the convenience of transactions and saving Gas fees. This makes the Uni and ETH ecosystems closely tied together, playing a role in feeding back Ethereum.
In terms of contract structure, V4's liquidity position data storage and packaging have also undergone tremendous changes. In the V2 version, the liquidity is distributed across the entire range (as shown in Figure 1 above), so the Uni protocol uses a homogeneous Token (ERC-20) as a liquidity certificate. In the V3 version, due to the addition of price limit liquidity, the selection of the corresponding liquidity display has changed to non-homogeneous tokens (ERC-721) for display. In the V4 version, we guess that the liquidity display will not be expressed in a tokenized way, but will be managed using the address of each wallet. In addition, the "transient storage" of EIP-1153 in the Cancun upgrade is also beneficial to the V4 system, which helps further cost optimization.
How to allow customized oracles and distribute internalized MEVs to LP holders
UniSwap V4 is a decentralized exchange protocol designed to enable trustless token transactions on Ethereum. It does so by using a custom oracle implementation and an internalized MEV (Maximize Transaction Value) distribution mechanism, which provides higher liquidity and a better transaction experience. To allow custom oracle implementation and distribution of internalized MEV to liquidity providers (LP holders), the following steps can be considered:
1 Design a custom Oracle: You need to develop an Oracle that can provide customized price data. Oracle is a contract for obtaining external data, which provides information such as real-time market prices to smart contracts. According to your own needs, you can develop an Oracle contract customized according to transaction pairs, time or other factors.
2 Internalized MEV distribution mechanism: MEV refers to the benefits generated due to changes in the order of transactions in blockchain transactions. UniSwap V4 distributes these benefits directly to liquidity providers through the internal MEV distribution mechanism. You can design a mechanism so that when MEV appears, a part of the income is directly distributed to the corresponding LP holders.
4 Notification and Incentive Mechanism: Promote this new feature to liquidity providers and provide them with appropriate incentives. Communicate with users through social media channels, or otherwise, about the benefits of the new custom Oracle and internalized MEV distribution mechanisms.
Advantages of customized liquidity pool
Uniswap V4 introduces the concept of a customized liquidity pool, but customization is recommended on the basis of centralized liquidity, so this transformation not only affects the development pattern of Fork Swap, the existence of aggregators, and even provides liquidity Investors and traders bring many advantages.
● Expand the choices of liquidity providers: Traditional AMM models usually have fixed rules and parameters, which limit the choice of liquidity providers. However, Uniswap V4 allows customized liquidity pools through the Hooks mechanism, enabling liquidity providers to create different types of liquidity pools according to their own preferences and strategies. This allows liquidity pools of various sizes to appear in the market, providing users with more choices and flexibility.
● Reduce costs and improve efficiency: Uniswap V4's architecture integrates all liquidity pools into one smart contract by introducing the "Singleton" contract. This architecture can reduce transaction costs, improve transaction efficiency, and simplify contract deployment and maintenance. In addition, the customized liquidity pool can also set a more suitable fee structure according to specific needs to meet the needs of different users.
● Provide a wider range of trading strategies and risk management tools: Customized liquidity pools provide traders with more opportunities for trading strategies and risk management tools. For example, by supporting the TWAMM strategy, large orders can be traded evenly over a period of time, thereby reducing the impact on market prices. In addition, customized liquidity pools can also be integrated with other DeFi protocols, such as lending protocols and custom oracles, to provide users with more comprehensive trading solutions.
● Comprehensively improve flexibility and creativity: Customized liquidity pools bring greater flexibility to liquidity providers. They can customize and manage their liquidity according to market needs and strategies. This flexibility and innovation potential can motivate more liquidity providers to participate and provide traders with diversified liquidity options.
Questions to think about
1. What problem does Curve solve for Uni V3?
The Uni V3 AMM model is a transaction model based on X*Y=K. In the process of actually combining LPs, we will find that when there is an extreme market, not only will there be a risk of free loss in the total value, but there will also be a liquidity pool A case where the exchange rate is out of range. Curve and Uniswap V3 are two different decentralized exchange protocols with slightly different problems and goals.
Compared to V3, Curve solves the following problems:
1 Earn profits in low liquidity ranges: Uniswap V3 is characterized by concentrating liquidity in a specific price range, which is affected by its AMM model, while other price ranges lack liquidity. This results in high transaction costs and limited liquidity when trading within a large price range. In contrast, Curve focuses on trading between stablecoins and increases liquidity within price ranges by using adaptive liquidity curves. This means users can trade stablecoins across a wide price range with lower slippage.
2 Low-cost transactions: Since Curve focuses on transactions between stablecoins, including assets with fixed price relationships, it employs specific algorithms and strategies to reduce slippage and costs of transactions. This allows users to trade stablecoins at more competitive prices.
3 Better price discovery: Curve provides a greater range of liquidity, especially when trading between stablecoins, it can provide better prices to be discovered. This means that users can more accurately obtain the market price of stablecoins, so as to make better trading decisions.
4 Efficient stablecoin transactions: Curve uses a specially optimized algorithm and liquidity curve to provide efficient stablecoin transactions. This allows users to quickly and securely exchange between stablecoins without excessive price slippage or cost.
2. Dual Token economic model DEX created by Uni V2: Camelot
Camelot was originally a project released by Fantom. Its original name was Excalibur. Later, it collapsed due to the adoption of UST as a stable currency. It was randomly migrated to the Arbitrum ecology and changed its name to Camelot. Different from GMX, Camelot focuses more on liquidity guidance for new projects. Its main innovation mechanism is the permissionless "Nitro Pools". Projects can fully control incentives by themselves to achieve the type of liquidity they need for their own development.
What needs to be emphasized is Camelot's dual-token economic model, which combines Uniswap V2 with Curve's decentralized trading protocol, and supports volatility and stability Token pair transactions at the same time, and disperses liquidity from zero to infinity throughout the range Inside. The most important thing is that it allows the project party to set the proportion of transaction fees according to market conditions and the specific conditions of the agreement, so as to achieve the purpose of managing dynamic directional transaction fees.
In addition, Camelot's custom Launchpad is also permissionless, allowing projects to issue Tokens and guide them to more liquidity. Not only that, each project that starts or cooperates with Camelot AMM can configure a specific transaction rate for its LP to adapt to its own liquidity strategy needs.
Summary of the above
As an important upgrade of decentralized exchanges, Uniswap V4 brings greater flexibility and room for creation to the DeFi ecosystem by introducing the concepts of Hooks and customized liquidity pools. The Hooks mechanism allows developers to create unique liquidity pools according to their own needs and strategies, and provides a wealth of trading strategies and risk management tools. Customized liquidity pools expand the options for liquidity provision, reduce fees and improve efficiency, and provide a wider range of trading strategies and risk management tools.
However, the emergence of V4 is bound to rebuild the underlying foundation of DeFi again. It provides a huge liquidity pool. Developers can use this pool to deploy their own Hooks or ecology, and even do not need a single-function xxSwap to obtain high The amount of liquidity allows more developers to develop various multifunctional ecosystems on the Uniswap platform. Let us wait and see whether Hooks + SingLeton will combine the advantages of Curve + Camelot to affect the next development trend of DeFi.