LiquidationEngine
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
Name | Type | Description |
---|---|---|
_liqEngineParams | LiquidationEngineParams | LiquidationEngine parameters struct |
cParams
Getter for the collateral parameters struct
function cParams(bytes32 _cType) external view returns (LiquidationEngineCollateralParams memory _liqEngineCParams);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_liqEngineCParams | LiquidationEngineCollateralParams | LiquidationEngine collateral parameters struct |
constructor
constructor(
address _safeEngine,
address _accountingEngine,
LiquidationEngineParams memory _liqEngineParams
) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address of the SAFEEngine contract |
_accountingEngine | address | Address of the AccountingEngine contract |
_liqEngineParams | LiquidationEngineParams | Initial valid LiquidationEngine parameters struct |
connectSAFESaviour
Authed function to add contracts that can save SAFEs from liquidation
function connectSAFESaviour(address _saviour) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_saviour | address | SAFE saviour contract to be whitelisted |
disconnectSAFESaviour
Authed function to remove contracts that can save SAFEs from liquidation
function disconnectSAFESaviour(address _saviour) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_saviour | address | SAFE saviour contract to be removed |
protectSAFE
Choose a saviour contract for your SAFE
function protectSAFE(bytes32 _cType, address _safe, address _saviour) external;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | The SAFE's collateral type |
_safe | address | The SAFE's address |
_saviour | address | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | The SAFE's collateral type |
_safe | address | The SAFE's address |
Returns
Name | Type | Description |
---|---|---|
_auctionId | uint256 | The 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
Name | Type | Description |
---|---|---|
_rad | uint256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | The SAFE's collateral type |
_safe | address | The SAFE's address |
Returns
Name | Type | Description |
---|---|---|
_limitAdjustedDebtToCover | uint256 | _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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to register |
_collateralParams | bytes | Collateral 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | String identifier of the collateral to modify |
_param | bytes32 | String identifier of the parameter to modify |
_data | bytes | Encoded 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;