Caveats reference
When constraining a delegation scope, you can specify the following caveat types.
You can use either a string literal or the CaveatType enum to define the caveat type.
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 enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: AllowedCalldataEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
startIndex | number | Yes | The index in the calldata byte array (including the 4-byte method selector) where the expected calldata starts. |
value | Hex | Yes | The expected calldata that must match at the specified index. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const value = encodeAbiParameters(
[{ type: 'string' }, { type: 'uint256' }],
['Hello Gator', 12345n]
)
const caveats = [
{
type: CaveatType.AllowedCalldata,
startIndex: 4,
value,
},
]
This example uses Viem's encodeAbiParameters utility to encode the parameters as ABI-encoded hex strings.
allowedMethods
Limits what methods the delegateDelegate account The account that receives delegated authority and can redeem a delegation under its constraints. can call.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: AllowedMethodsEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
selectors | MethodSelector[] | Yes | The list of method selectors that the delegate is allowed to call. The selector value can be 4-byte hex string, ABI function signature, or ABI function object. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.AllowedMethods,
selectors: [
// 4-byte Hex string.
'0xa9059cbb',
// ABI function signature.
'transfer(address,uint256)',
// ABI function object.
{
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 delegateDelegate account The account that receives delegated authority and can redeem a delegation under its constraints. can call.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: AllowedTargetsEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
targets | Address[] | Yes | The list of addresses that the delegate is allowed to call. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.AllowedTargets,
targets: [
'0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92',
'0xB2880E3862f1024cAC05E66095148C0a9251718b',
],
},
]
argsEqualityCheck
Ensures that the args provided when redeeming the delegation are equal to the terms specified on the caveat.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ArgsEqualityCheckEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
args | Hex | Yes | The expected arguments that must match exactly when redeeming the delegation. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.ArgsEqualityCheck,
args: '0xf2bef872456302645b7c0bb59dcd96ffe6d4a844f311ebf95e7cf439c9393de2',
},
]
blockNumber
Specifies a range of blocks through which the delegation will be valid.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: BlockNumberEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
afterThreshold | bigint | Yes | The block number after which the delegation is valid. Set the value to 0n to disable this threshold. |
beforeThreshold | bigint | Yes | The block number before which the delegation is valid. Set the value to 0n to disable this threshold. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.BlockNumber,
afterThreshold: 19426587n,
beforeThreshold: 0n,
},
]
deployed
Ensures a contract is deployed, and if not, deploys the contract.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: DeployedEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | Address | Yes | The contract address. |
salt | Hex | Yes | The salt to use with the deployment. |
bytecode | Hex | Yes | The bytecode of the contract. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.Deployed,
contractAddress: '0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92',
salt: '0x0e3e8e2381fde0e8515ed47ec9caec8ba2bc12603bc2b36133fa3e3fa4d88587',
bytecode: '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 enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ERC1155BalanceChangeEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-1155 token contract address. |
recipient | Address | Yes | The address on which the checks will be applied. |
tokenId | bigint | Yes | The ID of the ERC-1155 token. |
balance | bigint | Yes | The amount by which the balance must be changed. |
changeType | BalanceChangeType | Yes | The balance change type for the ERC-1155 token. Specifies whether the balance should have increased or decreased. Valid parameters are BalanceChangeType.Increase and BalanceChangeType.Decrease. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.Erc1155BalanceChange,
tokenAddress: '0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92',
recipient: '0x3fF528De37cd95b67845C1c55303e7685c72F319',
tokenId: 1n,
balance: 1000000n,
changeType: 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 enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ERC20BalanceChangeEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-20 token contract address. |
recipient | Address | Yes | The address on which the checks will be applied. |
balance | bigint | Yes | The amount by which the balance must be changed. |
changeType | BalanceChangeType | Yes | The balance change type for the ERC-20 token. Specifies whether the balance should have increased or decreased. Valid parameters are BalanceChangeType.Increase and BalanceChangeType.Decrease. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
const caveats = [
{
type: CaveatType.Erc20BalanceChange,
tokenAddress: '0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92',
recipient: '0x3fF528De37cd95b67845C1c55303e7685c72F319',
balance: 1000000n,
changeType: 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 enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ERC20PeriodTransferEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-20 token contract address as a hex string. |
periodAmount | bigint | Yes | The maximum amount of tokens that can be transferred per period. |
periodDuration | number | Yes | The duration of each period in seconds. |
startDate | number | Yes | The timestamp when the first period begins in seconds. |
Example
import { CaveatType } from '@metamask/smart-accounts-kit'
// Current time as start date.
// Since startDate is in seconds, we need to convert milliseconds to seconds.
const startDate = Math.floor(Date.now() / 1000)
const caveats = [
{
type: CaveatType.Erc20PeriodTransfer,
// Address of the ERC-20 token.
tokenAddress: '0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da',
// 1 ERC-20 token - 18 decimals, in wei.
periodAmount: 1000000000000000000n,
// 1 day in seconds.
periodDuration: 86400,
startDate,
},
]
erc20Streaming
Enforces a linear streaming transfer limit for ERC-20 tokens. Block token access until the specified start timestamp. At the start timestamp, immediately release the specified initial amount. Afterward, accrue tokens linearly at the specified rate, up to the specified maximum.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ERC20StreamingEnforcer.sol
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-20 token contract address. |
initialAmount | bigint | Yes | The initial amount that can be transferred at start time. |
maxAmount | bigint | Yes | The maximum total amount that can be unlocked. |
amountPerSecond | bigint | Yes | The rate at which tokens accrue per second. |
startTime | number | Yes | The start timestamp in seconds. |
Example
import { CaveatType } from "@metamask/smart-accounts-kit";
// Current time as start date.
// Since startDate is in seconds, we need to convert milliseconds to seconds.
const startDate = Math.floor(Date.now() / 1000);
const caveats = [{
type: CaveatType.Erc20Streaming,
// Address of the ERC-20 token.
tokenAddress: "0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
// 1 ERC-20 token - 18 decimals, in wei.
initialAmount: 1000000000000000000n,
// 10 ERC-20 token - 18 decimals, in wei.
maxAmount: 10000000000000000000n
// 0.00001 ERC-20 token - 18 decimals, in wei.
amountPerSecond: 10000000000000n,
startDate,
}];
erc20TransferAmount
Limits the transfer of ERC-20 tokens.
Caveat enforcerCaveat enforcer A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. contract: ERC20TransferAmountEnforcer.sol