-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtypes.ts
More file actions
282 lines (261 loc) · 9.34 KB
/
Copy pathtypes.ts
File metadata and controls
282 lines (261 loc) · 9.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// //////////////////////////////////////////////////
// General Types
// //////////////////////////////////////////////////
/**
* A hex-encoded string.
*/
export type Hex = `0x${string}`;
// //////////////////////////////////////////////////
// Permission Types
// //////////////////////////////////////////////////
/**
* A base permission type that all permissions must extend.
* `isAdjustmentAllowed` defines a boolean value that allows DApp to define whether the "permission" can be attenuated–adjusted to meet the user's terms.
*
* type - is an enum defined by the ERCs
*
* isAdjustmentAllowed - is a boolean that indicates whether the permission can be adjusted.
*
* data - is a record of the data that is associated with the permission, and the structure is defined by the ERCs.
*/
export type BasePermission = {
type: string;
isAdjustmentAllowed: boolean;
data: Record<string, any>;
};
/**
* A base rule type that all rules must extend.
*
* type - is an enum defined by the ERCs
*
* data - is a record of the data that is associated with the rule, and the structure is defined by the ERCs.
*/
export type Rule = {
type: string;
data: Record<string, any>;
};
// //////////////////////////////////////////////////
// MetaMask Permission Types
// //////////////////////////////////////////////////
/**
* Base data for all MetaMask permissions.
*
* justification - is a human-readable explanation of why the permission is being requested.
*/
export type MetaMaskBasePermissionData = {
justification?: string | null;
};
/**
* A permission to stream native tokens.
*
* data.initialAmount - is the initial amount of the native token to be streamed. Defaults to 0.
*
* data.maxAmount - is the maximum amount of the native token to be streamed. Defaults to Max Uint256.
*
* data.amountPerSecond - is the amount of the native token to be streamed per second.
*
* data.startTime - is the start time of the stream. Defaults to current time.
*/
export type NativeTokenStreamPermission = BasePermission & {
type: 'native-token-stream';
data: MetaMaskBasePermissionData & {
initialAmount?: Hex | null;
maxAmount?: Hex | null;
amountPerSecond: Hex;
startTime?: number | null;
};
};
/**
* A permission to stream native tokens periodically.
*
* data.periodAmount - is the amount of the native token to be streamed per period.
*
* data.periodDuration - is the duration of the period in seconds.
*
* data.startTime - is the start time of the stream. Defaults to current time.
*/
export type NativeTokenPeriodicPermission = BasePermission & {
type: 'native-token-periodic';
data: MetaMaskBasePermissionData & {
periodAmount: Hex;
periodDuration: number;
startTime?: number | null;
};
};
/**
* A permission to stream ERC20 tokens.
*
* data.initialAmount - is the initial amount of the ERC20 token to be streamed. Defaults to 0.
*
* data.maxAmount - is the maximum amount of the ERC20 token to be streamed. Defaults to Max Uint256.
*
* data.amountPerSecond - is the amount of the ERC20 token to be streamed per second.
*
* data.startTime - is the start time of the stream. Defaults to current time.
*
* data.tokenAddress - is the address of the ERC20 token to be streamed.
*/
export type Erc20TokenStreamPermission = BasePermission & {
type: 'erc20-token-stream';
data: MetaMaskBasePermissionData & {
initialAmount?: Hex | null;
maxAmount?: Hex | null;
amountPerSecond: Hex;
startTime?: number | null;
tokenAddress: Hex;
};
};
/**
* A permission to stream ERC20 tokens periodically.
*
* data.periodAmount - is the amount of the ERC20 token to be streamed per period.
*
* data.periodDuration - is the duration of the period in seconds.
*
* data.startTime - is the start time of the stream. Defaults to current time.
*
* data.tokenAddress - is the address of the ERC20 token to be streamed per period.
*/
export type Erc20TokenPeriodicPermission = BasePermission & {
type: 'erc20-token-periodic';
data: MetaMaskBasePermissionData & {
periodAmount: Hex;
periodDuration: number;
startTime?: number | null;
tokenAddress: Hex;
};
};
/**
* A permission for a single fixed native token allowance (cumulative cap).
*
* data.allowanceAmount - is the maximum amount of native token that may be transferred under the permission.
*
* data.startTime - is when the allowance starts. Defaults to current time.
*/
export type NativeTokenAllowancePermission = BasePermission & {
type: 'native-token-allowance';
data: MetaMaskBasePermissionData & {
allowanceAmount: Hex;
startTime?: number | null;
};
};
/**
* A permission for a single fixed ERC-20 token allowance (cumulative cap).
*
* data.allowanceAmount - is the maximum amount of the ERC-20 token that may be transferred.
*
* data.startTime - is when the allowance starts. Defaults to current time.
*
* data.tokenAddress - is the address of the ERC-20 token.
*/
export type Erc20TokenAllowancePermission = BasePermission & {
type: 'erc20-token-allowance';
data: MetaMaskBasePermissionData & {
allowanceAmount: Hex;
startTime?: number | null;
tokenAddress: Hex;
};
};
/**
* A permission to revoke an ERC20 token allowance.
*
* @deprecated Use {@link TokenApprovalRevocationPermission} instead.
*/
export type Erc20TokenRevocationPermission = BasePermission & {
/**
* @deprecated Use `token-approval-revocation` instead.
*/
type: 'erc20-token-revocation';
data: MetaMaskBasePermissionData;
};
/**
* A permission to revoke token approvals.
*/
export type TokenApprovalRevocationPermission = BasePermission & {
type: 'token-approval-revocation';
data: MetaMaskBasePermissionData & {
erc20Approve: boolean;
erc721Approve: boolean;
erc721SetApprovalForAll: boolean;
permit2ApproveZero: boolean;
permit2Lockdown: boolean;
permit2InvalidateNonces: boolean;
};
};
/**
* A custom permission.
*
* data - is a record of the data that is associated with the permission, and the structure is defined by the ERCs.
*/
// TODO: Consider opening up permission types with Custom / Unknown permissions in subsequent versions.
// export type CustomPermission = BasePermission & {
// type: 'custom';
// data: MetaMaskBasePermissionData & Record<string, unknown>;
// };
/**
* Represents the type of the ERC-7715 permissions that can be granted.
*/
export type PermissionTypes =
| NativeTokenStreamPermission
| NativeTokenPeriodicPermission
| NativeTokenAllowancePermission
| Erc20TokenStreamPermission
| Erc20TokenPeriodicPermission
| Erc20TokenAllowancePermission
| Erc20TokenRevocationPermission
| TokenApprovalRevocationPermission;
// //////////////////////////////////////////////////
// Permission Requests
// //////////////////////////////////////////////////
/**
* Parameters for the `wallet_requestExecutionPermissions` JSON-RPC method.
*
* chainId - chainId defines the chain with EIP-155 which applies to this permission request and all addresses can be found defined by other parameters.
*
* address - address identifies the account being targetted for this permission request which is useful when a connection has been established and multiple accounts have been exposed. It is optional to let the user choose which account to grant permission for.
*
* to - is a field that identifies the DApp session account associated with the permission.
*
* permission - permission defines the allowed behavior the signer can do on behalf of the account. See the "Permission" section for details.
*
* rules - rules defined the restrictions or conditions that a signer MUST abide by when using a permission to act on behalf of an account. See the "Rule" section for details.
*/
export type PermissionRequest<TPermission extends PermissionTypes> = {
chainId: Hex; // hex-encoding of uint256
from?: Hex;
to: Hex;
permission: TPermission;
rules?: Rule[] | null;
};
/**
* Response from the `wallet_requestExecutionPermissions` JSON-RPC method.
* First note that the response contains all of the parameters of the original request and it is not guaranteed that the values received are equivalent to those requested.
*
* context - is a catch-all to identify a permission for revoking permissions or submitting userOps, and can contain non-identifying data as well. It MAY be the `context` as defined in ERC-7679 and ERC-7710.
*
* dependencies - is an array of objects, each containing fields for `factory` and `factoryData` as defined in ERC-4337. Either both `factory` and `factoryData` must be specified in an entry, or neither. This array is used describe accounts that are not yet deployed but MUST be deployed in order for a permission to be successfully redeemed.
*
* delegationManager - is required as defined in ERC-7710.
*/
export type PermissionResponse<TPermission extends PermissionTypes> =
PermissionRequest<TPermission> & {
context: Hex;
dependencies: {
factory: Hex;
factoryData: Hex;
}[];
delegationManager: Hex;
};
/**
* Parameters for the `wallet_revokeExecutionPermission` JSON-RPC method.
*
* permissionContext - the context identifier for the permission to be revoked
*/
export type RevokeExecutionPermissionRequestParams = {
permissionContext: Hex;
};
/**
* Response from the `wallet_revokeExecutionPermission` JSON-RPC method.
* The wallet will respond with an empty response when successful.
*/
export type RevokeExecutionPermissionResponseResult = Record<string, never>;