Git Source

Inherits: IRuleProcessorErrors, IInputErrors, ITagRuleErrors, IMaxTagLimitError

Author: @ShaneDuncan602 @oscarsernarosero @TJ-Everett

Implements Token Rules on Tagged Accounts.

Contract implements rules to be checked by Handler.

State Variables

BLANK_TAG

bytes32 constant BLANK_TAG = bytes32("");

Functions

checkAccountMinMaxTokenBalance

Check the min/max token balance 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[] 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
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

checkAccountMinMaxTokenBalanceAMM

Check the min/max token balance rule through the AMM Swap

function checkAccountMinMaxTokenBalanceAMM(
    uint32 ruleIdToken0,
    uint32 ruleIdToken1,
    uint256 tokenBalance0,
    uint256 tokenBalance1,
    uint256 amountIn,
    uint256 amountOut,
    bytes32[] calldata fromTags
) public 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

checkAccountMaxTokenBalance

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.

Check if tagged account passes AccountMaxTokenBalance rule

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

Parameters

NameTypeDescription
balanceTouint256Number of tokens held by recipient address
toTagsbytes32[]Account tags applied to recipient via App Manager
amountuint256Number of tokens to be transferred
ruleIduint32Rule identifier for rule arguments

checkAccountMinTokenBalance

check if period is 0, 0 means a period hasn’t been applied to this rule if a max is 0 it means it is an empty-rule/no-rule. a max should be greater than 0

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.

Check if tagged account passes AccountMinTokenBalance rule

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

Parameters

NameTypeDescription
balanceFromuint256Number of tokens held by sender address
fromTagsbytes32[]Account tags applied to sender via App Manager
amountuint256Number of tokens to be transferred
ruleIduint32Rule identifier for rule arguments

getAccountMinMaxTokenBalanceStart

check if period is 0, 0 means a period hasn’t been applied to this rule Check to see if still in the hold period If the transaction will violate the rule, then revert if a min is 0 it means it is an empty-rule/no-rule. a min should be greater than 0

Function get the min/max rule start timestamp

function getAccountMinMaxTokenBalanceStart(uint32 _index) public view returns (uint64 startTime);

Parameters

NameTypeDescription
_indexuint32position of rule in array

Returns

NameTypeDescription
startTimeuint64rule start time

getAccountMinMaxTokenBalance

Function get the accountMinMaxTokenBalance Rule in the rule set that belongs to an account type

function getAccountMinMaxTokenBalance(uint32 _index, bytes32 _accountType)
    public
    view
    returns (TaggedRules.AccountMinMaxTokenBalance memory);

Parameters

NameTypeDescription
_indexuint32position of rule in array
_accountTypebytes32Type of Accounts

Returns

NameTypeDescription
<none>TaggedRules.AccountMinMaxTokenBalanceaccountMinMaxTokenBalance Rule at index location in array

getTotalAccountMinMaxTokenBalances

Function gets total AccountMinMaxTokenBalances rules

function getTotalAccountMinMaxTokenBalances() public view returns (uint32);

Returns

NameTypeDescription
<none>uint32Total length of array

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.

getAccountMaxTradeSize

Function get the account max Trade size rule in the rule set that belongs to an account type

function getAccountMaxTradeSize(uint32 _index, bytes32 _accountType)
    public
    view
    returns (TaggedRules.AccountMaxTradeSize memory);

Parameters

NameTypeDescription
_indexuint32position of rule in array
_accountTypebytes32Type of account

Returns

NameTypeDescription
<none>TaggedRules.AccountMaxTradeSizeAccountMaxTradeSize rule at index position

getAccountMaxTradeSizeStart

Function get the account max trade size rule start timestamp

function getAccountMaxTradeSizeStart(uint32 _index) public view returns (uint64 startTime);

Parameters

NameTypeDescription
_indexuint32position of rule in array

Returns

NameTypeDescription
startTimeuint64startTimestamp of rule at index position

getTotalAccountMaxTradeSize

Function to get total account max trade size rules

function getTotalAccountMaxTradeSize() public view returns (uint32);

Returns

NameTypeDescription
<none>uint32Total length of array