LiquidationEngine

Git Source

Inherits: Authorizable, Disableable, Modifiable, ModifiablePerCollateral, 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 => bool _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;

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

attemptSave

function attemptSave(
  bytes32 _cType,
  address _safe,
  address _liquidator,
  ISAFEEngine.SAFE calldata _safeData
) external returns (ISAFEEngine.SAFE memory _newSafeData);

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

_getLimitAdjustedDebt

function _getLimitAdjustedDebt(
  uint256 _generatedDebt,
  uint256 _accumulatedRate,
  uint256 _liquidationQuantity,
  uint256 _liquidationPenalty,
  uint256 _debtFloor
) internal pure returns (uint256 _limitAdjustedDebt);

_initializeCollateralType

Register a new collateral type in the SAFEEngine

function _initializeCollateralType(bytes32 _cType, bytes memory _collateralParams) internal override whenEnabled;

Parameters

NameTypeDescription
_cTypebytes32Collateral type to register
_collateralParamsbytesCollateral parameters

_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

Set a new value for a collateral specific parameter

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

Parameters

NameTypeDescription
_cTypebytes32String identifier of the collateral to modify
_parambytes32String identifier of the parameter to modify
_databytesEncoded data to modify the parameter

_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;