Departing from Fork Swap, Uniswap V4 is entering the era of “Ten Thousand Hooks”.
Uniswap V4 is moving on from Fork Swap and embarking on the "Ten Thousand Hooks" era.
Author: YBB Capital Researcher Ac-Core
Summary:
Compared to the V3 version two years ago, V4 has more flexible asset composability and significantly reduces the Gas fees required for providing liquidity and trading. With the help of the new Hooks feature, developers no longer need to develop xxSwap, but only need to customize liquidity in Hooks and add frontend pages and elements that meet their own needs to create a “designated place,” without worrying about insufficient liquidity in the “designated place.” Let’s explore how Uni V4 is leading DeFi from the “Lego era” to the “Ten Thousand Hooks” era.
YBB Capital Researcher Ac-Core self-made
- He Yi: Respecting regulatory institutions is the trend, regulatory ...
- ZKML and Distributed Computing: Potential Governance Narratives for...
- Has Azuki also fallen? Is the narrative of image NFTs over?
Uniswap V4 – A Rare True Innovation in the Bear Market
Uniswap’s iterative upgrade allows us to see the infinite potential of the DeFi world, and it has never deviated from the original intention and rules of X*Y=K. 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 to using V3, both developers and users can get more open, free, and efficient automated market maker services. The following article will comprehensively introduce the upgrade of V4 and the two most important changes: Hooks and Singleton.
The Introduction of Hooks That Changes Everything
The core feature of Uniswap V4 – Hooks, allows every developer to create a customized DEX that meets their scenario requirements and build their own “Lego blocks.” Hooks are an important concept introduced in Uniswap V4, and they are plugins for customizing liquidity pools, exchanges, fees, and liquidity provider (LP) position interactions. Through Hooks mechanism, developers can perform specific operations at critical moments in the lifecycle of liquidity pools, such as before/after the exchange or before/after the LP position changes.
At the same time, Hooks are also smart contracts that interact with the core contracts of Uniswap V4, and can execute custom logic in a flexible way at different “key points” in the liquidity pool (key points refer to operations before/after the exchange or when LP deposits/withdrawals occur), allowing developers to define and execute custom logic flexibly. Hooks can be bound to specific liquidity pools to control the behavior and interaction of the pool. For example, developers can create a Hook that verifies specific conditions before each exchange or performs additional operations when the LP position changes.
YBB Capital Researcher Ac-Core
Through Hooks, the creator of a mining pool can adjust pool parameters and introduce new features to AMM, even allowing for the creation of various DeFi strategies on Uniswap, ultimately benefitting LPs/swappers more. The introduction of Hooks is expected to provide greater flexibility and innovation space for developers, who can create unique liquidity pools tailored 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 liquidity pools that support TWAMM strategies to average out large orders over a period of time.
● Dynamic Fees: Through Hooks, liquidity pools can dynamically adjust fees based on market volatility or other input parameters to better adapt to market conditions.
● On-chain Limit Orders: Hooks can enable the creation and execution of limit orders on-chain, allowing users to trade at a specified price.
● Interaction with lending protocols: Developers can automatically deposit funds beyond the liquidity range into lending protocols through Hooks to maximize the utility of funds.
Meanwhile, Uniswap V4 currently supports eight Hooks callbacks as shown in the figure below, which can be used to implement on-chain limit orders. In practice, a limit price can be set before the transaction starts, and then checked after the transaction ends to determine whether the limit is met. If it is met, the transaction is executed, otherwise it is cancelled.
YBB Capital Researcher Ac-Core
Another Hooks in V4 —— “ Action Hooks”
In addition to Hooks, there is another “Action Hooks” in Uniswap V4. It can only trigger the contract to run when the Flag condition is met, so it can call logic during contract execution. Refer to the flowchart below to explain that 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 our Hooks will run. If the liquidity is insufficient, the Flag will become False and reject the Hooks, keeping the interaction unchanged. By executing the operation shown in the figure below, “Action Hooks” enables a more gas-saving method to execute the Hooks we need. Next, the Singleton structure and Flash accounting will be introduced to achieve a cheaper asset exchange and contract deployment experience in V4.
YBB Capital Researcher Ac-Core 自制
New Singleton Structure: Singleton
In previous versions of Uniswap, Factory-Pool was the contract architecture that was used from V1 until now, and it is also the contract architecture that is most commonly used by DEX and derivatives in the DeFi world. However, in V4, it abandoned the Factory-Pool and replaced it with the Singleton contract structure. In V3, every time a liquidity pool is created, a brand new contract needs to be redeployed, which is very costly, but in V4, the Singleton structure saves all liquidity pools in one contract, which maximizes the reduction of gas consumption in creating liquidity and cross-chain pools (contracts), so token transactions do not need to be transferred between different contracts, and it can even reduce 99% of gas fees from V3.
This Singleton architecture also comes with a brand-new “Flash Accounting” system. In V3, when each interaction ends, assets need to be transferred between liquidity pools, but in V4, this system only transfers assets on the “net balance”, and each operation (exchange/deployment) only causes changes in the internal balance, and the asset balance is represented in “delta” units. At the end of the exchange, it only swaps the net “delta” balance after a series of calculations, which means that a more efficient system can provide Uniswap V4 with additional gas savings.
With “Singleton” and “Flash Accounting”, Uniswap V4 supports Native ETH. Users can directly use Ether (ETH) for trading without the need for additional conversion, thus improving the convenience of trading and saving gas fees. This makes Uni and ETH ecosystems closely tied, playing a role in contributing to Ethereum.
In terms of contract structure, there have also been huge changes in liquidity position data storage and encapsulation in V4. In V2, liquidity was distributed across the entire range (as shown in Figure 1), so the Uni protocol used homogeneous tokens (ERC-20) as liquidity vouchers. In V3, due to the addition of limit liquidity, the corresponding liquidity display was changed to non-homogeneous tokens (ERC-721) for display. In V4, we speculate that the liquidity display will not be tokenized, but will be managed by each wallet address. In addition, the EIP-1153 in the Cancun upgrade with “transient storage” is also beneficial to the V4 system, which helps to further achieve cost optimization.
YBB Capital Researcher Ac-Core 自制
How to Allow Custom Oracle and Distribute Internalized MEV to LP Holders
UniSwap V4 is a decentralized trading protocol designed to facilitate trustless token trading on Ethereum. It offers higher liquidity and better trading experience by using custom Oracle implementation and internalized MEV (Maximize Extractable Value) distribution mechanism. To allow custom Oracle implementation and distribute internalized MEV to liquidity providers (LP holders), you can consider the following steps:
1. Design custom Oracle: You need to develop an Oracle that can provide customized price data. Oracle is a contract that retrieves external data and provides real-time market prices and other information to smart contracts. You can develop an Oracle contract that is customized based on trading pairs, time, or other factors according to your own needs.
2. Implement internalized MEV distribution mechanism: MEV refers to the benefits generated in blockchain transactions due to changes in transaction order. UniSwap V4 distributes these benefits directly to liquidity providers through internalized MEV distribution mechanism. You can design a mechanism to allocate a portion of the profits directly to the corresponding LP holders when MEV occurs.
3. Contract integration and deployment: Integrate the custom Oracle and internalized MEV distribution mechanism into UniSwap V4’s smart contracts. Only modification and extension are needed in the corresponding contracts to support these functions. Ensure compliance with security best practices during contract development and modification, and conduct sufficient testing and auditing.
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 other means to make them aware of the benefits of the new customized Oracle and internalized MEV distribution mechanism.
5. Monitoring and improvement: After deployment, closely monitor the operation of the system. Monitor the effects of transactions and MEV distribution and make improvements as needed. Feedback and participation in community suggestions are crucial for further optimization of this mechanism.
Advantages of Customized Liquidity Pools
Uniswap V4 introduces the concept of customized liquidity pools, 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, but also brings many advantages to liquidity providers and traders.
● Choices for expanding liquidity: Traditional AMM models usually have fixed rules and parameters, which limit the choices of liquidity providers. However, Uniswap V4 allows for customized liquidity pools through the Hooks mechanism, enabling liquidity providers to create different types of liquidity pools based on their preferences and strategies. This allows for a variety of liquidity pools to be available in the market, providing users with more choices and flexibility.
● Reducing costs and increasing efficiency: Uniswap V4’s architecture concentrates all liquidity pools in a single smart contract through the introduction of a “Singleton” contract. This architecture can reduce the cost of transactions, increase transaction efficiency, and simplify contract deployment and maintenance. In addition, customized liquidity pools can also set up more suitable fee structures according to specific needs to meet the needs of different users.
● Providing 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 TWAMM strategies, large orders can be executed at an average rate over a period of time to reduce the impact on market prices. In addition, customized liquidity pools can be integrated with other DeFi protocols, such as lending protocols and custom oracles, to provide users with more comprehensive trading solutions.
● Enhancing flexibility and creativity: Customized liquidity pools bring greater flexibility to liquidity providers. They can customize the management of their liquidity based on market demand and strategy. This flexibility and innovation potential can motivate more liquidity providers to participate, providing traders with diversified liquidity options.
Questions worth considering
YBB Capital Researcher Ac-Core 自制
1. What problem does Curve solve for Uni V3?
The Uni V3 AMM model is based on the X*Y=K trading model. In the process of combining LPs, we will find that when extreme market conditions occur, there is not only a risk of total value loss without compensation, but also a risk of the exchange rate of the liquidity pool exceeding the range. Curve and Uniswap V3 are two different decentralized trading protocols, with slightly different problems and goals.
Compared to V3, Curve solved the following issues:
1. Earning profits from low liquidity ranges: Uniswap V3 concentrates liquidity within specific price ranges due to its AMM model, leaving other price ranges without liquidity. This leads to higher transaction costs and limited liquidity when trading over a larger price range. In contrast, Curve focuses on stablecoin trading and increases liquidity within price ranges by using an adaptive liquidity curve. This allows users to trade stablecoins over a larger price range with lower slippage.
2. Low-cost trading: Because Curve focuses on stablecoin trading, including assets with fixed price relationships, it uses specific algorithms and strategies to reduce slippage and costs. This enables users to trade stablecoins at more competitive prices.
3. Better price discovery: Curve provides greater liquidity over a wider range, especially when trading stablecoins, leading to better price discovery. This means users can more accurately obtain the market price of stablecoins and make better trading decisions.
4. Efficient stablecoin trading: Curve uses specially optimized algorithms and liquidity curves to provide efficient stablecoin trading. This allows users to exchange stablecoins quickly and securely without excessive price slippage or costs.
2. Camelot: A DEX with a dual-token economic model created using Uni V2
Camelot was originally a project released on Fantom called Excalibur, but it collapsed due to the use of UST as a stablecoin and randomly migrated to the Arbitrum ecosystem, where it was renamed Camelot. Unlike GMX, Camelot focuses more on guiding liquidity for new projects, and its main innovation is the permissionless “Nitro Pools.” The project can fully control incentive measures and establish the liquidity type needed for its own development.
It is important to emphasize Camelot’s dual-token economic model, which combines Uniswap V2 with Curve’s decentralized trading protocol and supports trading of both volatile and stable tokens. Liquidity is dispersed throughout the entire range from zero to infinity. Most importantly, the project can set the trading fee ratio based on market conditions and the specific situation of the protocol to manage dynamic directional trading fees.