PCL Policy Structure
Three-tier hierarchy — PolicyTemplate (registered template type) → PolicySet (template + ABI-encoded params + optional selector) → PolicyConfig (the bag of PolicySets that get applied).
PCL stores compliance rules as Solidity-defined ABI tuples, not as JSON objects. The hierarchy has three tiers: a PolicyTemplate (the type of rule, registered by the policy admin) is instantiated as a PolicySet (the type ID plus an ABI-encoded parameters blob plus an optional function selector) and bundled into a PolicyConfig (either the global config or a per-contract config). PolicyTemplate itself is metadata-only — it carries templateId, name, and description, so the shape of each template's parameters must come from the template-specific struct in IPcl.sol.
The Solidity structs
IPcl.sol:struct PolicyTemplate {
string templateId; // e.g. "DENY_LIST_POLICY"
string name;
string description;
}
struct PolicySet {
string templateId; // which template this is an instance of
bytes policy; // abi.encode(<template-specific struct>)
bytes selector; // optional 4-byte function selector; empty bytes = applies to all calls
}
struct GlobalPolicyConfig {
PolicySet[] policies;
}
struct ContractPolicyConfig {
address _contract; // the contract this applies to
address admin; // who can change this config later
PolicySet[] policies;
} PolicySet.policy — it is bytes carrying the ABI encoding of the template-specific parameter struct. Don't construct it as JSON; use abi.encode(<struct>) from the Solidity / ethers / viem side. Each PolicySet binds exactly one policy instance; to apply multiple rules to the same scope, submit multiple PolicySet entries in the enclosing PolicyConfig.policies array. PolicyTemplate is a pure descriptor: templateId (the machine-readable ID), a human-readable name, and a description. It does not embed a parameter schema; consult the template-specific struct in IPcl.sol to learn the parameter shape for each templateId.Address lists are shared, referenced by ID
listId and declares which endpoint of the operation (From, To, or Both) to inspect. This lets the same list back many policies, and lets the list admin add or remove members without rewriting any PolicySet. The v0.10 inline DENYLIST_POLICY (with its own address[] addresses) was REMOVED in v0.11 — its id is reserved and the testnet rejects it with UnknownPolicyType. The upgrade migrated every inline denylist into an address list and bound a DENY_LIST_POLICY referencing it.enum AddressListTarget { Unspecified, From, To, Both }
enum AddressListStatus { Unspecified, Active, Disabled }
struct AddressList {
uint64 id;
address admin;
AddressListStatus status;
}
// The two list-referencing templates:
struct AllowListPolicy { uint64 listId; AddressListTarget target; }
struct DenyListPolicy { uint64 listId; AddressListTarget target; } DenyListPolicy may be used at global OR contract scope; an AllowListPolicy is contract-scope only. The list itself is managed through IPcl.createAddressList, IPcl.updateAddressList(listId, add, remove), IPcl.changeAddressListAdmin, and IPcl.setAddressListStatus. Only the list's current admin may mutate it; setting the status to Disabled keeps the list readable but makes any referencing policy revert with AddressListDisabled(listId) at evaluation time. A policy whose target is Both checks both endpoints against the list; use From or To to constrain only one side.How callers construct a PolicySet
pcl-policy-templates for the full list). To register a policy you:1. Build the template-specific struct with concrete values.
2. Encode it as bytes via
abi.encode.3. Wrap in a
PolicySet with the template id and (optionally) a 4-byte function selector.Example — deny-listing via a shared address list. First create the list and populate it; then bind a
DENY_LIST_POLICY that references it.import { IPcl, PolicySet, ContractPolicyConfig, DenyListPolicy, AddressListTarget } from "@maroo-chain/contracts/precompiles/pcl/IPcl.sol";
function buildDenyListPolicy(address pcl, address sanctionedA, address sanctionedB) internal returns (PolicySet memory) {
// 1) Create a shared list and add members. The caller becomes the list admin.
// The PCL precompile has no EVM bytecode, and solc's code-size check reverts a
// high-level call to a function that returns nothing (updateAddressList), so both
// calls go low-level; createAddressList returns the new listId.
(bool ok, bytes memory ret) = pcl.call(abi.encodeCall(IPcl.createAddressList, ()));
require(ok, "createAddressList reverted");
uint64 listId = abi.decode(ret, (uint64));
address[] memory toAdd = new address[](2);
toAdd[0] = sanctionedA;
toAdd[1] = sanctionedB;
address[] memory toRemove = new address[](0);
(ok, ret) = pcl.call(abi.encodeCall(IPcl.updateAddressList, (listId, toAdd, toRemove)));
if (!ok) { assembly { revert(add(ret, 32), mload(ret)) } }
// 2) Build the policy that references the list.
DenyListPolicy memory dl = DenyListPolicy({
listId: listId,
target: AddressListTarget.Both // reject if either sender or recipient is listed
});
return PolicySet({
templateId: "DENY_LIST_POLICY",
policy: abi.encode(dl),
selector: "" // empty → applies to all calls in this scope
});
} ContractPolicyConfig and submit via IPcl.changeContractPolicies(...), or set at global scope via IPcl.setGlobalPolicies(...). Multiple PolicySet entries can share the same enclosing config — but each selector value may appear at most once within a single config (a duplicate selector reverts with the typed error InvalidParameter(bytes input); see the selector field below).Global vs Contract policies
GlobalPolicyConfig— applied to every transaction on the chain. Managed by the chain-wide policy admin (seepcl-policy-admin). Typical contents: aDENY_LIST_POLICYreferencing a sanctions list, a periodic-volume cap on un-attested users, etc.ContractPolicyConfig— applied only when a transaction targets a specific contract address through the PCL-wrapped proxy hook path. Each contract config carries its ownadminso the contract owner can update its own policies independently of the chain-wide admin. Only contract scope acceptsALLOW_LIST_POLICY.
When a transaction comes in, PCL evaluates the applicable policies in the global config (see the selector section below for which entries apply). If the call also targets a contract with a registered ContractPolicyConfig and goes through the regulated path, the applicable policies in that contract config run as well. Any single failure rejects the whole transaction with the corresponding ReasonCode.
The selector field
PolicySet carries an optional selector (4-byte function selector encoded as bytes). When non-empty, the policy only applies to calls invoking a function with that selector on the target contract. This lets a single scope apply different rules to different functions:import {
EasPolicy, PolicySet, LogicalPolicy, ForEachPolicy, LogicalQuantifier, ForEachQuantifier,
ForEachSubject, VolumePolicy, VolumeUnitPolicy, PeriodicVolumePolicy, UnitPeriodicVolumePolicy,
ContractPolicyConfig, GlobalPolicyConfig, AllowListPolicy, DenyListPolicy, AddressListTarget
} from "@maroo-chain/contracts/precompiles/pcl/IPcl.sol";
// the policy this selector rule carries (see the VOLUME_POLICY page for the fields):
string[] memory toks = new string[](1);
toks[0] = "atokrw";
VolumeUnitPolicy[] memory lims = new VolumeUnitPolicy[](1);
lims[0] = VolumeUnitPolicy({ minLimit: 0, maxLimit: 10_000_000 ether });
VolumePolicy memory volumePolicy = VolumePolicy({ tokens: toks, limits: lims });
// rule applies only to calls of `foo(uint256)`:
bytes memory fooSel = abi.encodePacked(bytes4(keccak256("foo(uint256)")));
PolicySet memory ps = PolicySet({
templateId: "VOLUME_POLICY",
policy: abi.encode(volumePolicy),
selector: fooSel
}); selector ("") means "any call in this scope." Within a single config, every PolicySet must use a distinct selector value — reusing the same selector across two entries reverts with the typed error InvalidParameter(bytes input), where input is that selector as text — its lowercase hex without 0x (for example the bytes of "a9059cbb"), or __all__ for the empty selector. Decode it with decodeErrorResult like any other PCL error, then read input as text (viem's hexToString).Selector matching applies to both scopes:
- Global config — PCL first evaluates the empty-selector
PolicySet(a chain-wide rule such as a universalDENY_LIST_POLICY), then the entry whose selector matches the 4-byte function selector of the call it is checking, if any. For the transaction's own call that selector ismsg.data[:4]. A call into a PCL-wrapped proxy (or a UserOperation's call through a trusted EntryPoint) is checked again inpreCall/postCallwith that call's own selector, so a transaction that reaches a proxy through another contract (Multicall3, a router,handleOps) can run the selector-matched global entries for both its outer and its inner call. - Contract config — same rule, scoped to the target proxy: the empty-selector entry runs before the entry for the proxy call's selector.
Order matters: the empty-selector entry runs first, so a coarse chain-wide check (e.g. a shared sanctions deny-list) can short-circuit before a per-function rule is even considered.