Protocol Rule Processor Diamond Libraries
Purpose
The Rule Processor Diamond Libraries store functions used by the diamond structure. The Rule Processor Diamond Lib contract holds the function to store rules when added to the protocol, the diamond cut function for upgrading the diamond and adding or removing functions from facets. The Rule Processor Common Lib holds functions used throughout the facets to validate rules and parameters passed to the rule check functions.
Using these singular library contracts prevents data storage collision as functionality is added or removed from the protocol. Facets should always be removed through the diamond cut function in Rule Processor Diamond Lib.This prevents a situation where a facet may have been self destructed but the function selectors are still stored in the diamond. This could result in a “false posistive” successful transaction when attempting to add a rule and the rule is never added to the diamond. Protocol Rule Processor facets are never written with self destruct functionality.
Functions
Rule Processor Diamond Lib Functions
The Rule Processor Diamond Lib follows ERC 2535 standards for storage and functions.
ERC 2535: Diamond Proxies
Rule Processor Common Lib Functions
The Rule Processor Common Lib holds the following validation functions:
Timestamp validation:
Rule existence validation:
Is the rule active validation:
Is the rule within the rule period validation:
Max tag limit validation:
Is the rule applicable to all users validation:
Retrieve the max size for the risk score provided:
Tag validation:
These validation functions are utilized throughout the diamond facets in order to validate rules when added or checked via the check all rules function.
Data Structures
The Rule Processor Diamond Lib stores the rules, the facet addresses and their function selectors.
The facet addresses and selectors are stored in the struct:
Those structs are then stored in a mapping:
Rules are stored in the struct:
Events
- event DiamondCut(_diamondCut, init, data):
- Emitted when: the Rule Processor Diamond has been upgraded.
- Parameters:
- _diamondCut: Facets Array
- init: Address of the contract or facet to execute “data”
- data: A function call, including function selector and arguments calldata is executed with delegatecall on “init”