StabilityFeeTreasury

Git Source

Inherits: Authorizable, Modifiable, Disableable, IStabilityFeeTreasury

This contract is in charge of distributing the accrued stability fees to allowed addresses

State Variables

safeEngine

Address of the SAFEEngine contract

ISAFEEngine public safeEngine;

systemCoin

Address of the SystemCoin contract

ISystemCoin public systemCoin;

coinJoin

Address of the CoinJoin contract

ICoinJoin public coinJoin;

extraSurplusReceiver

Address that receives surplus funds when treasury exceeds capacity (or is disabled)

address public extraSurplusReceiver;

_params

Getter for the unpacked contract parameters struct

StabilityFeeTreasuryParams public _params;

_allowance

Getter for the unpacked allowance struct of a given account

A null per hour allowance means that the account has no per hour limit

mapping(address _account => Allowance) public _allowance;

pulledPerHour

Amount of internal coins a given account has pulled from the treasury in a given block hour

mapping(address _account => mapping(uint256 _blockHour => uint256 _rad)) public pulledPerHour;

latestSurplusTransferTime

Timestamp of the last time that surplus funds were transferred

uint256 public latestSurplusTransferTime;

Functions

params

Getter for the contract parameters struct

function params() external view returns (StabilityFeeTreasuryParams memory _sfTreasuryParams);

Returns

NameTypeDescription
_sfTreasuryParamsStabilityFeeTreasuryParamsStabilityFee parameters struct

allowance

Getter for the allowance struct of a given account

function allowance(address _account) external view returns (Allowance memory __allowance);

Parameters

NameTypeDescription
_accountaddressThe account to query

Returns

NameTypeDescription
__allowanceAllowanceData structure containing total and per hour allowance for the given account

accountNotTreasury

Modifier to check if an account is not the treasury (this contract)

This modifier is used to prevent the treasury from giving funds to itself

modifier accountNotTreasury(address _account);

Parameters

NameTypeDescription
_accountaddressThe account to check whether it's the treasury or not

constructor

constructor(
  address _safeEngine,
  address _extraSurplusReceiver,
  address _coinJoin,
  StabilityFeeTreasuryParams memory _sfTreasuryParams
) Authorizable(msg.sender) validParams;

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine contract
_extraSurplusReceiveraddressAddress that receives surplus funds when treasury exceeds capacity
_coinJoinaddressAddress of the CoinJoin contract
_sfTreasuryParamsStabilityFeeTreasuryParamsInitial valid StabilityFeeTreasury parameters struct

_onContractDisable

Disable this contract (normally called by GlobalSettlement)

This method is virtual and should be overriden to implement

function _onContractDisable() internal override;

_joinAllCoins

Join all ERC20 system coins that the treasury has inside the SAFEEngine

Converts all ERC20 system coins to internal system coins

function _joinAllCoins() internal;

settleDebt

Settle as much bad debt as possible (if this contract has any)

function settleDebt() external returns (uint256 _coinBalance, uint256 _debtBalance);

Returns

NameTypeDescription
_coinBalanceuint256Amount of internal system coins that this contract has after settling debt
_debtBalanceuint256Amount of bad debt that this contract has after settling debt

_settleDebt

Settle as much bad debt as possible (if this contract has any)

function _settleDebt() internal returns (uint256 _coinBalance, uint256 _debtBalance);

Returns

NameTypeDescription
_coinBalanceuint256Amount of internal system coins that this contract has after settling debt
_debtBalanceuint256Amount of bad debt that this contract has after settling debt

setTotalAllowance

Modify an address' total allowance in order to withdraw SF from the treasury

function setTotalAllowance(address _account, uint256 _rad) external isAuthorized accountNotTreasury(_account);

Parameters

NameTypeDescription
_accountaddressThe approved address
_raduint256The total approved amount of SF to withdraw [rad]

setPerHourAllowance

Modify an address' per hour allowance in order to withdraw SF from the treasury

function setPerHourAllowance(address _account, uint256 _rad) external isAuthorized accountNotTreasury(_account);

Parameters

NameTypeDescription
_accountaddressThe approved address
_raduint256The per hour approved amount of SF to withdraw [rad]

giveFunds

Governance transfers SF to an address

function giveFunds(address _account, uint256 _rad) external isAuthorized accountNotTreasury(_account);

Parameters

NameTypeDescription
_accountaddressAddress to transfer SF to
_raduint256Amount of internal system coins to transfer [rad]

takeFunds

Governance takes funds from an address

function takeFunds(address _account, uint256 _rad) external isAuthorized accountNotTreasury(_account);

Parameters

NameTypeDescription
_accountaddressAddress to take system coins from
_raduint256Amount of internal system coins to take from the account [rad]

pullFunds

Pull stability fees from the treasury

The caller of this method needs to have enough allowance in order to pull funds

function pullFunds(address _dstAccount, uint256 _wad) external;

Parameters

NameTypeDescription
_dstAccountaddressAddress to transfer funds to
_waduint256Amount of system coins (SF) to transfer [wad]

transferSurplusFunds

Transfer surplus stability fees to the extraSurplusReceiver. This is here to make sure that the treasury doesn't accumulate fees that it doesn't even need in order to pay for allowances. It ensures that there are enough funds left in the treasury to account for posterior expenses

function transferSurplusFunds() external;

_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;

_validateParameters

Internal function to be overriden with custom logic to validate parameters

function _validateParameters() internal view override;