Git Source Author: @ShaneDuncan602 @oscarsernarosero @TJ-Everett Stores common functions used throughout the protocol rule checks

State Variables

MAX_TAGS

uint8 constant MAX_TAGS = 10;

Functions

validateTimestamp

Validate a user entered timestamp to ensure that it is valid. Validity depends on it being greater than UNIX epoch and not more than 1 year into the future. It reverts with custom error if invalid
function validateTimestamp(uint64 _startTime) internal view;

checkRuleExistence

Generic function to check the existence of a rule
function checkRuleExistence(uint32 _ruleIndex, uint32 _ruleTotal) internal pure;
Parameters
NameTypeDescription
_ruleIndexuint32index of the current rule
_ruleTotaluint32total rules in existence for the rule type

isRuleActive

Determine is the rule is active. This is only for use in rules that are stored with activation timestamps.
function isRuleActive(uint64 _startTime) internal view returns (bool);

isWithinPeriod

Determine if transaction should be accumulated with the previous or it is a new period which requires reset of accumulators
function isWithinPeriod(uint64 _startTime, uint32 _period, uint64 _lastTransferTime) internal view returns (bool);
Parameters
NameTypeDescription
_startTimeuint64the timestamp the rule was enabled
_perioduint32amount of hours in the rule period
_lastTransferTimeuint64the last transfer timestamp
Returns
NameTypeDescription
<none>bool_withinPeriod returns true if current block time is within the rules period, else false.

checkMaxTags

if no transactions have happened in the past, it’s new current timestamp subtracted by the remainder of seconds since the rule was active divided by period in seconds Determine if the max tag number is reached
function checkMaxTags(bytes32[] memory _tags) internal pure;
Parameters
NameTypeDescription
_tagsbytes32[]tags associated with the rule

isApplicableToAllUsers

Determine if the rule applies to all users
function isApplicableToAllUsers(bytes32[] memory _tags) internal pure returns (bool _isAll);
Parameters
NameTypeDescription
_tagsbytes32[]the timestamp the rule was enabled

retrieveRiskScoreMaxSize

Retrieve the max size of the risk rule for the risk score provided.
function retrieveRiskScoreMaxSize(uint8 _riskScore, uint8[] memory _riskScores, uint48[] memory _maxValues)
    internal
    pure
    returns (uint256);
Parameters
NameTypeDescription
_riskScoreuint8risk score of the account
_riskScoresuint8[]array of risk scores for the rule
_maxValuesuint48[]array of max values from the rule
Returns
NameTypeDescription
<none>uint256maxValue uint256 max value for the risk score for rule validation

validateTags

validate tags to ensure only a blank or valid tags were submitted.
function validateTags(bytes32[] calldata _accountTags) internal pure;
Parameters
NameTypeDescription
_accountTagsbytes32[]the timestamp the rule was enabled

calculateVolatility

If more than one tag, none can be blank. Perform the common volatility function
function calculateVolatility(int256 _volumeTotalForPeriod, uint256 _volumeMultiplier, uint256 _totalSupply)
    internal
    pure
    returns (int256 _volatility);
Parameters
NameTypeDescription
_volumeTotalForPeriodint256total volume within the period
_volumeMultiplieruint256volume muliplier
_totalSupplyuint256token total supply
Returns
NameTypeDescription
_volatilityint256calculated volatility

Errors

InvalidTimestamp

error InvalidTimestamp(uint64 _timestamp);

MaxTagLimitReached

error MaxTagLimitReached();

RuleDoesNotExist

error RuleDoesNotExist();

TagListMustBeSingleBlankOrValueList

error TagListMustBeSingleBlankOrValueList();