createRule(config, rulesEnginePolicyContract, policyId, ruleS, foreignCallNameToID, trackerNameToID): Promise<number>

Asynchronously creates a new rule in the rules engine policy contract.

Parameters

ParameterTypeDescription
configConfig-
rulesEnginePolicyContractobjectThe contract instance for interacting with the rules engine policy.
rulesEnginePolicyContract.abi(object | object | object)[]-
rulesEnginePolicyContract.address`0x${string}`-
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.

Throws

Will log errors to the console if the contract simulation fails and retry the operation after a delay.

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.
  • If the rule creation is successful, it writes the contract, generates a rule modifier, and optionally injects the modifier into the specified contract.

Defined in

src/modules/rules.ts:56