The purpose of this rule is to prevent a sudden increase or decrease in the supply of a token. This can help to prevent a sudden crash or spike in the price of a token due to sharp changes in the supply side, which could lead to severe damages to the health of the economy in the long run.
A token-max-supply-volatility rule is composed of 4 variables:
Max Change (uint16): the maximum percentage change allowed in the supply during a period of time (expressed in basis points).
Period (uint16): the amount of hours that defines a period.
Starting timestamp (uint64): the timestamp of the date when the rule starts the first period.
Total Supply (uint256): if not zero, this value will always be used as the token’s total supply for rule evaluation. This can be used when the amount of circulating supply is much smaller than the amount of the token totalSupply due to some tokens being locked in a dev account or a vesting contract, etc. Only use this value in such cases.
Copy
Ask AI
/// ******** Token Max Supply Volatility ******** struct TokenMaxSupplyVolatility { uint16 max; /// from 0000 to 10000 => 0.00% to 100.00%. uint16 period; // hours uint64 startTime; // UNIX date MUST be at a time with 0 minutes, 0 seconds. i.e: 20:00 on Jan 01 2024(basically 0-23) uint256 totalSupply; // If specified, this is the circulating supply value to use. If not specified, it defaults to token's totalSupply. }
The rule will be evaluated with the following logic:
The handler determines if the rule is active from the supplied action. If not, processing does not continue past this step.
The asset handler keeps track of the total supply per period, the net supply increase/decrease per period, and the date of the last mint/burn transaction.
The asset handler first checks if the transaction is a minting or burning operation. If it is, then it sends the aforementioned data to the rule processor with the rule Id, and the amount of tokens being minted/burned in the transaction.
The rule processor evaluates if the current transaction is in a new period or part of the same period as the last burning/minting transactions.
If it is a new period, the absolute net supply change for the period is equal to the amount of tokens minted/burned in current transaction. Also, the totalSupply for the current period is set to current value.
If it is not a new period, then the absolute net supply change for the period accumulates the amount of tokens minted/burned in current transaction. The totalSupply for the current period remains fixed to the value set in the first transaction of the period.
After current period’s net supply change and totalSupply have been defined, the rule processor calculates the change in supply. If the change is greater than the rule’s maximum, it reverts.
The list of available actions rules can be applied to can be found at ACTION_TYPES
This rule doesn’t apply when a treasuryAccount address is in either the from or the to side of the transaction. This doesn’t necessarily mean that if an treasury account is the one executing the transaction it will bypass the rule, unless the aforementioned condition is true.
_appManagerAddr (address): the address of the application manager to verify that the caller has rule administrator privileges.
_maxPercentage (uint16): Maximum percentage change of supply allowed expressed in basis points (1 -> 0.01%; 100 -> 1.0%).
_period (uint16): amount of hours that defines a period.
_startTime (uint64): Unix timestamp for the _periods to start counting.
_totalSupply (uint256): (optional) if not 0, then this is the value used for totalSupply instead of the live token’s totalSupply value at rule processing time.
Volume Total For Period (int256): the updated value for the total volume during the period.
Total Supply For Period (uint256): the updated value of the total supply for the period in the case of the first transaction in a period, or the fixed initial total supply for the period in the rest of the transactions.
This rule requires recording of the following information in the asset handler:
Volume Total For Period (int256): the updated value for the total volume during the period.
Total Supply For Period (uint256): the updated value of the total supply for the period in the case of the first transaction in a period, or the fixed initial total supply for the period in the rest of the transactions.
Last Supply Update Time (uint64): the Unix timestamp of the last update in the Total-Supply-For-Period variable