SAFEEngine
Inherits: Authorizable, Disableable, Modifiable, ModifiablePerCollateral, ISAFEEngine
Core contract that manages the state of the SAFE system
State Variables
_params
Getter for the unpacked contract parameters struct
SAFEEngineParams public _params;
_cParams
Getter for the unpacked collateral parameters struct
mapping(bytes32 _cType => SAFEEngineCollateralParams) public _cParams;
_cData
Getter for the unpacked collateral data struct
mapping(bytes32 _cType => SAFEEngineCollateralData) public _cData;
_safes
Unpacked data about each SAFE
mapping(bytes32 _cType => mapping(address _safe => SAFE)) public _safes;
safeRights
Who can transfer collateral & debt in/out of a SAFE
mapping(address _caller => mapping(address _account => bool _isAllowed)) public safeRights;
tokenCollateral
Balance of each collateral type
mapping(bytes32 _cType => mapping(address _safe => uint256 _wad)) public tokenCollateral;
coinBalance
Internal balance of system coins held by an account
mapping(address _safe => uint256 _rad) public coinBalance;
debtBalance
Amount of debt held by an account
mapping(address _safe => uint256 _rad) public debtBalance;
globalDebt
Total amount of debt (coins) currently issued
uint256 public globalDebt;
globalUnbackedDebt
'Bad' debt that's not covered by collateral
uint256 public globalUnbackedDebt;
Functions
params
Getter for the contract parameters struct
function params() external view returns (SAFEEngineParams memory _safeEngineParams);
Returns
Name | Type | Description |
---|---|---|
_safeEngineParams | SAFEEngineParams | The active SAFEEngineParams |
cParams
Getter for the collateral parameters struct
function cParams(bytes32 _cType) external view returns (SAFEEngineCollateralParams memory _safeEngineCParams);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_safeEngineCParams | SAFEEngineCollateralParams | SAFEEngineCollateralParams for the collateral type |
cData
Getter for the collateral data struct
function cData(bytes32 _cType) external view returns (SAFEEngineCollateralData memory _safeEngineCData);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_safeEngineCData | SAFEEngineCollateralData | SAFEEngineCollateralData for the collateral type |
safes
Data about each SAFE
function safes(bytes32 _cType, address _safe) external view returns (SAFE memory _safeData);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safe | address |
Returns
Name | Type | Description |
---|---|---|
_safeData | SAFE | SAFE data for the specified collateral type of the specified safe. |
constructor
constructor(SAFEEngineParams memory _safeEngineParams) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngineParams | SAFEEngineParams | Initial SAFEEngine valid parameters struct |
transferCollateral
Transfer collateral between accounts
function transferCollateral(
bytes32 _cType,
address _source,
address _destination,
uint256 _wad
) external isSAFEAllowed(_source, msg.sender);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type transferred |
_source | address | Collateral source |
_destination | address | Collateral destination |
_wad | uint256 | Amount of collateral transferred |
transferInternalCoins
Transfer internal coins (does not affect external balances from Coin.sol)
function transferInternalCoins(
address _source,
address _destination,
uint256 _rad
) external isSAFEAllowed(_source, msg.sender);
Parameters
Name | Type | Description |
---|---|---|
_source | address | Coins source |
_destination | address | Coins destination |
_rad | uint256 | Amount of coins transferred |
modifyCollateralBalance
Join/exit collateral into and and out of the system
function modifyCollateralBalance(bytes32 _cType, address _account, int256 _wad) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to join/exit |
_account | address | Account that gets credited/debited |
_wad | int256 | Amount of collateral |
modifySAFECollateralization
Add/remove collateral or put back/generate more debt in a SAFE
function modifySAFECollateralization(
bytes32 _cType,
address _safe,
address _collateralSource,
address _debtDestination,
int256 _deltaCollateral,
int256 _deltaDebt
) external whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Type of collateral to withdraw/deposit in and from the SAFE |
_safe | address | Target SAFE |
_collateralSource | address | Account we take collateral from/put collateral into |
_debtDestination | address | Account from which we credit/debit coins and debt |
_deltaCollateral | int256 | Amount of collateral added/extracted from the SAFE [wad] |
_deltaDebt | int256 | Amount of debt to generate/repay [wad] |
transferSAFECollateralAndDebt
Transfer collateral and/or debt between SAFEs
function transferSAFECollateralAndDebt(
bytes32 _cType,
address _src,
address _dst,
int256 _deltaCollateral,
int256 _deltaDebt
) external isSAFEAllowed(_src, msg.sender) isSAFEAllowed(_dst, msg.sender);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type transferred between SAFEs |
_src | address | Source SAFE |
_dst | address | Destination SAFE |
_deltaCollateral | int256 | Amount of collateral to take/add into src and give/take from dst [wad] |
_deltaDebt | int256 | Amount of debt to take/add into src and give/take from dst [wad] |
confiscateSAFECollateralAndDebt
Normally used by the LiquidationEngine in order to confiscate collateral and debt from a SAFE and give them to someone else
function confiscateSAFECollateralAndDebt(
bytes32 _cType,
address _safe,
address _collateralSource,
address _debtDestination,
int256 _deltaCollateral,
int256 _deltaDebt
) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type the SAFE has locked inside |
_safe | address | Target SAFE |
_collateralSource | address | Who we take/give collateral to |
_debtDestination | address | Who we take/give debt to |
_deltaCollateral | int256 | Amount of collateral taken/added into the SAFE [wad] |
_deltaDebt | int256 | Amount of debt taken/added into the SAFE [wad] |
settleDebt
Nullify an amount of coins with an equal amount of debt
Coins & debt are like matter and antimatter, they nullify each other
function settleDebt(uint256 _rad) external;
Parameters
Name | Type | Description |
---|---|---|
_rad | uint256 | Amount of debt & coins to destroy |
createUnbackedDebt
Allows an authorized contract to create debt without collateral
Usually called by DebtAuctionHouse in order to terminate auctions prematurely post settlement
function createUnbackedDebt(address _debtDestination, address _coinDestination, uint256 _rad) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_debtDestination | address | The account that will receive the newly created debt |
_coinDestination | address | The account that will receive the newly created coins |
_rad | uint256 | Amount of debt to create |
updateAccumulatedRate
Allows an authorized contract to accrue interest on a specific collateral type
The rateMultiplier is usually calculated by the TaxCollector contract
function updateAccumulatedRate(
bytes32 _cType,
address _surplusDst,
int256 _rateMultiplier
) external isAuthorized whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type we accrue interest for |
_surplusDst | address | Destination for the newly created surplus |
_rateMultiplier | int256 | Multiplier applied to the debtAmount in order to calculate the surplus [ray] |
updateCollateralPrice
Allows an authorized contract to update the safety price and liquidation price of a collateral type
function updateCollateralPrice(
bytes32 _cType,
uint256 _safetyPrice,
uint256 _liquidationPrice
) external isAuthorized whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type we update the prices for |
_safetyPrice | uint256 | New safety price [ray] |
_liquidationPrice | uint256 | New liquidation price [ray] |
addAuthorization
Add auth to an account
This overriden method avoids adding new authorizations after the contract has been disabled
function addAuthorization(address _account) external override(Authorizable, IAuthorizable) isAuthorized whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account to add auth to |
removeAuthorization
Remove auth from an account
function removeAuthorization(address _account) external override(Authorizable, IAuthorizable) isAuthorized whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account to remove auth from |
approveSAFEModification
Allow an address to modify your SAFE
function approveSAFEModification(address _account) external;
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account to give SAFE permissions to |
denySAFEModification
Deny an address the rights to modify your SAFE
function denySAFEModification(address _account) external;
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account that is denied SAFE permissions |
canModifySAFE
Checks whether an account has the right to modify a SAFE
function canModifySAFE(address _safe, address _account) public view returns (bool _canModifySafe);
Parameters
Name | Type | Description |
---|---|---|
_safe | address | The safe to check |
_account | address | The account to check |
Returns
Name | Type | Description |
---|---|---|
_canModifySafe | bool | _allowed Whether the account can modify the safe |
_modifyCollateralBalance
function _modifyCollateralBalance(bytes32 _cType, address _account, int256 _wad) internal;
_modifyInternalCoins
function _modifyInternalCoins(address _dst, int256 _rad) internal;
_modifySAFECollateralization
function _modifySAFECollateralization(
bytes32 _cType,
address _safe,
int256 _deltaCollateral,
int256 _deltaDebt
) internal;
_emitTransferCollateral
function _emitTransferCollateral(bytes32 _cType, address _src, address _dst, int256 _deltaCollateral) internal;
_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 |
isSAFEAllowed
modifier isSAFEAllowed(address _safe, address _account);