and, if user's liability exceeds this value, the account can be liquidated.
Overall collateral and liability values are calculated
here in
LiquidityUtils.sol, where each collateral of the user is summarized. All values are measured in the current vault's
unitOfaccount. Here is the
calculation of collateral value (multiplied by the LTV factor at the end).
The possibility of liquidation is calculated in
Liquidation.sol here. The profitability of liquidation (
discount factor) depends on how deeply the position is in violation (the relation between total collateral and debt is
here). So, while the liability increases with time, the discount factor decreases, making liquidation more and more attractive to the liquidator.
Liquidations in Euler V2 are not restricted, and the liquidator can repay any amount of the user's debt.
Next stop - "forgiveness" and "acceptance" :) Euler v2 prohibits operations that lead to an unhealthy status of the user, and after almost every operation, a health check is performed. However, in the case of liquidation, when the liquidator can repay only part of the debt, leaving the violator's account in an unhealthy status, the special
forgiveAccountStatusCheck() function is used to temporarily disable the health check. This part of code can be found
here. Health checks are restored in later operations, but, anyway, this part of code remains risky, and all operations within the liquidation should be performed carefully.
Bad debt. The worst-case scenario for any lending. In Euler V2 bad debt (indicating there is debt but insufficient collateral available for liquidation) is handled using socialization. It means that bad debt simply disappears, decreasing the total amount of borrowing and "socialising" the losses to all vault depositors. This procedure is performed within the liquidation process (if it's not fully finished)
here.