When a collateral type is removed from the CollateralLiquidationPriority
, its loanToValue
is not set to 0. This means that collateral of the removed type will still be included in the margin balance calculation of a user account, even though it is no longer accepted for paying fees and losses of an account. This leads to an overestimation of the margin balance of an account and can result in bad debt for the protocol.
CollateralLiquidationPriority
is an EnumerableSet of collateral addresses which are accepted for paying fees or accrued losses of an account. When a position of an account is filled or an account is liquidated, the deductAccountMargin()
function in TradingAccount.sol
iterates over the collateralLiquidationPriority
to pay fees or negaitve PnL of an account by sending the collaterals deposted by the user to the feerecipients.
To determine if an account is liquidatable or meets the margin requirements for filling a position, the required margin is compared to the marginBalance of the account. The marginBalance of the account is calculated by iterating over each collateral deposited to the account and determining its value by multiplying the deposited collateral amount with its price and with its loanToValue (% of value to be considdered as margin):
However, if a collateral type is removed from this CollateralLiquidationPriority
and is no longer usable for paying fees or losses of an account, its loanToValue is not reset to 0, causing it to still be considered in the margin balance calculation. This results in a marginBalance which is to high and can result in losses for the protocol.
Collateral of type A and type B are included in the CollateralLiquidationPriority
A user deposits collateral of type A and type B and opens a position
The admin removes collateral type A from the CollateralLiquidationPriority
.
The user should be liquidatable becasue the deposited collateral of type B does not cover the required margin but he is not becasue the user’s margin balance is still calculated including collateral type A.
The user’s position incurs losses, but the system cannot deduct the required margin due to the overestimation, leading to a loss for the protocol
To prevent this issue, ensure that when a collateral type is removed from the CollateralLiquidationPriority
, the values of its MarginCollateralConfiguration are set to 0. This can be done by modifying the removeCollateralFromLiquidationPriority()
function in GlobalConfiguration.sol
:
This ensures that the removed collateral type is no longer considered in the margin balance calculation even if a user has deposited the collateral before.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.