Skip to content

Commit 9574dc2

Browse files
update docs for v0.12
1 parent 6b63da5 commit 9574dc2

File tree

6 files changed

+169
-63
lines changed

6 files changed

+169
-63
lines changed

delegation-toolkit/concepts/environment.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Your wallet must have sufficient native token balance to deploy the contracts.
9898
```typescript
9999
import { walletClient, publicClient } from "./config.ts";
100100
import { lineaSepolia as chain } from "viem/chains";
101+
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit/utils";
101102

102103
const environment = await deployDeleGatorEnvironment(
103104
walletClient,
@@ -140,6 +141,7 @@ For example, if you've already deployed the `EntryPoint` contract on the target
140141
// The config.ts is the same as in the previous example.
141142
import { walletClient, publicClient } from "./config.ts";
142143
import { lineaSepolia as chain } from "viem/chains";
144+
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit/utils";
143145

144146
const environment = await deployDeleGatorEnvironment(
145147
walletClient,
@@ -164,11 +166,11 @@ To override the delegator environment, the toolkit provides a `overrideDeployedE
164166
// The config.ts is the same as in the previous example.
165167
import { walletClient, publicClient } from "./config.ts";
166168
import { lineaSepolia as chain } from "viem/chains";
169+
import { DeleGatorEnvironment } from "@metamask/delegation-toolkit";
167170
import {
168-
DeleGatorEnvironment,
169171
overrideDeployedEnvironment,
170-
deployDeleGatorEnvironment
171-
} from "@metamask/delegation-toolkit";
172+
deployDeleGatorEnvironment
173+
} from '@metamask/delegation-toolkit/utils';
172174

173175
const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment(
174176
walletClient,
@@ -190,12 +192,12 @@ If you've already deployed the contracts using a different method, you can creat
190192
- import { walletClient, publicClient } from "./config.ts";
191193
- import { lineaSepolia as chain } from "viem/chains";
192194
// remove-end
195+
import { DeleGatorEnvironment } from "@metamask/delegation-toolkit";
193196
import {
194-
DeleGatorEnvironment,
195197
overrideDeployedEnvironment,
196198
// remove-next-line
197199
- deployDeleGatorEnvironment
198-
} from "@metamask/delegation-toolkit";
200+
} from "@metamask/delegation-toolkit/utils";
199201

200202
// remove-start
201203
- const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment(

delegation-toolkit/get-started/quickstart.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,16 @@ executes actions on the delegator's behalf.
137137
To prepare the calldata for the redeem transaction, use the `redeemDelegation` utility function from the Delegation Toolkit.
138138

139139
```typescript
140-
import {
141-
createExecution,
142-
DelegationFramework,
143-
SINGLE_DEFAULT_MODE,
144-
} from "@metamask/delegation-toolkit";
140+
import { createExecution } from "@metamask/delegation-toolkit";
141+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
142+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
145143
import { zeroAddress } from "viem";
146144

147145
const delegations = [ signedDelegation ];
148146

149-
const executions = createExecution(zeroAddress);
147+
const executions = createExecution({ target: zeroAddress });
150148

151-
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
149+
const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({
152150
delegations: [ delegations ],
153151
modes: [ SINGLE_DEFAULT_MODE ],
154152
executions: [ executions ]

delegation-toolkit/get-started/supported-networks.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,31 @@ If you don't see the network you're looking for, you can request support by emai
1111

1212
## Mainnet networks
1313

14-
| Network Name | v0.10.1 | v0.10.2 | v0.11.0 |
14+
| Network Name | v0.10.2 | v0.11.0 | v0.12.0 |
1515
| ------------------- | ------- | ------- | ------- |
1616
| Ethereum ||||
1717
| Polygon ||||
1818
| Binance Smart Chain ||||
1919
| Optimism ||||
20-
| Arbitrum ||||
20+
| Arbitrum One ||||
2121
| Base ||||
2222
| Gnosis Chain ||||
23+
| Unichain ||||
24+
| Arbitrum Nova ||||
25+
| Berachain ||||
2326

2427
## Testnet networks
2528

26-
| Network Name | v0.10.1 | v0.10.2 | v0.11.0 |
27-
| ---------------- | ------- | ------- | ------- |
28-
| Ethereum Sepolia ||||
29-
| Base Sepolia ||||
30-
| MegaEth ||||
31-
| Gnosis Chiado ||||
29+
| Network Name | v0.10.2 | v0.11.0 | v0.12.0 |
30+
| --------------------------- | ------- | ------- | ------- |
31+
| Ethereum Sepolia ||||
32+
| Base Sepolia ||||
33+
| MegaEth ||||
34+
| Gnosis Chiado ||||
35+
| Arbitrum Sepolia ||||
36+
| Unichain Sepolia ||||
37+
| Berachain Bepolia ||||
38+
| Optimism Sepolia ||||
39+
| Binance Smart Chain ||||
40+
| Polygon Amoy ||||
41+
| Monad ||||

delegation-toolkit/how-to/redeem-delegation.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ It assumes you have a delegation signed by the delegator, and that the delegate
3636
<TabItem value="example.ts">
3737

3838
```typescript
39-
import {
40-
DelegationFramework,
41-
SINGLE_DEFAULT_MODE,
42-
ExecutionStruct
43-
} from "@metamask/delegation-toolkit";
39+
import { ExecutionStruct } from "@metamask/delegation-toolkit";
40+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
41+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
4442
import { bundlerClient, pimlicoClient } from "./client.ts";
4543
import { delegateSmartAccount } from "./account.ts";
4644

@@ -56,7 +54,7 @@ const executions: ExecutionStruct[] = [{
5654
callData: "0x"
5755
}];
5856

59-
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
57+
const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({
6058
delegations: [ delegations ],
6159
modes: [ mode ],
6260
executions: [ executions ]
@@ -139,10 +137,13 @@ The following example demonstrates how to submit a transaction to redeem a deleg
139137

140138
```typescript
141139
import {
142-
DelegationFramework,
143-
SINGLE_DEFAULT_MODE,
144-
ExecutionStruct
140+
ExecutionStruct,
141+
ExecutionMode
142+
Delegation,
143+
getDeleGatorEnvironment,
145144
} from "@metamask/delegation-toolkit";
145+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
146+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
146147
import { lineaSepolia as chain } from "viem/chains";
147148
import { delegateWalletClient } from "./account.ts";
148149

@@ -159,7 +160,7 @@ const executions: ExecutionStruct[] = [{
159160
callData: "0x"
160161
}];
161162

162-
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
163+
const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({
163164
delegations: [ delegations ],
164165
modes: [ mode ],
165166
executions: [ executions ]
@@ -207,10 +208,12 @@ the primary difference is that an EOA submits a regular transaction instead of a
207208

208209
```typescript
209210
import {
210-
DelegationFramework,
211-
SINGLE_DEFAULT_MODE,
212-
ExecutionStruct
211+
ExecutionStruct,
212+
Delegation,
213+
ExecutionMode,
213214
} from "@metamask/delegation-toolkit";
215+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
216+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
214217
import { bundlerClient, pimlicoClient } from "./client.ts";
215218
import { delegateSmartAccount } from "./account.ts";
216219

@@ -241,7 +244,7 @@ const executionsArray: ExecutionStruct:[][] = [
241244
execution
242245
];
243246

244-
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
247+
const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({
245248
delegations: [ delegations ],
246249
modes: [ mode ],
247250
executions: [ executions ]

delegation-toolkit/reference/api/delegation.md

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Builds an array of caveats.
1919
### Parameters
2020

2121
| Name | Type | Required | Description |
22-
| ---- | ---- | -------- | ----------- |
22+
| --- | --- | --- | --- |
2323
| `environment` | `DeleGatorEnvironment` | Yes | Environment to resolve the smart contracts for the current chain. |
2424
| `config` | `CaveatBuilderConfig` | No | Configuration for `CaveatBuilder`. |
2525

@@ -77,8 +77,64 @@ import { delegatorSmartAccount } from "./config.ts";
7777

7878
const caveats = createCaveatBuilder(delegatorSmartAccount.environment, {
7979
// add-next-line
80-
allowEmptyCaveats: true
81-
})
80+
allowEmptyCaveats: true,
81+
});
82+
```
83+
84+
## `createDelegation`
85+
86+
Creates a delegation with specific delegate.
87+
88+
### Parameters
89+
90+
| Name | Type | Required | Description |
91+
| ---- | ---- | -------- | ----------- |
92+
| `from` | `Hex` | Yes | The address that is granting the delegation. |
93+
| `to` | `Hex` | Yes | The address to which the delegation is being granted. |
94+
| `caveats` | `Caveats` | Yes | Caveats to restrict the authority being granted. |
95+
| `parentDelegation` | `Delegation \| Hex` | No | The parent delegation or it's corresponding hex to create a delegation chain. |
96+
| `salt` | `Hex` | No | The salt for generating the delegation hash. This helps prevent hash collisions when creating identical delegations. |
97+
98+
### Example
99+
100+
```typescript
101+
import { createDelegation } from "@metamask/delegation-toolkit";
102+
103+
const delegation = createDelegation({
104+
// Address that is granting the delegation
105+
from: "0x7E48cA6b7fe6F3d57fdd0448B03b839958416fC1",
106+
// Address to which the delegation is being granted
107+
to: "0x2B2dBd1D5fbeB77C4613B66e9F35dBfE12cB0488",
108+
// Empty caveats array - we recommend adding appropriate restrictions
109+
caveats: [],
110+
});
111+
```
112+
113+
## `createOpenDelegation`
114+
115+
Creates an open delegation that can be redeemed by any delegate.
116+
117+
### Parameters
118+
119+
| Name | Type | Required | Description |
120+
| ---- | ---- | -------- | ----------- |
121+
| `from` | `Hex` | Yes | The address that is granting the delegation. |
122+
| `caveats` | `Caveats` | Yes | Caveats to restrict the authority being granted. |
123+
| `parentDelegation` | `Delegation \| Hex` | No | The parent delegation or it's corresponding hex to create a delegation chain. |
124+
| `salt` | `Hex` | No | The salt for generating the delegation hash. This helps prevent hash collisions when creating identical delegations. |
125+
126+
127+
### Example
128+
129+
```typescript
130+
import { createOpenDelegation } from "@metamask/delegation-toolkit";
131+
132+
const delegation = createOpenDelegation({
133+
// Address that is granting the delegation
134+
from: "0x7E48cA6b7fe6F3d57fdd0448B03b839958416fC1",
135+
// Empty caveats array - we recommend adding appropriate restrictions
136+
caveats: [],
137+
});
82138
```
83139

84140
## `createExecution`
@@ -88,8 +144,8 @@ Creates an `ExecutionStruct` instance.
88144
### Parameters
89145

90146
| Name | Type | Required | Description |
91-
| ---- | ---- | -------- | ----------- |
92-
| `target` | `Hex` | No | Address of the contract or recipient that the call is directed to. |
147+
| --- | --- | --- | --- |
148+
| `target` | `Address` | No | Address of the contract or recipient that the call is directed to. |
93149
| `value` | `bigint` | No | Value of native tokens to send along with the call in wei. |
94150
| `callData` | `Hex` | No | Encoded function data or payload to be executed on the target address. |
95151

@@ -98,14 +154,14 @@ Creates an `ExecutionStruct` instance.
98154
```ts
99155
import { createExecution } from "@metamask/delegation-toolkit";
100156

101-
// Creates an ExecutionStruct to transfer 0.01 ETH to
157+
// Creates an ExecutionStruct to transfer 0.01 ETH to
102158
// 0xe3C818389583fDD5cAC32f548140fE26BcEaE907 address.
103-
const caveats = createExecution(
104-
"0xe3C818389583fDD5cAC32f548140fE26BcEaE907",
159+
const caveats = createExecution({
160+
target: 0xe3C818389583fDD5cAC32f548140fE26BcEaE907",
105161
// 0.01 ETH in wei
106-
10000000000000000n,
107-
"0x",
108-
);
162+
value: 10000000000000000n,
163+
callData: "0x",
164+
});
109165
```
110166

111167
## `deployDeleGatorEnvironment`
@@ -127,7 +183,7 @@ Deploys the Delegation Framework contracts to an EVM chain.
127183
<TabItem value="example.ts">
128184

129185
```ts
130-
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit";
186+
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit/utils";
131187
import { walletClient, publicClient } from "./config.ts";
132188
import { lineaSepolia as chain } from "viem/chains";
133189

@@ -173,11 +229,11 @@ environment using `overrideDeployedEnvironment`.
173229
```ts title="example.ts"
174230
import { walletClient, publicClient } from "./config.ts";
175231
import { lineaSepolia as chain } from "viem/chains";
232+
import { DeleGatorEnvironment } from "@metamask/delegation-toolkit";
176233
import {
177-
DeleGatorEnvironment,
178234
overrideDeployedEnvironment,
179-
deployDeleGatorEnvironment
180-
} from "@metamask/delegation-toolkit";
235+
deployDeleGatorEnvironment,
236+
} from "@metamask/delegation-toolkit/utils";
181237

182238
const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment(
183239
walletClient,
@@ -233,7 +289,7 @@ Overrides or adds the `DeleGatorEnvironment` for a chain and supported version.
233289

234290
```ts
235291
import { environment } from "./environment.ts";
236-
import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit";
292+
import { overrideDeployedEnvironment } from "@metamask/delegation-toolkit/utils";
237293
import { sepolia } from "viem/chains";
238294

239295
overrideDeployedEnvironment(
@@ -253,7 +309,7 @@ export const environment: DeleGatorEnvironment = {
253309
SimpleFactory: "0x124..",
254310
// ...
255311
implementations: {
256-
// ...
312+
// ...
257313
},
258314
};
259315
```
@@ -268,7 +324,7 @@ Encodes calldata for redeeming delegations.
268324
### Parameters
269325

270326
| Name | Type | Required | Description |
271-
| ---- | ---- | -------- | ----------- |
327+
| --- | --- | --- | --- |
272328
| `delegations` | `Delegation[][]` | Yes | A nested collection representing chains of delegations. Each inner collection contains a chain of delegations to be redeemed. |
273329
| `modes` | `ExecutionMode[]` | Yes | A collection specifying the execution mode for each corresponding delegation chain. |
274330
| `executions` | `ExecutionStruct[][]` | Yes | A nested collection where each inner collection contains a list of `ExecutionStruct` objects associated with a specific delegation chain. |
@@ -278,13 +334,12 @@ Encodes calldata for redeeming delegations.
278334
This example assumes you have a delegation signed by the delegator.
279335

280336
```ts
281-
import {
282-
createExecution,
283-
DelegationFramework,
284-
} from "@metamask/delegation-toolkit";
337+
import { createExecution } from "@metamask/delegation-toolkit";
338+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
339+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
340+
import { zeroAddress } from "viem";
285341

286-
const execution = createExecution();
287-
const data = DelegationFramework.encode.redeemDelegations({
342+
const data = DelegationManager.encode.redeemDelegations({
288343
delegations: [[ signedDelegation ]],
289344
modes: [ SINGLE_DEFAULT_MODE ],
290345
executions: [[ execution ]],
@@ -298,7 +353,7 @@ Signs the delegation and returns the delegation signature.
298353
### Parameters
299354

300355
| Name | Type | Required | Description |
301-
| ---- | ---- | -------- | ----------- |
356+
| --- | --- | --- | --- |
302357
| `signer` | `WalletClient` | Yes | [Viem Wallet Client](https://viem.sh/docs/clients/wallet#wallet-client) to sign the delegation. |
303358
| `delegation` | `Omit<Delegation, "signature">` | Yes | The unsigned delegation object to sign. |
304359
| `chainId` | `number` | Yes | The chain ID on which the delegation manager is deployed. |
@@ -329,7 +384,7 @@ const signature = signDelegation({
329384

330385
```ts
331386
import {
332-
getDeleGatorEnvironment,
387+
getDeleGatorEnvironment,
333388
createDelegation,
334389
} from "@metamask/delegation-toolkit";
335390
import { createWalletClient } from "viem";
@@ -348,7 +403,7 @@ export const walletClient = createWalletClient({
348403
chain: sepolia,
349404
});
350405

351-
// The address to which the delegation is granted. It can be an EOA address, or
406+
// The address to which the delegation is granted. It can be an EOA address, or
352407
// smart account address.
353408
const delegate = "0x2FcB88EC2359fA635566E66415D31dD381CF5585";
354409

0 commit comments

Comments
 (0)