TaxCollector
Inherits: Authorizable, Modifiable, ModifiablePerCollateral, 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;
_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
Name | Type | Description |
---|---|---|
_taxCollectorParams | TaxCollectorParams | Tax collector parameters struct |
cParams
Getter for the collateral parameters struct
function cParams(bytes32 _cType) external view returns (TaxCollectorCollateralParams memory _taxCollectorCParams);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_taxCollectorCParams | TaxCollectorCollateralParams | Tax collector collateral parameters struct |
cData
Getter for the collateral data struct
function cData(bytes32 _cType) external view returns (TaxCollectorCollateralData memory _taxCollectorCData);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_taxCollectorCData | TaxCollectorCollateralData | Tax 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
_receiver | address | Tax receiver address to check |
Returns
Name | Type | Description |
---|---|---|
_secondaryTaxReceiver | TaxReceiver | Tax receiver struct |
constructor
constructor(address _safeEngine, TaxCollectorParams memory _taxCollectorParams) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address of the SAFEEngine contract |
_taxCollectorParams | TaxCollectorParams | Initial valid TaxCollector parameters struct |
collectedManyTax
Check if multiple collateral types are up to date with taxation
function collectedManyTax(uint256 _start, uint256 _end) public view returns (bool _ok);
Parameters
Name | Type | Description |
---|---|---|
_start | uint256 | Index of the first collateral type to check |
_end | uint256 | Index of the last collateral type to check |
Returns
Name | Type | Description |
---|---|---|
_ok | bool | Whether 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
Name | Type | Description |
---|---|---|
_start | uint256 | Index in collateralList from which to start looping and calculating the tax outcome |
_end | uint256 | Index in collateralList at which we stop looping and calculating the tax outcome |
Returns
Name | Type | Description |
---|---|---|
_ok | bool | Whether the tax outcome can be computed |
_rad | int256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to compute the taxation outcome for |
Returns
Name | Type | Description |
---|---|---|
_newlyAccumulatedRate | uint256 | The newly accumulated rate |
_deltaRate | int256 | The 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
Name | Type | Description |
---|---|---|
_receiver | address | Tax receiver address to check |
Returns
Name | Type | Description |
---|---|---|
_isSecondaryReceiver | bool | Whether the tax receiver for at least one collateral type |
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
Name | Type | Description |
---|---|---|
_secondaryReceiver | address | Secondary tax receiver address to check |
Returns
Name | Type | Description |
---|---|---|
_secondaryReceiverRevenueSourcesList | bytes32[] | 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
Name | Type | Description |
---|---|---|
_start | uint256 | Index in collateralList from which to start looping and calculating the tax outcome |
_end | uint256 | Index 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to tax |
Returns
Name | Type | Description |
---|---|---|
_latestAccumulatedRate | uint256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 identifier of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_nextStabilityFee | uint256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to distribute SF for |
_debtAmount | uint256 | Total debt currently issued for the collateral type |
_deltaRate | int256 | Difference 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to distribute SF for |
_receiver | address | Tax receiver address |
_debtAmount | uint256 | Total debt currently issued |
_deltaRate | int256 | Difference between the latest and the last accumulated rates for the collateralType |
_initializeCollateralType
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
function _initializeCollateralType(bytes32 _cType, bytes memory _collateralParams) internal override;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to register |
_collateralParams | bytes | Collateral parameters |
_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;
_modifyParameters
Set a new value for a collateral specific parameter
function _modifyParameters(bytes32 _cType, bytes32 _param, bytes memory _data) internal override;
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | String identifier of the collateral to modify |
_param | bytes32 | String identifier of the parameter to modify |
_data | bytes | Encoded data to modify the parameter |
_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
Name | Type | Description |
---|---|---|
_primaryTaxReceiver | address | Address 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type that will give SF to the tax receiver |
_data | TaxReceiver | Encoded data containing the receiver, tax percentage, and whether it supports negative tax |