Lucky Peach Barbel
Medium
If totalCollateral
is negative, the redemptionEligible
calculation will be incorrect, leading to improper allocation of collateral across markets
The _manage function is responsible for managing the internal collateral and position strategy of the vault. It uses the context.totalCollateral
value to determine whether to proceed with rebalancing. However, there is a critical flaw in the logic where context.totalCollateral
is checked against Fixed6Lib.ZERO
:
if (context.totalCollateral.lt(Fixed6Lib.ZERO)) return;
This check is intended to prevent rebalancing if the total collateral is negative. However, the issue arises because context.totalCollateral
is calculated as the sum of collaterals across all markets, and this sum can be negative even if individual market collaterals are positive or zero. This can happen due to rounding errors, market-specific adjustments, or other edge cases in the underlying market contracts.
If context.totalCollateral
is incorrectly calculated as negative, the _manage
function will prematurely exit, skipping the rebalancing process. This can lead to the vault fail to allocate collateral correctly across markets, leading to underfunded or overfunded positions. The vault's positions may also become misaligned with the intended strategy, increasing the risk of losses. The vault may as well miss opportunities to optimize its positions, leading to suboptimal performance.
- Suppose the vault has two markets:
- Market A has a collateral of
+100
. - Market B has a collateral of
-50
.
- Market A has a collateral of
- The total collateral (
context.totalCollateral
) would be+50
, which is positive. - However, due to a bug or rounding error, the calculation incorrectly results in
-50
. - The
_manage
function exits prematurely, skipping the rebalancing process. - As a result, the vault's positions are not updated, leading to potential misallocation of collateral.
Instead of relying solely on the sum of collaterals, the _manage
function should ensure that each individual market's collateral is non-negative before proceeding with rebalancing.