Git Source

Inherits: [FacetCommonImports](/v2(/v2/reference/engine/facets/FacetCommonImports.sol/abstract.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, function signatures, 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.

function createForeignCall(uint256 _policyId, ForeignCall calldata _foreignCall)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId)
    returns (uint256);

Parameters

NameTypeDescription
_policyIduint256The policy ID the foreign call will be mapped to.
_foreignCallForeignCallThe definition of the foreign call to create.

Returns

NameTypeDescription
<none>uint256The index of the created foreign call.

_storeForeignCall

Stores a foreign call in the contract’s storage.

Ensures the foreign call is properly set before storing it.

function _storeForeignCall(uint256 _policyId, ForeignCall memory _foreignCall) internal;

Parameters

NameTypeDescription
_policyIduint256The policy ID the foreign call is associated with.
_foreignCallForeignCallThe foreign call to store.

deleteForeignCall

Deletes a foreign call from the contract’s storage.

function deleteForeignCall(uint256 _policyId, uint256 _foreignCallId)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId);

Parameters

NameTypeDescription
_policyIduint256The policy ID the foreign call is associated with.
_foreignCallIduint256The ID of the foreign call to delete.

updateForeignCall

Updates a foreign call in the contract’s storage.

function updateForeignCall(uint256 _policyId, uint256 _foreignCallId, ForeignCall calldata _foreignCall)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId)
    returns (ForeignCall memory fc);

Parameters

NameTypeDescription
_policyIduint256The policy ID the foreign call is associated with.
_foreignCallIduint256The ID of the foreign call to update.
_foreignCallForeignCallThe updated foreign call structure.

Returns

NameTypeDescription
fcForeignCallThe updated foreign call structure.

getForeignCall

Retrieves a foreign call from the contract’s storage.

function getForeignCall(uint256 _policyId, uint256 _foreignCallId) public view returns (ForeignCall memory fc);

Parameters

NameTypeDescription
_policyIduint256The policy ID of the foreign call to retrieve.
_foreignCallIduint256The ID of the foreign call to retrieve.

Returns

NameTypeDescription
fcForeignCallThe foreign call structure.

getAllForeignCalls

Retrieve Foreign Call Set from storage

function getAllForeignCalls(uint256 _policyId) external view returns (ForeignCall[] memory fc);

Parameters

NameTypeDescription
_policyIduint256the policy Id of the foreign call to retrieve

Returns

NameTypeDescription
fcForeignCall[]the foreign call set structure

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)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId)
    returns (uint256);

Parameters

NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerTrackersThe tracker to add.

Returns

NameTypeDescription
<none>uint256trackerIndex 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.

function updateTracker(uint256 _policyId, uint256 _trackerIndex, Trackers calldata _tracker)
    external
    policyAdminOnly(_policyId, msg.sender);

Parameters

NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to update.
_trackerTrackersThe updated tracker data.

_storeTracker

Stores a tracker in the tracker storage mapping.

Sets the tracker data and marks it as active.

function _storeTracker(TrackerS storage _data, uint256 _policyId, uint256 _trackerIndex, Trackers memory _tracker)
    internal;

Parameters

NameTypeDescription
_dataTrackerSThe tracker storage structure.
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to store.
_trackerTrackersThe tracker data to store.

getTracker

Retrieves a tracker from the tracker storage mapping.

function getTracker(uint256 _policyId, uint256 _index) public view returns (Trackers memory tracker);

Parameters

NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_indexuint256The index of the tracker to retrieve.

Returns

NameTypeDescription
trackerTrackersThe tracker data.

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.

deleteTracker

Deletes a tracker from the tracker storage mapping.

function deleteTracker(uint256 _policyId, uint256 _trackerIndex)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId);

Parameters

NameTypeDescription
_policyIduint256The policy ID the tracker is associated with.
_trackerIndexuint256The index of the tracker to delete.

createFunctionSignature

Creates a new function signature and stores it in the function signature storage mapping.

Associates the function signature with the specified policy ID and parameter types.

function createFunctionSignature(uint256 _policyId, bytes4 _functionSignature, PT[] memory _pTypes)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId)
    returns (uint256);

Parameters

NameTypeDescription
_policyIduint256The policy ID the function signature is associated with.
_functionSignaturebytes4The function signature to create.
_pTypesPT[]The parameter types for the function signature.

Returns

NameTypeDescription
<none>uint256functionId The index of the created function signature.

updateFunctionSignature

Updates an existing function signature by appending new parameter types.

Ensures that the new parameter types are compatible with the existing ones.

function updateFunctionSignature(
    uint256 _policyId,
    uint256 _functionSignatureId,
    bytes4 _functionSignature,
    PT[] memory _pTypes
) external policyAdminOnly(_policyId, msg.sender) notCemented(_policyId) returns (uint256);

Parameters

NameTypeDescription
_policyIduint256The policy ID the function signature is associated with.
_functionSignatureIduint256The ID of the function signature to update.
_functionSignaturebytes4The function signature to update.
_pTypesPT[]The new parameter types to append.

Returns

NameTypeDescription
<none>uint256functionId The updated function signature ID.

deleteFunctionSignature

Deletes a function signature from storage.

Removes the function signature and its associated rules and mappings.

function deleteFunctionSignature(uint256 _policyId, uint256 _functionSignatureId)
    external
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId);

Parameters

NameTypeDescription
_policyIduint256The policy ID the function signature is associated with.
_functionSignatureIduint256The ID of the function signature to delete.

getFunctionSignature

Retrieves a function signature from storage.

function getFunctionSignature(uint256 _policyId, uint256 _functionSignatureId)
    public
    view
    returns (FunctionSignatureStorageSet memory);

Parameters

NameTypeDescription
_policyIduint256The policy ID the function signature is associated with.
_functionSignatureIduint256The ID of the function signature to retrieve.

Returns

NameTypeDescription
<none>FunctionSignatureStorageSetfunctionSignatureSet The function signature data.

getAllFunctionSignatures

Retrieves all function signatures associated with a specific policy ID.

function getAllFunctionSignatures(uint256 _policyId) public view returns (FunctionSignatureStorageSet[] memory);

Parameters

NameTypeDescription
_policyIduint256The policy ID the function signatures are associated with.

Returns

NameTypeDescription
<none>FunctionSignatureStorageSet[]functionSignatureStorageSets An array of function signature data.

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
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId);

Parameters

NameTypeDescription
_policyIduint256The ID of the policy.
_subscriberaddressThe address to add to 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.

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
    policyAdminOnly(_policyId, msg.sender)
    notCemented(_policyId);

Parameters

NameTypeDescription
_policyIduint256The ID of the policy.
_subscriberaddressThe address to remove from the policy subscription.

isCemented

Checks if a policy is cemented.

function isCemented(uint256 _policyId) public view returns (bool _cemented);

Parameters

NameTypeDescription
_policyIduint256The ID of the policy.

Returns

NameTypeDescription
_cementedboolTrue if the policy is cemented, false otherwise.

notCemented

Modifier to ensure that cemented policies cannot be modified.

modifier notCemented(uint256 _policyId);

Parameters

NameTypeDescription
_policyIduint256The ID of the policy.