RulesEngineComponentFacet
Inherits: FacetCommonImports
Author: @mpetersoCode55, @ShaneDuncan602, @TJ-Everett, @VoR0220
This contract is a critical component of the Rules Engine, enabling secure and flexible data management.
This contract serves as the data facet for the Rules Engine subcomponents. It provides functionality for managing foreign calls, trackers, calling functions, and policy subscriptions. 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
createForeignCall
Creates a foreign call and stores it in the contract’s storage.
Builds a foreign call structure and maps it to the associated policy ID.
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the foreign call will be mapped to. |
_foreignCall | ForeignCall | The definition of the foreign call to create. |
foreignCallName | string |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The index of the created foreign call. |
updateForeignCall
Updates a foreign call in the contract’s storage.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the foreign call is associated with. |
foreignCallId | uint256 | The ID of the foreign call to update. |
foreignCall | ForeignCall | The updated foreign call structure. |
Returns
Name | Type | Description |
---|---|---|
fc | ForeignCall | The updated foreign call structure. |
deleteForeignCall
Deletes a foreign call from the contract’s storage.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the foreign call is associated with. |
foreignCallId | uint256 | The ID of the foreign call to delete. |
getAllForeignCalls
Retrieve Foreign Call Set from storage
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | the policy Id of the foreign call to retrieve |
Returns
Name | Type | Description |
---|---|---|
fc | ForeignCall[] | the foreign call set structure |
getForeignCall
Retrieves a foreign call from the contract’s storage.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID of the foreign call to retrieve. |
foreignCallId | uint256 | The ID of the foreign call to retrieve. |
Returns
Name | Type | Description |
---|---|---|
fc | ForeignCall | The foreign call structure. |
getForeignCallMetadata
retrieves the foreign call metadata
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the foreign call is associated with. |
foreignCallId | uint256 | The identifier for the foreign call |
Returns
Name | Type | Description |
---|---|---|
fcMeta | string | the metadata for the foreign call |
_storeForeignCall
Stores a foreign call in the contract’s storage.
Ensures the foreign call is properly set before storing it.
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the foreign call is associated with. |
_foreignCall | ForeignCall | The foreign call to store. |
_incrementForeignCallIndex
Helper function to increment the foreign call index
Ensures the foreign call is properly set before storing it.
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the foreign call is associated with. |
_storeForeignCallData
Helper function to store the foreign call data
Ensures the foreign call is properly set before storing it.
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the foreign call is associated with. |
_foreignCall | ForeignCall | The foreign call to store. |
_foreignCallIndex | uint256 | The index of the foreign call. |
_storeForeignCallMetadata
Helper function to store the foreign call metadata
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the foreign call is associated with. |
_foreignCallIndex | uint256 | The index of the foreign call. |
_foreignCallName | string | The name of the foreign call. |
createTracker
Adds a tracker to the tracker storage mapping.
Creates a new tracker and associates it with the specified policy ID.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the tracker is associated with. |
tracker | Trackers | The tracker to add. |
trackerName | string |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | trackerIndex The index of the created tracker. |
updateTracker
Updates an existing tracker in the tracker storage mapping.
Modifies the tracker associated with the specified policy ID and tracker index.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the tracker is associated with. |
trackerIndex | uint256 | The index of the tracker to update. |
tracker | Trackers | The updated tracker data. |
deleteTracker
Deletes a tracker from the tracker storage mapping.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the tracker is associated with. |
trackerIndex | uint256 | The index of the tracker to delete. |
getAllTrackers
Retrieves all trackers associated with a specific policy ID.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the trackers are associated with. |
Returns
Name | Type | Description |
---|---|---|
<none> | Trackers[] | trackers An array of tracker data. |
getTrackerMetadata
retrieves the tracker metadata
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the tracker is associated with. |
trackerId | uint256 | The identifier for the tracker |
Returns
Name | Type | Description |
---|---|---|
trMeta | string | the metadata for the tracker |
getTracker
Retrieves a tracker from the tracker storage mapping.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the tracker is associated with. |
index | uint256 | The index of the tracker to retrieve. |
Returns
Name | Type | Description |
---|---|---|
tracker | Trackers | The tracker data. |
_storeTracker
Stores a tracker in the tracker storage mapping.
Sets the tracker data and marks it as active.
Parameters
Name | Type | Description |
---|---|---|
_data | TrackerStorage | The tracker storage structure. |
_policyId | uint256 | The policy ID the tracker is associated with. |
_trackerIndex | uint256 | The index of the tracker to store. |
_tracker | Trackers | The tracker data to store. |
_incrementTrackerIndex
Helper function to increment tracker index
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the tracker is associated with. |
_storeTrackerData
Helper function to store tracker data
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the tracker is associated with. |
_trackerIndex | uint256 | The index of the tracker to store |
_tracker | Trackers |
_storeTrackerMetadata
Helper function to store tracker metadata
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the tracker is associated with. |
_trackerIndex | uint256 | The index of the tracker |
_trackerName | string | Name of the tracker |
createCallingFunction
Creates a new calling function and stores it in the calling function storage mapping.
Associates the calling function with the specified policy ID and parameter types.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling function is associated with. |
functionSignature | bytes4 | The function signature of the calling function. |
pTypes | ParamTypes[] | The parameter types for the calling function. |
callingFunctionName | string | the name of the calling function (to be stored in metadata) |
encodedValues | string | the string representation of the values encoded with the calling function (to be stored in metadata) |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | functionId The index of the created calling function. |
updateCallingFunction
Updates an existing calling function by appending new parameter types.
Ensures that the new parameter types are compatible with the existing ones.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling function is associated with. |
callingFunctionID | uint256 | The ID of the calling function to update. |
functionSignature | bytes4 | The function signature of the calling function. |
pTypes | ParamTypes[] | The new parameter types to append. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | functionId The updated calling function ID. |
deleteCallingFunction
Deletes a calling function from storage.
Removes the calling function and its associated rules and mappings.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling function is associated with. |
callingFunctionId | uint256 | The ID of the calling function to delete. |
getCallingFunction
Retrieves a calling function from storage.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling function is associated with. |
callingFunctionId | uint256 | The ID of the calling function to retrieve. |
Returns
Name | Type | Description |
---|---|---|
<none> | CallingFunctionStorageSet | CallngFunctionStorageSet The calling function data. |
getCallingFunctionMetadata
retrieves the calling function metadata
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling function is associated with. |
callingFunctionId | uint256 | The identifier for the calling function |
Returns
Name | Type | Description |
---|---|---|
<none> | CallingFunctionHashMapping | the metadata for the calling function |
getAllCallingFunctions
Retrieves all calling functions associated with a specific policy ID.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The policy ID the calling functions are associated with. |
Returns
Name | Type | Description |
---|---|---|
<none> | CallingFunctionStorageSet[] | CallingFunctionStorageSet An array of calling function data. |
_incrementFunctionId
Helper function to increment function ID
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the calling function is associated with. |
_storeCallingFunctionData
Helper function to store calling function data
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the calling function is associated with. |
_functionId | uint256 | The ID of the function |
_functionSignature | bytes4 | The function signature of the calling function |
_pTypes | ParamTypes[] | The parameter types for the calling function. |
_storeCallingFunctionMetadata
Helper function to store calling function metadata
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The policy ID the calling function is associated with. |
_functionId | uint256 | The ID of the function |
_functionSignature | bytes4 | The function signature of the calling function |
_callingFunctionName | string | Name of the calling function |
_encodedValues | string | Arguments to be encoded |
addClosedPolicySubscriber
Adds an address to the subscriber list of a specified policy.
Only callable by a policy admin. The policy must not be cemented.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The ID of the policy. |
subscriber | address | The address to add to the policy subscription. |
removeClosedPolicySubscriber
Removes an address from the subscriber list of a specified policy.
Only callable by a policy admin. The policy must not be cemented.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The ID of the policy. |
subscriber | address | The address to remove from the policy subscription. |
isClosedPolicySubscriber
Checks if an address is a subscriber of the specified policy.
Parameters
Name | Type | Description |
---|---|---|
policyId | uint256 | The ID of the policy. |
subscriber | address | The address to check for policy subscription. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool True if the address is a subscriber, false otherwise. |
_notCemented
Checks that a policy is not cemented.
Parameters
Name | Type | Description |
---|---|---|
_policyId | uint256 | The ID of the policy. |