Dynamic Fees By Volume UniswapV4 Hook

Brokkr Finance
4 min readJan 30, 2024

--

The second hook from our Hook POC Uniswap Foundation grant adjusts the swapping fees based on the trading volume. In our concept, we use volume as a proxy for volatility. Market volatility has a major impact on the liquidity providers’ profitability, often leading to frequent position rebalancing and realizing (im)permanent loss. With this design, we aim to improve LP profitability by capturing more value during volatile periods and distributing it back to them.

If you are interested in building your own hooks, we recommend reading the V4 documentation for a general introduction to UniswapV4 and hooks. This article has been written in cooperation with Atis, who researched various dynamic fee approaches.

❓Why Do Liquidity Providers Want Dynamic Fees?

Providing liquidity in V3 pools is risky for LPs because they’re exposed to LVR and impermanent loss. Dynamic fees can limit the effects of both factors and increase LP’s profits. Liquidity providers’ profitability has been a big topic already since V3 pools launched, as it has been found that around 50% of LPs are not profitable or would be better if they just HODL’d.

💲How Brokkr Dynamic Fees Work

In our hook, we use volume as a proxy for volatility as we operate under the assumption they correlate. The hook uses a cumulative volume as a threshold to adjust the fee. At the deployment, the pool operator sets a volume that needs to be reached (the volume threshold) to increase the fee. When the volume threshold is about to be reached with a swap, the fee increases before the swap happens. To counterbalance the increases, fees automatically decrease over time.

The main benefit of using volume is that it can adjust the fee immediately on the incoming swap, instead of changing it after it’s finished. It is also gas-efficient and agile compared to other dynamic fee approaches that can adjust the fee only after the swap and are very gas-intensive as they store all information. On the other hand, during our collaboration with Atis, he found out the hook may not be able to set the perfect fee as it also depends on the uninformed flow volume that our hook can’t recognize. But the hook could track a swap size, so transactions below a certain size would not increase the fee, which might help the uninformed flow.

How Brokkr Dynamic Fees by Volume work

🔮Behind The Scenes

To get the dynamic fees going, it is necessary to set up boundaries for the swapping fees within which it moves, the increment to know how much the fee should increase, the volume threshold to know when to increase the fee and in what timeframe, and the speed of decreasing the fee.

During each swap, the hook records the total volume swapped and compares the current transaction volume to the threshold volume. When comparing the volumes, it also considers the time passed between the transactions to adjust the fee according to the setup. The fee increments can be as low as basis points (0.01%), which enables granular adjustments and quick reaction to market changes.

Example:
USDC-ETH pool with 1,000,000 USDC and 500 ETH
Min fee = 0.05%
Max fee = 0.5%
Fee increment = 0.01%
Time frame = 100 seconds
Volume threshold = 5,000 USDC

The user wants to swap $10,000 worth of ETH for USDC. Before this swap, the accumulated volume was 4,000 USDC with the initial 0.05% fee. However, because this swap exceeds the volume threshold twice, the fee for this swap increases by 0.02% (2x0.01%) to 0.07%. If there are no other incoming transactions in the next 100 seconds, the fee decreases by 0.01% (and will continue decreasing if the volume threshold is not reached).

⚙️Other Dynamic Fee Hook Options

In Atis’ research on other approaches to dynamic fees, he looked into how fees are affected by the pool depth, fee size, asset volatility, and order type flow. In our hook, we use a “volume as a proxy” design as it can adjust the fees on the incoming swap and is gas efficient. But there are other options based on Volatility, Transaction source, Price oracles, Coprocessors, and many others.

Each has its benefits but frequently suffers from being very gas-intensive, unable to change the fee on the incoming swap, and way too complex for POC purposes.

For example, the hook could track the volatility directly through price movement, but that gets very gas-intensive, complicated, and requires implementing price oracles vulnerable to various attacks.

🔒Risks And Mitigation

Uniswap’s partial swap feature could manipulate dynamic fees to keep the fees high with artificial volume. The hook would consider the whole amount proposed for trade as a volume instead of what was actually swapped. To prevent this, we revert the transaction if less than 99% of the initial tokens for the trade are swapped.

Example
A swap request for 100 USDC to ETH goes through, but only 50 USDC would be traded into ETH due to partial swap configuration. However, the swap will revert because less than 99 USDC is swapped.

Our Other Hooks

  1. Liquidity Locking Hook + Liquidity incentives
  2. Dynamic Fee By Volume
  3. Liquidity Management Hook (WIP)
  4. Liquidity Locking + Dynamic Fee Combo-Hook (WIP)

Follow Brokkr on:
🌎 BRO Website
🐦 BRO Twitter
🎮 BRO Discord

--

--