Caveats
When restricting a delegation, you can specify the following caveat types in the CaveatBuilder
.
allowedCalldata
Limits the calldata that is executed.
You can use this caveat to enforce function parameters.
We strongly recommend using this caveat to validate static types and not dynamic types.
You can validate dynamic types through a series of allowedCalldata
terms, but this is tedious and error-prone.
Caveat enforcer contract: AllowedCalldataEnforcer.sol
Parameters
- Index in the calldata byte array (including the 4-byte method selector) where the expected calldata starts
- Expected calldata as a hex string
Example
caveatBuilder.addCaveat("allowedCalldata",
4,
encodeAbiParameters([
{ type: "string" },
{ type: "uint256" }
], [
"Hello Gator",
12345n
])
);
This example uses Viem's encodeAbiParameters
utility to encode the parameters as ABI-encoded hex strings.
allowedMethods
Limits what methods the delegate can call.
Caveat enforcer contract: AllowedMethodsEnforcer.sol
Parameters
- An array of methods as 4-byte hex strings, ABI function signatures, or
ABIFunction
objects
Example
caveatBuilder.addCaveat("allowedMethods", [
"0xa9059cbb",
"transfer(address,uint256)",
{
name: 'transfer',
type: 'function',
inputs: [
{ name: 'recipient', type: 'address' },
{ name: 'amount', type: 'uint256' }
],
outputs: [],
stateMutability: 'nonpayable',
}
]);
This example adds the transfer
function to the allowed methods in three different ways - as the 4-byte function selector, the ABI function signature, and the ABIFunction
object.
allowedTargets
Limits what addresses the delegate can call.
Caveat enforcer contract: AllowedTargetsEnforcer.sol
Parameters
- An array of addresses as hex strings
Example
caveatBuilder.addCaveat("allowedTargets", [
"0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
"0xB2880E3862f1024cAC05E66095148C0a9251718b"
]);
argsEqualityCheck
Ensures that the args
provided when redeeming the delegation are equal to the terms specified on the caveat.
Caveat enforcer contract: ArgsEqualityCheckEnforcer.sol
Parameters
- The expected
args
as a hex string
Example
caveatBuilder.addCaveat("argsEqualityCheck",
"0xf2bef872456302645b7c0bb59dcd96ffe6d4a844f311ebf95e7cf439c9393de2"
);
blockNumber
Specifies a range of blocks through which the delegation will be valid.
Caveat enforcer contract: BlockNumberEnforcer.sol
Parameters
- After threshold block number as a
bigint
- Before threshold block number as a
bigint
You can specify 0n
to indicate that there is no limitation on a threshold.
Example
caveatBuilder.addCaveat("blocknumber",
19426587n,
0n
);
deployed
Ensures a contract is deployed, and if not, deploys the contract.
Caveat enforcer contract: DeployedEnforcer.sol
Parameters
- A contract address as a hex string
- The salt to use with the contract, as a hex string
- The bytecode of the contract as a hex string
Example
caveatBuilder.addCaveat("deployed",
"0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
"0x0e3e8e2381fde0e8515ed47ec9caec8ba2bc12603bc2b36133fa3e3fa4d88587",
"0x..." // The deploy bytecode for the contract at 0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92
);
erc1155BalanceChange
Ensures that the recipient's ERC-1155 token balance has changed within the allowed bounds — either increased by a minimum or decreased by a maximum specified amount.
Caveat enforcer contract: ERC1155BalanceBalanceEnforcer.sol
Parameters
- An ERC-1155 contract address as a hex string
- The recipient's address as a hex string
- The ID of the ERC-1155 token as a bigint
- The amount by which the balance must have changed as a
bigint
- The balance change type for the ERC-1155 token. Specifies whether the
balance should have increased or decreased. Valid parameters are
BalanceChangeType.Increase
andBalanceChangeType.Decrease
.
Example
caveatBuilder.addCaveat("erc1155BalanceChange",
"0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
"0x3fF528De37cd95b67845C1c55303e7685c72F319",
1n,
1_000_000n,
BalanceChangeType.Increase,
);
erc20BalanceChange
Ensures that the recipient's ERC-20 token balance has changed within the allowed bounds — either increased by a minimum or decreased by a maximum specified amount.
Caveat enforcer contract: ERC20BalanceChangeEnforcer.sol
Parameters
- An ERC-20 contract address as a hex string
- The recipient's address as a hex string
- The amount by which the balance must have changed as a
bigint
- The balance change type for the ERC-20 token. Specifies whether the
balance should have increased or decreased. Valid parameters are
BalanceChangeType.Increase
andBalanceChangeType.Decrease
.
Example
caveatBuilder.addCaveat("erc20BalanceChange",
"0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
"0x3fF528De37cd95b67845C1c55303e7685c72F319",
1_000_000n,
BalanceChangeType.Increase,
);
erc20PeriodTransfer
Ensures that ERC-20 token transfers remain within a predefined limit during a specified time window. At the start of each new period, the allowed transfer amount resets. Any unused transfer allowance from the previous period does not carry over and is forfeited.
Caveat enforcer contract: ERC20PeriodTransferEnforcer.sol
Parameters
- The address of the ERC-20 token contract.
- The maximum amount of tokens that can be transferred per period, in wei.
- The duration of each period in seconds.
- The timestamp when the first period begins.
Example
caveatBuilder.addCaveat("erc20PeriodTransfer",
"0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da", // Address of the ERC-20 token
1000000000000000000n, // 1 ERC-20 token - 18 decimals, in wei
86400, // 1 day in seconds
1743763600, // April 4th, 2025, at 00:00:00 UTC
);