AccountingEngine
Inherits: Authorizable, Modifiable, Disableable, IAccountingEngine
This contract is responsible for handling protocol surplus and debt
It allows the system to auction surplus and debt, as well as transfer surplus
This is a system contract, therefore it is not meant to be used by users directly
State Variables
safeEngine
Address of the SAFEEngine contract
ISAFEEngine public safeEngine;
surplusAuctionHouse
Address of the SurplusAuctionHouse contract
ISurplusAuctionHouse public surplusAuctionHouse;
debtAuctionHouse
Address of the DebtAuctionHouse contract
IDebtAuctionHouse public debtAuctionHouse;
postSettlementSurplusDrain
The post settlement surplus drain is used to transfer remaining surplus after settlement is triggered
Usually the SettlementSurplusAuctioneer
contract
address public postSettlementSurplusDrain;
extraSurplusReceiver
The extra surplus receiver is used to transfer surplus if is not being auctioned
address public extraSurplusReceiver;
_params
Getter for the unpacked contract parameters struct
AccountingEngineParams public _params;
debtQueue
A mapping storing debtBlocks that need to be covered by auctions
A debtBlock can be popped from the queue (to be auctioned) if more than popDebtDelay
has elapsed since creation
mapping(uint256 _timestamp => uint256 _rad) public debtQueue;
totalOnAuctionDebt
The total amount of debt that is currently on auction in the DebtAuctionHouse
uint256 public totalOnAuctionDebt;
totalQueuedDebt
The total amount of debt that is currently in the debtQueue to be auctioned
uint256 public totalQueuedDebt;
lastSurplusTime
The timestamp of the last time surplus was transferred or auctioned
uint256 public lastSurplusTime;
disableTimestamp
When the contract is disabled (usually by GlobalSettlement
) it has to wait disableCooldown
before any remaining surplus can be transferred to postSettlementSurplusDrain
uint256 public disableTimestamp;
Functions
addAuthorization
Overriding method allows new authorizations only if the contract is enabled
Method will revert if the account is already authorized
function addAuthorization(address _account) external override(Authorizable, IAuthorizable) isAuthorized whenEnabled;
Parameters
Name | Type | Description |
---|---|---|
_account | address | The account to authorize |
params
Getter for the contract parameters struct
function params() external view returns (AccountingEngineParams memory _accEngineParams);
Returns
Name | Type | Description |
---|---|---|
_accEngineParams | AccountingEngineParams | _params AccountingEngine parameters struct |
constructor
constructor(
address _safeEngine,
address _surplusAuctionHouse,
address _debtAuctionHouse,
AccountingEngineParams memory _accEngineParams
) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address of the SAFEEngine |
_surplusAuctionHouse | address | Address of the SurplusAuctionHouse |
_debtAuctionHouse | address | Address of the DebtAuctionHouse |
_accEngineParams | AccountingEngineParams | Initial valid AccountingEngine parameters struct |
unqueuedUnauctionedDebt
Returns the amount of bad debt that is not in the debtQueue and is not currently handled by debt auctions
The difference between the debt in the SAFEEngine and the debt in the debtQueue and on auction
function unqueuedUnauctionedDebt() external view returns (uint256 __unqueuedUnauctionedDebt);
Returns
Name | Type | Description |
---|---|---|
__unqueuedUnauctionedDebt | uint256 | _unqueuedUnauctionedDebt Amount of debt in RAD that is currently not in the debtQueue and not on auction [rad] |
_unqueuedUnauctionedDebt
function _unqueuedUnauctionedDebt(uint256 _debtBalance) internal view returns (uint256 __unqueuedUnauctionedDebt);
pushDebtToQueue
Push a block of debt to the debt queue
Usually called by the LiquidationEngine
when a SAFE is liquidated
function pushDebtToQueue(uint256 _debtBlock) external isAuthorized;
Parameters
Name | Type | Description |
---|---|---|
_debtBlock | uint256 | Amount of debt to push [rad] |
popDebtFromQueue
Pop a block of debt from the debt queue
A debtBlock can be popped from the queue after popDebtDelay
seconds have passed since creation
function popDebtFromQueue(uint256 _debtBlockTimestamp) external;
Parameters
Name | Type | Description |
---|---|---|
_debtBlockTimestamp | uint256 | Timestamp of the block of debt that should be popped out |
settleDebt
Destroy an equal amount of coins and debt
It can only destroy debt that is not locked in the queue and also not in a debt auction (unqueuedUnauctionedDebt
)
function settleDebt(uint256 _rad) external;
Parameters
Name | Type | Description |
---|---|---|
_rad | uint256 | Amount of coins & debt to destroy [rad] |
_settleDebt
function _settleDebt(
uint256 _coinBalance,
uint256 _debtBalance,
uint256 _rad
) internal returns (uint256 _newCoinBalance, uint256 _newDebtBalance);
cancelAuctionedDebtWithSurplus
Use surplus coins to destroy debt that was in a debt auction
Usually called by the DebtAuctionHouse
after a debt bid is made
function cancelAuctionedDebtWithSurplus(uint256 _rad) external;
Parameters
Name | Type | Description |
---|---|---|
_rad | uint256 | Amount of coins & debt to destroy with surplus [rad] |
auctionDebt
Start a debt auction (print protocol tokens in exchange for coins so that the system can be recapitalized)
It can only auction debt that has been popped from the debt queue and is not already being auctioned
function auctionDebt() external returns (uint256 _id);
Returns
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the debt auction that was started |
auctionSurplus
Start a surplus auction (sell surplus stability fees for protocol tokens)
It can only auction surplus if surplusIsTransferred
is set to false
function auctionSurplus() external returns (uint256 _id);
Returns
Name | Type | Description |
---|---|---|
_id | uint256 | Id of the surplus auction that was started |
transferExtraSurplus
Transfer surplus to an address as an alternative to surplus auctions
It can only transfer surplus if surplusIsTransferred
is set to true
function transferExtraSurplus() external;
_onContractDisable
Runtime to be run when the contract is disabled (normally triggered by GlobalSettlement)
When it's being disabled, the contract will record the current timestamp. Afterwards, the contract tries to settle as much debt as possible (if there's any) with any surplus that's left in the AccountingEngine
function _onContractDisable() internal override;
transferPostSettlementSurplus
Transfer any remaining surplus after the disable cooldown has passed. Meant to be a backup in case GlobalSettlement.processSAFE has a bug, governance doesn't have power over the system and there's still surplus left in the AccountingEngine which then blocks GlobalSettlement.setOutstandingCoinSupply.
Transfer any remaining surplus after disableCooldown
seconds have passed since disabling the contract
function transferPostSettlementSurplus() external whenDisabled;
_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;
_setSurplusAuctionHouse
Set the surplus auction house, deny permissions on the old one and approve on the new one
function _setSurplusAuctionHouse(address _surplusAuctionHouse) internal;
_validateParameters
Internal function to be overriden with custom logic to validate parameters
function _validateParameters() internal view override;