IPcl.registerContractPolicies
registerContractPolicies(ContractPolicyConfig calldata policy) 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, the admin address for future changes, and an array of UnitPolicy structs to be applied. |
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 `UnitPolicy`s uses a `templateId` that has not been registered on the network. |
Examples
Register a Denylist Policy
This example shows an admin contract setting a simple denylist policy on a token contract. The admin contract itself is designated as the policy admin for future changes.
import { IPcl, PCL_CONTRACT, UnitPolicy, ContractPolicyConfig } from "./IPcl.sol";
contract MyTokenAdmin {
address public myTokenAddress;
constructor(address token) {
myTokenAddress = token;
}
function setInitialDenylist(address[] calldata denylisted) external {
// ABI-encode the address array for the 'parameters' field
bytes memory params = abi.encode(denylisted);
// Create a reference to the 'DENYLIST' policy template
UnitPolicy[] memory policies = new UnitPolicy[](1);
policies[0] = UnitPolicy({
templateId: "DENYLIST",
parameters: params,
paramNames: new string[](1), // Optional for on-chain use
selector: bytes4(0) // Apply to all functions
});
// Create the full configuration
ContractPolicyConfig memory config = ContractPolicyConfig({
_contract: myTokenAddress,
admin: address(this), // This contract is the admin
policies: policies
});
// Call the PCL precompile to register the policy
PCL_CONTRACT.registerContractPolicies(config);
}
}