LiquidationEngine

Git Source

Inherits: Authorizable, Modifiable, Disableable, ReentrancyGuard, ILiquidationEngine

Handles the liquidations of SAFEs if the accumulated debt is higher than the collateral liquidation value

State Variables

safeSaviours

Allowed contracts that can be chosen to save SAFEs from liquidation

mapping(address _saviour => uint256 _allowed) public safeSaviours;

chosenSAFESaviour

Saviour contract chosen for each SAFE by its owner

mapping(bytes32 _cType => mapping(address _safe => address _saviour)) public chosenSAFESaviour;

currentOnAuctionSystemCoins

Total amount of system coins currently being auctioned

uint256 public currentOnAuctionSystemCoins;

safeEngine

The SAFEEngine is used to query the state of the SAFEs, confiscate the collateral and transfer the debt

ISAFEEngine public safeEngine;

accountingEngine

The AccountingEngine is used to push the debt into the system, and set as the first bidder on the collateral auctions

IAccountingEngine public accountingEngine;

_params

Getter for the unpacked contract parameters struct

LiquidationEngineParams public _params;

_cParams

Getter for the unpacked collateral parameters struct

mapping(bytes32 _cType => LiquidationEngineCollateralParams) public _cParams;

_collateralList

EnumerableSet.Bytes32Set internal _collateralList;

Functions

params

Getter for the contract parameters struct

function params() external view returns (LiquidationEngineParams memory _liqEngineParams);

Returns

NameTypeDescription
_liqEngineParamsLiquidationEngineParamsLiquidationEngine parameters struct

cParams

Getter for the collateral parameters struct

function cParams(bytes32 _cType) external view returns (LiquidationEngineCollateralParams memory _liqEngineCParams);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

Returns

NameTypeDescription
_liqEngineCParamsLiquidationEngineCollateralParamsLiquidationEngine collateral parameters struct

constructor

constructor(
  address _safeEngine,
  address _accountingEngine,
  LiquidationEngineParams memory _liqEngineParams
) Authorizable(msg.sender) validParams;

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine contract
_accountingEngineaddressAddress of the AccountingEngine contract
_liqEngineParamsLiquidationEngineParamsInitial valid LiquidationEngine parameters struct

connectSAFESaviour

Authed function to add contracts that can save SAFEs from liquidation

function connectSAFESaviour(address _saviour) external isAuthorized;

Parameters

NameTypeDescription
_saviouraddressSAFE saviour contract to be whitelisted

disconnectSAFESaviour

Authed function to remove contracts that can save SAFEs from liquidation

function disconnectSAFESaviour(address _saviour) external isAuthorized;

Parameters

NameTypeDescription
_saviouraddressSAFE saviour contract to be removed

protectSAFE

Choose a saviour contract for your SAFE

function protectSAFE(bytes32 _cType, address _safe, address _saviour) external;

Parameters

NameTypeDescription
_cTypebytes32The SAFE's collateral type
_safeaddressThe SAFE's address
_saviouraddressThe chosen saviour

liquidateSAFE

Liquidate a SAFE

A SAFE can be liquidated if the accumulated debt plus the liquidation penalty is higher than the collateral value

function liquidateSAFE(bytes32 _cType, address _safe) external whenEnabled nonReentrant returns (uint256 _auctionId);

Parameters

NameTypeDescription
_cTypebytes32The SAFE's collateral type
_safeaddressThe SAFE's address

Returns

NameTypeDescription
_auctionIduint256The auction id of the collateral auction

initializeCollateralType

Authed function to initialize a brand new collateral type

function initializeCollateralType(
  bytes32 _cType,
  LiquidationEngineCollateralParams memory _liqEngineCParams
) external isAuthorized whenEnabled validCParams(_cType);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type
_liqEngineCParamsLiquidationEngineCollateralParams

removeCoinsFromAuction

Remove debt that was being auctioned

Usually called by CollateralAuctionHouse when an auction is settled

function removeCoinsFromAuction(uint256 _rad) public isAuthorized;

Parameters

NameTypeDescription
_raduint256The amount of debt in RAD to withdraw from currentOnAuctionSystemCoins

getLimitAdjustedDebtToCover

The limit adjusted debt to cover

function getLimitAdjustedDebtToCover(
  bytes32 _cType,
  address _safe
) external view returns (uint256 _limitAdjustedDebtToCover);

Parameters

NameTypeDescription
_cTypebytes32The SAFE's collateral type
_safeaddressThe SAFE's address

Returns

NameTypeDescription
_limitAdjustedDebtToCoveruint256_wad The limit adjusted debt to cover

collateralList

List of all collateral types initialized in the LiquidationEngine

function collateralList() external view returns (bytes32[] memory __collateralList);

Returns

NameTypeDescription
__collateralListbytes32[]Array of collateral types

_modifyParameters

Internal function to be overriden with custom logic to modify parameters

This function is set to revert if not overriden

function _modifyParameters(bytes32 _param, bytes memory _data) internal override;

_modifyParameters

Internal function to be overriden with custom logic to modify parameters

This function is set to revert if not overriden

function _modifyParameters(bytes32 _cType, bytes32 _param, bytes memory _data) internal override;

_validateParameters

Internal function to be overriden with custom logic to validate parameters

function _validateParameters() internal view override;

_validateCParameters

Internal function to be overriden with custom logic to validate collateral parameters

function _validateCParameters(bytes32 _cType) internal view override;

_setCollateralAuctionHouse

Set the collateral auction house, deny permissions on the old one and approve on the new one

function _setCollateralAuctionHouse(bytes32 _cType, address _newCollateralAuctionHouse) internal;