IPcl.changeContractPolicies
changeContractPolicies(ContractPolicyConfig calldata policy) external Upserts the ContractPolicyConfig for a target address. The target must be either a PCL-registered proxy (deployed via deployPclProxy) OR a binary-supported policy-aware precompile — currently only the Privacy precompile at 0x100000000000000000000000000000000000000b. msg.sender must be the target's current contract admin — for a proxy, the account that called deployPclProxy (it became the admin in that same call); for a policy-aware precompile, the admin the chain installed — and the new admin value in the payload replaces the old one atomically with the policy replacement. Passing an empty policies array to a policy-aware precompile is rejected — those targets must always carry at least one PolicySet. Ordinary PCL proxies may carry an empty policies array (equivalent to no contract-scope rules). The chain-wide policyAdmin cannot mutate these configs unless it also happens to be the stored contract admin. The contract scope accepts both ALLOW_LIST_POLICY and DENY_LIST_POLICY, which reference a shared address list by listId rather than carrying addresses inline.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
policy | ContractPolicyConfig | ✓ | The new configuration: _contract is the target address (a registered PCL proxy or a policy-aware precompile address), admin is the next gatekeeper for this target's policy config, and policies is the full replacement PolicySet[]. If _contract is neither — an EOA, an agent wallet, a raw implementation or a contract deployed some other way has no contract policy binding — the call reverts with ContractPolicyNotRegistered(contractAddress). If _contract is a policy-aware precompile and policies is empty, the call reverts with CannotEmpty("policy-aware precompile policies"). |
Returns
void No return value. Emits ContractPoliciesChanged(contractAddress, admin, policies) on success.
Errors
| Code | Name | Description |
|---|---|---|
Unauthorized | Unauthorized | Reverts when msg.sender is not the target's currently stored admin — including on the first call for a new proxy, whose admin is already its deployer. The chain-wide policyAdmin does not bypass this check. |
ContractPolicyNotRegistered | ContractPolicyNotRegistered | Reverts when _contract has no contract policy binding — it was not deployed through deployPclProxy and is not a policy-aware precompile (an EOA, an agent wallet, a raw implementation, a contract deployed some other way). This is the first check after the input is decoded. Encoded as ContractPolicyNotRegistered(address contractAddress). |
PclProxyNotRegistered | PclProxyNotRegistered | Reverts when _contract has a contract policy binding (for example one set in genesis) but is neither a registered PCL proxy nor a policy-aware precompile. A target with no binding gets ContractPolicyNotRegistered instead. Encoded as PclProxyNotRegistered(address contractAddress). |
CannotEmpty | CannotEmpty | Reverts when the target is a policy-aware precompile but policies is empty. Encoded as CannotEmpty(string field) with the field value policy-aware precompile policies. Policy-aware precompiles must always carry at least one PolicySet. |
UnknownPolicyType | UnknownPolicyType | Reverts when a PolicySet.templateId in policies is not a known policy type — including retired ids like DENYLIST_POLICY, OKRW_EAS_TRANSFER_LIMIT_POLICY, OKRW_EAS_PERIODIC_VOLUME_LIMIT_POLICY. Encoded as UnknownPolicyType(string templateId); it is raised while the input is decoded, before the admin check. |
PolicyNotRegistered | PolicyNotRegistered | Reverts when a policy in policies (a nested LOGICAL_POLICY / FOR_EACH_POLICY child included) uses a template that is not registered on this network — the policy admin never registered it, or removed it. Encoded as PolicyNotRegistered(string templateId). On the testnet this is what a policy set using ALLOW_LIST_POLICY gets today: that template is not registered yet. |
AddressListNotFound | AddressListNotFound | Reverts when an ALLOW_LIST_POLICY or DENY_LIST_POLICY in the new policy set references a listId that does not exist — this call checks the reference when it binds the policy. Encoded as AddressListNotFound(uint64 listId). Create the list with IPcl.createAddressList before binding a policy that references it. |
Examples
Bind a DENY_LIST_POLICY to a PCL-wrapped ERC20 proxy
DENY_LIST_POLICY references a shared address list by listId. Create the list once with IPcl.createAddressList, populate it with IPcl.updateAddressList, then bind a policy that references it. Membership changes later without rewriting the PolicySet. The same listId can back multiple policies at both global and contract scope.
import { createWalletClient, createPublicClient, http, encodeAbiParameters, toHex, parseEventLogs } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { iPclAbi as pclAbi } from "@maroo-chain/contracts/abi/precompiles/pcl/IPcl";
const PCL = "0x1000000000000000000000000000000000000005" as const;
const admin = privateKeyToAccount(process.env.ADMIN_KEY as `0x${string}`);
const wallet = createWalletClient({ account: admin, transport: http("https://rpc-testnet.maroo.io") });
const publicClient = createPublicClient({ transport: http("https://rpc-testnet.maroo.io") });
// TODO: replace with the real proxy and admin addresses before production.
const proxyAddress = "0x8f3ac2b1d9e74c05a6b18fe27dc4913e5a0f7b62";
const adminAddress = "0x2c7f09b81a6d3ff1e5a0d4c6bc2a8f7e19dc3a4b";
// 1) Create a shared address list and populate it. The caller becomes the list admin.
// createAddressList returns the new listId; updateAddressList has no return.
const createHash = await wallet.writeContract({
address: PCL,
abi: pclAbi,
functionName: "createAddressList",
});
const createReceipt = await publicClient.waitForTransactionReceipt({ hash: createHash });
const [created] = parseEventLogs({ abi: pclAbi, eventName: "AddressListCreated", logs: createReceipt.logs });
if (!created) throw new Error("createAddressList did not emit AddressListCreated");
const listId = created.args.listId;
await wallet.writeContract({
address: PCL,
abi: pclAbi,
functionName: "updateAddressList",
args: [
listId,
[
"0x5ab7c1e40b8da46f9c7e29d3fa614e97b8f0ac21",
"0x6bc8d2a03e91ffa5b8c4e0f3bd7a0e15c24bda8e",
],
[], // nothing to remove
],
});
// 2) abi.encode(DenyListPolicy({ listId, target })) — a tuple, as the chain decodes it.
// target = 3 is AddressListTarget.Both (reject if either sender or recipient is listed).
const denyListBytes = encodeAbiParameters(
[{
type: "tuple",
components: [
{ type: "uint64", name: "listId" },
{ type: "uint8", name: "target" },
],
}],
[{ listId, target: 3 }],
);
await wallet.writeContract({
address: PCL,
abi: pclAbi,
functionName: "changeContractPolicies",
args: [{
_contract: proxyAddress,
admin: adminAddress,
policies: [{
templateId: "DENY_LIST_POLICY",
policy: denyListBytes,
selector: toHex("", { size: 0 }),
}],
}],
}); Attach a policy set to the Privacy precompile (policy-aware precompile)
Policy-aware precompiles use the same entry point as PCL proxies, but the target address is the precompile itself. Empty policy sets are rejected — swap the rules by submitting a new non-empty PolicySet[] rather than clearing and re-adding.
import { encodeAbiParameters, toHex } from "viem";
const PCL = "0x1000000000000000000000000000000000000005" as const;
const PRIVACY = "0x100000000000000000000000000000000000000b" as const;
// TODO: replace with the real privacy-admin multisig before production.
const privacyAdmin = "0x2c7f09b81a6d3ff1e5a0d4c6bc2a8f7e19dc3a4b";
// Example: a DENY_LIST_POLICY applied to every Privacy call, referencing a
// previously created shared list by listId. target = 3 is AddressListTarget.Both.
const listId = 42n;
const denyListBytes = encodeAbiParameters(
[{
type: "tuple",
components: [
{ type: "uint64", name: "listId" },
{ type: "uint8", name: "target" },
],
}],
[{ listId, target: 3 }],
);
await wallet.writeContract({
address: PCL,
abi: pclAbi,
functionName: "changeContractPolicies",
args: [{
_contract: PRIVACY,
admin: privacyAdmin,
policies: [{
templateId: "DENY_LIST_POLICY",
policy: denyListBytes,
selector: toHex("", { size: 0 }),
}],
}],
});
// NOTE: passing an empty policies array here reverts with
// CannotEmpty("policy-aware precompile policies"). To rotate rules,
// always submit a non-empty replacement set. Decode the CannotEmpty revert when clearing is attempted
The revert data is ABI-encoded with the CannotEmpty(string field) selector; the payload distinguishes this case from other empty-field violations elsewhere in PCL.
import { BaseError, ContractFunctionRevertedError, decodeErrorResult } from "viem";
try {
await wallet.writeContract({
address: PCL,
abi: pclAbi,
functionName: "changeContractPolicies",
args: [{
_contract: PRIVACY,
admin: privacyAdmin,
policies: [], // empty — will revert for policy-aware precompiles
}],
});
} catch (err) {
// viem keeps the revert data on the ContractFunctionRevertedError in the cause chain, not on err.
const revert = err instanceof BaseError ? err.walk((e) => e instanceof ContractFunctionRevertedError) : null;
if (revert instanceof ContractFunctionRevertedError && revert.raw) {
const decoded = decodeErrorResult({ abi: pclAbi, data: revert.raw });
// decoded.errorName === "CannotEmpty"
// decoded.args[0] === "policy-aware precompile policies"
console.error(`changeContractPolicies reverted: ${decoded.errorName}`, decoded.args);
} else {
throw err;
}
}