Skip to content

Commit 509cef0

Browse files
alexandratranAyush Bherwani
andauthored
Add ERC-7715 permissions reference
* Add ERC-7715 permissions reference * update permission params * fix typos * update code snippets --------- Co-authored-by: Ayush Bherwani <“[email protected]”>
1 parent d33f82b commit 509cef0

File tree

4 files changed

+166
-10
lines changed

4 files changed

+166
-10
lines changed

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

File renamed without changes.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{
117117
initialAmount: parseEther("0.1"),
118118
// 1 ETH in wei format.
119119
maxAmount: parseEther("1"),
120-
// 1 hour in seconds.
121-
duration: 3600,
122120
startTime: currentTime,
123121
justification: "Permission to use 0.0001 ETH per second",
124122
},
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
description: ERC-7715 permissions reference.
3+
sidebar_label: Permissions
4+
keywords: [ERC-7715, permissions, ERC-20 token, native token, reference]
5+
---
6+
7+
# ERC-7715 permissions
8+
9+
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.
10+
Learn [how to use ERC-7715 permissions](../../guides/erc7715/use-permissions/erc20-token.md).
11+
12+
## ERC-20 token permissions
13+
14+
### ERC-20 periodic permission
15+
16+
Ensures a per-period limit for ERC-20 token transfers.
17+
At the start of each new period, the allowance resets.
18+
19+
#### Parameters
20+
21+
| Name | Type | Required | Description |
22+
| ---------------- | --------- | -------- | ---------------------------------------------------------------------- |
23+
| `tokenAddress` | `Address` | Yes | The ERC-20 token contract address as a hex string. |
24+
| `periodAmount` | `bigint` | Yes | The maximum amount of tokens that can be transferred per period. |
25+
| `periodDuration` | `number` | Yes | The duration of each period in seconds. |
26+
| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. |
27+
| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. |
28+
29+
#### Example
30+
31+
```typescript
32+
import { parseUnits } from "viem";
33+
34+
const currentTime = Math.floor(Date.now() / 1000);
35+
const expiry = currentTime + 604800;
36+
37+
const permission = {
38+
type: "erc20-token-periodic",
39+
data: {
40+
tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
41+
periodAmount: parseUnits("10", 6),
42+
periodDuration: 86400,
43+
justification?: "Permission to transfer 1 USDC every day",
44+
},
45+
};
46+
```
47+
48+
### ERC-20 stream permission
49+
50+
Ensures a linear streaming transfer limit for ERC-20 tokens.
51+
Token transfers are blocked until the defined start timestamp.
52+
At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount.
53+
54+
#### Parameters
55+
56+
| Name | Type | Required | Description |
57+
| ----------------- | --------- | -------- | ----------------------------------------------------------------------------- |
58+
| `tokenAddress` | `Address` | Yes | The ERC-20 token contract address. |
59+
| `initialAmount` | `bigint` | No | The initial amount that can be transferred at start time. The default is `0`. |
60+
| `maxAmount` | `bigint` | No | The maximum total amount that can be unlocked. The default is no limit. |
61+
| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. |
62+
| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. |
63+
| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. |
64+
65+
#### Example
66+
67+
```typescript
68+
import { parseUnits } from "viem";
69+
70+
const currentTime = Math.floor(Date.now() / 1000);
71+
const expiry = currentTime + 604800;
72+
73+
const permission = {
74+
type: "erc20-token-stream",
75+
data: {
76+
tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
77+
amountPerSecond: parseUnits("0.1", 6),
78+
initialAmount: parseUnits("1", 6),
79+
maxAmount: parseUnits("2", 6),
80+
startTime: currentTime,
81+
justification: "Permission to use 0.1 USDC per second",
82+
},
83+
};
84+
```
85+
86+
## Native token permissions
87+
88+
### Native token periodic permission
89+
90+
Ensures a per-period limit for native token transfers.
91+
At the start of each new period, the allowance resets.
92+
93+
#### Parameters
94+
95+
| Name | Type | Required | Description |
96+
| ---------------- | --------- | -------- | ---------------------------------------------------------------------- |
97+
| `periodAmount` | `bigint` | Yes | The maximum amount of tokens that can be transferred per period. |
98+
| `periodDuration` | `number` | Yes | The duration of each period in seconds. |
99+
| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. |
100+
| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. |
101+
102+
#### Example
103+
104+
```typescript
105+
import { parseEther } from "viem";
106+
107+
const currentTime = Math.floor(Date.now() / 1000);
108+
const expiry = currentTime + 604800;
109+
110+
const permission = {
111+
type: "native-token-periodic",
112+
data: {
113+
periodAmount: parseEther("0.001"),
114+
periodDuration: 86400,
115+
startTime: currentTime,
116+
justification: "Permission to use 0.001 ETH every day",
117+
},
118+
};
119+
```
120+
121+
### Native token stream permission
122+
123+
Ensures a linear streaming transfer limit for native tokens.
124+
Token transfers are blocked until the defined start timestamp.
125+
At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount.
126+
127+
#### Parameters
128+
129+
| Name | Type | Required | Description |
130+
| ----------------- | --------- | -------- | ----------------------------------------------------------------------------- |
131+
| `initialAmount` | `bigint` | No | The initial amount that can be transferred at start time. The default is `0`. |
132+
| `maxAmount` | `bigint` | No | The maximum total amount that can be unlocked. The default is no limit. |
133+
| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. |
134+
| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. |
135+
| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. |
136+
137+
#### Example
138+
139+
```typescript
140+
import { sepolia as chain } from "viem/chains";
141+
import { parseEther } from "viem";
142+
import { walletClient } from "./client.ts"
143+
144+
const currentTime = Math.floor(Date.now() / 1000);
145+
const expiry = currentTime + 604800;
146+
147+
const permission = {
148+
type: "native-token-stream",
149+
data: {
150+
amountPerSecond: parseEther("0.0001"),
151+
initialAmount: parseEther("0.1"),
152+
maxAmount: parseEther("1"),
153+
startTime: currentTime,
154+
justification: "Permission to use 0.0001 ETH per second",
155+
},
156+
};
157+
```

gator-sidebar.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const sidebar = {
8989
label: 'ERC-7715',
9090
collapsed: true,
9191
items: [
92-
'guides/erc7715/execute-on-metamask-user-behalf',
92+
'guides/erc7715/execute-on-metamask-users-behalf',
9393
{
9494
type: 'category',
9595
label: 'Use permissions',
@@ -156,15 +156,16 @@ const sidebar = {
156156
'reference/delegation/caveat-enforcer-client',
157157
],
158158
},
159-
// {
160-
// type: 'category',
161-
// label: 'ERC-7715',
162-
// collapsed: false,
163-
// items: [
159+
{
160+
type: 'category',
161+
label: 'ERC-7715',
162+
collapsed: true,
163+
items: [
164+
'reference/erc7715/permissions',
164165
// 'reference/erc7715/wallet-client',
165166
// 'reference/erc7715/bundler-client',
166-
// ],
167-
// },
167+
],
168+
},
168169
],
169170
},
170171
],

0 commit comments

Comments
 (0)