Git Source 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

createTracker

Adds a tracker to the tracker storage mapping. Creates a new tracker and associates it with the specified policy ID.
function createTracker(
    uint256 policyId,
    Trackers calldata tracker,
    string calldata trackerName,
    TrackerArrayTypes arrayType
) external returns (uint256);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerTrackersThe tracker to add.
trackerNamestringName of the tracker
arrayTypeTrackerArrayTypes
Returns
NameTypeDescription
<none>uint256trackerIndex The index of the created tracker.

createMappedTracker

Adds a mapped tracker to tracker storage. Creates a new tracker and associates it with the specified policy ID and assigns the tracker to addresses.
function createMappedTracker(
    uint256 policyId,
    Trackers memory tracker,
    string calldata trackerName,
    bytes[] calldata trackerKeys,
    bytes[] calldata trackerValues,
    TrackerArrayTypes arrayType
) external returns (uint256);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerTrackersThe tracker to add.
trackerNamestringNames of the trackers
trackerKeysbytes[]
trackerValuesbytes[]
arrayTypeTrackerArrayTypes
Returns
NameTypeDescription
<none>uint256trackerIndex The index of the created tracker.

_validateTrackerType

function _validateTrackerType(Trackers memory _tracker) internal pure;

_validateCallingFunctionPType

function _validateCallingFunctionPType(ParamTypes[] memory types) internal pure;

_incrementTrackerIndex

Helper function to increment tracker index
function _incrementTrackerIndex(uint256 _policyId) private returns (uint256);
Parameters
NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.

_storeTrackerData

Helper function to store tracker data
function _storeTrackerData(
    uint256 _policyId,
    uint256 _trackerIndex,
    Trackers memory _tracker,
    bytes calldata _trackerKey,
    bytes calldata _trackerValue
) internal;
Parameters
NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to store
_trackerTrackersThe tracker to store.
_trackerKeybytesThe key for the tracker mapping.
_trackerValuebytesThe value for the tracker mapping.

_storeTrackerMetadata

Helper function to store tracker metadata
function _storeTrackerMetadata(
    uint256 _policyId,
    uint256 _trackerIndex,
    string calldata _trackerName,
    bytes calldata initialValue,
    TrackerArrayTypes arrayType
) internal;
Parameters
NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker
_trackerNamestringName of the tracker
initialValuebytes
arrayTypeTrackerArrayTypes

_storeMappedTrackerMetadata

function _storeMappedTrackerMetadata(
    uint256 _policyId,
    uint256 _trackerIndex,
    string calldata _trackerName,
    bytes[] calldata initialKeys,
    bytes[] calldata initialValues,
    TrackerArrayTypes arrayType
) internal;

_storeTracker

Stores a tracker in the tracker storage mapping. Sets the tracker data and marks it as active.
function _storeTracker(TrackerStorage storage _data, uint256 _policyId, uint256 _trackerIndex, Trackers memory _tracker)
    internal;
Parameters
NameTypeDescription
_dataTrackerStorageThe tracker storage structure.
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to store.
_trackerTrackersThe tracker data to store.

_storeTrackerMapping

Stores mapping data in the tracker storage mapping. Sets the tracker mapped bool to active.
function _storeTrackerMapping(
    TrackerStorage storage _data,
    uint256 _policyId,
    uint256 _trackerIndex,
    Trackers memory _tracker,
    bytes memory _trackerKey,
    bytes memory _trackerValue
) internal;
Parameters
NameTypeDescription
_dataTrackerStorageThe tracker storage structure.
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to store.
_trackerTrackersThe tracker data to store.
_trackerKeybytesThe keys for the tracker mapping.
_trackerValuebytesThe values for the tracker mapping.

_storeTrackerData

Helper function to store tracker data
function _storeTrackerData(uint256 _policyId, uint256 _trackerIndex, Trackers calldata _tracker) internal;
Parameters
NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to store
_trackerTrackers

getTrackerMetadata

retrieves the tracker metadata
function getTrackerMetadata(uint256 policyId, uint256 trackerId) public view returns (TrackerMetadataStruct memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerIduint256The identifier for the tracker
Returns
NameTypeDescription
<none>TrackerMetadataStructthe metadata for the tracker

getAllTrackers

Retrieves all trackers associated with a specific policy ID.
function getAllTrackers(uint256 policyId) external view returns (Trackers[] memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the trackers are associated with.
Returns
NameTypeDescription
<none>Trackers[]trackers An array of tracker data.

getTracker

Retrieves a tracker from the tracker storage mapping.
function getTracker(uint256 policyId, uint256 index) public view returns (Trackers memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
indexuint256The index of the tracker to retrieve.
Returns
NameTypeDescription
<none>TrackersThe tracker data.

getTrackerToRuleIds

Retrieves the rule IDs associated with a specific tracker index for a given policy ID.
function getTrackerToRuleIds(uint256 policyId, uint256 trackerIndex) external view returns (uint256[] memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerIndexuint256The index of the tracker to retrieve rule IDs for.
Returns
NameTypeDescription
<none>uint256[]An array of rule IDs associated with the specified tracker index.

getMappedTrackerValue

Retrieves a tracker from the tracker storage mapping.
function getMappedTrackerValue(uint256 policyId, uint256 index, bytes memory trackerKey)
    public
    view
    returns (bytes memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
indexuint256The index of the tracker to retrieve.
trackerKeybytes
Returns
NameTypeDescription
<none>bytestracker The tracker data.

updateTracker

Updates an existing tracker in the tracker storage mapping. Modifies the tracker associated with the specified policy ID and tracker index.
function updateTracker(uint256 policyId, uint256 trackerIndex, Trackers calldata tracker) external;
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerIndexuint256The index of the tracker to update.
trackerTrackersThe updated tracker data.

updateTracker

Updates an existing tracker in the tracker storage mapping. Modifies the tracker associated with the specified policy ID and tracker index.
function updateTracker(
    uint256 _policyId,
    uint256 _trackerIndex,
    Trackers calldata _tracker,
    bytes calldata _trackerKey,
    bytes calldata _trackerValue
) external;
Parameters
NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to update.
_trackerTrackersThe updated tracker data.
_trackerKeybytesThe keys for the tracker mapping.
_trackerValuebytesThe values for the tracker mapping.

deleteTracker

Tracker mappings are not deleted, since trackerIds are not reused that data will never clash with new trackers. Helper function to store tracker data
function deleteTracker(uint256 policyId, uint256 trackerIndex) external;
Parameters
NameTypeDescription
policyIduint256The policy ID the tracker is associated with.
trackerIndexuint256The index of the tracker to store

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.
function createCallingFunction(
    uint256 policyId,
    bytes4 functionSignature,
    ParamTypes[] memory pTypes,
    string memory callingFunctionName,
    string memory encodedValues
) external returns (bytes4);
Parameters
NameTypeDescription
policyIduint256The policy ID the calling function is associated with.
functionSignaturebytes4The function signature of the calling function.
pTypesParamTypes[]The parameter types for the calling function.
callingFunctionNamestringthe name of the calling function (to be stored in metadata)
encodedValuesstringthe string representation of the values encoded with the calling function (to be stored in metadata)
Returns
NameTypeDescription
<none>bytes4functionId 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.
function updateCallingFunction(uint256 policyId, bytes4 functionSignature, ParamTypes[] memory pTypes)
    external
    returns (bytes4);
Parameters
NameTypeDescription
policyIduint256The policy ID the calling function is associated with.
functionSignaturebytes4The function signature of the calling function.
pTypesParamTypes[]The new parameter types to append.
Returns
NameTypeDescription
<none>bytes4functionId The updated calling function ID.

deleteCallingFunction

Deletes a calling function from storage. Removes the calling function and its associated rules and mappings.
function deleteCallingFunction(uint256 policyId, bytes4 sig) external;
Parameters
NameTypeDescription
policyIduint256The policy ID the calling function is associated with.
sigbytes4The selector of the calling function to delete.

getCallingFunction

Retrieves a calling function from storage.
function getCallingFunction(uint256 policyId, bytes4 sig) public view returns (CallingFunctionStorageSet memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the calling function is associated with.
sigbytes4The selector of the calling function to retrieve.
Returns
NameTypeDescription
<none>CallingFunctionStorageSetCallngFunctionStorageSet The calling function data.

getCallingFunctionMetadata

retrieves the calling function metadata
function getCallingFunctionMetadata(uint256 policyId, bytes4 sig)
    public
    view
    returns (CallingFunctionHashMapping memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the calling function is associated with.
sigbytes4The selector for the calling function
Returns
NameTypeDescription
<none>CallingFunctionHashMappingthe metadata for the calling function

getAllCallingFunctions

Retrieves all calling functions associated with a specific policy ID.
function getAllCallingFunctions(uint256 policyId) public view returns (CallingFunctionStorageSet[] memory);
Parameters
NameTypeDescription
policyIduint256The policy ID the calling functions are associated with.
Returns
NameTypeDescription
<none>CallingFunctionStorageSet[]CallingFunctionStorageSet An array of calling function data.

_storeCallingFunctionData

Helper function to store calling function data
function _storeCallingFunctionData(uint256 _policyId, bytes4 _functionSignature, ParamTypes[] memory _pTypes) private;
Parameters
NameTypeDescription
_policyIduint256The policy ID the calling function is associated with.
_functionSignaturebytes4The function signature of the calling function
_pTypesParamTypes[]The parameter types for the calling function.

_storeCallingFunctionMetadata

Helper function to store calling function metadata
function _storeCallingFunctionMetadata(
    uint256 _policyId,
    bytes4 _functionSignature,
    string memory _callingFunctionName,
    string memory _encodedValues
) private;
Parameters
NameTypeDescription
_policyIduint256The policy ID the calling function is associated with.
_functionSignaturebytes4The function signature of the calling function
_callingFunctionNamestringName of the calling function
_encodedValuesstringArguments 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.
function addClosedPolicySubscriber(uint256 policyId, address subscriber) external;
Parameters
NameTypeDescription
policyIduint256The ID of the policy.
subscriberaddressThe 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.
function removeClosedPolicySubscriber(uint256 policyId, address subscriber) external;
Parameters
NameTypeDescription
policyIduint256The ID of the policy.
subscriberaddressThe address to remove from the policy subscription.

isClosedPolicySubscriber

Checks if an address is a subscriber of the specified policy.
function isClosedPolicySubscriber(uint256 policyId, address subscriber) external view returns (bool);
Parameters
NameTypeDescription
policyIduint256The ID of the policy.
subscriberaddressThe address to check for policy subscription.
Returns
NameTypeDescription
<none>boolbool True if the address is a subscriber, false otherwise.

_notCemented

Checks that a policy is not cemented.
function _notCemented(uint256 _policyId) internal view;
Parameters
NameTypeDescription
_policyIduint256The ID of the policy.

_policyAdminOnly

Checks that the caller is a policy admin
function _policyAdminOnly(uint256 _policyId, address _address) internal;
Parameters
NameTypeDescription
_policyIduint256The ID of the policy.
_addressaddressThe address to check for policy admin status.