PolicyBuilder
Fluent API for drafting policies from constraints.
Functions
createRaw
Creates a selectorless draft from a comma-separated type list.
function createRaw(string memory typesCsv) internal pure returns (PolicyDraft memory draft);Parameters
| Name | Type | Description |
|---|---|---|
typesCsv | string | The comma-separated ABI types (for example "uint256,address"). |
Returns
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The initialized draft. |
create
Creates a draft from a function signature.
function create(string memory signature) internal pure returns (PolicyDraft memory draft);Parameters
| Name | Type | Description |
|---|---|---|
signature | string | The function signature. |
Returns
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The initialized draft. |
add
Adds a constraint to the active group with validation. A path through Path.ALL or Path.ANY adds
its operators to the body of the group's loop over that array with that quantifier.
function add(PolicyDraft memory draft, Constraint memory constraint) internal pure returns (PolicyDraft memory);Parameters
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The draft state. |
constraint | Constraint | The constraint to add. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | PolicyDraft | The updated draft state with the constraint's rules appended. |
or
Starts a new constraint group (OR semantics between groups).
function or(PolicyDraft memory draft) internal pure returns (PolicyDraft memory);Parameters
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The draft state. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | PolicyDraft | The updated draft state with a new empty group. |
build
Builds the final policy blob with strict validation.
Reverts with the storage validation error of a blob that fails it, and with every validation issue when there is any.
function build(PolicyDraft memory draft) internal pure returns (bytes memory policy);Parameters
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The draft state to build from. |
Returns
| Name | Type | Description |
|---|---|---|
policy | bytes | The encoded policy blob. |
buildUnsafe
Builds the final policy blob without validation.
Skips validation. The resulting policy can be invalid.
function buildUnsafe(PolicyDraft memory draft) internal pure returns (bytes memory);Parameters
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The draft state to build from. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes | The encoded policy blob. |
validate
Validates the policy that a draft contains.
function validate(PolicyDraft memory draft) internal pure returns (Issue[] memory);Parameters
| Name | Type | Description |
|---|---|---|
draft | PolicyDraft | The draft state to validate. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Issue[] | Every issue validation reports on the encoded policy. |
Errors
NoConstraintOperators
Thrown when the constraint has no operators.
error NoConstraintOperators();InvalidContextPath
Thrown when a context-scope path does not have exactly one step.
error InvalidContextPath(uint256 depth);Parameters
| Name | Type | Description |
|---|---|---|
depth | uint256 | The path depth. |
UnknownPathStep
Thrown when a path step lies in the reserved marker range and is neither Path.ALL nor Path.ANY.
error UnknownPathStep(bytes path, uint256 stepIndex);Parameters
| Name | Type | Description |
|---|---|---|
path | bytes | The encoded be16 path. |
stepIndex | uint256 | The step index of the marker. |
InvalidNestedLoop
Thrown when a path contains more than one quantifier step.
error InvalidNestedLoop(bytes path, uint256 stepIndex);Parameters
| Name | Type | Description |
|---|---|---|
path | bytes | The encoded be16 path. |
stepIndex | uint256 | The step index of the second quantifier. |
SetTooLarge
Thrown when a set contains more members than the data length can represent at its operand type's width.
error SetTooLarge();EmptyGroup
Thrown when a group is empty.
error EmptyGroup(uint256 groupIndex);Parameters
| Name | Type | Description |
|---|---|---|
groupIndex | uint256 | The index of the empty group. |