Combining Hooks For UniV4 — Dynamic Fees + Liquidity Locking

Brokkr Finance
5 min readMar 8, 2024

--

In this article, we explain how we combined two of our previous hooks — Dynamic fees based on volume and Liquidity locking with incentives. It is part of our design series from our Uniswap Foundation Hook POC grant.

The hook enables locking liquidity for LP incentives and dynamically adjusts the pool fees based on the incoming swapping volume. It is a demonstration of how the hooks can be combined together, and how the utility of a hook can be extended by using multiple mechanics. By using this hook, the users are rewarded for locking their liquidity and will gather more fees through the dynamic fees.

If you are interested in building your own hooks, we recommend reading the V4 documentation for a general introduction to UniswapV4 and hooks.

➕Benefits Of Combining Hooks

Being able to combine hooks (hook functions) gives the pool more flexibility in what it can offer. Liquidity providers and traders will want the pool to have more functions, not just one.

For example, Dynamic fees can be included in every pool because they increase (or should increase) the LP performance, but that’s already one hook. By combining multiple of them, the pool could enable not only dynamic fees, but also TWAMM (time weighted average market maker, streaming swaps), Order book, or Liquidity locking like in our example.

Combining hooks also lets builders develop directly on Uniswap, making Uniswap the infrastructure layer. Instead of asking developers “Are you building on Arbitrum”, the question might be “Are you building on Uniswap” because the hooks can get as complex as regular protocols.

However, combining hooks adds another layer of risks and complexity. The underlying hooks can be quite complicated and work in unique ways, and therefore it’s necessary to align their core functions before combining them to ensure proper functionality.

📐The Hook Design

We considered two options for combining multiple hooks. Either we refer from the first hook to the second one, or we create a single contract that inherits functionalities from both. We chose the latter one and created a single contract for both of the functions as it is more gas efficient.

Brokkr Liquidity Locking & Dynamic Fees Hooks

This hook provides rewards to liquidity providers who lock their tokens and adjusts the swapping fee based on the incoming trading volume. It is made of two underlying hooks:

  1. Liquidity locking & LP incentives
    It enables locking liquidity in the pool, rewarding LPs with a reward token, and early withdrawals. The liquidity is deposited in an infinite range.
  2. Dynamic fees based on volume
    It automatically adjusts the swapping fee based on the incoming volume. The volume is used as a proxy for volatility.

The Liquidity locking hook adds constraints when providing and withdrawing liquidity. The Dynamic fees hook interacts with the pool only during swapping. Based on that, they look like they should be easily combined as they don’t seem to interfere with each other.

However, it’s not that simple. During withdrawals, the hook auto-compounds the generated fees, but they might be imbalanced compared to the current pool ratio. To swap the fees to the correct ratio, the hook needs to use partial swaps, and that’s where the intricacies of combining hooks show up.

In the original Dynamic fees hook, we disabled partial swaps because they could artificially increase the volume and the swapping fees. So in the Combo hook, we had to make adjustments — We enabled partial swaps, but only for rebalancing the position, and we excluded this volume from the dynamic fee calculation.

This shows that even hooks that seem to be unrelated can’t be blindly combined.

♻️ Changes In The Combo Hook

The main change in the design compared to the underlying hooks is during withdrawals. This is due to the occasional usage of partial swaps for rebalancing. The diagram shows the specific sequencing and parts of the transaction calls used in the combo hook.

You can check the diagrams for the underlying hooks in their articles — Dynamic fees, Liquidity locking.

⚠️ What To Watch Out For When Combining Hooks

Combo hooks introduce important features to the pool but also increase the risk and complexity. They inherit the risks of the underlying hooks, struggle with compatibility, and make the initial hook setup more difficult.

1. Underlying Hooks
Each hook has its own risks derived from its function. If they are not mitigated before combining the hooks, resolving them after becomes much more difficult and time consuming.

2. Compatibility Issues
Combining hooks is not straightforward, this applies especially to complex and intertwined hooks that influence each other. These issues are often not obvious, which complicates the process of finding the route cause of the problems. Protocol builders will need to nail this down, especially if they reuse code from others.

Another example; our Locking hook enables depositing liquidity both into the hook or the pool, while our Liquidity management hook enables depositing only into the hook. To combine them safely and effectively, these core functions need to be aligned to avoid various edge cases and potential vulnerabilities.

3. Initial Pool Setup
Using more hooks will complicate the initial setup process and it will increase the chance of something going wrong as there are more moving parts that influence each other. Complex hooks like Liquidity management or Dynamic fees should be theory-crafted or consulted with experts as they have a small margin of error.

We expect best practices will form over time, which resolve the issue for the pool deployers, but they won’t be present at the beginning of V4.

🪝 Check Our Other Hooks

  1. Locking liquidity for incentives
  2. Dynamic fees by Volume
  3. Liquidity Management
  4. Combo hook — Dynamic fees + Liquidity locking & Incentives

Follow Brokkr

🌎 BRO Website
🐦 BRO Twitter
🎮 BRO Discord

--

--

Brokkr Finance
Brokkr Finance

Written by Brokkr Finance

Optimized asset and yield management

No responses yet