Git Source

Author: @ShaneDuncan602 @oscarsernarosero @TJ-Everett

the light version of the Rule Processor for an efficient import into the other contracts for calls to the checkAllRules function. This is only used internally by the protocol.

Functions

checkAccountMinMaxTokenBalance

Check the AccountMinMaxTokenBalance rule. This rule ensures that both the to and from accounts do not exceed the max balance or go below the min balance.

function checkAccountMinMaxTokenBalance(
    uint32 ruleId,
    uint256 balanceFrom,
    uint256 balanceTo,
    uint256 amount,
    bytes32[] calldata toTags,
    bytes32[] calldata fromTags
) external view;

Parameters

NameTypeDescription
ruleIduint32Uint value of the ruleId storage pointer for applicable rule.
balanceFromuint256Token balance of the sender address
balanceTouint256Token balance of the recipient address
amountuint256total number of tokens to be transferred
toTagsbytes32[]tags applied via App Manager to recipient address
fromTagsbytes32[]tags applied via App Manager to sender address

checkAccountMinTokenBalance

Check the AccountMinTokenBalance half of the AccountMinMaxTokenBalance rule. This rule ensures that the from account does not exceed the min balance.

function checkAccountMinTokenBalance(uint256 balanceFrom, bytes32[] memory fromTags, uint256 amount, uint32 ruleId)
    external
    view;

Parameters

NameTypeDescription
balanceFromuint256Token balance of the sender address
fromTagsbytes32[]tags applied via App Manager to sender address
amountuint256total number of tokens to be transferred
ruleIduint32Uint value of the ruleId storage pointer for applicable rule.

checkAccountMaxTokenBalance

Check the AccountMaxTokenBalance half of the AccountMinMaxTokenBalance rule. This rule ensures that the to account does not exceed the max balance.

function checkAccountMaxTokenBalance(uint256 balanceTo, bytes32[] memory toTags, uint256 amount, uint32 ruleId)
    external
    view;

Parameters

NameTypeDescription
balanceTouint256Token balance of the recipient address
toTagsbytes32[]tags applied via App Manager to recipient address
amountuint256total number of tokens to be transferred
ruleIduint32Uint value of the ruleId storage pointer for applicable rule.

checkTokenMinTxSize

Check the TokenMinTxSize rule. This rule ensures accounts cannot transfer less than the specified amount.

function checkTokenMinTxSize(uint32 ruleId, uint256 amount) external view;

Parameters

NameTypeDescription
ruleIduint32Uint value of the ruleId storage pointer for applicable rule.
amountuint256total number of tokens to be transferred

checkMinMaxAccountBalanceERC721

Check the MinMaxAccountBalanceERC721 rule. This rule ensures accounts cannot exceed or drop below specified account balances via account tags.

function checkMinMaxAccountBalanceERC721(
    uint32 ruleId,
    uint256 balanceFrom,
    uint256 balanceTo,
    bytes32[] memory toTags,
    bytes32[] memory fromTags
) external view;

Parameters

NameTypeDescription
ruleIduint32Uint value of the ruleId storage pointer for applicable rule.
balanceFromuint256Token balance of the sender address
balanceTouint256Token balance of the recipient address
toTagsbytes32[]tags applied via App Manager to recipient address
fromTagsbytes32[]tags applied via App Manager to sender address

checkAccountApproveDenyOracles

This function receives an array of rule ids, which it uses to get the oracle details, then calls the oracle to determine permissions.

function checkAccountApproveDenyOracles(Rule[] memory _rules, address _address) external view;

Parameters

NameTypeDescription
_rulesRule[]Rule Id Array
_addressaddressuser address to be checked

checkBalanceByAccessLevelPasses

Check if transaction passes Balance by AccessLevel rule.

function checkBalanceByAccessLevelPasses(
    uint32 _ruleId,
    uint8 _accessLevel,
    uint256 _balance,
    uint256 _amountToTransfer
) external view;

Parameters

NameTypeDescription
_ruleIduint32Rule Identifier for rule arguments
_accessLeveluint8the Access Level of the account
_balanceuint256account’s beginning balance
_amountToTransferuint256total number of tokens to be transferred

checkAccountMaxTradeSize

If the rule applies to all users, it checks blank tag only. Otherwise loop through tags and check for specific application. This was done in a minimal way to allow for modifications later while not duplicating rule check logic.

Rule checks if recipient balance + amount exceeded max amount for that action type during rule period, prevent transactions for that action for freeze period

function checkAccountMaxTradeSize(
    uint32 ruleId,
    uint256 transactedInPeriod,
    uint256 amount,
    bytes32[] memory toTags,
    uint64 lastTransactionTime
) external view returns (uint256);

Parameters

NameTypeDescription
ruleIduint32Rule identifier for rule arguments
transactedInPerioduint256Number of tokens transacted during Period
amountuint256Number of tokens to be transferred
toTagsbytes32[]Account tags applied to sender via App Manager
lastTransactionTimeuint64block.timestamp of most recent transaction transaction from sender for action type.

Returns

NameTypeDescription
<none>uint256cumulativeTotal total amount of tokens bought or sold within Trade period.

checkAccountMinMaxTokenBalanceAMM

Check the minimum/maximum rule through the AMM Swap

function checkAccountMinMaxTokenBalanceAMM(
    uint32 ruleIdToken0,
    uint32 ruleIdToken1,
    uint256 tokenBalance0,
    uint256 tokenBalance1,
    uint256 amountIn,
    uint256 amountOut,
    bytes32[] calldata fromTags
) external view;

Parameters

NameTypeDescription
ruleIdToken0uint32Uint value of the ruleId storage pointer for applicable rule.
ruleIdToken1uint32Uint value of the ruleId storage pointer for applicable rule.
tokenBalance0uint256Token balance of the token being swapped
tokenBalance1uint256Token balance of the received token
amountInuint256total number of tokens to be swapped
amountOutuint256total number of tokens to be received
fromTagsbytes32[]tags applied via App Manager to sender address

checkTokenMaxDailyTrades

This function receives a rule id, which it uses to get the TokenMaxDailyTrades rule to check if the transfer is valid.

function checkTokenMaxDailyTrades(
    uint32 ruleId,
    uint256 transfersWithinPeriod,
    bytes32[] calldata nftTags,
    uint64 lastTransferTime
) external view returns (uint256);

Parameters

NameTypeDescription
ruleIduint32Rule identifier for rule arguments
transfersWithinPerioduint256Number of transfers within the time period
nftTagsbytes32[]NFT tags applied
lastTransferTimeuint64block.timestamp of most recent transaction from sender.

assessAMMFee

Assess the fee associated with the AMM Fee Rule

function assessAMMFee(uint32 _ruleId, uint256 _collateralizedTokenAmount) external view returns (uint256);

Parameters

NameTypeDescription
_ruleIduint32Rule Identifier for rule arguments
_collateralizedTokenAmountuint256total number of collateralized tokens to be swapped(this could be the “token in” or “token out” as the fees are always * assessed from the collateralized token)

checkAccountMaxValueByRiskScore

--------------------------- APPLICATION LEVEL --------------------------------

This function checks if the requested action is valid according to the AccountMaxValueByRiskScore rule

function checkAccountMaxValueByRiskScore(
    uint32 _ruleId,
    address _toAddress,
    uint8 _riskScoreTo,
    uint128 _totalValueTo,
    uint128 _amountToTransfer
) external view;

Parameters

NameTypeDescription
_ruleIduint32Rule Identifier
_toAddressaddressAddress of the recipient
_riskScoreTouint8the Risk Score of the recepient account
_totalValueTouint128recepient account’s beginning balance in USD with 18 decimals of precision
_amountToTransferuint128total dollar amount to be transferred in USD with 18 decimals of precision

checkAccountMaxValueByAccessLevel

This function checks if the requested action is valid according to the AccountMaxValueByAccessLevel rule

function checkAccountMaxValueByAccessLevel(
    uint32 _ruleId,
    uint8 _accessLevelTo,
    uint128 _totalValueTo,
    uint128 _amountToTransfer
) external view;

Parameters

NameTypeDescription
_ruleIduint32Rule Identifier
_accessLevelTouint8the Access Level of the recepient account
_totalValueTouint128recepient account’s beginning balance in USD with 18 decimals of precision
_amountToTransferuint128total dollar amount to be transferred in USD with 18 decimals of precision

checkAccountMaxTxValueByRiskScore

that these ranges are set by ranges.

Rule that checks if the tx exceeds the limit size in USD for a specific risk profile within a specified period of time.

this check will cause a revert if the new value of _valueTransactedInPeriod in USD exceeds the limit for the address risk profile.

function checkAccountMaxTxValueByRiskScore(
    uint32 ruleId,
    uint128 _valueTransactedInPeriod,
    uint128 amount,
    uint64 lastTxDate,
    uint8 riskScore
) external view returns (uint128);

Parameters

NameTypeDescription
ruleIduint32to check against.
_valueTransactedInPerioduint128the cumulative amount of tokens recorded in the last period.
amountuint128in USD of the current transaction with 18 decimals of precision.
lastTxDateuint64timestamp of the last transfer of this token by this address.
riskScoreuint8of the address (0 -> 100)

Returns

NameTypeDescription
<none>uint128updated value for the _valueTransactedInPeriod. If _valueTransactedInPeriod are inside the current period, then this value is accumulated. If not, it is reset to current amount.

checkTokenMaxBuySellVolume

Function receives a rule id, retrieves the rule data and checks if the Token Max Buy Sell Volume Rule passes

function checkTokenMaxBuySellVolume(
    uint32 ruleId,
    uint256 currentTotalSupply,
    uint256 amountToTransfer,
    uint64 lastTransactionTime,
    uint256 totalWithinPeriod
) external view returns (uint256);

Parameters

NameTypeDescription
ruleIduint32id of the rule to be checked
currentTotalSupplyuint256total supply value passed in by the handler. This is for ERC20 tokens with a fixed total supply.
amountToTransferuint256total number of tokens to be transferred in transaction.
lastTransactionTimeuint64time of the most recent purchase from AMM. This starts the check if current transaction is within a purchase window.
totalWithinPerioduint256total amount of tokens sold within current period

checkAccountDenyForNoAccessLevel

Ensure that AccountDenyForNoAccessLevel passes.

function checkAccountDenyForNoAccessLevel(uint8 _accessLevel) external view;

Parameters

NameTypeDescription
_accessLeveluint8account access level

checkAccountMaxValueOutByAccessLevel

that these ranges are set by ranges.

Rule that checks if the value out exceeds the limit size in USD for a specific access level

function checkAccountMaxValueOutByAccessLevel(
    uint32 _ruleId,
    uint8 _accessLevel,
    uint128 _withdrawal,
    uint128 _amountToTransfer
) external view returns (uint128);

Parameters

NameTypeDescription
_ruleIduint32to check against.
_accessLeveluint8access level of the sending account
_withdrawaluint128the amount, in USD, of previously withdrawn assets
_amountToTransferuint128total value of the transfer

Returns

NameTypeDescription
<none>uint128Sending account’s new total withdrawn.

checkPauseRules

This function checks if the requested action is valid according to pause rules.

function checkPauseRules(address _dataServer) external view;

Parameters

NameTypeDescription
_dataServeraddressaddress of the Application Rule Processor Diamond contract

checkTokenMaxTradingVolume

Rule checks if the token max trading volume rule will be violated.

function checkTokenMaxTradingVolume(
    uint32 _ruleId,
    uint256 _volume,
    uint256 _supply,
    uint256 _amount,
    uint64 _lastTransferTime
) external view returns (uint256);

Parameters

NameTypeDescription
_ruleIduint32Rule identifier for rule arguments
_volumeuint256token’s trading volume thus far
_supplyuint256Number of tokens in supply
_amountuint256Number of tokens to be transferred from this account
_lastTransferTimeuint64the time of the last transfer

Returns

NameTypeDescription
<none>uint256volumeTotal new accumulated volume

checkTokenMaxSupplyVolatility

Rule checks if the tokenMaxSupplyVolatility rule will be violated.

function checkTokenMaxSupplyVolatility(
    uint32 _ruleId,
    int256 _volumeTotalForPeriod,
    uint256 _totalSupplyForPeriod,
    uint256 _supply,
    int256 _amount,
    uint64 _lastSupplyUpdateTime
) external view returns (int256, uint256);

Parameters

NameTypeDescription
_ruleIduint32Rule identifier for rule arguments
_volumeTotalForPeriodint256token’s increase/decreased volume total in period
_totalSupplyForPerioduint256token total supply updated at begining of period
_supplyuint256Number of tokens in supply
_amountint256Number of tokens to be minted/burned
_lastSupplyUpdateTimeuint64the time of the last transfer

Returns

NameTypeDescription
<none>int256volumeTotal new accumulated volume
<none>uint256

checkTokenMinHoldTime

This function receives data needed to check Minimum hold time rule. This a simple rule and thus is not stored in the rule storage diamond.

function checkTokenMinHoldTime(uint32 _holdHours, uint256 _ownershipTs) external view;

Parameters

NameTypeDescription
_holdHoursuint32minimum number of hours the asset must be held
_ownershipTsuint256beginning of hold period

validateAMMFee

Validate the existence of the rule

function validateAMMFee(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTransactionLimitByRiskScore

Validate the existence of the rule

function validateTransactionLimitByRiskScore(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMinMaxTokenBalanceERC721

Validate the existence of the rule

function validateAccountMinMaxTokenBalanceERC721(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMaxDailyTrades

Validate the existence of the rule

function validateTokenMaxDailyTrades(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMinMaxTokenBalance

Validate the existence of the rule

function validateAccountMinMaxTokenBalance(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMaxTradeSize

Validate the existence of the rule

function validateAccountMaxTradeSize(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMinTxSize

Validate the existence of the rule

function validateTokenMinTxSize(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountApproveDenyOracle

Validate the existence of the rule

function validateAccountApproveDenyOracle(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMaxBuySellVolume

Validate the existence of the rule

function validateTokenMaxBuySellVolume(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMaxTradingVolume

Validate the existence of the rule

function validateTokenMaxTradingVolume(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMaxSupplyVolatility

Validate the existence of the rule

function validateTokenMaxSupplyVolatility(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMaxValueByRiskScore

Validate the existence of the rule

function validateAccountMaxValueByRiskScore(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMaxTxValueByRiskScore

Validate the existence of the rule

function validateAccountMaxTxValueByRiskScore(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validatePause

Validate the existence of the rule

function validatePause(uint8[] memory _actions, uint32 _ruleId, address _dataServer) external view;

Parameters

NameTypeDescription
_actionsuint8[]
_ruleIduint32Rule Identifier
_dataServeraddressaddress of the appManager contract

validateAccountMaxValueByAccessLevel

Validate the existence of the rule

function validateAccountMaxValueByAccessLevel(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateAccountMaxValueOutByAccessLevel

Validate the existence of the rule

function validateAccountMaxValueOutByAccessLevel(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier

validateTokenMinHoldTime

Validate the existence of the rule

function validateTokenMinHoldTime(ActionTypes[] memory _actions, uint32 _ruleId) external view;

Parameters

NameTypeDescription
_actionsActionTypes[]
_ruleIduint32Rule Identifier