Skip to content

Commit 9f00e57

Browse files
AyushBherwani1998Ayush Bherwanialexandratran
authored
Enable Wallet and Bundler Client actions (MetaMask#2364)
* enable wallet and bundler client actions * edits * api methods -> actions * minor fix --------- Co-authored-by: Ayush Bherwani <“[email protected]”> Co-authored-by: Alexandra Carrillo <[email protected]>
1 parent 38ba477 commit 9f00e57

File tree

10 files changed

+54
-51
lines changed

10 files changed

+54
-51
lines changed

delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ const sessionAccount = privateKeyToAccount("0x...");
9898
### 4. Request ERC-7715 permissions
9999

100100
Request ERC-7715 permissions from the user. In this example, you'll request an ERC-20 periodic
101-
permission using the `grantPermissions` method.
101+
permission using the Wallet Client's [`requestExecutionPermissions`](../../reference/erc7715/wallet-client.md#requestexecutionpermissions) action.
102102

103103
```typescript
104104
import { sepolia as chain } from "viem/chains";
105+
import { parseUnits } from "viem";
105106

106107
// Since current time is in seconds, we need to convert milliseconds to seconds.
107108
const currentTime = Math.floor(Date.now() / 1000);
@@ -125,12 +126,13 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{
125126
data: {
126127
tokenAddress,
127128
// 1 USDC in WEI format. Since USDC has 6 decimals, 10 * 10^6
128-
periodAmount: 1000000n,
129+
periodAmount: parseUnits("10", 6),
129130
// 1 day in seconds
130131
periodDuration: 86400,
131132
justification?: "Permission to transfer 1 USDC every day",
132133
},
133134
},
135+
isAdjustmentAllowed: true,
134136
}]);
135137
```
136138

@@ -183,9 +185,11 @@ const sessionAccountWalletClient = createWalletClient({
183185

184186
### 6. Redeem ERC-7715 permissions
185187

186-
The session account can now [redeem the delegation](../experimental/erc-7710-redeem-delegations.md). The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.
188+
The session account can now redeem the permissions. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.
187189

188-
To redeem the permissions, use the appropriate client action based on your session account type:
190+
To redeem the permissions, use the client action based on your session account type.
191+
A smart account uses the Bundler Client's [`sendUserOperationWithDelegation`](../../reference/erc7715/bundler-client.md#senduseroperationwithdelegation) action,
192+
and an EOA uses the Wallet Client's [`sendTransactionWithDelegation`](../../reference/erc7715/wallet-client.md#sendtransactionwithdelegation) action:
189193

190194
<Tabs>
191195
<TabItem value="Smart account">

delegation-toolkit/guides/erc7715/use-permissions/erc20-token.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ permissions for ERC-20 token transfers with time-based (periodic) or streaming c
1515

1616
- [Install and set up the Delegation Toolkit.](../../../get-started/install.md)
1717
- [Configure the Delegation Toolkit.](../../configure-toolkit.md)
18-
- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account)
18+
- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account)
1919

2020
## ERC-20 periodic permission
2121

@@ -124,8 +124,6 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{
124124
initialAmount: parseUnits("1", 6),
125125
// 2 USDC in WEI format. Since USDC has 6 decimals, 2 * 10^6.
126126
maxAmount: parseUnits("2", 6),
127-
// 1 hour in seconds.
128-
duration: 3600,
129127
startTime: currentTime,
130128
justification: "Permission to use 0.1 USDC per second",
131129
},

delegation-toolkit/guides/erc7715/use-permissions/native-token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ permissions for native token transfers with time-based (periodic) or streaming c
1515

1616
- [Install and set up the Delegation Toolkit.](../../../get-started/install.md)
1717
- [Configure the Delegation Toolkit.](../../configure-toolkit.md)
18-
- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account)
18+
- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account)
1919

2020
## Native token periodic permission
2121

delegation-toolkit/reference/delegation/caveat-enforcer-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords: [delegation state, caveat enforcer client, API, methods, reference]
88
import Tabs from "@theme/Tabs";
99
import TabItem from "@theme/TabItem";
1010

11-
# Caveat Enforcer Client
11+
# Caveat Enforcer Client reference
1212

1313
The following API methods are related to `CaveatEnforcerClient` used to [check the delegation state](../../guides/delegation/check-delegation-state.md).
1414

delegation-toolkit/reference/delegation/caveats.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
description: Caveat enforcers reference.
3+
sidebar_label: Caveats
34
toc_max_heading_level: 2
45
keywords: [caveats, caveat enforcers, configuration, smart contracts, reference]
56
---
67

7-
# Caveats
8+
# Caveats reference
89

910
When [constraining a delegation scope](../../guides/delegation/use-delegation-scopes/constrain-scope.md), you can specify the following caveat types.
1011

delegation-toolkit/reference/delegation/delegation-scopes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: Delegation scopes reference.
3+
sidebar_label: Delegation scopes
34
keywords: [delegation scopes, configuration, reference]
45
---
56

delegation-toolkit/reference/erc7715/bundler-client.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
---
2-
description: Bundler Client API methods reference.
3-
sidebar_label: Bundler Client
2+
description: Bundler Client actions reference.
3+
sidebar_label: Bundler Client actions
44
toc_max_heading_level: 2
5+
keywords: [ERC-7715, Viem, bundler client, actions, reference]
56
---
67

78
import Tabs from "@theme/Tabs";
89
import TabItem from "@theme/TabItem";
910

10-
# Bundler Client API reference
11+
# Bundler Client actions reference
1112

12-
The following API methods are related to the [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler).
13+
The following actions are related to the [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) used to [execute on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md).
1314

1415
## `sendUserOperationWithDelegation`
1516

16-
Sends a user operation to redeem delegated permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications.
17+
Sends a user operation with redeem permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications.
1718

1819
:::info
1920
To use `sendUserOperationWithDelegation`, the Viem Bundler Client must be
@@ -29,16 +30,16 @@ Objects in the `calls` array also require the following parameters:
2930

3031
| Name | Type | Required | Description |
3132
| ---- | ---- | -------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
32-
| `delegationManager` | `0x${string}` | Yes | The address of Delegation Manager. |
33-
| `permissionsContext` | `0x${string}` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
33+
| `delegationManager` | `Address` | Yes | The address of Delegation Manager. |
34+
| `permissionsContext` | `Hex` | Yes | Encoded calldata for redeeming permissions. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
3435

3536
### Example
3637

3738
<Tabs>
3839
<TabItem value ="example.ts">
3940

4041
```ts
41-
import { sessionAccount, bundlerClient, publicClient } from "./config.ts";
42+
import { sessionAccount, bundlerClient, publicClient } from "./client.ts";
4243

4344
// These properties must be extracted from the permission response.
4445
const permissionsContext = permissionsResponse[0].context;
@@ -67,7 +68,7 @@ const userOperationHash = await bundlerClient.sendUserOperationWithDelegation({
6768
```
6869

6970
</TabItem>
70-
<TabItem value ="config.ts">
71+
<TabItem value ="client.ts">
7172

7273
```ts
7374
import { createPublicClient, http, createBundlerClient } from "viem";

delegation-toolkit/reference/erc7715/permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_label: Permissions
44
keywords: [ERC-7715, permissions, ERC-20 token, native token, reference]
55
---
66

7-
# ERC-7715 permissions
7+
# ERC-7715 permissions reference
88

99
When [executing on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md), you can request the following permission types for ERC-20 token and native token transfers.
1010
Learn [how to use ERC-7715 permissions](../../guides/erc7715/use-permissions/erc20-token.md).

delegation-toolkit/reference/erc7715/wallet-client.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
---
2-
description: Wallet Client API methods reference.
3-
sidebar_label: Wallet Client
2+
description: Wallet Client actions reference.
3+
sidebar_label: Wallet Client actions
44
toc_max_heading_level: 2
5+
keywords: [ERC-7715, Viem, wallet client, actions, reference]
56
---
67

78
import Tabs from "@theme/Tabs";
89
import TabItem from "@theme/TabItem";
910

10-
# Wallet Client API reference
11+
# Wallet Client actions reference
1112

12-
The following API methods are related to the [Viem Wallet Client](https://viem.sh/docs/clients/wallet).
13+
The following actions are related to the [Viem Wallet Client](https://viem.sh/docs/clients/wallet) used to [execute on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md).
1314

14-
## `grantPermissions`
15+
## `requestExecutionPermissions`
1516

1617
Requests permissions from the MetaMask extension account according to the [ERC-7715](https://eips.ethereum.org/EIPS/eip-7715) specifications.
1718

1819
:::info
19-
To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`.
20+
To use `requestExecutionPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`.
2021
:::
2122

2223
### Parameters
@@ -26,9 +27,9 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715
2627
| `chainId` | `number` | Yes | The chain ID on which the permission is being requested. |
2728
| `address` | `Address` | No | Address of the wallet to which the permission is being requested. |
2829
| `expiry` | `number` | Yes | The timestamp (in seconds) by which the permission must expire. |
29-
| `permission` | `Permission` | Yes | The permission to grant to the user. |
30-
| `signer` | `Signer` | Yes | The account to which the permission will be assigned. |
31-
| `isAdjustmentAllowed` | `boolean` | No | Whether the user is allowed to modify the requested permission. The default is `true`. |
30+
| `permission` | `SupportedPermissionParams` | Yes | The permission to be requested. The toolkit supports multiple [ERC-7715 permissions](permissions.md). |
31+
| `signer` | `SignerParam` | Yes | The account to which the permission will be assigned. |
32+
| `isAdjustmentAllowed` | `boolean` | Yes | Defines whether the user is allowed to modify the requested permission. |
3233

3334
### Example
3435

@@ -37,39 +38,36 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715
3738

3839
```ts
3940
import { sepolia as chain } from "viem/chains";
40-
import { walletClient } from "./config.ts";
41+
import { parseUnits } from "viem";
42+
import { walletClient } from "./client.ts";
4143

42-
const expiry = Math.floor(Date.now() / 1000 + 604_800); // 1 week from now.
43-
const currentTime = Math.floor(Date.now() / 1000); // now
44+
const currentTime = Math.floor(Date.now() / 1000);
45+
const expiry = currentTime + 604800;
4446

45-
// Address of the wallet that will manage the session. It can
46-
// be either a smart account or an externally owned account (EOA)
47-
const sessionAccount = "0x1431..";
48-
49-
const grantedPermissions = await walletClient.grantPermissions([{
47+
const grantedPermissions = await walletClient.requestExecutionPermissions([{
5048
chainId: chain.id,
5149
expiry,
5250
signer: {
5351
type: "account",
5452
data: {
55-
address: sessionAccount,
53+
address: "0x0955fFD7b83e5493a8c1FD5dC87e2CF37Eacc44a",
5654
},
5755
},
5856
permission: {
59-
type: "native-token-stream",
57+
type: "erc20-token-periodic",
6058
data: {
61-
initialAmount: 1n, // 1 wei
62-
amountPerSecond: 1n, // 1 wei per second
63-
maxAmount: 10n, // 10 wei
64-
startTime: currentTime,
65-
justification: "Payment for a week long subscription",
59+
tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
60+
periodAmount: parseUnits("10", 6),
61+
periodDuration: 86400,
62+
justification?: "Permission to transfer 1 USDC every day",
6663
},
6764
},
65+
isAdjustmentAllowed: true,
6866
}]);
6967
```
7068

7169
</TabItem>
72-
<TabItem value ="config.ts">
70+
<TabItem value ="client.ts">
7371

7472
```ts
7573
import { createWalletClient, custom } from "viem";
@@ -99,16 +97,16 @@ This function has the same parameters, and it also requires the following parame
9997

10098
| Name | Type | Required | Description |
10199
| ---- | ---- | -------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
102-
| `delegationManager` | `0x${string}` | Yes | The address of the Delegation Manager. |
103-
| `permissionsContext` | `0x${string}` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
100+
| `delegationManager` | `Address` | Yes | The address of the Delegation Manager. |
101+
| `permissionsContext` | `Hex` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
104102

105103
### Example
106104

107105
<Tabs>
108106
<TabItem value ="example.ts">
109107

110108
```ts
111-
import { walletClient, publicClient } from "./config.ts";
109+
import { walletClient, publicClient } from "./client.ts";
112110

113111
// These properties must be extracted from the permission response. See
114112
// `grantPermissions` action to learn how to request permissions.
@@ -141,7 +139,7 @@ const hash = walletClient.sendTransactionWithDelegation({
141139
```
142140

143141
</TabItem>
144-
<TabItem value ="config.ts">
142+
<TabItem value ="client.ts">
145143

146144
```ts
147145
import { http, createPublicClient, createWalletClient } from "viem";

gator-sidebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ const sidebar = {
162162
collapsed: true,
163163
items: [
164164
'reference/erc7715/permissions',
165-
// 'reference/erc7715/wallet-client',
166-
// 'reference/erc7715/bundler-client',
165+
'reference/erc7715/wallet-client',
166+
'reference/erc7715/bundler-client',
167167
],
168168
},
169169
],

0 commit comments

Comments
 (0)