Git Source Author: @mpetersoCode55, @ShaneDuncan602, @TJ-Everett, @VoR0220 This contract is intended to be used internally by facets in the Rules Engine to streamline cross-facet interactions. This contract provides utility functions for interacting with other facets in the Rules Engine. It includes functionality for performing delegate calls to other facets using their function selectors.

State Variables

FLAG_FOREIGN_CALL

uint8 constant FLAG_FOREIGN_CALL = 0x01;

FLAG_TRACKER_VALUE

uint8 constant FLAG_TRACKER_VALUE = 0x02;

MASK_GLOBAL_VAR

uint8 constant MASK_GLOBAL_VAR = 0x1C;

SHIFT_GLOBAL_VAR

uint8 constant SHIFT_GLOBAL_VAR = 2;

Functions

_callAnotherFacet

Performs a delegate call to another facet in the Rules Engine. Uses the function selector to locate the target facet and executes the provided call data. Reverts with the returned error message if the delegate call fails.
function _callAnotherFacet(bytes4 _functionSelector, bytes memory _callData)
    internal
    returns (bool _success, bytes memory _res);
Parameters
NameTypeDescription
_functionSelectorbytes4The function selector of the target function in the other facet.
_callDatabytesThe encoded call data to pass to the target function.
Returns
NameTypeDescription
_successboolA boolean indicating whether the delegate call was successful.
_resbytesThe returned data from the delegate call.

_isForeignCall

Checks if the foreign call flag is set in a Placeholder using assembly Uses optimized assembly to extract the flag bit directly from memory
function _isForeignCall(Placeholder memory placeholder) internal pure returns (bool result);
Parameters
NameTypeDescription
placeholderPlaceholderThe Placeholder struct to check
Returns
NameTypeDescription
resultboolTrue if the foreign call flag is set, false otherwise

_isTrackerValue

Checks if the tracker value flag is set in a Placeholder using assembly Uses optimized assembly to extract the flag bit directly from memory
function _isTrackerValue(Placeholder memory placeholder) internal pure returns (bool result);
Parameters
NameTypeDescription
placeholderPlaceholderThe Placeholder struct to check
Returns
NameTypeDescription
resultboolTrue if the tracker value flag is set, false otherwise

_extractFlags

Helper function to extract flags from a placeholder
function _extractFlags(Placeholder memory placeholder)
    internal
    pure
    returns (bool isTrackerValue, bool isForeignCall, uint8 globalVarType);
Parameters
NameTypeDescription
placeholderPlaceholderThe placeholder to extract flags from
Returns
NameTypeDescription
isTrackerValueboolWhether the tracker value flag is set
isForeignCallboolWhether the foreign call flag is set
globalVarTypeuint8The global variable type

_isThereDuplicatesInCalldataValueTypeArray

this is only useful for an array passed as an argument to an external/public function and the function explicitely uses the calldata keyword. This won’t work if the array is stored in memory. this is a type-agnostic solution for determining if an array of value types from calldata contains duplicates in it
function _isThereDuplicatesInCalldataValueTypeArray(uint256 len, uint256 start)
    internal
    pure
    returns (bool duplicatesFound);
Parameters
NameTypeDescription
lenuint256the length of the array. Can be easily retrieved in Solidity by using array.length;
startuint256the location in the calldata of the first element of the array. Can be retrieved with Yul by doing array.offset
Returns
NameTypeDescription
duplicatesFoundbooltrue if at least one element is repeated in the array. False otherwise