IAccountingEngine

Git Source

Inherits: IAuthorizable, IDisableable, IModifiable

Functions

safeEngine

Address of the SAFEEngine contract

function safeEngine() external view returns (ISAFEEngine _safeEngine);

surplusAuctionHouse

Address of the SurplusAuctionHouse contract

function surplusAuctionHouse() external view returns (ISurplusAuctionHouse _surplusAuctionHouse);

debtAuctionHouse

Address of the DebtAuctionHouse contract

function debtAuctionHouse() external view returns (IDebtAuctionHouse _debtAuctionHouse);

postSettlementSurplusDrain

The post settlement surplus drain is used to transfer remaining surplus after settlement is triggered

Usually the SettlementSurplusAuctioneer contract

function postSettlementSurplusDrain() external view returns (address _postSettlementSurplusDrain);

Returns

NameTypeDescription
_postSettlementSurplusDrainaddressAddress of the contract that handles post settlement surplus

extraSurplusReceiver

The extra surplus receiver is used to transfer surplus if is not being auctioned

function extraSurplusReceiver() external view returns (address _extraSurplusReceiver);

Returns

NameTypeDescription
_extraSurplusReceiveraddressAddress of the contract that handles extra surplus transfers

params

Getter for the contract parameters struct

function params() external view returns (AccountingEngineParams memory _params);

Returns

NameTypeDescription
_paramsAccountingEngineParamsAccountingEngine parameters struct

_params

Getter for the unpacked contract parameters struct

function _params()
  external
  view
  returns (
    uint256 _surplusIsTransferred,
    uint256 _surplusDelay,
    uint256 _popDebtDelay,
    uint256 _disableCooldown,
    uint256 _surplusAmount,
    uint256 _surplusBuffer,
    uint256 _debtAuctionMintedTokens,
    uint256 _debtAuctionBidSize
  );

Returns

NameTypeDescription
_surplusIsTransferreduint256Whether the system transfers surplus instead of auctioning it [0/1]
_surplusDelayuint256Amount of seconds between surplus actions
_popDebtDelayuint256Amount of seconds after which debt can be popped from debtQueue
_disableCooldownuint256Amount of seconds to wait (post settlement) until surplus can be drained
_surplusAmountuint256Amount of surplus transferred or sold in one surplus action [rad]
_surplusBufferuint256Amount of surplus that needs to accrue in this contract before any surplus action can start [rad]
_debtAuctionMintedTokensuint256Amount of protocol tokens to be minted in debt auctions [wad]
_debtAuctionBidSizeuint256Amount of debt sold in one debt auction [rad]

totalOnAuctionDebt

The total amount of debt that is currently on auction in the DebtAuctionHouse

function totalOnAuctionDebt() external view returns (uint256 _totalOnAuctionDebt);

Returns

NameTypeDescription
_totalOnAuctionDebtuint256Total amount of debt that is currently on auction [rad]

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

function debtQueue(uint256 _blockTimestamp) external view returns (uint256 _debtBlock);

Parameters

NameTypeDescription
_blockTimestampuint256The timestamp of the debtBlock

Returns

NameTypeDescription
_debtBlockuint256The amount of debt created in the inputted blockTimestamp [rad]

totalQueuedDebt

The total amount of debt that is currently in the debtQueue to be auctioned

function totalQueuedDebt() external view returns (uint256 _totalQueuedDebt);

Returns

NameTypeDescription
_totalQueuedDebtuint256Total amount of debt in RAD that is currently in the debtQueue [rad]

lastSurplusTime

The timestamp of the last time surplus was transferred or auctioned

function lastSurplusTime() external view returns (uint256 _lastSurplusTime);

Returns

NameTypeDescription
_lastSurplusTimeuint256Timestamp of when the last surplus transfer or auction was triggered

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

NameTypeDescription
_unqueuedUnauctionedDebtuint256Amount of debt in RAD that is currently not in the debtQueue and not on auction [rad]

disableTimestamp

When the contract is disabled (usually by GlobalSettlement) it has to wait disableCooldown before any remaining surplus can be transferred to postSettlementSurplusDrain

function disableTimestamp() external view returns (uint256 _disableTimestamp);

Returns

NameTypeDescription
_disableTimestampuint256Timestamp of when the contract was disabled

pushDebtToQueue

Push a block of debt to the debt queue

Usually called by the LiquidationEngine when a SAFE is liquidated

Debt is locked in a queue to give the system enough time to auction collateral and gather surplus

function pushDebtToQueue(uint256 _debtBlock) external;

Parameters

NameTypeDescription
_debtBlockuint256Amount 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

NameTypeDescription
_debtBlockTimestampuint256Timestamp 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

NameTypeDescription
_raduint256Amount of coins & debt to destroy [rad]

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

NameTypeDescription
_raduint256Amount 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

NameTypeDescription
_iduint256Id 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

It can only auction surplus if surplusDelay seconds have elapsed since the last surplus auction/transfer was triggered

It can only auction surplus if enough surplus remains in the buffer and if there is no more debt left to settle

function auctionSurplus() external returns (uint256 _id);

Returns

NameTypeDescription
_iduint256Id 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

It can only transfer surplus if surplusDelay seconds have elapsed since the last surplus auction/transfer was triggered

It can only transfer surplus if enough surplus remains in the buffer and if there is no more debt left to settle

function transferExtraSurplus() external;

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;

Events

PushDebtToQueue

Emitted when a block of debt is pushed to the debt queue

event PushDebtToQueue(uint256 indexed _timestamp, uint256 _debtAmount);

Parameters

NameTypeDescription
_timestampuint256Timestamp of the block of debt that was pushed
_debtAmountuint256Amount of debt that was pushed [rad]

PopDebtFromQueue

Emitted when a block of debt is popped from the debt queue

event PopDebtFromQueue(uint256 indexed _timestamp, uint256 _debtAmount);

Parameters

NameTypeDescription
_timestampuint256Timestamp of the block of debt that was popped
_debtAmountuint256Amount of debt that was popped [rad]

SettleDebt

Emitted when the contract destroys an equal amount of coins and debt

event SettleDebt(uint256 _rad, uint256 _coinBalance, uint256 _debtBalance);

Parameters

NameTypeDescription
_raduint256Amount of coins & debt that was destroyed [rad]
_coinBalanceuint256Amount of coins that remains after debt settlement [rad]
_debtBalanceuint256Amount of debt that remains after debt settlement [rad]

CancelDebt

Emitted when the contract destroys an equal amount of coins and debt with surplus

Normally called with coins received from the DebtAuctionHouse

event CancelDebt(uint256 _rad, uint256 _coinBalance, uint256 _debtBalance);

Parameters

NameTypeDescription
_raduint256Amount of coins & debt that was destroyed with surplus [rad]
_coinBalanceuint256Amount of coins that remains after debt settlement [rad]
_debtBalanceuint256Amount of debt that remains after debt settlement [rad]

AuctionDebt

Emitted when a debt auction is started

event AuctionDebt(uint256 indexed _id, uint256 _initialBid, uint256 _debtAuctioned);

Parameters

NameTypeDescription
_iduint256Id of the debt auction that was started
_initialBiduint256Amount of protocol tokens that are initially offered in the debt auction [wad]
_debtAuctioneduint256Amount of debt that is being auctioned [rad]

AuctionSurplus

Emitted when a surplus auction is started

event AuctionSurplus(uint256 indexed _id, uint256 _initialBid, uint256 _surplusAuctioned);

Parameters

NameTypeDescription
_iduint256Id of the surplus auction that was started
_initialBiduint256Amount of protocol tokens that are initially bidded in the surplus auction [wad]
_surplusAuctioneduint256Amount of surplus that is being auctioned [rad]

TransferSurplus

Emitted when surplus is transferred to an address

event TransferSurplus(address indexed _extraSurplusReceiver, uint256 _surplusTransferred);

Parameters

NameTypeDescription
_extraSurplusReceiveraddressAddress that received the surplus
_surplusTransferreduint256Amount of surplus that was transferred [rad]

Errors

AccEng_DebtAuctionDisabled

Throws when trying to auction debt when it is disabled

error AccEng_DebtAuctionDisabled();

AccEng_SurplusAuctionDisabled

Throws when trying to auction surplus when it is disabled

error AccEng_SurplusAuctionDisabled();

AccEng_SurplusTransferDisabled

Throws when trying to transfer surplus when it is disabled

error AccEng_SurplusTransferDisabled();

AccEng_InsufficientDebt

Throws when trying to settle debt when there is not enough debt left to settle

error AccEng_InsufficientDebt();

AccEng_InsufficientSurplus

Throws when trying to auction / transfer surplus when there is not enough surplus

error AccEng_InsufficientSurplus();

AccEng_NullAmount

Throws when trying to push / pop / auction a null amount of debt / surplus

error AccEng_NullAmount();

AccEng_NullSurplusReceiver

Throws when trying to transfer surplus to a null address

error AccEng_NullSurplusReceiver();

AccEng_SurplusCooldown

Throws when trying to auction / transfer surplus before the cooldown has passed

error AccEng_SurplusCooldown();

AccEng_PopDebtCooldown

Throws when trying to pop debt before the cooldown has passed

error AccEng_PopDebtCooldown();

AccEng_PostSettlementCooldown

Throws when trying to transfer post-settlement surplus before the disable cooldown has passed

error AccEng_PostSettlementCooldown();

Structs

AccountingEngineParams

struct AccountingEngineParams {
  uint256 surplusIsTransferred;
  uint256 surplusDelay;
  uint256 popDebtDelay;
  uint256 disableCooldown;
  uint256 surplusAmount;
  uint256 surplusBuffer;
  uint256 debtAuctionMintedTokens;
  uint256 debtAuctionBidSize;
}