Autonomous Rebalancing
Autonomous rebalancing is a key feature of Bunni v2 that enables pools to maintain optimal token ratios without requiring external keepers. This is particularly important for pools that use shapeshifting and/or rehypothecation.
Why Autonomous Rebalancing?
When a Bunni v2 pool's Liquidity Density Function (LDF) shifts or changes shape, the current ratio between the two tokens in the pool will likely be different from what the updated LDF specifies. Rebalancing is necessary to maximize the utilization rate of the token reserves and ensure that the pool can provide the best possible liquidity for swaps.
How Autonomous Rebalancing Works
Bunni v2's autonomous rebalancing system consists of three main components:
- Detecting imbalances
- Determining rebalance parameters
- Executing rebalance swaps
Detecting Imbalances
After each swap, if the LDF has been updated since the previous swap, the pool computes the excess liquidity and initiates a rebalance if it is greater than a threshold proportion of the total liquidity.
The excess liquidity for token is defined as:
where is the excess token amount and is the cumulative amount function per total liquidity unit.
A rebalance is initiated if , where is a threshold value.
Determining Rebalance Parameters
When a rebalance is needed, the pool computes the optimal swap parameters using the following process:
Query the Time-Weighted Average Price (TWAP) oracle to get the average square root price and the corresponding rick .
Compute total token densities using the TWAP value:
Compute target token amounts and :
Submit an intent to swap of token₀ for at least of token₁, where is the slippage parameter.
Executing Rebalance Swaps
Bunni v2 uses flood.bid, an intent-based DEX aggregator, to execute rebalance swaps. This allows the pool to broadcast a swap intent on-chain and let off-chain solvers provide optimal swap execution.
To protect against malicious solvers, Bunni v2 uses a whitelist of approved solvers. This whitelist is primarily set by governance, but the am-AMM manager of a pool is also automatically part of the whitelist for that pool.
Benefits
- Efficiency: Maximizes the utilization of token reserves, ensuring optimal liquidity provision.
- Automation: Eliminates the need for external keepers to monitor and rebalance pools.
- Flexibility: Enables more dynamic liquidity strategies through shapeshifting without manual intervention.
- MEV Capture: By using the am-AMM mechanism, any MEV from rebalance swaps can be recaptured for the benefit of LPs.