Call Policy
The call policy limits the target (either contract or EOA) that the UserOp can interact with. If the target is a contract, then you can further specify the functions the UserOp can interact with, as well as putting constraints on the values of the function arguments.
API
import { ParamCondition, toCallPolicy, CallPolicyVersion } from "@zerodev/permissions/policies"
const callPolicy = toCallPolicy({
policyVersion: CallPolicyVersion.V0_0_3,
permissions: [
{
// target address
target: contractAddress,
// Maximum value that can be transferred. In this case we
// set it to zero so that no value transfer is possible.
valueLimit: BigInt(0),
// Contract abi
abi: contractABI,
// Function name
functionName: "mint",
// An array of conditions, each corresponding to an argument for
// the function.
args: [
{
condition: ParamCondition.EQUAL,
value: value,
},
],
},
],
})
const validator = toPermissionValidator(publicClient, {
entryPoint,
kernelVersion,
signer: someSigner,
policies: [
callPolicy,
// ...other policies
],
})target: the target contract to call or address to send ETH to. If this iszeroAddress, then the target can be any contract as long as the ABI matches (or it can be any address if no ABI is specified).valueLimit: the maximum value. that can be transmitted.abi: the contract ABIfunctionName: the function nameselector: if you have multiple functions with the same name, you can distinguish them withselector. For example:selector: toFunctionSelector("transfer(uint256, uint256)").args: an array of conditions, each corresponding to an argument, in the order that the arguments are laid out. usenullto skip an argument.operator: this can beEQUAL,GREATER_THAN,LESS_THAN,GREATER_THAN_OR_EQUAL,LESS_THAN_OR_EQUAL,NOT_EQUAL.value: the value of the argument to use with the operator. For instance,operator = EQUALandvalue = 2would mean "the argument must be equal to 2".
operation: whether this is a call or a delegatecall. Defaults to call.