IPcl.registerContractPolicies
registerContractPolicies(ContractPolicyConfig calldata policy) external Registers a new set of compliance policies for a specific smart contract. This function sets the initial policy configuration. If policies are already registered for the target contract, this call will fail. Use changeContractPolicies to update an existing configuration. The caller must be the designated admin for the contract as defined in the policy struct, or the contract itself.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
policy | ContractPolicyConfig | ✓ | A struct containing the target contract address (_contract), the admin address for future changes, and an array of PolicySet entries to be applied. Each PolicySet is { templateId, policy, selector } where policy is abi.encode'd from the template's parameter struct. |
Returns
Type:
void This function does not return any value.
Errors
| Code | Name | Description |
|---|---|---|
Unauthorized | Unauthorized | Reverts if the msg.sender is not the admin specified in the policy.admin field. |
PolicyAlreadyRegistered | PolicyAlreadyRegistered | Reverts if a policy configuration already exists for the target policy._contract address. |
UnknownPolicyType | UnknownPolicyType | Reverts if one of the PolicySet entries uses a templateId that has not been registered on the network. |
Examples
Register a DENYLIST_POLICY
An admin contract attaches a DENYLIST_POLICY to a token contract. The admin contract itself is designated as the policy admin (so it — and only it — can call changeContractPolicies / removeContractPolicies later).
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.18;
import { IPcl, PolicySet, ContractPolicyConfig, DenylistPolicy } from "@maroo-chain/contracts/IPcl.sol";
contract MyTokenAdmin {
IPcl constant PCL = IPcl(0x1000000000000000000000000000000000000005);
address public myTokenAddress;
constructor(address token) {
myTokenAddress = token;
}
function setInitialDenylist(address[] calldata denylisted) external {
// ABI-encode the DenylistPolicy struct into the PolicySet's `policy` bytes.
DenylistPolicy memory dl = DenylistPolicy({ addresses: denylisted });
bytes memory policyBytes = abi.encode(dl);
PolicySet[] memory policies = new PolicySet[](1);
policies[0] = PolicySet({
templateId: "DENYLIST_POLICY",
policy: policyBytes,
selector: bytes4(0) // Apply to all functions on the contract
});
ContractPolicyConfig memory config = ContractPolicyConfig({
_contract: myTokenAddress,
admin: address(this),
policies: policies
});
PCL.registerContractPolicies(config);
}
}