RuleProcessorCommonLib
Author: @ShaneDuncan602 @oscarsernarosero @TJ-Everett
Stores common functions used throughout the protocol rule checks
State Variables
MAX_TAGS
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
checkRuleExistence
Generic function to check the existence of a rule
Parameters
Name | Type | Description |
---|---|---|
_ruleIndex | uint32 | index of the current rule |
_ruleTotal | uint32 | total 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.
isWithinPeriod
Determine if transaction should be accumulated with the previous or it is a new period which requires reset of accumulators
Parameters
Name | Type | Description |
---|---|---|
_startTime | uint64 | the timestamp the rule was enabled |
_period | uint32 | amount of hours in the rule period |
_lastTransferTime | uint64 | the last transfer timestamp |
Returns
Name | Type | Description |
---|---|---|
<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
Parameters
Name | Type | Description |
---|---|---|
_tags | bytes32[] | tags associated with the rule |
isApplicableToAllUsers
Determine if the rule applies to all users
Parameters
Name | Type | Description |
---|---|---|
_tags | bytes32[] | the timestamp the rule was enabled |
retrieveRiskScoreMaxSize
Retrieve the max size of the risk rule for the risk score provided.
Parameters
Name | Type | Description |
---|---|---|
_riskScore | uint8 | risk score of the account |
_riskScores | uint8[] | array of risk scores for the rule |
_maxValues | uint48[] | array of max values from the rule |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | maxValue uint256 max value for the risk score for rule validation |
validateTags
validate tags to ensure only a blank or valid tags were submitted.
Parameters
Name | Type | Description |
---|---|---|
_accountTags | bytes32[] | the timestamp the rule was enabled |
calculateVolatility
If more than one tag, none can be blank.
Perform the common volatility function
Parameters
Name | Type | Description |
---|---|---|
_volumeTotalForPeriod | int256 | total volume within the period |
_volumeMultiplier | uint256 | volume muliplier |
_totalSupply | uint256 | token total supply |
Returns
Name | Type | Description |
---|---|---|
_volatility | int256 | calculated volatility |