You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: delegation-toolkit/concepts/delegation/index.md
+25-30Lines changed: 25 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,24 +22,22 @@ For example: Alice delegates the ability to spend her USDC to Bob, limiting the
22
22
23
23
The delegation lifecycle is as follows:
24
24
25
-
1.**Create a delegation** - The delegator account creates and signs a delegation.
26
-
27
-
2.**Apply caveats** - The caveats applied to the delegation specify conditions under which
28
-
the delegation can be redeemed.
25
+
1.**Create a delegation** - The delegator account creates a delegation, applying *caveats* which specify conditions under which the delegation can be redeemed.
26
+
The delegator signs the delegation.
29
27
30
28
3.**Store the delegation** - A dapp can store the delegation, enabling retrieval for future redemption.
31
29
32
30
4.**Redeem the delegation** - The delegate (the account being granted the permission) redeems the delegation via the Delegation Manager,
33
31
which verifies that the delegated authority is valid in order to perform the execution.
34
32
35
-
See [how to perform executions on a user's behalf](../../guides/delegation/execute-on-users-behalf.md) to get started with the delegation lifecycle.
33
+
See [how to perform executions on a smart account's behalf](../../guides/delegation/execute-on-smart-accounts-behalf.md) to get started with the delegation lifecycle.
36
34
37
35
## Delegation types
38
36
39
37
You can create the following delegation types:
40
38
41
-
-**Root delegation** - A root delegation is a delegation that doesn't derive its authority from another delegation.
42
-
It is when a delegator delegates its own authority away.
39
+
-**Root delegation** - A root delegation is when a delegator delegates their own authority away, as opposed to *redelegating* permissions they received from a previous delegation.
40
+
In a chain of delegations, the first delegation is the root delegation.
43
41
For example, Alice delegates the ability to spend her USDC to Bob, limiting the amount to 100 USDC.
44
42
45
43
Use [`createDelegation`](../../reference/api/delegation.md#createdelegation) to create a root delegation.
@@ -49,7 +47,7 @@ You can create the following delegation types:
49
47
For example, Alice delegates the ability to spend 100 of her USDC to anyone.
50
48
51
49
You must create open root delegations carefully, to ensure that they are not misused.
52
-
Use [`createOpenDelegation`](../../reference/api/delegation.md#createopendelegation) to create a root delegation.
50
+
Use [`createOpenDelegation`](../../reference/api/delegation.md#createopendelegation) to create an open root delegation.
53
51
54
52
-**Redelegation** - A delegate can redelegate permissions that have been granted to them, creating a chain of delegations across trusted parties.
55
53
For example, Alice delegates the ability to spend 100 of her USDC to Bob.
@@ -87,18 +85,18 @@ It consists of the following components:
87
85
88
86
1. Validates the input data by ensuring the lengths of `delegations`, `modes`, and
89
87
`executions` match.
90
-
2. Decodes and validates the delegation, checking that the caller is the delegate
88
+
2. Decodes and validates the delegation, checking that the caller is the delegate
91
89
and that there are no empty signatures.
92
-
3. Verifies delegation signatures, ensuring validity using ECDSA (for EOAs) or
90
+
3. Verifies delegation signatures, ensuring validity using ECDSA (for EOAs) or
93
91
`isValidSignature` (for contracts).
94
-
4. Validates the delegation chain's authority and ensures delegations are not disabled.
95
-
5. Executes the `beforeHook` for each [caveat](caveat-enforcers.md) in the delegation, passing relevant data (`terms`,
92
+
4. Validates the delegation chain's authority and ensures delegations are not disabled.
93
+
5. Executes the `beforeHook` for each [caveat](caveat-enforcers.md) in the delegation, passing relevant data (`terms`,
96
94
`arguments`, `mode`, `execution``calldata`, and `delegationHash`) to the caveat enforcer.
97
-
6. Calls `executeFromExecutor` to perform the delegation's execution, either by the delegator or
95
+
6. Calls `executeFromExecutor` to perform the delegation's execution, either by the delegator or
98
96
the caller for self-authorized executions.
99
-
7. Executes the `afterHook` for each caveat, similar to the `beforeHook`, passing required data
97
+
7. Executes the `afterHook` for each caveat, similar to the `beforeHook`, passing required data
100
98
to enforce post-execution conditions.
101
-
8. Emits `RedeemedDelegation` events for each delegation that was successfully redeemed.
99
+
8. Emits `RedeemedDelegation` events for each delegation that was successfully redeemed.
102
100
103
101
-**Caveat enforcers** - [Caveat enforcers](caveat-enforcers.md) manage rules and restrictions for delegations,
104
102
providing fine-tuned control over delegated executions.
@@ -154,32 +152,29 @@ sequenceDiagram
154
152
## Execution modes
155
153
156
154
When redeeming a delegation using [`redeemDelegations`](../../reference/api/delegation.md#redeemdelegations), you must pass an execution mode for each delegation chain you pass to the method.
157
-
The Delegation Toolkit supports several execution modes based on [ERC-7579](https://erc7579.com/): `SINGLE_DEFAULT_MODE`, `SINGLE_TRY_MODE`, `BATCH_DEFAULT_MODE`, and `BATCH_TRY_MODE`.
155
+
The Delegation Toolkit supports the following execution modes, based on [ERC-7579](https://erc7579.com/):
156
+
157
+
| Execution mode | Number of delegation chains passed to `redeemDelegations`| Processing method | Does user operation continue execution if redemption reverts? |
158
+
|--|--|--|--|
159
+
|`SINGLE_DEFAULT_MODE`| One | Sequential | No |
160
+
|`SINGLE_TRY_MODE`| One | Sequential | Yes |
161
+
|`BATCH_DEFAULT_MODE`| Multiple | Interleaved | No |
162
+
|`BATCH_TRY_MODE`| Multiple | Interleaved | Yes |
158
163
159
-
### `SINGLE` execution modes
164
+
### Sequential processing
160
165
161
-
In `SINGLE` modes, you can provide only one delegation chain and one execution.
162
-
Processing is sequential:
166
+
In `SINGLE` modes, processing is sequential:
163
167
164
168
1. For each delegation in the chain, all caveats' `before` hooks are called.
165
169
2. The single redeemed action is executed.
166
170
3. For each delegation in the chain, all caveats' `after` hooks are called.
167
171
168
-
### `BATCH` execution modes
172
+
### Interleaved processing
169
173
170
-
In `BATCH` modes, you can provide multiple delegation chains and multiple executions.
171
-
Processing is interleaved:
174
+
In `BATCH` modes, processing is interleaved:
172
175
173
176
1. For each chain in the batch, and each delegation in the chain, all caveats' `before` hooks are called.
174
177
2. Each redeemed action is executed.
175
178
3. For each chain in the batch, and each delegation in the chain, all caveats' `after` hooks are called.
176
179
177
180
`BATCH` mode allows for powerful use cases, but the Delegation Framework currently does not include any `BATCH` compatible caveat enforcers.
178
-
179
-
### `DEFAULT` modes
180
-
181
-
In `DEFAULT` modes, if a revert occurs during redemption, the entire user operation reverts at that point.
182
-
183
-
### `TRY` modes
184
-
185
-
In `TRY` modes, if a revert occurs during redemption, execution of the user operation continues.
- To grant specific permissions to other accounts from your smart account, [create a delegation](../../guides/delegation/execute-on-users-behalf.md).
159
+
- To grant specific permissions to other accounts from your smart account, [create a delegation](../../guides/delegation/execute-on-smart-accounts-behalf.md).
160
160
- To quickly bootstrap a MetaMask Smart Accounts project, [use the CLI](../use-the-cli.md).
161
161
- You can also [use MetaMask SDK to upgrade a MetaMask account to a smart account](/sdk/tutorials/upgrade-eoa-to-smart-account).
- To grant specific permissions to other accounts from your smart account, [create a delegation](../../guides/delegation/execute-on-users-behalf.md).
97
+
- To grant specific permissions to other accounts from your smart account, [create a delegation](../../guides/delegation/execute-on-smart-accounts-behalf.md).
98
98
- This quickstart example uses a Hybrid smart account.
99
99
You can also [configure other smart account types](../../guides/smart-accounts/create-smart-account.md).
100
100
- To upgrade an EOA to a smart account, see the [EIP-7702 quickstart](eip7702.md).
Copy file name to clipboardExpand all lines: delegation-toolkit/guides/delegation/execute-on-smart-accounts-behalf.md
+8-12Lines changed: 8 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
-
description: Use delegations to perform executions on a user's behalf.
2
+
description: Use delegations to perform executions on a smart account's behalf.
3
3
sidebar_position: 1
4
-
sidebar_label: Execute on a user's behalf
4
+
sidebar_label: Execute on a smart account's behalf
5
5
---
6
6
7
7
import Tabs from "@theme/Tabs";
8
8
import TabItem from "@theme/TabItem";
9
9
10
-
# Perform executions on a user's behalf
10
+
# Perform executions on a smart account's behalf
11
11
12
12
[Delegation](../../concepts/delegation/index.md) is the ability for a [MetaMask smart account](../../concepts/smart-accounts.md) to grant permission to another account to perform executions on its behalf.
Create an account to represent Alice, the delegator who will create a delegation.
55
55
The delegator must be a MetaMask smart account; use the toolkit's [`toMetaMaskSmartAccount`](../../reference/api/smart-account.md#tometamasksmartaccount) method to create the delegator account.
56
56
57
-
This example configures a Hybrid smart account,
58
-
which is a flexible smart account implementation that supports both an externally owned account (EOA) owner and any number of P256 (passkey) signers:
57
+
A Hybrid smart account is a flexible smart account implementation that supports both an externally owned account (EOA) owner and any number of P256 (passkey) signers.
58
+
This examples configures a [Hybrid smart account with an Account signatory](../smart-accounts/create-smart-account.md#create-a-hybrid-smart-account-with-an-account-signatory):
Create a [root delegation](../../concepts/delegation/index.md#delegation-types) from Alice to Bob.
124
-
A root delegation is a delegation that doesn't derive its authority from another delegation.
125
-
Alice is delegating her own authority away, as opposed to *redelegating* permissions she received from a previous delegation.
124
+
With a root delegation, Alice is delegating her own authority away, as opposed to *redelegating* permissions she received from a previous delegation.
126
125
127
126
Use the toolkit's [`createDelegation`](../../reference/api/delegation.md#createdelegation) method to create a root delegation.
128
127
This example passes an empty `caveats` array, which means Bob can perform any action on Alice's behalf. We recommend [restricting the delegation](restrict-delegation.md) by adding caveat enforcers.
@@ -162,7 +161,9 @@ const signedDelegation = {
162
161
### 7. Redeem the delegation
163
162
164
163
Bob can now redeem the delegation. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on Alice's behalf.
164
+
165
165
To prepare the calldata for the redeem transaction, use the [`redeemDelegations`](../../reference/api/delegation.md#redeemdelegations) method from `DelegationManager`.
166
+
Since Bob is redeeming a single delegation chain, use the [`SINGLE_DEFAULT_MODE`](../../concepts/delegation/index.md#execution-modes) execution mode.
166
167
167
168
Bob can redeem the delegation by submitting a user operation if his account is a smart account, or a regular transaction if his account is an EOA:
Copy file name to clipboardExpand all lines: delegation-toolkit/guides/smart-accounts/create-smart-account.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ You can create a Hybrid smart account with the following types of signatories.
23
23
24
24
### Create a Hybrid smart account with an Account signatory
25
25
26
-
Use [`toMetaMaskSmartAccount`](../../reference/api/smart-account.md#tometamasksmartaccount) and Viem's [`privateKeyToAccount`](https://viem.sh/docs/accounts/local/privateKeyToAccount) to create a Hybrid smart account with a signatory from a private key:
26
+
Use [`toMetaMaskSmartAccount`](../../reference/api/smart-account.md#tometamasksmartaccount), and Viem's [`privateKeyToAccount` and `generatePrivateKey`](https://viem.sh/docs/accounts/local/privateKeyToAccount), to create a Hybrid smart account with a signatory from a randomly generated private key:
27
27
28
28
<Tabs>
29
29
<TabItemvalue="example.ts">
@@ -415,5 +415,5 @@ With a MetaMask smart account, you can perform the following functions:
415
415
416
416
- In conjunction with [Viem Account Abstraction clients](../configure.md), deploy the smart account
417
417
and [send user operations](send-user-operation.md).
418
-
-[Create delegations](../delegation/execute-on-users-behalf.md) that can be used to grant specific rights and permissions to other accounts.
418
+
-[Create delegations](../delegation/execute-on-smart-accounts-behalf.md) that can be used to grant specific rights and permissions to other accounts.
419
419
Smart accounts that create delegations are called *delegator accounts*.
0 commit comments