@guardian-network/policy-contracts
v0.3.6
Published
Policy with dynamic conditions defined onchain
Readme
Contracts for Composable policy with arbitrary artifacts system
DO NOT USE IN PRODUCTION.
This implementation is in early development. It has not been reviewed or audited. It is not suitable to be used in production. Expect bugs!
The policy system needs to be backed with all kinds of setellite contracts to work properly. This package provides them.
Predefined artifacts
Provides a set of already writted basic artifacts to start with.
They include some kinds of logical operators, mathematical operations, language constructions and so on.packages/contracts/contracts/pre-definedPolicy handler entrypoint
The main contract a third-party developer will interact with.packages/contracts/contracts/PolicyHandler.sol
Contains 3 crusial methods:
set
Creates the policy using its definition in final representation form (IR translator output, DSL compiler output).evaluate
Evaluates the policy agains provided variables. That is the main method to use when one wants to test if the operation (transaction, action, request, etc) complies with the policy created on step 1 (set). The variables must be provided in a specific format which can be fitted in with the help ofvariablespackage.getVariablesList
Used to obtain, enumerate or show to the client all the variables that must be filled forevaluateto be dispatched. Contains descriptors of the variables, their types and other metadata.
To use the policy system, one needs to deploy PolicyHandler.sol and all needed artifacts (ours or writted by third-party). After this, the following steps are considered standard:
- Create policy
Freshly deployedPolicyHandlerdo not contain any policy logic. Create the policy using DSL or other instrument that translates into FR, and then use the output to invokeset. - Prepare arguments
If the policy contains any variables that need to be filled, usegetVariablesListto get them and format their values in any convenient way (e.g. with the help ofvariablespackage). - Evaluate policy
Use values obtained on step 2 to dispatchevaluatemethod. The policy may pass or reject - get the evaluation result as the method return value or viaEvaluated(bool result, bytes32 rootNode)event.
