Defined in: src/modules/rules-engine.ts:121

Methods

addAdminToPermissionList()

addAdminToPermissionList(foreignCallAddress, functionSelector, policyAdminToAdd): Promise<number>
Defined in: src/modules/rules-engine.ts:733 Adds a new address to the permission list for a foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`the address of the contract the foreign call belongs to.
functionSelectorstringThe selector for the specific foreign call
policyAdminToAdd`0x${string}`The address of the admin to add to the list

Returns

Promise<number> A promise that resolves to a number: - 0 if the operation is successful. - -1 if an error occurs during the simulation of the contract interaction.

Throws

Will log an error to the console if the operation fails.

addClosedPolicySubscriber()

addClosedPolicySubscriber(policyId, subscriber): Promise<number>
Defined in: src/modules/rules-engine.ts:419 Adds a subscriber to the closed policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to add to.
subscriber`0x${string}`The address of the subscriber to add.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

addMultipleAdminsToPermissionList()

addMultipleAdminsToPermissionList(foreignCallAddress, functionSelector, policyAdminsToAdd): Promise<number>
Defined in: src/modules/rules-engine.ts:760 Adds multiple addresses to the permission list for a foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`the address of the contract the foreign call belongs to.
functionSelectorstringThe selector for the specific foreign call
policyAdminsToAdd`0x${string}`[]The addresses of the admins to add to the list

Returns

Promise<number> A promise that resolves to a number: - 0 if the operation is successful. - -1 if an error occurs during the simulation of the contract interaction.

Throws

Will log an error to the console if the operation fails.

appendPolicy()

appendPolicy(policyId, contractAddressForPolicy): void
Defined in: src/modules/rules-engine.ts:297 Appends a policy to the list of policies applied to a specific contract address.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to apply.
contractAddressForPolicy`0x${string}`The address of the contract to which the policy will be applied.

Returns

void

cementPolicy()

cementPolicy(policyId): Promise<number>
Defined in: src/modules/rules-engine.ts:1173 Cements a policy on the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to cement.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

closePolicy()

closePolicy(policyId): Promise<number>
Defined in: src/modules/rules-engine.ts:388 Closes a policy on the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to close.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

confirmNewCallingContractAdmin()

confirmNewCallingContractAdmin(callingContractAddress): void
Defined in: src/modules/rules-engine.ts:1067 Confirm a new calling contract admin in the rules engine admin contract. This function confirms a new admin for a specific calling contract.

Parameters

ParameterTypeDescription
callingContractAddress`0x${string}`The address of the calling contract to set the admin for.

Returns

void A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

confirmNewForeignCallAdmin()

confirmNewForeignCallAdmin(foreignCallAddress, foreignCallSelector): void
Defined in: src/modules/rules-engine.ts:1129 Confirm a new foreign call admin in the rules engine admin contract. This function confirms a new admin for a specific foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`The address of the foreign call to set the admin for.
foreignCallSelectorstring-

Returns

void A promise.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

confirmNewPolicyAdmin()

confirmNewPolicyAdmin(policyId): void
Defined in: src/modules/rules-engine.ts:1017 Confirm a new admin in the rules engine admin contract. This function confirms a new admin for a specific policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to set the admin for.

Returns

void A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

createCallingFunction()

createCallingFunction(policyId, callingFunction, encodedValues): Promise<number>
Defined in: src/modules/rules-engine.ts:951 Creates a calling function in the rules engine component contract. This function parses the provided calling function, maps its arguments to their respective types, and interacts with the smart contract to create the calling function. If the contract interaction fails, it retries with a delay until successful.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy for which the calling contract is being created.
callingFunctionstringThe calling function string to be parsed and added to the contract.
encodedValuesstringthe encoded values that will be sent along with the rules invocation.

Returns

Promise<number> A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

createForeignCall()

createForeignCall(policyId, fcSyntax): Promise<number>
Defined in: src/modules/rules-engine.ts:585 Creates a foreign call in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to associate with the foreign call.
fcSyntaxstringA JSON string representing the foreign call definition.

Returns

Promise<number> A promise that resolves to the foreign call index. Returns -1 if the operation fails.

Remarks

  • The function retries the contract interaction in case of failure, with a delay of 1 second between attempts.
  • The simulateContract function is used to simulate the contract interaction before writing to the blockchain.
  • The writeContract function is used to execute the contract interaction on the blockchain.
  • The function returns the foreignCallIndex for an updated foreign call or the result of the newly created foreign call.

Throws

Will throw an error if the JSON parsing of fcSyntax fails.

createNewRule()

createNewRule(policyId, ruleS, foreignCallNameToID, trackerNameToID): Promise<number>
Defined in: src/modules/rules-engine.ts:459 Asynchronously creates a new rule in the rules engine policy contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to which the rule belongs.
ruleSstringA JSON string representing the rule to be created.
foreignCallNameToIDFCNameToID[]An array mapping foreign call names to their corresponding IDs.
trackerNameToIDFCNameToID[]An array mapping tracker names to their corresponding IDs.

Returns

Promise<number> A promise that resolves to the result of the rule creation operation. Returns the rule ID if successful, or -1 if the operation fails.

Remarks

  • The function parses the rule JSON string to build the rule and effect structures.
  • It uses a retry mechanism with a delay to handle potential failures during contract simulation.

createPolicy()

createPolicy(policyJSON): Promise<{ policyId: number; }>
Defined in: src/modules/rules-engine.ts:216 Creates a policy in the Rules Engine.

Parameters

ParameterTypeDescription
policyJSONstringPolicy defined in a JSON string.

Returns

Promise<{ policyId: number; }> The ID of the newly created policy.

createTracker()

createTracker(policyId, trSyntax): Promise<number>
Defined in: src/modules/rules-engine.ts:833 Asynchronously creates a tracker in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the tracker.
trSyntaxstringA JSON string representing the tracker syntax.

Returns

Promise<number> A promise that resolves to the new tracker ID

Throws

Will retry indefinitely with a 1-second delay between attempts if an error occurs during the contract simulation. Ensure proper error handling or timeout mechanisms are implemented to avoid infinite loops.

deleteForeignCall()

deleteForeignCall(policyId, foreignCallId): Promise<number>
Defined in: src/modules/rules-engine.ts:637 Deletes a foreign call associated with a specific policy in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to which the foreign call belongs.
foreignCallIdnumberThe ID of the foreign call to be deleted.

Returns

Promise<number> A promise that resolves to a number: - 0 if the operation is successful. - -1 if an error occurs during the simulation of the contract interaction.

Throws

This function does not explicitly throw errors but will return -1 if an error occurs during the simulation phase.

deletePolicy()

deletePolicy(policyId): Promise<number>
Defined in: src/modules/rules-engine.ts:313 Deletes a policy from the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to delete.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

deleteRule()

deleteRule(policyId, ruleId): Promise<number>
Defined in: src/modules/rules-engine.ts:523 Deletes a rule from the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to which the rule belongs.
ruleIdnumberThe ID of the rule to be deleted.

Returns

Promise<number> A promise that resolves to a number: - 0 if the rule was successfully deleted. - -1 if an error occurred during the deletion process.

Throws

This function does not throw errors directly but returns -1 in case of an exception.

deleteTracker()

deleteTracker(policyId, trackerId): Promise<number>
Defined in: src/modules/rules-engine.ts:870 Deletes a tracker associated with a specific policy in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to which the tracker belongs.
trackerIdnumberThe ID of the tracker to be deleted.

Returns

Promise<number> A promise that resolves to a number: - 0 if the tracker was successfully deleted. - -1 if an error occurred during the simulation of the contract interaction.

Throws

This function does not explicitly throw errors but will return -1 if an error occurs during the simulation phase.

getAllForeignCalls()

getAllForeignCalls(policyId, blockParams?): Promise<Maybe<any[]>>
Defined in: src/modules/rules-engine.ts:670 Retrieves all foreign calls associated with a specific policy ID from the Rules Engine Component Contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy for which foreign calls are to be retrieved.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<any[]>> A promise that resolves to an array of foreign calls if successful, or null if an error occurs.

Throws

Will log an error to the console if the operation fails.

getAllRules()

getAllRules(policyId, blockParams?): Promise<Maybe<any[]>>
Defined in: src/modules/rules-engine.ts:566 Retrieves all rules associated with a specific policy ID from the Rules Engine Policy Contract.

Parameters

ParameterTypeDescription
policyIdnumberThe unique identifier of the policy for which rules are to be retrieved.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<any[]>> A promise that resolves to an array of rules if successful, or null if an error occurs.

Throws

Will log an error to the console if the operation fails.

getAllTrackers()

getAllTrackers(policyId, blockParams?): Promise<Maybe<any[]>>
Defined in: src/modules/rules-engine.ts:897 Retrieves all trackers associated with a specific policy ID from the Rules Engine Component Contract.

Parameters

ParameterTypeDescription
policyIdnumberThe unique identifier of the policy for which trackers are to be retrieved.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<any[]>> A promise that resolves to an array of trackers if successful, or null if an error occurs.

Throws

Will log an error to the console if the operation fails.

getAppliedPolicyIds()

getAppliedPolicyIds(address, blockParams?): Promise<number[]>
Defined in: src/modules/rules-engine.ts:358 Retrieves the IDs of all of the policies that have been applied to a contract address.

Parameters

ParameterTypeDescription
addressstringThe address to check.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<number[]> array of all of the policy ids applied to the contract

getCallingFunctionMetadata()

getCallingFunctionMetadata(policyId, callingFunctionId, blockParams?): Promise<CallingFunctionHashMapping>
Defined in: src/modules/rules-engine.ts:972 retrieves the metadata for a calling function from the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy which the calling function belongs to.
callingFunctionIdstringThe Calling Function ID.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<CallingFunctionHashMapping> A promise that resolves to the result of the contract interaction.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

getForeignCall()

getForeignCall(policyId, foreignCallId, blockParams?): Promise<any>
Defined in: src/modules/rules-engine.ts:657 Retrieves the result of a foreign call from the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the foreign call.
foreignCallIdnumberThe ID of the foreign call to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<any> A promise that resolves to the result of the foreign call, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getForeignCallMetadata()

getForeignCallMetadata(policyId, foreignCallId, blockParams?): Promise<any>
Defined in: src/modules/rules-engine.ts:683 Retrieves the metadata for a foreign call from the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the foreign call.
foreignCallIdnumberThe ID of the foreign call to retrieve.
blockParams?ContractBlockParameters-

Returns

Promise<any> A promise that resolves to the result of the foreign call, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getForeignCallPermissionList()

getForeignCallPermissionList(foreignCallAddress, functionSelector, blockParams?): Promise<`0x${string}`[]>
Defined in: src/modules/rules-engine.ts:707 Retrieves the permission list for a permissioned foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`the address of the contract the foreign call belongs to.
functionSelectorstringThe selector for the specific foreign call
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<`0x${string}`[]> Array of addresses that make up the permission list

Throws

Will log an error to the console if the operation fails.

getPolicy()

getPolicy(policyId, blockParams?): Promise<Maybe<PolicyResult>>
Defined in: src/modules/rules-engine.ts:324 Retrieves the full policy, including rules, trackers, and foreign calls, as a JSON string.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<PolicyResult>> — A PolicyResult object containing both the policy object and JSON string, or an empty string if an error occurs.

getPolicyMetadata()

getPolicyMetadata(policyId, blockParams?): Promise<Maybe<PolicyMetadataStruct>>
Defined in: src/modules/rules-engine.ts:345 Retrieves the metadata for a policy from the Rules Engine Policy Contract based on the provided policy ID.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<PolicyMetadataStruct>> A promise that resolves to the policy metadata result if successful, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getRule()

getRule(policyId, ruleId, blockParams?): Promise<Maybe<RuleStruct>>
Defined in: src/modules/rules-engine.ts:535 Retrieves a specific rule from the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy containing the rule.
ruleIdnumberThe ID of the rule to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<RuleStruct>> The retrieved rule as a RuleStruct, or null if retrieval fails.

getRuleMetadata()

getRuleMetadata(policyId, ruleId, blockParams?): Promise<Maybe<RuleMetadataStruct>>
Defined in: src/modules/rules-engine.ts:549 Retrieves the metadata for a rule from the Rules Engine Rules Contract based on the provided policy ID and rule ID.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the rule.
ruleIdnumberThe ID of the rule to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<RuleMetadataStruct>> A promise that resolves to the rule metadata result if successful, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getRulesEngineComponentContract()

getRulesEngineComponentContract(): object
Defined in: src/modules/rules-engine.ts:173

Returns

object
abi
abi: ({ anonymous: undefined; inputs: ({ components: undefined; internalType: string; name: string; type: string; } | { components: object[]; internalType: string; name: string; type: string; })[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: undefined; inputs: object[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: boolean; inputs: object[]; name: string; outputs: undefined; stateMutability: undefined; type: string; })[]
address
address: `0x${string}`

getRulesEngineForeignCallContract()

getRulesEngineForeignCallContract(): object
Defined in: src/modules/rules-engine.ts:179

Returns

object
abi
abi: ({ anonymous: undefined; inputs: ({ components: undefined; internalType: string; name: string; type: string; } | { components: ({ components: undefined; internalType: string; name: string; type: string; } | { components: …[]; internalType: string; name: string; type: string; })[]; internalType: string; name: string; type: string; })[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: undefined; inputs: ({ components: undefined; internalType: string; name: string; type: string; } | { components: ({ components: undefined; internalType: string; name: string; type: string; } | { components: …[]; internalType: string; name: string; type: string; })[]; internalType: string; name: string; type: string; })[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: boolean; inputs: object[]; name: string; outputs: undefined; stateMutability: undefined; type: string; })[]
address
address: `0x${string}`

getRulesEnginePolicyContract()

getRulesEnginePolicyContract(): object
Defined in: src/modules/rules-engine.ts:170

Returns

object
abi
abi: ({ anonymous: undefined; inputs: object[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: undefined; inputs: object[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: boolean; inputs: object[]; name: string; outputs: undefined; stateMutability: undefined; type: string; })[]
address
address: `0x${string}`

getRulesEngineRulesContract()

getRulesEngineRulesContract(): object
Defined in: src/modules/rules-engine.ts:176

Returns

object
abi
abi: ({ anonymous: undefined; inputs: ({ components: undefined; internalType: string; name: string; type: string; } | { components: ({ components: undefined; internalType: string; name: string; type: string; } | { components: …[]; internalType: string; name: string; type: string; })[]; internalType: string; name: string; type: string; })[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: undefined; inputs: object[]; name: string; outputs: object[]; stateMutability: string; type: string; } | { anonymous: boolean; inputs: object[]; name: string; outputs: undefined; stateMutability: undefined; type: string; })[]
address
address: `0x${string}`

getRulesEngineVersion()

getRulesEngineVersion(): Promise<string>
Defined in: src/modules/rules-engine.ts:228

Returns

Promise<string>

getTracker()

getTracker(policyId, trackerId, blockParams?): Promise<any>
Defined in: src/modules/rules-engine.ts:884 Retrieves a tracker from the Rules Engine Component Contract based on the provided policy ID and tracker ID.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the tracker.
trackerIdnumberThe ID of the tracker to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<any> A promise that resolves to the tracker result if successful, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getTrackerMetadata()

getTrackerMetadata(policyId, trackerId, blockParams?): Promise<Maybe<TrackerMetadataStruct>>
Defined in: src/modules/rules-engine.ts:911 Retrieves the metadata for a tracker from the Rules Engine Component Contract based on the provided policy ID and tracker ID.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the tracker.
trackerIdnumberThe ID of the tracker to retrieve.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<Maybe<TrackerMetadataStruct>> A promise that resolves to the tracker metadata result if successful, or null if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getTrackerToRuleIds()

getTrackerToRuleIds(policyId, trackerId, blockParams?): Promise<Maybe<number[]>>
Defined in: src/modules/rules-engine.ts:929 Retrieves the rule IDs associated with a specific tracker from the Rules Engine Component Contract based on the provided policy ID and tracker ID.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the tracker.
trackerIdnumberThe ID of the tracker for which rule IDs are to be retrieved.
blockParams?ContractBlockParameters-

Returns

Promise<Maybe<number[]>> A promise that resolves to an array of rule IDs if successful, or an empty array if an error occurs.

Throws

Will log an error to the console if the contract interaction fails.

getVersionCompatible()

getVersionCompatible(): Promise<boolean>
Defined in: src/modules/rules-engine.ts:232

Returns

Promise<boolean>

isCallingContractAdmin()

isCallingContractAdmin(callingContract, account, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:1087 Determine if address is the calling contract admin. This function determines whether or not an address is the admin for a specific calling contract.

Parameters

ParameterTypeDescription
callingContract`0x${string}`The address of the contract to check the admin for.
account`0x${string}`The address to check
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> whether or not the address is the calling contract admin.

isCementedPolicy()

isCementedPolicy(policyId, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:1183 Retrieves whether a policy is cemented.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to check.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> True if the policy is cemented, false otherwise

isClosedPolicy()

isClosedPolicy(policyId, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:368 Retrieves whether a policy is open or closed.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to check.
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> True if the policy is closed, false otherwise

isClosedPolicySubscriber()

isClosedPolicySubscriber(policyId, subscriber, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:399 Retrieves whether an address is a possible subscriber to the closed policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to check.
subscriber`0x${string}`The address to check
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> True if the address is a subscriber to the closed policy, false otherwise

isForeignCallAdmin()

isForeignCallAdmin(foreignCallAddress, account, foreignCallSelector, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:1151 Determine if address is the foreign call admin. This function determines whether or not an address is the admin for a specific foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`-
account`0x${string}`The address to check
foreignCallSelectorstring-
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> whether or not the address is the foreign call admin.

isPolicyAdmin()

isPolicyAdmin(policyId, adminAddress, blockParams?): Promise<boolean>
Defined in: src/modules/rules-engine.ts:1032 Determine if address is policy admin. This function determines whether or not an address is the admin for a specific policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to check the admin for.
adminAddress`0x${string}`The address to check
blockParams?ContractBlockParametersOptional parameters to specify block number or tag for the contract read operation.

Returns

Promise<boolean> whether or not the address is the policy admin.

openPolicy()

openPolicy(policyId): Promise<number>
Defined in: src/modules/rules-engine.ts:378 Opens a policy on the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to open.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

policyExists()

policyExists(policyId): Promise<boolean>
Defined in: src/modules/rules-engine.ts:242 Checks if a policy exists in the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to check.

Returns

Promise<boolean> True if the policy exists, false otherwise.

proposeCallingContractAdmin()

proposeCallingContractAdmin(callingContractAddress, newAdminAddress): void
Defined in: src/modules/rules-engine.ts:1047 Propose a new calling contract admin in the rules engine admin contract. This function proposes a new admin for a specific calling contract.

Parameters

ParameterTypeDescription
callingContractAddress`0x${string}`The address of the calling contract to set the admin for.
newAdminAddress`0x${string}`The address to propose as the new admin

Returns

void A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

proposeForeignCallAdmin()

proposeForeignCallAdmin(foreignCallAddress, newAdminAddress, foreignCallSelector): void
Defined in: src/modules/rules-engine.ts:1107 Propose a new foreign call admin in the rules engine admin contract. This function proposes a new admin for a specific foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`The address of the foreign call contract to set the admin for.
newAdminAddress`0x${string}`The address to propose as the new admin
foreignCallSelectorstring-

Returns

void A promise.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

proposeNewPolicyAdmin()

proposeNewPolicyAdmin(policyId, newAdminAddress): void
Defined in: src/modules/rules-engine.ts:997 Propose a new admin in the rules engine admin contract. This function proposes a new admin for a specific policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to set the admin for.
newAdminAddress`0x${string}`The address to propose as the new admin

Returns

void A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.

Throws

Will retry indefinitely on contract interaction failure, with a delay between attempts.

removeAllFromPermissionList()

removeAllFromPermissionList(foreignCallAddress, functionSelector): Promise<number>
Defined in: src/modules/rules-engine.ts:813 Removes all addresses from the permission list for a foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`the address of the contract the foreign call belongs to.
functionSelectorstringThe selector for the specific foreign call

Returns

Promise<number> A promise that resolves to a number: - 0 if the operation is successful. - -1 if an error occurs during the simulation of the contract interaction.

Throws

Will log an error to the console if the operation fails.

removeClosedPolicySubscriber()

removeClosedPolicySubscriber(policyId, subscriber): Promise<number>
Defined in: src/modules/rules-engine.ts:436 Removes a subscriber from the closed policy.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to remove from.
subscriber`0x${string}`The address of the subscriber to remove.

Returns

Promise<number> 0 if successful, -1 if an error occurs.

removeMultipleAdminsFromPermissionList()

removeMultipleAdminsFromPermissionList(foreignCallAddress, functionSelector, policyAdminsToRemove): Promise<number>
Defined in: src/modules/rules-engine.ts:787 Removes multiple addresses from the permission list for a foreign call.

Parameters

ParameterTypeDescription
foreignCallAddress`0x${string}`the address of the contract the foreign call belongs to.
functionSelectorstringThe selector for the specific foreign call
policyAdminsToRemove`0x${string}`[]The address of the admins to remove from the list

Returns

Promise<number> A promise that resolves to a number: - 0 if the operation is successful. - -1 if an error occurs during the simulation of the contract interaction.

Throws

Will log an error to the console if the operation fails.

setPolicies()

setPolicies(policyIds, contractAddressForPolicy): void
Defined in: src/modules/rules-engine.ts:281 Sets the policies appled to a specific contract address.

Parameters

ParameterTypeDescription
policyIds[number]The list of IDs of all of the policies that will be applied to the contract
contractAddressForPolicy`0x${string}`The address of the contract to which the policy will be applied.

Returns

void

updateForeignCall()

updateForeignCall(policyId, foreignCallId, fcSyntax): Promise<number>
Defined in: src/modules/rules-engine.ts:613 Updates a foreign call in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to associate with the foreign call.
foreignCallIdnumberThe ID of the foreign call to update.
fcSyntaxstringA JSON string representing the foreign call definition.

Returns

Promise<number> A promise that resolves to the foreign call index. Returns -1 if the operation fails.

Remarks

  • The function retries the contract interaction in case of failure, with a delay of 1 second between attempts.
  • The simulateContract function is used to simulate the contract interaction before writing to the blockchain.
  • The writeContract function is used to execute the contract interaction on the blockchain.
  • The function returns the foreignCallIndex for an updated foreign call or the result of the newly created foreign call.

Throws

Will throw an error if the JSON parsing of fcSyntax fails.

updatePolicy()

updatePolicy(policyId, callingFunctions, ids, ruleIds, name, description): Promise<number>
Defined in: src/modules/rules-engine.ts:255 Updates an existing policy in the Rules Engine.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to update.
callingFunctionsany[]The calling functions associated with the policy.
idsnumber[]The IDs of the rules associated with the policy.
ruleIdsany[]The mapping of rules to calling functions.
namestring-
descriptionstring-

Returns

Promise<number> The result of the policy update.

updateRule()

updateRule(policyId, ruleId, ruleS, foreignCallNameToID, trackerNameToID): Promise<number>
Defined in: src/modules/rules-engine.ts:490 Updates an existing rule in the Rules Engine Policy Contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy to which the rule belongs.
ruleIdnumberThe ID of the rule to be updated.
ruleSstringA JSON string representing the rule’s structure and logic.
foreignCallNameToIDFCNameToID[]A mapping of foreign call names to their corresponding IDs.
trackerNameToIDFCNameToID[]A mapping of tracker names to their corresponding IDs.

Returns

Promise<number> A promise that resolves to the result of the rule update operation. Returns the result ID if successful, or -1 if the operation fails.

updateTracker()

updateTracker(policyId, trackerId, trSyntax): Promise<number>
Defined in: src/modules/rules-engine.ts:848 Asynchronously updates a tracker in the rules engine component contract.

Parameters

ParameterTypeDescription
policyIdnumberThe ID of the policy associated with the tracker.
trackerIdnumberThe ID of the tracker to update.
trSyntaxstringA JSON string representing the tracker syntax.

Returns

Promise<number> A promise that resolves to the existing tracker ID is returned. Returns -1 if the operation fails.

Throws

Will retry indefinitely with a 1-second delay between attempts if an error occurs during the contract simulation. Ensure proper error handling or timeout mechanisms are implemented to avoid infinite loops.

create()

static create(rulesEngineAddress, localConfig, client, localConfirmationCount): Promise<Maybe<RulesEngine>>
Defined in: src/modules/rules-engine.ts:191 Creates a Rules Engine instance using the private constructor if the supplied rules engine address is compatible.

Parameters

ParameterTypeDefault valueDescription
rulesEngineAddress`0x${string}`undefinedThe address of the deployed Rules Engine smart contract.
localConfigConfigundefinedThe configuration object containing network and wallet information.
clientanyundefinedThe client instance for interacting with the blockchain.
localConfirmationCountnumber1The number of confirmations (blocks that have passed) to wait before resolving transaction receipts (default is 1).

Returns

Promise<Maybe<RulesEngine>>