Git Source Inherits: FacetCommonImports Author: @mpetersoCode55, @ShaneDuncan602, @TJ-Everett, @VoR0220 This contract is a critical component of the Rules Engine, enabling secure and flexible policy management. This contract serves as the primary data facet for the Rules Engine rules. It is responsible for creating, updating, retrieving, and managing rules. It enforces role-based access control and ensures that only authorized users can modify or retrieve data. The contract also supports policy cementing to prevent further modifications.

Functions

createRule

Creates a rule in storage. Adds a new rule to the specified policy. Only accessible by policy admins.
function createRule(uint256 policyId, Rule calldata rule)
    external
    policyAdminOnly(policyId, msg.sender)
    returns (uint256);
Parameters
NameTypeDescription
policyIduint256ID of the policy the rule will be added to.
ruleRuleThe rule to create.
Returns
NameTypeDescription
<none>uint256ruleId The generated rule ID.

updateRule

Updates a rule in storage. Modifies an existing rule in the specified policy. Only accessible by policy admins.
function updateRule(uint256 policyId, uint256 ruleId, Rule calldata rule)
    external
    policyAdminOnly(policyId, msg.sender)
    returns (uint256);
Parameters
NameTypeDescription
policyIduint256ID of the policy the rule belongs to.
ruleIduint256The ID of the rule to update.
ruleRuleThe updated rule data.
Returns
NameTypeDescription
<none>uint256ruleId The updated rule ID.

getAllRules

Retrieves all rules associated with a specific policy.
function getAllRules(uint256 policyId) external view returns (Rule[][] memory);
Parameters
NameTypeDescription
policyIduint256The ID of the policy.
Returns
NameTypeDescription
<none>Rule[][]rules A two-dimensional array of rules grouped by calling functions.

deleteRule

Deletes a rule from storage.
function deleteRule(uint256 policyId, uint256 ruleId) public policyAdminOnly(policyId, msg.sender);
Parameters
NameTypeDescription
policyIduint256The ID of the policy the rule belongs to.
ruleIduint256The ID of the rule to delete.

getRule

Retrieves a rule from storage.
function getRule(uint256 policyId, uint256 ruleId) public view returns (RuleStorageSet memory);
Parameters
NameTypeDescription
policyIduint256The ID of the policy the rule belongs to.
ruleIduint256The ID of the rule to retrieve.
Returns
NameTypeDescription
<none>RuleStorageSetruleStorageSets The rule data.

_storeRule

Stores a rule in storage. Validates the policy existence before storing the rule.
function _storeRule(RuleStorage storage _data, uint256 _policyId, uint256 _ruleId, Rule calldata _rule)
    internal
    returns (uint256);
Parameters
NameTypeDescription
_dataRuleStorageThe rule storage structure.
_policyIduint256The ID of the policy the rule belongs to.
_ruleIduint256The ID of the rule to store.
_ruleRuleThe rule to store.
Returns
NameTypeDescription
<none>uint256ruleId The stored rule ID.