๐ Math behind Liquidations
Value
Description
Possible Values

Last updated

Last updated
// SPDX-License-Identifier: BUSL-1.1
/// @notice Returns the liquidation numbers for the user
/// @param user The user id
/// @return debtChange The debt change
function _liquidationAmount(
uint256 user
) internal view returns (uint256 debtChange) {
VaultStorage storage s = _s();
UserInfo storage info = s.userInfo[user];
uint256 collateral = _scaleFromAsset(_deposit(user) * _price()) / 1 ether;
uint256 debt = _debtValueUser(user);
if (collateral == 0 || debt == 0) return 0;
uint256 feefullDebt = _withFee(debt);
if (debt < _stepMinDeposit() || feefullDebt >= collateral) {
return debt;
}
uint256 liquidationFee = s.liquidationFee;
uint256 maxCollateralRatio = s.maxCollateralRatio;
uint256 targetHealth = info.healthTarget;
uint256 scalar = 1 ether * 1 ether;
uint256 debtHealth = (debt * scalar) / targetHealth;
uint256 healthScalar = scalar / targetHealth;
uint256 feeMultiplier = (liquidationFee * maxCollateralRatio) / 1 ether;
debtChange =
(debtHealth - collateral * maxCollateralRatio) /
(healthScalar - maxCollateralRatio - feeMultiplier);
}