Skip to main content

Liquidation

Git Source

State Variables

START_NEGATIVE_PREMIUM_LTV_BIPS

uint256 internal constant START_NEGATIVE_PREMIUM_LTV_BIPS = 6000;

START_PREMIUM_LTV_BIPS

uint256 private constant START_PREMIUM_LTV_BIPS = 7500;

NEGATIVE_PREMIUM_SLOPE_IN_BIPS

uint256 private constant NEGATIVE_PREMIUM_SLOPE_IN_BIPS = 66_667;

NEGATIVE_PREMIUM_INTERCEPT_IN_BIPS

uint256 private constant NEGATIVE_PREMIUM_INTERCEPT_IN_BIPS = 40_000;

POSITIVE_PREMIUM_SLOPE_IN_BIPS

uint256 private constant POSITIVE_PREMIUM_SLOPE_IN_BIPS = 7408;

POSITIVE_PREMIUM_INTERCEPT_IN_BIPS

uint256 private constant POSITIVE_PREMIUM_INTERCEPT_IN_BIPS = 4444;

LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR

uint256 private constant LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR = 5;

MAX_PREMIUM_IN_BIPS

uint256 private constant MAX_PREMIUM_IN_BIPS = 11_111;

HARD

uint256 internal constant HARD = 0;

SOFT

uint256 internal constant SOFT = 1;

LEVERAGE

uint256 internal constant LEVERAGE = 2;

Functions

checkHardPremiums

function checkHardPremiums(
uint256 repaidDebtInL,
uint256 seizedCollateralValueInL,
uint256 maxPremiumInBips
) internal pure returns (bool maxPremiumExceeded);

calculateNetDebtAndSeizedDeposits

function calculateNetDebtAndSeizedDeposits(
Validation.InputParams memory inputParams,
HardLiquidationParams memory hardLiquidationParams,
uint256 actualRepaidLiquidityAssets
) internal pure returns (uint256 netDebtInLAssets, uint256 netCollateralInLAssets, bool netDebtX);

checkSoftPremiums

function checkSoftPremiums(
ISaturationAndGeometricTWAPState saturationAndGeometricTWAPState,
Validation.InputParams memory inputParams,
address borrower,
uint256 depositLToTransferInLAssets,
uint256 depositXToTransferInXAssets,
uint256 depositYToTransferInYAssets
) external view;

liquidateLeverageCalcDeltaAndPremium

Calculate the amount to be closed (from both deposit and borrow) and premium to be paid.

function liquidateLeverageCalcDeltaAndPremium(
Validation.InputParams memory inputParams,
bool depositL,
bool repayL
) external pure returns (LeveragedLiquidationParams memory leveragedLiquidationParams);

Parameters

NameTypeDescription
inputParamsValidation.InputParamsThe params representing the position of the borrower.
depositLboolFlag indicating whether the liquidator is transferring depositL.
repayLboolFlag indicating whether the liquidator is repaying borrowL.

Returns

NameTypeDescription
leveragedLiquidationParamsLeveragedLiquidationParamsa struct of type LeveragedLiquidationParams containing the amounts to be closed and the premium to be paid.

calcHardMaxPremiumInBips

Calculate the maximum premium the liquidator may receive given the LTV of the borrower.

We min the result to favor the borrower.

function calcHardMaxPremiumInBips(
Validation.InputParams memory inputParams
) internal pure returns (uint256 maxPremiumInBips);

Parameters

NameTypeDescription
inputParamsValidation.InputParamsParams containing the prices to be used.

Returns

NameTypeDescription
maxPremiumInBipsuint256The max premium allowed to be received by the liquidator.

calcHardPremiumInBips

Calculate the premium being afforded to the liquidator given the repay and depositToTransfer amounts.

We use prices to maximize the premiumInBips to favor the borrower

function calcHardPremiumInBips(
uint256 repaidDebtInL,
uint256 seizedCollateralValueInL
) internal pure returns (uint256 premiumInBips);

Parameters

NameTypeDescription
repaidDebtInLuint256The amount of debt being repaid in L assets.
seizedCollateralValueInLuint256The value of the collateral being seized in L assets.

Returns

NameTypeDescription
premiumInBipsuint256The premium being received by the liquidator.

convertLtvToPremium

Calculate the maximum premium the liquidator should receive based on the LTV of the borrower. maxPremiumInBips is linear in between the following points

0<=LTV<START_NEGATIVE_PREMIUM_LTV_BIPS=>maxPremiumInBips=0START_NEGATIVE_PREMIUM_LTV_BIPS=LTV=>maxPremiumInBips==0(negativepremium)START_PREMIUM_LTV_BIPS=LTV=>maxPremiumInBips==1(nopremium)0.9=LTV=>maxPremiumInBips==1/0.9(fullpremium)\begin{gather*} 0 <= LTV < START\_NEGATIVE\_PREMIUM\_LTV\_BIPS => maxPremiumInBips = 0 \\ START\_NEGATIVE\_PREMIUM\_LTV\_BIPS = LTV => maxPremiumInBips == 0 \quad (negative premium) \\ START\_PREMIUM\_LTV\_BIPS = LTV => maxPremiumInBips == 1 \quad (no premium) \\ 0.9 = LTV => maxPremiumInBips == 1/0.9 \quad (full premium) \end{gather*}

internal for testing only

function convertLtvToPremium(
uint256 ltvBips
) internal pure returns (uint256 maxPremiumInBips);

Parameters

NameTypeDescription
ltvBipsuint256LTV of the borrower.

Returns

NameTypeDescription
maxPremiumInBipsuint256The maximum premium for the liquidator.

calculateNetDebtAndCollateral

function calculateNetDebtAndCollateral(
Validation.InputParams memory inputParams
) internal pure returns (uint256 netDebtInLAssets, uint256 netCollateralInLAssets);

calcSoftPremiumBips

Calculate the premium the soft liquidator is receiving given the borrowers deposit and the depositToTransfer to the liquidator. The end premium is the max of the premiums in L, X, Y If no soft liq is requested (liquidationParams.softDepositLToBeTransferred==liquidationParams.softDepositXToBeTransferred==liquidationParams.softDepositYToBeTransferred==0), the premium will be 0

function calcSoftPremiumBips(
Validation.InputParams memory inputParams,
uint256 depositLToTransferInLAssets,
uint256 depositXToTransferInXAssets,
uint256 depositYToTransferInYAssets
) internal pure returns (uint256 premiumInBips);

Parameters

NameTypeDescription
inputParamsValidation.InputParamsThe params containing the position of the borrower.
depositLToTransferInLAssetsuint256
depositXToTransferInXAssetsuint256
depositYToTransferInYAssetsuint256

Returns

NameTypeDescription
premiumInBipsuint256The premium being received by the liquidator.

calcSoftMaxPremiumInBips

Calculate the max premium the soft liquidator can receive given position of account.

function calcSoftMaxPremiumInBips(
ISaturationAndGeometricTWAPState saturationAndGeometricTWAPState,
Validation.InputParams memory inputParams,
address account
) internal view returns (uint256 maxPremiumBips);

Parameters

NameTypeDescription
saturationAndGeometricTWAPStateISaturationAndGeometricTWAPStateThe contract containing the saturation state.
inputParamsValidation.InputParamsThe params containing the position of account.
accountaddressThe account of the borrower.

Returns

NameTypeDescription
maxPremiumBipsuint256The max premium for the liquidator.

Errors

LiquidationPremiumTooHigh

error LiquidationPremiumTooHigh();

NotEnoughRepaidForLiquidation

error NotEnoughRepaidForLiquidation();

TooMuchDepositToTransferForLeverageLiquidation

error TooMuchDepositToTransferForLeverageLiquidation();

Structs

LeveragedLiquidationParams

struct LeveragedLiquidationParams {
uint256 closeInLAssets;
uint256 closeInXAssets;
uint256 closeInYAssets;
uint256 premiumInLAssets;
uint256 premiumLInXAssets;
uint256 premiumLInYAssets;
bool badDebt;
}

HardLiquidationParams

struct HardLiquidationParams {
uint256 depositLToBeTransferredInLAssets;
uint256 depositXToBeTransferredInXAssets;
uint256 depositYToBeTransferredInYAssets;
uint256 repayLXInXAssets;
uint256 repayLYInYAssets;
uint256 repayXInXAssets;
uint256 repayYInYAssets;
}