Liquidating a credit account
When an account becomes unhealthy, it can be liquidated by anyone. The liquidator is allowed to perform almost any actions (with some restrictions) to convert collateral assets into underlying and fully repay the debt. After liquidation, the account owner retains the Credit Account with any remaining funds and zero debt.
To perform a liquidation, the liquidator must call the following function:
MultiCall calldata calls
) external payable;
|The address of a Credit Account to liquidate.
|Address to transfer leftover underlying after liquidation.
|The array of
MultiCall structs to be executed immediately after opening an account.
Liquidations proceed as follows:
- The liquidator initiates a liquidation;
- On demand price updates are applied, if needed;
totalValueis computed (see the formula);
- Credit Facades stores balances of existing collateral tokens;
- Actions submitted in
- Credit Facade checks that collateral balances did not increase;
- Credit Manager computes
totalFunds = totalValue * (1 - liquidation premium),
amountToPool = min(totalDebt, totalFunds),
remainingFunds = totalFunds - amountToPool;
- Credit Manager sends
amountToPoolof underlying to the pool;
- Credit Manager checks that the value of assets (
leftover value) left on the account is not less than
min(leftover value - remainingFunds, underlyingBalance)of underlying is sent to the liquidator;
- All non-zero quotas are removed;
- Debt is set to zero;
- If there is any loss, then borrowing is prohibited, or, if a certain loss threshold is reached, the contracts are paused;
The liquidator has two main goals with their
- Ensure that there is enough underlying after calls to cover the total debt;
- Ensure that they receive their premium in collateral assets or underlying;
To that end, they would either:
- Use external calls to convert collateral assets fully or partially into underlying, to cover
amountToPool + totalValue * liquidationPremium(i.e., enough to cover total debt and liquidation profit). In this case the liquidation premium will be sent to the liquidator automatically in underlying;
- Add enough underlying to cover debt. Then withdraw the assets they want to receive as premium, making sure that enough remains to cover
Or some combination of the two.
remainingFunds are calculated based on oracle prices, which do not account for price impact, slippage and trading fees. When converting assets using external calls, all of these incurred losses are essentially borne by the liquidator and are subtracted from the premium. It is recommended to account for on-chain liquidity when using DEXes such as Uniswap or Curve to liquidate, especially for medium- and long-tail assets.
Both liquidations due to low health and expiration are handled by the same
liquidateCreditAccount function. The particular type of liquidation is chosen as follows:
- If the account is unhealthy, perform a normal liquidation regardless of expiration status
- If the account is healthy, but expired, perform a liquidation due to expiration
Since liquidation premiums are different for the two (and that can influence values such as
remainingFunds), it's advised to check which liquidation the account is eligible for before liquidation.
The total debt grows dynamically over time due to interest on principal and quotas. This means that the exact total debt amount received in a previous block will likely be slightly smaller than the total debt at execution time. It's advised to send the underlying amount with a small buffer to fully cover debt - the remainder will be sent back to the liquidator.