Token Min Tx Size
Purpose
The purpose of the token-min-tx-size rule is to prevent micro-trades or dust trades within an ecosystem. A developer can set the minimum number of tokens required per transfer to prevent these types of trades.
Scope
This rule works at a token level. It must be activated and configured for each desired token in the corresponding token handler.
Data Structure
A token-min-tx-size rule is composed of 1 component:
- minSize (uint256): minimum number of tokens that must be transferred for each transaction.
see RuleDataInterfaces
The token-min-tx-size rules are stored in a mapping indexed by ruleId(uint32) in order of creation:
see IRuleStorage
Configuration and Enabling/Disabling
- This rule can only be configured in the protocol by a rule administrator.
- This rule can only be set in the asset handler by a rule administrator.
- This rule can only be activated/deactivated in the asset handler by a rule administrator.
- This rule can only be updated in the asset handler by a rule administrator.
Rule Evaluation
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 processor receives the ID of the token-min-tx-size rule set in the token handler.
- The processor receives the
amount
of tokens from the handler. - The processor evaluates the
amount
against the ruleminSize
and reverts if theamount
less than the rule minimum. - If it’s a non-custodial style Buy
- When the Sell action is also active, checks steps 1-4 for from address.
- If it’s a non-custodial style Sell
- When the Buy action is also active, checks steps 1-4 for to address.
The list of available actions rules can be applied to can be found at ACTION_TYPES
see ERC20RuleProcessorFacet -> checkTokenMinTxSize
Evaluation Exceptions
- 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.
Revert Message
The rule processor will revert with the following error if the rule check fails:
The selector for this error is 0x7a78c901
.
Create Function
Adding a token-min-tx-size rule is done through the function:
see RuleDataFacet
The add function will return the protocol ID of the rule.
Parameters:
- _appManagerAddr (address): The address of the application manager to verify that the caller has Rule administrator privileges.
- _minSize (uint256): Minimum number of tokens for the transaction.
Parameter Optionality:
There is no parameter optionality for this rule.
Parameter Validation:
The following validation will be carried out by the add function in order to ensure that these parameters are valid and make sense:
_appManagerAddr
is not the zero address._minSize
is greater than 0.
see RuleDataFacet
Other Functions:
- In Protocol Rule Processor:
- Function to get a rule by its ID:
- Function to get current amount of rules in the protocol:
- Function to get a rule by its ID:
- In Protocol Rule Processor:
- Function that evaluates the rule:
- Function that evaluates the rule:
- in Asset Handler:
- Function to set and activate at the same time the rule for the supplied actions in an asset handler:
- Function to activate/deactivate the rule for the supplied actions actions in an asset handler:
- Function to know the activation state of the rule for the supplied action in an asset handler:
- Function to get the rule Id for the supplied action from an asset handler:
- Function to set and activate at the same time the rule for the supplied actions in an asset handler:
Return Data
This rule does not return any data.
Data Recorded
This rule does not require any data to be recorded.
Events
-
event AD1467_ProtocolRuleCreated(bytes32 indexed ruleType, uint32 indexed ruleId, bytes32[] extraTags):
- Emitted when: the rule has been created in the protocol.
- Parameters:
- ruleType: “TOKEN_MIN_TX_SIZE”.
- ruleId: the index of the rule created in the protocol by rule type.
- extraTags: an empty array.
-
event AD1467_ApplicationHandlerActionApplied(bytes32 indexed ruleType, ActionTypes action, uint32 indexed ruleId):
- Emitted when: rule has been applied in an asset handler.
- parameters:
- ruleType: “TOKEN_MIN_TX_SIZE”.
- action: the protocol action the rule is being applied to.
- ruleId: the index of the rule created in the protocol by rule type.
-
event AD1467_ApplicationHandlerActionActivated(bytes32 indexed ruleType, ActionTypes actions, uint256 indexed ruleId)
- Emitted when: A Token Min Transaction Size rule has been activated in an asset handler:
- Parameters:
- ruleType: “TOKEN_MIN_TX_SIZE”.
- actions: the protocol actions for which the rule is being activated.
- ruleId: a placeholder of 0 will be passed for ruleId
-
event AD1467_ApplicationHandlerActionDeactivated(bytes32 indexed ruleType, ActionTypes actions, uint256 indexed ruleId)
- Emitted when: A Token Min Transaction Size rule has been deactivated in an asset handler:
- Parameters:
- ruleType: “TOKEN_MIN_TX_SIZE”.
- actions: the protocol actions for which the rule is being deactivated.
- ruleId: a placeholder of 0 will be passed for ruleId
Dependencies
- This rule has no dependencies.