Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 0 additions & 140 deletions delegation-toolkit/concepts/delegation.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
description: Learn about caveat enforcers and how they restrict delegations.
sidebar_position: 4
sidebar_position: 2
---

# Caveat enforcers

The MetaMask Delegation Toolkit provides *caveat enforcers*, which are smart contracts that implement rules and restrictions (*caveats*) on delegations.
They serve as the underlying mechanism that enables conditional execution within the [Delegation Framework](delegation.md#delegation-framework).
They serve as the underlying mechanism that enables conditional execution within the [Delegation Framework](index.md#delegation-framework).

A caveat enforcer acts as a gate that validates whether a delegation can be used for a particular execution. When a delegate attempts to execute an action on behalf of a delegator, each caveat enforcer specified in the delegation evaluates whether the execution meets its defined criteria.

Expand Down Expand Up @@ -119,23 +119,23 @@ This "all-or-nothing" approach ensures that delegations only execute exactly as

## Caveat builder

While caveat enforcers operate at the smart contract level, most developers interact with them through the [`CaveatBuilder`](../guides/create-delegation/restrict-delegation.md) interface in the MetaMask Delegation Toolkit.
While caveat enforcers operate at the smart contract level, most developers interact with them through the [`CaveatBuilder`](../../guides/delegation/restrict-delegation.md) interface in the MetaMask Delegation Toolkit.

The `CaveatBuilder` provides a developer-friendly TypeScript API that:

- Abstracts away the complexity of correctly formatting and encoding caveat terms.
- Provides type-checking and validation for caveat parameters.
- Handles the creation of the `caveats` array needed when creating a delegation.

Each [caveat type](../reference/caveats.md) in the `CaveatBuilder`
Each [caveat type](../../reference/caveats.md) in the `CaveatBuilder`
corresponds to a specific caveat enforcer contract. For example, when you use:

```typescript
caveatBuilder.addCaveat("allowedTargets", ["0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92"]);
```

The builder is creating a caveat that references the
[`AllowedTargetsEnforcer`](../reference/caveats.md#allowedtargets) contract address and
[`AllowedTargetsEnforcer`](../../reference/caveats.md#allowedtargets) contract address and
properly encodes the provided addresses as terms for that enforcer.

## Caveat enforcer best practices
Expand All @@ -145,26 +145,26 @@ When designing delegations with caveats, consider these best practices:
- **Combine caveat enforcers appropriately** - Use multiple caveat enforcers to create comprehensive restrictions.

- **Consider caveat enforcer order** - When using caveat enforcers that modify external contract states, the order matters.
For example, using [`NativeTokenPaymentEnforcer`](../reference/caveats.md#nativetokenpayment) before
[`NativeBalanceChangeEnforcer`](../reference/caveats.md#nativebalancechange) might cause validation failures.
For example, using [`NativeTokenPaymentEnforcer`](../../reference/caveats.md#nativetokenpayment) before
[`NativeBalanceChangeEnforcer`](../../reference/caveats.md#nativebalancechange) might cause validation failures.

- **Be careful with unbounded delegations** - Always include appropriate caveat enforcers to limit what a delegate can do.

## Available caveat enforcers

The Delegation Toolkit provides [many out-of-the-box caveat enforcers](../reference/caveats.md)
The Delegation Toolkit provides [many out-of-the-box caveat enforcers](../../reference/caveats.md)
for common restriction patterns, including:

- Limiting target addresses and methods.
- Setting time or block number constraints.
- Restricting token transfers and approvals.
- Limiting execution frequency.

For more complex scenarios, you can also [create custom caveat enforcers](../guides/create-delegation/create-custom-caveat-enforcer.md) by implementing the `ICaveatEnforcer` interface.
For more complex scenarios, you can also [create custom caveat enforcers](../../guides/delegation/create-custom-caveat-enforcer.md) by implementing the `ICaveatEnforcer` interface.

## Attenuating authority with redelegations

When [creating chains of delegations](../guides/create-delegation/index.md#create-a-redelegation), it's important to understand how authority flows and can be restricted.
When creating chains of delegations via [redelegations](index.md#delegation-types), it's important to understand how authority flows and can be restricted.

Caveats applied to a chain of delegations are *accumulative*—they stack on top of each other:

Expand Down
Loading
Loading