diff --git a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md index 4634456aa3c..209d234808c 100644 --- a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md @@ -98,10 +98,11 @@ const sessionAccount = privateKeyToAccount("0x..."); ### 4. Request ERC-7715 permissions Request ERC-7715 permissions from the user. In this example, you'll request an ERC-20 periodic -permission using the `grantPermissions` method. +permission using the Wallet Client's [`requestExecutionPermissions`](../../reference/erc7715/wallet-client.md#requestexecutionpermissions) action. ```typescript import { sepolia as chain } from "viem/chains"; +import { parseUnits } from "viem"; // Since current time is in seconds, we need to convert milliseconds to seconds. const currentTime = Math.floor(Date.now() / 1000); @@ -125,12 +126,13 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{ data: { tokenAddress, // 1 USDC in WEI format. Since USDC has 6 decimals, 10 * 10^6 - periodAmount: 1000000n, + periodAmount: parseUnits("10", 6), // 1 day in seconds periodDuration: 86400, justification?: "Permission to transfer 1 USDC every day", }, }, + isAdjustmentAllowed: true, }]); ``` @@ -183,9 +185,11 @@ const sessionAccountWalletClient = createWalletClient({ ### 6. Redeem ERC-7715 permissions -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. +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. -To redeem the permissions, use the appropriate client action based on your session account type: +To redeem the permissions, use the client action based on your session account type. +A smart account uses the Bundler Client's [`sendUserOperationWithDelegation`](../../reference/erc7715/bundler-client.md#senduseroperationwithdelegation) action, +and an EOA uses the Wallet Client's [`sendTransactionWithDelegation`](../../reference/erc7715/wallet-client.md#sendtransactionwithdelegation) action: diff --git a/delegation-toolkit/guides/erc7715/use-permissions/erc20-token.md b/delegation-toolkit/guides/erc7715/use-permissions/erc20-token.md index f4760607d8f..a3182e68a7d 100644 --- a/delegation-toolkit/guides/erc7715/use-permissions/erc20-token.md +++ b/delegation-toolkit/guides/erc7715/use-permissions/erc20-token.md @@ -15,7 +15,7 @@ permissions for ERC-20 token transfers with time-based (periodic) or streaming c - [Install and set up the Delegation Toolkit.](../../../get-started/install.md) - [Configure the Delegation Toolkit.](../../configure-toolkit.md) -- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account) +- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account) ## ERC-20 periodic permission @@ -124,8 +124,6 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{ initialAmount: parseUnits("1", 6), // 2 USDC in WEI format. Since USDC has 6 decimals, 2 * 10^6. maxAmount: parseUnits("2", 6), - // 1 hour in seconds. - duration: 3600, startTime: currentTime, justification: "Permission to use 0.1 USDC per second", }, diff --git a/delegation-toolkit/guides/erc7715/use-permissions/native-token.md b/delegation-toolkit/guides/erc7715/use-permissions/native-token.md index 32e0fef169f..5d8fd06f698 100644 --- a/delegation-toolkit/guides/erc7715/use-permissions/native-token.md +++ b/delegation-toolkit/guides/erc7715/use-permissions/native-token.md @@ -15,7 +15,7 @@ permissions for native token transfers with time-based (periodic) or streaming c - [Install and set up the Delegation Toolkit.](../../../get-started/install.md) - [Configure the Delegation Toolkit.](../../configure-toolkit.md) -- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account) +- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account) ## Native token periodic permission diff --git a/delegation-toolkit/reference/delegation/caveat-enforcer-client.md b/delegation-toolkit/reference/delegation/caveat-enforcer-client.md index d6095faf7b2..74bc8aeb89c 100644 --- a/delegation-toolkit/reference/delegation/caveat-enforcer-client.md +++ b/delegation-toolkit/reference/delegation/caveat-enforcer-client.md @@ -8,7 +8,7 @@ keywords: [delegation state, caveat enforcer client, API, methods, reference] import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -# Caveat Enforcer Client +# Caveat Enforcer Client reference The following API methods are related to `CaveatEnforcerClient` used to [check the delegation state](../../guides/delegation/check-delegation-state.md). diff --git a/delegation-toolkit/reference/delegation/caveats.md b/delegation-toolkit/reference/delegation/caveats.md index 435ccbaa434..ece2cf40f8c 100644 --- a/delegation-toolkit/reference/delegation/caveats.md +++ b/delegation-toolkit/reference/delegation/caveats.md @@ -1,10 +1,11 @@ --- description: Caveat enforcers reference. +sidebar_label: Caveats toc_max_heading_level: 2 keywords: [caveats, caveat enforcers, configuration, smart contracts, reference] --- -# Caveats +# Caveats reference When [constraining a delegation scope](../../guides/delegation/use-delegation-scopes/constrain-scope.md), you can specify the following caveat types. diff --git a/delegation-toolkit/reference/delegation/delegation-scopes.md b/delegation-toolkit/reference/delegation/delegation-scopes.md index 2d3b9e9679a..f95e2ceea3f 100644 --- a/delegation-toolkit/reference/delegation/delegation-scopes.md +++ b/delegation-toolkit/reference/delegation/delegation-scopes.md @@ -1,5 +1,6 @@ --- description: Delegation scopes reference. +sidebar_label: Delegation scopes keywords: [delegation scopes, configuration, reference] --- diff --git a/delegation-toolkit/reference/erc7715/bundler-client.md b/delegation-toolkit/reference/erc7715/bundler-client.md index 7ef51bc55e2..038fcd61a6f 100644 --- a/delegation-toolkit/reference/erc7715/bundler-client.md +++ b/delegation-toolkit/reference/erc7715/bundler-client.md @@ -1,19 +1,20 @@ --- -description: Bundler Client API methods reference. -sidebar_label: Bundler Client +description: Bundler Client actions reference. +sidebar_label: Bundler Client actions toc_max_heading_level: 2 +keywords: [ERC-7715, Viem, bundler client, actions, reference] --- import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -# Bundler Client API reference +# Bundler Client actions reference -The following API methods are related to the [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler). +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). ## `sendUserOperationWithDelegation` -Sends a user operation to redeem delegated permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications. +Sends a user operation with redeem permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications. :::info To use `sendUserOperationWithDelegation`, the Viem Bundler Client must be @@ -29,8 +30,8 @@ Objects in the `calls` array also require the following parameters: | Name | Type | Required | Description | | ---- | ---- | -------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `delegationManager` | `0x${string}` | Yes | The address of Delegation Manager. | -| `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. | +| `delegationManager` | `Address` | Yes | The address of Delegation Manager. | +| `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. | ### Example @@ -38,7 +39,7 @@ Objects in the `calls` array also require the following parameters: ```ts -import { sessionAccount, bundlerClient, publicClient } from "./config.ts"; +import { sessionAccount, bundlerClient, publicClient } from "./client.ts"; // These properties must be extracted from the permission response. const permissionsContext = permissionsResponse[0].context; @@ -67,7 +68,7 @@ const userOperationHash = await bundlerClient.sendUserOperationWithDelegation({ ``` - + ```ts import { createPublicClient, http, createBundlerClient } from "viem"; diff --git a/delegation-toolkit/reference/erc7715/permissions.md b/delegation-toolkit/reference/erc7715/permissions.md index d219f159c47..e6c0090d306 100644 --- a/delegation-toolkit/reference/erc7715/permissions.md +++ b/delegation-toolkit/reference/erc7715/permissions.md @@ -4,7 +4,7 @@ sidebar_label: Permissions keywords: [ERC-7715, permissions, ERC-20 token, native token, reference] --- -# ERC-7715 permissions +# ERC-7715 permissions reference 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. Learn [how to use ERC-7715 permissions](../../guides/erc7715/use-permissions/erc20-token.md). diff --git a/delegation-toolkit/reference/erc7715/wallet-client.md b/delegation-toolkit/reference/erc7715/wallet-client.md index 6aa3e66c8df..85e75cbaf12 100644 --- a/delegation-toolkit/reference/erc7715/wallet-client.md +++ b/delegation-toolkit/reference/erc7715/wallet-client.md @@ -1,22 +1,23 @@ --- -description: Wallet Client API methods reference. -sidebar_label: Wallet Client +description: Wallet Client actions reference. +sidebar_label: Wallet Client actions toc_max_heading_level: 2 +keywords: [ERC-7715, Viem, wallet client, actions, reference] --- import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -# Wallet Client API reference +# Wallet Client actions reference -The following API methods are related to the [Viem Wallet Client](https://viem.sh/docs/clients/wallet). +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). -## `grantPermissions` +## `requestExecutionPermissions` Requests permissions from the MetaMask extension account according to the [ERC-7715](https://eips.ethereum.org/EIPS/eip-7715) specifications. :::info -To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`. +To use `requestExecutionPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`. ::: ### Parameters @@ -26,9 +27,9 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715 | `chainId` | `number` | Yes | The chain ID on which the permission is being requested. | | `address` | `Address` | No | Address of the wallet to which the permission is being requested. | | `expiry` | `number` | Yes | The timestamp (in seconds) by which the permission must expire. | -| `permission` | `Permission` | Yes | The permission to grant to the user. | -| `signer` | `Signer` | Yes | The account to which the permission will be assigned. | -| `isAdjustmentAllowed` | `boolean` | No | Whether the user is allowed to modify the requested permission. The default is `true`. | +| `permission` | `SupportedPermissionParams` | Yes | The permission to be requested. The toolkit supports multiple [ERC-7715 permissions](permissions.md). | +| `signer` | `SignerParam` | Yes | The account to which the permission will be assigned. | +| `isAdjustmentAllowed` | `boolean` | Yes | Defines whether the user is allowed to modify the requested permission. | ### Example @@ -37,39 +38,36 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715 ```ts import { sepolia as chain } from "viem/chains"; -import { walletClient } from "./config.ts"; +import { parseUnits } from "viem"; +import { walletClient } from "./client.ts"; -const expiry = Math.floor(Date.now() / 1000 + 604_800); // 1 week from now. -const currentTime = Math.floor(Date.now() / 1000); // now +const currentTime = Math.floor(Date.now() / 1000); +const expiry = currentTime + 604800; -// Address of the wallet that will manage the session. It can -// be either a smart account or an externally owned account (EOA) -const sessionAccount = "0x1431.."; - -const grantedPermissions = await walletClient.grantPermissions([{ +const grantedPermissions = await walletClient.requestExecutionPermissions([{ chainId: chain.id, expiry, signer: { type: "account", data: { - address: sessionAccount, + address: "0x0955fFD7b83e5493a8c1FD5dC87e2CF37Eacc44a", }, }, permission: { - type: "native-token-stream", + type: "erc20-token-periodic", data: { - initialAmount: 1n, // 1 wei - amountPerSecond: 1n, // 1 wei per second - maxAmount: 10n, // 10 wei - startTime: currentTime, - justification: "Payment for a week long subscription", + tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", + periodAmount: parseUnits("10", 6), + periodDuration: 86400, + justification?: "Permission to transfer 1 USDC every day", }, }, + isAdjustmentAllowed: true, }]); ``` - + ```ts import { createWalletClient, custom } from "viem"; @@ -99,8 +97,8 @@ This function has the same parameters, and it also requires the following parame | Name | Type | Required | Description | | ---- | ---- | -------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `delegationManager` | `0x${string}` | Yes | The address of the Delegation Manager. | -| `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. | +| `delegationManager` | `Address` | Yes | The address of the Delegation Manager. | +| `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. | ### Example @@ -108,7 +106,7 @@ This function has the same parameters, and it also requires the following parame ```ts -import { walletClient, publicClient } from "./config.ts"; +import { walletClient, publicClient } from "./client.ts"; // These properties must be extracted from the permission response. See // `grantPermissions` action to learn how to request permissions. @@ -141,7 +139,7 @@ const hash = walletClient.sendTransactionWithDelegation({ ``` - + ```ts import { http, createPublicClient, createWalletClient } from "viem"; diff --git a/gator-sidebar.js b/gator-sidebar.js index 4306d8938fa..5a0d248f896 100644 --- a/gator-sidebar.js +++ b/gator-sidebar.js @@ -162,8 +162,8 @@ const sidebar = { collapsed: true, items: [ 'reference/erc7715/permissions', - // 'reference/erc7715/wallet-client', - // 'reference/erc7715/bundler-client', + 'reference/erc7715/wallet-client', + 'reference/erc7715/bundler-client', ], }, ],