Levva Vault Liquidity Balancing

Learn how Levva Vault Liquidity Balancing is working.

General

The balancer fetches a list of all existing vaults from the database (they appear in the database after an event from the smart contract), excluding the disabled ones (where the DisabledAt field in the database is manually set to a specific date). Then filters them according to the balancer settings EnabledVaults from appsettings. It iterates through all vaults and performs rebalancing for each vault.

Balancing

  1. The balancer iterates over the protocols supported by the vault (e.g., Marginly, Aave, Etherfi), generating arguments for a rebalancing transaction for each as needed. The need for rebalancing is determined by the following settings:

private const decimal DeviationPercentage = 0.05m; // if >= 5%, then rebalance

private static readonly Dictionary<LevvaVaultProtocolType, decimal> TotalLentTargetByProtocol = new()
{
    { LevvaVaultProtocolType.Marginly, 0.60m }, // 60% to Marginly pools
    { LevvaVaultProtocolType.Aave, 0.30m }, // 30% to Aave or...
    { LevvaVaultProtocolType.Etherfi, 0.30m } // ...30% to Etherfi
};

private static readonly Dictionary<HashSet<string>, HashSet<LevvaVaultProtocolType>> AllowedProtocolsBySymbols = new()
{
    { new HashSet<string> { "USDC", "WBTC" }, new HashSet<LevvaVaultProtocolType> { LevvaVaultProtocolType.Marginly, LevvaVaultProtocolType.Aave } },
    { new HashSet<string> { "WETH" }, new HashSet<LevvaVaultProtocolType> { LevvaVaultProtocolType.Marginly, LevvaVaultProtocolType.Etherfi } }
};
"MinOperationsThreshold": {
    "arb-mainnet|USDC": 100.00,
    "arb-mainnet|WETH": 0.1,
    "arb-mainnet|WBTC": 0.01,

    "eth-mainnet|USDC": 1000.00,
    "eth-mainnet|WETH": 1,
    "eth-mainnet|WBTC": 0.1
}

For Marginly

The Balancer adds/removes liquidity based on the target percentage set in the configuration (currently 60%). The Balancer checks pool utilization levels: when depositing, it adds to the pool with the highest utilization (if all utilization levels are equal, it distributes evenly across all pools). When withdrawing, The Balancer withdraws in ascending order of utilization, starting with the pools with the lowest utilization.

For Aave

The Balancer also relies on the target percentage from the settings (currently 30%). When depositing, The Balancer simply deposits into the protocol, and when withdrawing, The Balancer withdraws from it.

For Etherfi

The Balancer similarly follows the target percentage from the settings (currently 30%); when depositing, The Balancer simply adds funds to the protocol, and when withdrawing, The Balancer sends a withdrawal request and records this request in the database to avoid attempting to withdraw the same amount again during future withdrawals or rebalancing.

For all protocols

The Balancer checks the current balance in the protocol and does not attempt to withdraw more than that balance. For Aave, there is also a specific condition to withdraw the entire balance if the difference between the current balance and the rebalancing target is small (the delta is specified as an absolute value in the balancer settings).

If a rebalancing transaction is generated for at least one protocol, it executes the transaction. If not, it skips the rebalancing iteration for the current vault. Further rebalancing occurs on a scheduled basis.

Last updated