IPcl.changeContractPolicies
changeContractPolicies(ContractPolicyConfig calldata policy) external Updates an existing set of compliance policies for a smart contract. This call completely replaces the old policy configuration with the new one. To add or remove a single policy, read the existing configuration, modify the PolicySet array, then submit the whole new configuration. The caller must be the currently registered admin for the target contract.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
policy | ContractPolicyConfig | ✓ | A struct containing the target contract address and the new PolicySet[]. Setting the admin field to a new address rotates admin rights atomically with the policy update. |
Returns
Type:
void This function does not return any value.
Errors
| Code | Name | Description |
|---|---|---|
Unauthorized | Unauthorized | Reverts if the msg.sender is not the current policy admin for the contract. |
PolicyNotRegistered | PolicyNotRegistered | Reverts if no policies are currently registered for the target contract. |
Examples
Add a VOLUME_POLICY
Read-modify-write pattern for policy updates. Fetches the current PolicySet[], appends a VOLUME_POLICY capping per-transaction transfer size in aokrw, then submits the combined list. Note that changeContractPolicies replaces the entire PolicySet array; there is no per-entry add/remove call.
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.18;
import {
IPcl,
PolicySet,
ContractPolicyConfig,
VolumePolicy,
VolumeUnitPolicy
} from "@maroo-chain/contracts/IPcl.sol";
contract MyTokenAdmin {
IPcl constant PCL = IPcl(0x1000000000000000000000000000000000000005);
address public myTokenAddress;
function addVolumeLimit(uint256 maxLimitAokrw) external {
// 1. Read existing policies (read-modify-write).
ContractPolicyConfig memory cur = PCL.contractPolicies(myTokenAddress);
// 2. Build a VOLUME_POLICY parameter struct: cap each `aokrw` transfer
// at maxLimitAokrw. The min/max are *per-transaction* (no rolling window).
string[] memory tokens = new string[](1);
tokens[0] = "aokrw";
VolumeUnitPolicy[] memory limits = new VolumeUnitPolicy[](1);
limits[0] = VolumeUnitPolicy({ minLimit: 0, maxLimit: maxLimitAokrw });
bytes memory policyBytes = abi.encode(VolumePolicy({ tokens: tokens, limits: limits }));
PolicySet memory volumeLimit = PolicySet({
templateId: "VOLUME_POLICY",
policy: policyBytes,
selector: bytes4(0) // Apply to every function on the contract
});
// 3. Append to the existing PolicySet[].
PolicySet[] memory newPolicies = new PolicySet[](cur.policies.length + 1);
for (uint i = 0; i < cur.policies.length; i++) newPolicies[i] = cur.policies[i];
newPolicies[cur.policies.length] = volumeLimit;
// 4. Submit the full replacement.
PCL.changeContractPolicies(ContractPolicyConfig({
_contract: myTokenAddress,
admin: address(this), // Keep the same admin
policies: newPolicies
}));
}
}