ISAFEEngine
Inherits: IAuthorizable, IDisableable, IModifiable, IModifiablePerCollateral
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 |
_params
Getter for the unpacked contract parameters struct
function _params() external view returns (uint256 _safeDebtCeiling, uint256 _globalDebtCeiling);
Returns
Name | Type | Description |
---|---|---|
_safeDebtCeiling | uint256 | Total amount of debt that a single safe can generate [wad] |
_globalDebtCeiling | uint256 | Maximum amount of debt that can be issued [rad] |
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 |
_cParams
Getter for the unpacked collateral parameters struct
function _cParams(bytes32 _cType) external view returns (uint256 _debtCeiling, uint256 _debtFloor);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_debtCeiling | uint256 | Maximum amount of debt that can be generated with this collateral type |
_debtFloor | uint256 | Minimum amount of debt that must be generated by a SAFE using this collateral |
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 |
_cData
Getter for the unpacked collateral data struct
function _cData(bytes32 _cType)
external
view
returns (
uint256 _debtAmount,
uint256 _lockedAmount,
uint256 _accumulatedRate,
uint256 _safetyPrice,
uint256 _liquidationPrice
);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_debtAmount | uint256 | Total amount of debt issued by a collateral type [wad] |
_lockedAmount | uint256 | Total amount of collateral locked in all SAFEs of the collateral type [wad] |
_accumulatedRate | uint256 | Accumulated rate of a collateral type [ray] |
_safetyPrice | uint256 | Floor price at which a SAFE is allowed to generate debt [ray] |
_liquidationPrice | uint256 | Price at which a SAFE gets liquidated [ray] |
safes
Data about each SAFE
function safes(bytes32 _cType, address _safeAddress) external view returns (SAFE memory _safeData);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safeAddress | address | Address of the SAFE |
Returns
Name | Type | Description |
---|---|---|
_safeData | SAFE | SAFE data for the specified collateral type of the specified safe. |
_safes
Unpacked data about each SAFE
function _safes(
bytes32 _cType,
address _safeAddress
) external view returns (uint256 _lockedCollateral, uint256 _generatedDebt);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safeAddress | address | Address of the SAFE |
Returns
Name | Type | Description |
---|---|---|
_lockedCollateral | uint256 | Total amount of collateral locked in a SAFE [wad] |
_generatedDebt | uint256 | Total amount of debt generated by a SAFE [wad] |
safeRights
Who can transfer collateral & debt in/out of a SAFE
function safeRights(address _caller, address _account) external view returns (bool _safeRights);
Parameters
Name | Type | Description |
---|---|---|
_caller | address | Address to check for SAFE permissions for |
_account | address | Account to check if caller has permissions for |
Returns
Name | Type | Description |
---|---|---|
_safeRights | bool | Boolean representation of the SAFE rights (0/1) |
tokenCollateral
Balance of each collateral type
function tokenCollateral(bytes32 _cType, address _account) external view returns (uint256 _collateralBalance);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type to check balance for |
_account | address | Account to check balance for |
Returns
Name | Type | Description |
---|---|---|
_collateralBalance | uint256 | Collateral balance of the account [wad] |
coinBalance
Internal balance of system coins held by an account
function coinBalance(address _account) external view returns (uint256 _balance);
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account to check balance for |
Returns
Name | Type | Description |
---|---|---|
_balance | uint256 | Internal coin balance of the account [rad] |
debtBalance
Amount of debt held by an account
function debtBalance(address _account) external view returns (uint256 _debtBalance);
Parameters
Name | Type | Description |
---|---|---|
_account | address | Account to check balance for |
Returns
Name | Type | Description |
---|---|---|
_debtBalance | uint256 | Debt balance of the account [rad] |
globalDebt
Total amount of debt (coins) currently issued
function globalDebt() external returns (uint256 _globalDebt);
Returns
Name | Type | Description |
---|---|---|
_globalDebt | uint256 | Global debt [rad] |
globalUnbackedDebt
'Bad' debt that's not covered by collateral
function globalUnbackedDebt() external view returns (uint256 _globalUnbackedDebt);
Returns
Name | Type | Description |
---|---|---|
_globalUnbackedDebt | uint256 | Global unbacked debt [rad] |
transferCollateral
Transfer collateral between accounts
function transferCollateral(bytes32 _cType, address _source, address _destination, uint256 _wad) external;
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;
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;
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;
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;
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;
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;
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;
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;
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] |
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) external view returns (bool _allowed);
Parameters
Name | Type | Description |
---|---|---|
_safe | address | The safe to check |
_account | address | The account to check |
Returns
Name | Type | Description |
---|---|---|
_allowed | bool | Whether the account can modify the safe |
Events
ApproveSAFEModification
Emitted when an address authorizes another address to modify its SAFE
event ApproveSAFEModification(address _sender, address _account);
Parameters
Name | Type | Description |
---|---|---|
_sender | address | Address that sent the authorization |
_account | address | Address that is authorized to modify the SAFE |
DenySAFEModification
Emitted when an address denies another address to modify its SAFE
event DenySAFEModification(address _sender, address _account);
Parameters
Name | Type | Description |
---|---|---|
_sender | address | Address that sent the denial |
_account | address | Address that is denied to modify the SAFE |
TransferCollateral
Emitted when collateral is transferred between accounts
event TransferCollateral(bytes32 indexed _cType, address indexed _src, address indexed _dst, uint256 _wad);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_src | address | Address that sent the collateral |
_dst | address | Address that received the collateral |
_wad | uint256 | Amount of collateral transferred |
TransferInternalCoins
Emitted when internal coins are transferred between accounts
event TransferInternalCoins(address indexed _src, address indexed _dst, uint256 _rad);
Parameters
Name | Type | Description |
---|---|---|
_src | address | Address that sent the coins |
_dst | address | Address that received the coins |
_rad | uint256 | Amount of coins transferred |
ModifySAFECollateralization
Emitted when the SAFE state is modified by the owner or authorized accounts
event ModifySAFECollateralization(
bytes32 indexed _cType,
address indexed _safe,
address _collateralSource,
address _debtDestination,
int256 _deltaCollateral,
int256 _deltaDebt
);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safe | address | Address of the SAFE |
_collateralSource | address | Address that sent/receives the collateral |
_debtDestination | address | Address that sent/receives the debt |
_deltaCollateral | int256 | Amount of collateral added/extracted from the SAFE [wad] |
_deltaDebt | int256 | Amount of debt to generate/repay [wad] |
TransferSAFECollateralAndDebt
Emitted when collateral and/or debt is transferred between SAFEs
event TransferSAFECollateralAndDebt(
bytes32 indexed _cType, address indexed _src, address indexed _dst, int256 _deltaCollateral, int256 _deltaDebt
);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_src | address | Address that sent the collateral |
_dst | address | Address that received the collateral |
_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
Emitted when collateral and debt is confiscated from a SAFE
event ConfiscateSAFECollateralAndDebt(
bytes32 indexed _cType,
address indexed _safe,
address _collateralSource,
address _debtDestination,
int256 _deltaCollateral,
int256 _deltaDebt
);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safe | address | Address of the SAFE |
_collateralSource | address | Address that sent/receives the collateral |
_debtDestination | address | Address that sent/receives the debt |
_deltaCollateral | int256 | Amount of collateral added/extracted from the SAFE [wad] |
_deltaDebt | int256 | Amount of debt to generate/repay [wad] |
SettleDebt
Emitted when an account's debt is settled with coins
Accounts (not SAFEs) can only settle unbacked debt
event SettleDebt(address indexed _account, uint256 _rad);
Parameters
Name | Type | Description |
---|---|---|
_account | address | Address of the account |
_rad | uint256 | Amount of debt & coins to destroy |
CreateUnbackedDebt
Emitted when an unbacked debt is created to an account
event CreateUnbackedDebt(address indexed _debtDestination, address indexed _coinDestination, uint256 _rad);
Parameters
Name | Type | Description |
---|---|---|
_debtDestination | address | Address that received the newly created debt |
_coinDestination | address | Address that received the newly created coins |
_rad | uint256 | Amount of debt to create |
UpdateAccumulatedRate
Emit when the accumulated rate of a collateral type is updated
event UpdateAccumulatedRate(bytes32 indexed _cType, address _surplusDst, int256 _rateMultiplier);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_surplusDst | address | Address that received the newly created surplus |
_rateMultiplier | int256 | Delta of the accumulated rate [ray] |
UpdateCollateralPrice
Emitted when the safety price and liquidation price of a collateral type is updated
event UpdateCollateralPrice(bytes32 indexed _cType, uint256 _safetyPrice, uint256 _liquidationPrice);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_safetyPrice | uint256 | New price at which a SAFE is allowed to generate debt [ray] |
_liquidationPrice | uint256 | New price at which a SAFE gets liquidated [ray] |
Errors
SAFEEng_CollateralTypeNotInitialized
Throws when trying to modify parameters of an uninitialized collateral type
error SAFEEng_CollateralTypeNotInitialized();
SAFEEng_SAFENotSafe
Throws when trying to modify a SAFE into an unsafe state
error SAFEEng_SAFENotSafe();
SAFEEng_DustySAFE
Throws when trying to modify a SAFE into a dusty safe (debt non-zero and below debtFloor
)
error SAFEEng_DustySAFE();
SAFEEng_GlobalDebtCeilingHit
Throws when trying to generate debt that would put the system over the global debt ceiling
error SAFEEng_GlobalDebtCeilingHit();
SAFEEng_CollateralDebtCeilingHit
Throws when trying to generate debt that would put the system over the collateral debt ceiling
error SAFEEng_CollateralDebtCeilingHit();
SAFEEng_SAFEDebtCeilingHit
Throws when trying to generate debt that would put the SAFE over the SAFE debt ceiling
error SAFEEng_SAFEDebtCeilingHit();
SAFEEng_NotSAFEAllowed
Throws when an account tries to modify a SAFE without the proper permissions
error SAFEEng_NotSAFEAllowed();
SAFEEng_NotCollateralSrcAllowed
Throws when an account tries to pull collateral from a SAFE without the proper permissions
error SAFEEng_NotCollateralSrcAllowed();
SAFEEng_NotDebtDstAllowed
Throws when an account tries to push debt to a SAFE without the proper permissions
error SAFEEng_NotDebtDstAllowed();
Structs
SAFE
struct SAFE {
uint256 lockedCollateral;
uint256 generatedDebt;
}
SAFEEngineParams
struct SAFEEngineParams {
uint256 safeDebtCeiling;
uint256 globalDebtCeiling;
}
SAFEEngineCollateralData
struct SAFEEngineCollateralData {
uint256 debtAmount;
uint256 lockedAmount;
uint256 accumulatedRate;
uint256 safetyPrice;
uint256 liquidationPrice;
}
SAFEEngineCollateralParams
struct SAFEEngineCollateralParams {
uint256 debtCeiling;
uint256 debtFloor;
}