PolicyBuilder
ThePolicyBuilder provides a fluent (chainable) API for constructing policies. It validates your configuration at build time and produces a well-formed Policy object.
Basic Usage
Constructor
| Parameter | Type | Description |
|---|---|---|
id | string | A unique, human-readable identifier for the policy |
Tier 1 Methods (Stateless On-Chain)
.allowTargets(addresses)
Whitelist contract addresses. Only transactions to these addresses will be allowed.
| Parameter | Type | Description |
|---|---|---|
addresses | Address[] | Array of allowed contract addresses |
PolicyBuilder (for chaining)
.denyTargets(addresses)
Blacklist contract addresses. Transactions to these addresses will be blocked.
| Parameter | Type | Description |
|---|---|---|
addresses | Address[] | Array of denied contract addresses |
PolicyBuilder (for chaining)
.allowSelectors(selectors)
Whitelist function selectors. Only calls to these functions will be allowed.
| Parameter | Type | Description |
|---|---|---|
selectors | Hex[] | Array of 4-byte function selectors |
PolicyBuilder (for chaining)
.denySelectors(selectors)
Blacklist function selectors.
| Parameter | Type | Description |
|---|---|---|
selectors | Hex[] | Array of 4-byte function selectors |
PolicyBuilder (for chaining)
.maxValue(wei)
Set a maximum ETH value per transaction.
| Parameter | Type | Description |
|---|---|---|
wei | bigint | Maximum value in wei |
PolicyBuilder (for chaining)
Tier 2 Methods (Stateful On-Chain)
.spendLimit(token, amount, windowSeconds)
Set a spending limit for a specific ERC-20 token within a rolling time window.
| Parameter | Type | Description |
|---|---|---|
token | Address | ERC-20 token contract address |
amount | bigint | Maximum spend amount in token decimals |
windowSeconds | number | Rolling time window in seconds |
PolicyBuilder (for chaining)
.cooldown(seconds)
Enforce a minimum time between transactions.
| Parameter | Type | Description |
|---|---|---|
seconds | number | Minimum seconds between transactions |
PolicyBuilder (for chaining)
Tier 3 Methods (Off-Chain)
.maxSlippageBps(bps)
Set maximum acceptable slippage for swap transactions.
| Parameter | Type | Description |
|---|---|---|
bps | number | Maximum slippage in basis points (1 bps = 0.01%) |
PolicyBuilder (for chaining)
.requireSimulation(enabled)
Require that the transaction succeeds when simulated.
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | Whether simulation is required |
PolicyBuilder (for chaining)
.customRule(config)
Add a custom off-chain rule with IPFS-hosted logic.
| Parameter | Type | Description |
|---|---|---|
config.name | string | Human-readable rule name |
config.description | string | Description of what the rule checks |
config.cid | string | IPFS CID of the rule logic |
config.params | Record<string, unknown> | Parameters passed to the rule logic |
PolicyBuilder (for chaining)
Configuration Methods
.setFailMode(mode)
Set the fail mode for off-chain rule evaluation.
| Parameter | Type | Description |
|---|---|---|
mode | "closed" | "open" | Fail mode |
PolicyBuilder (for chaining)
Build
.build()
Validate and build the policy.
Policy
Throws: ValidationError if the policy configuration is invalid.
Validation checks include:
- At least one rule is defined
- Rule parameters are within valid ranges
- Addresses are valid checksummed hex
- Selectors are exactly 4 bytes
- Spend limit amounts are positive
- Cooldown and window values are positive integers

