@@ -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
7878const 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
99155import { 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 " ;
131187import { walletClient , publicClient } from " ./config.ts" ;
132188import { lineaSepolia as chain } from " viem/chains" ;
133189
@@ -173,11 +229,11 @@ environment using `overrideDeployedEnvironment`.
173229``` ts title="example.ts"
174230import { walletClient , publicClient } from " ./config.ts" ;
175231import { lineaSepolia as chain } from " viem/chains" ;
232+ import { DeleGatorEnvironment } from " @metamask/delegation-toolkit" ;
176233import {
177- DeleGatorEnvironment ,
178234 overrideDeployedEnvironment ,
179- deployDeleGatorEnvironment
180- } from " @metamask/delegation-toolkit" ;
235+ deployDeleGatorEnvironment ,
236+ } from " @metamask/delegation-toolkit/utils " ;
181237
182238const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment (
183239 walletClient ,
@@ -233,7 +289,7 @@ Overrides or adds the `DeleGatorEnvironment` for a chain and supported version.
233289
234290``` ts
235291import { environment } from " ./environment.ts" ;
236- import { getDeleGatorEnvironment } from " @metamask/delegation-toolkit" ;
292+ import { overrideDeployedEnvironment } from " @metamask/delegation-toolkit/utils " ;
237293import { sepolia } from " viem/chains" ;
238294
239295overrideDeployedEnvironment (
@@ -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.
278334This 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
331386import {
332- getDeleGatorEnvironment ,
387+ getDeleGatorEnvironment ,
333388 createDelegation ,
334389} from " @metamask/delegation-toolkit" ;
335390import { 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.
353408const delegate = " 0x2FcB88EC2359fA635566E66415D31dD381CF5585" ;
354409
0 commit comments