TaxCollector

Git Source

Inherits: Authorizable, Modifiable, ITaxCollector

This contract calculates and collects the stability fee from all collateral types

State Variables

safeEngine

Address of the SAFEEngine contract

ISAFEEngine public safeEngine;

_params

Getter for the unpacked contract parameters struct

TaxCollectorParams public _params;

_cParams

Getter for the unpacked collateral parameters struct

mapping(bytes32 _cType => TaxCollectorCollateralParams) public _cParams;

_cData

Getter for the unpacked collateral data struct

mapping(bytes32 _cType => TaxCollectorCollateralData) public _cData;

_secondaryReceiverRevenueSources

List of collateral types that send SF to a specific tax receiver

mapping(address _taxReceiver => EnumerableSet.Bytes32Set) internal _secondaryReceiverRevenueSources;

_secondaryTaxReceivers

Getter for the unpacked data about a specific secondary tax receiver

mapping(bytes32 _cType => mapping(address _taxReceiver => TaxReceiver)) public _secondaryTaxReceivers;

_collateralList

Enumerable set with the initialized collateral types

EnumerableSet.Bytes32Set internal _collateralList;

_secondaryReceivers

Enumerable set with the active secondary tax receivers

EnumerableSet.AddressSet internal _secondaryReceivers;

Functions

params

Getter for the contract parameters struct

function params() external view returns (TaxCollectorParams memory _taxCollectorParams);

Returns

NameTypeDescription
_taxCollectorParamsTaxCollectorParamsTax collector parameters struct

cParams

Getter for the collateral parameters struct

function cParams(bytes32 _cType) external view returns (TaxCollectorCollateralParams memory _taxCollectorCParams);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

Returns

NameTypeDescription
_taxCollectorCParamsTaxCollectorCollateralParamsTax collector collateral parameters struct

cData

Getter for the collateral data struct

function cData(bytes32 _cType) external view returns (TaxCollectorCollateralData memory _taxCollectorCData);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

Returns

NameTypeDescription
_taxCollectorCDataTaxCollectorCollateralDataTax collector collateral data struct

secondaryTaxReceivers

Getter for the data about a specific secondary tax receiver

function secondaryTaxReceivers(
  bytes32 _cType,
  address _receiver
) external view returns (TaxReceiver memory _secondaryTaxReceiver);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type
_receiveraddressTax receiver address to check

Returns

NameTypeDescription
_secondaryTaxReceiverTaxReceiverTax receiver struct

constructor

constructor(address _safeEngine, TaxCollectorParams memory _taxCollectorParams) Authorizable(msg.sender) validParams;

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine contract
_taxCollectorParamsTaxCollectorParamsInitial valid TaxCollector parameters struct

initializeCollateralType

Initialize a brand new collateral type

function initializeCollateralType(
  bytes32 _cType,
  TaxCollectorCollateralParams memory _taxCollectorCParams
) external isAuthorized validCParams(_cType);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type
_taxCollectorCParamsTaxCollectorCollateralParams

collectedManyTax

Check if multiple collateral types are up to date with taxation

function collectedManyTax(uint256 _start, uint256 _end) public view returns (bool _ok);

Parameters

NameTypeDescription
_startuint256Index of the first collateral type to check
_enduint256Index of the last collateral type to check

Returns

NameTypeDescription
_okboolWhether all collateral types are up to date

taxManyOutcome

Check how much SF will be charged (to collateral types between indexes 'start' and 'end' in the collateralList) during the next taxation

function taxManyOutcome(uint256 _start, uint256 _end) public view returns (bool _ok, int256 _rad);

Parameters

NameTypeDescription
_startuint256Index in collateralList from which to start looping and calculating the tax outcome
_enduint256Index in collateralList at which we stop looping and calculating the tax outcome

Returns

NameTypeDescription
_okboolWhether the tax outcome can be computed
_radint256The total amount of SF that will be charged during the next taxation

taxSingleOutcome

Get how much SF will be distributed after taxing a specific collateral type

function taxSingleOutcome(bytes32 _cType) public view returns (uint256 _newlyAccumulatedRate, int256 _deltaRate);

Parameters

NameTypeDescription
_cTypebytes32Collateral type to compute the taxation outcome for

Returns

NameTypeDescription
_newlyAccumulatedRateuint256The newly accumulated rate
_deltaRateint256The delta between the new and the last accumulated rates

secondaryReceiversListLength

Get the secondary tax receiver list length

function secondaryReceiversListLength() public view returns (uint256 _secondaryReceiversListLength);

collateralListLength

Get the collateralList length

function collateralListLength() public view returns (uint256 _collateralListLength);

isSecondaryReceiver

Check if a tax receiver is at a certain position in the list

function isSecondaryReceiver(address _receiver) public view returns (bool _isSecondaryReceiver);

Parameters

NameTypeDescription
_receiveraddressTax receiver address to check

Returns

NameTypeDescription
_isSecondaryReceiverboolWhether the tax receiver for at least one collateral type

collateralList

Get the list of all initialized collateral types

function collateralList() external view returns (bytes32[] memory __collateralList);

secondaryReceiversList

Get the list of all secondary tax receivers

function secondaryReceiversList() external view returns (address[] memory _secondaryReceiversList);

secondaryReceiverRevenueSourcesList

Get the list of all collateral types for which a specific address is a secondary tax receiver

function secondaryReceiverRevenueSourcesList(address _secondaryReceiver)
  external
  view
  returns (bytes32[] memory _secondaryReceiverRevenueSourcesList);

Parameters

NameTypeDescription
_secondaryReceiveraddressSecondary tax receiver address to check

Returns

NameTypeDescription
_secondaryReceiverRevenueSourcesListbytes32[]List of collateral types for which the address is a secondary tax receiver

taxMany

Collect tax from multiple collateral types at once

function taxMany(uint256 _start, uint256 _end) external;

Parameters

NameTypeDescription
_startuint256Index in collateralList from which to start looping and calculating the tax outcome
_enduint256Index in collateralList at which we stop looping and calculating the tax outcome

taxSingle

Collect tax from a single collateral type

function taxSingle(bytes32 _cType) public returns (uint256 _latestAccumulatedRate);

Parameters

NameTypeDescription
_cTypebytes32Collateral type to tax

Returns

NameTypeDescription
_latestAccumulatedRateuint256The newly accumulated rate after taxation

_getNextStabilityFee

Compute the next stability fee for a collateral type, bounded by the maxStabilityFeeRange

The stability fee calculation is bounded by the maxStabilityFeeRange

function _getNextStabilityFee(bytes32 _cType) internal view returns (uint256 _nextStabilityFee);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 identifier of the collateral type

Returns

NameTypeDescription
_nextStabilityFeeuint256The next stability fee to be applied for the collateral type

_splitTaxIncome

Split SF between all tax receivers

function _splitTaxIncome(bytes32 _cType, uint256 _debtAmount, int256 _deltaRate) internal;

Parameters

NameTypeDescription
_cTypebytes32Collateral type to distribute SF for
_debtAmountuint256Total debt currently issued for the collateral type
_deltaRateint256Difference between the last and the latest accumulate rates for the collateralType

_distributeTax

Give/withdraw SF from a tax receiver

function _distributeTax(bytes32 _cType, address _receiver, uint256 _debtAmount, int256 _deltaRate) internal;

Parameters

NameTypeDescription
_cTypebytes32Collateral type to distribute SF for
_receiveraddressTax receiver address
_debtAmountuint256Total debt currently issued
_deltaRateint256Difference between the latest and the last accumulated rates for the collateralType

_modifyParameters

If SF is negative and a tax receiver doesn't have enough coins to absorb the loss, compute a new tax cut that can be absorbed If the tax receiver's tax cut is not null and if the receiver accepts negative SF offer/take SF to/from them

This function is set to revert if not overriden

function _modifyParameters(bytes32 _param, bytes memory _data) internal override;

_modifyParameters

Internal function to be overriden with custom logic to modify parameters

This function is set to revert if not overriden

function _modifyParameters(bytes32 _cType, bytes32 _param, bytes memory _data) internal override;

_validateParameters

Internal function to be overriden with custom logic to validate parameters

function _validateParameters() internal view override;

_validateCParameters

Internal function to be overriden with custom logic to validate collateral parameters

function _validateCParameters(bytes32 _cType) internal view override;

_setPrimaryTaxReceiver

Sets the primary tax receiver, the address that receives the unallocated SF from all collateral types

function _setPrimaryTaxReceiver(address _primaryTaxReceiver) internal;

Parameters

NameTypeDescription
_primaryTaxReceiveraddressAddress of the primary tax receiver

_setSecondaryTaxReceiver

Add a new secondary tax receiver or update data (add a new SF source or modify % of SF taken from a collateral type)

function _setSecondaryTaxReceiver(bytes32 _cType, TaxReceiver memory _data) internal;

Parameters

NameTypeDescription
_cTypebytes32Collateral type that will give SF to the tax receiver
_dataTaxReceiverEncoded data containing the receiver, tax percentage, and whether it supports negative tax