Liquidation

Git Source

The liquidation module for the IonPool. Liquidations at Ion operate a little differently than traditional liquidation schemes. Usually, liquidations are a function of the market price of an asset. However, the liquidation module is function of the reserve oracle price which reflects a rate based on beacon-chain balances. There are 3 different types of liquidations that can take place:

  • Partial Liquidation: The liquidator pays off a portion of the debt and receives a portion of the collateral.

  • Dust Liquidation: The liquidator pays off all of the debt and receives some or all of the collateral.

  • Protocol Liquidation: The liquidator transfers the position's debt and collateral onto the protocol's balance sheet. NOTE: Protocol liqudations are unlikely to ever be executed since there is no profit incentive for a liquidator to do so. They exist solely as a fallback if a liquidator were to ever execute a liquidation onto a vault that had fallen into bad debt.

State Variables

TARGET_HEALTH

uint256 public immutable TARGET_HEALTH;

BASE_DISCOUNT

uint256 public immutable BASE_DISCOUNT;

MAX_DISCOUNT_0

uint256 public immutable MAX_DISCOUNT_0;

MAX_DISCOUNT_1

uint256 public immutable MAX_DISCOUNT_1;

MAX_DISCOUNT_2

uint256 public immutable MAX_DISCOUNT_2;

LIQUIDATION_THRESHOLD_0

uint256 public immutable LIQUIDATION_THRESHOLD_0;

LIQUIDATION_THRESHOLD_1

uint256 public immutable LIQUIDATION_THRESHOLD_1;

LIQUIDATION_THRESHOLD_2

uint256 public immutable LIQUIDATION_THRESHOLD_2;

RESERVE_ORACLE_0

address public immutable RESERVE_ORACLE_0;

RESERVE_ORACLE_1

address public immutable RESERVE_ORACLE_1;

RESERVE_ORACLE_2

address public immutable RESERVE_ORACLE_2;

PROTOCOL

address public immutable PROTOCOL;

POOL

IonPool public immutable POOL;

UNDERLYING

IERC20 public immutable UNDERLYING;

Functions

constructor

Creates a new Liquidation instance.

constructor(
    address _ionPool,
    address _protocol,
    address[] memory _reserveOracles,
    uint256[] memory _liquidationThresholds,
    uint256 _targetHealth,
    uint256 _reserveFactor,
    uint256[] memory _maxDiscounts
);

Parameters

NameTypeDescription

_ionPool

address

The address of the IonPool contract.

_protocol

address

The address that will represent the protocol balance sheet (for protocol liquidation purposes).

_reserveOracles

address[]

List of reserve oracle addresses for each ilk.

_liquidationThresholds

uint256[]

List of liquidation thresholds for each ilk.

_targetHealth

uint256

The target health ratio for positions.

_reserveFactor

uint256

Base discount for collateral.

_maxDiscounts

uint256[]

List of max discounts for each ilk.

_getConfigs

Returns the exchange rate, liquidation threshold, and max discount for the given ilk.

function _getConfigs(uint8 ilkIndex) internal view returns (Configs memory configs);

Parameters

NameTypeDescription

ilkIndex

uint8

The index of the ilk.

getRepayAmt

If liquidation is possible, returns the amount of WETH necessary to liquidate a vault.

function getRepayAmt(uint8 ilkIndex, address vault) public view returns (uint256 repay);

Parameters

NameTypeDescription

ilkIndex

uint8

The index of the ilk.

vault

address

The address of the vault.

Returns

NameTypeDescription

repay

uint256

The amount of WETH necessary to liquidate the vault.

_getRepayAmt

Internal helper function for calculating the repay amount.

function _getRepayAmt(
    uint256 debtValue,
    uint256 collateralValue,
    uint256 liquidationThreshold,
    uint256 discount
)
    internal
    view
    returns (uint256 repay);

Parameters

NameTypeDescription

debtValue

uint256

The total debt. [RAD]

collateralValue

uint256

Calculated with collateral * exchangeRate * liquidationThreshold. [RAD]

liquidationThreshold

uint256

Ratio at which liquidation can occur. [RAY]

discount

uint256

The discount from the exchange rate at which the collateral is sold. [RAY]

Returns

NameTypeDescription

repay

uint256

The amount of WETH necessary to liquidate the vault. [RAD]

liquidate

Closes an unhealthy position on IonPool.

function liquidate(uint8 ilkIndex, address vault, address kpr) external returns (uint256 repayAmount, uint256 gemOut);

Parameters

NameTypeDescription

ilkIndex

uint8

The index of the collateral.

vault

address

The position to be liquidated.

kpr

address

Receiver of the collateral.

Returns

NameTypeDescription

repayAmount

uint256

The amount of WETH paid to close the position.

gemOut

uint256

The amount of collateral received from the liquidation.

Events

Liquidate

event Liquidate(address indexed initiator, address indexed kpr, uint8 indexed ilkIndex, uint256 repay, uint256 gemOut);

Errors

ExchangeRateCannotBeZero

error ExchangeRateCannotBeZero();

VaultIsNotUnsafe

error VaultIsNotUnsafe(uint256 healthRatio);

InvalidReserveOraclesLength

error InvalidReserveOraclesLength(uint256 length);

InvalidLiquidationThresholdsLength

error InvalidLiquidationThresholdsLength(uint256 length);

InvalidMaxDiscountsLength

error InvalidMaxDiscountsLength(uint256 length);

InvalidTargetHealth

error InvalidTargetHealth(uint256 targetHealth);

InvalidLiquidationThreshold

error InvalidLiquidationThreshold(uint256 liquidationThreshold);

InvalidMaxDiscount

error InvalidMaxDiscount(uint256 maxDiscount);

Structs

Configs

struct Configs {
    uint256 liquidationThreshold;
    uint256 maxDiscount;
    address reserveOracle;
}

LiquidateArgs

struct LiquidateArgs {
    uint256 repay;
    uint256 gemOut;
    uint256 dart;
    uint256 fee;
    uint256 price;
}