@metamask/smart-accounts-kit 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/dist/actions/index.cjs +4 -4
- package/dist/actions/index.d.cts +2 -2
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.mjs +3 -3
- package/dist/{chunk-L5DLMBDC.mjs → chunk-26PADMXR.mjs} +4 -4
- package/dist/{chunk-UB2FLPP3.cjs → chunk-3PBVHNYP.cjs} +10 -10
- package/dist/{chunk-UB2FLPP3.cjs.map → chunk-3PBVHNYP.cjs.map} +1 -1
- package/dist/{chunk-HFRQNSZE.cjs → chunk-57I2FJY7.cjs} +102 -102
- package/dist/{chunk-HFRQNSZE.cjs.map → chunk-57I2FJY7.cjs.map} +1 -1
- package/dist/{chunk-VJXM3LWA.mjs → chunk-AC2BQSYP.mjs} +2 -2
- package/dist/{chunk-T4IAMAB2.cjs → chunk-AJWMPR7X.cjs} +101 -61
- package/dist/chunk-AJWMPR7X.cjs.map +1 -0
- package/dist/{chunk-UZO5OYCD.cjs → chunk-DLCTHNAE.cjs} +11 -11
- package/dist/{chunk-UZO5OYCD.cjs.map → chunk-DLCTHNAE.cjs.map} +1 -1
- package/dist/{chunk-734MOPHR.mjs → chunk-FKI4OME5.mjs} +49 -9
- package/dist/chunk-FKI4OME5.mjs.map +1 -0
- package/dist/{chunk-3SHZ7PV2.cjs → chunk-GZ7HHI2D.cjs} +12 -12
- package/dist/{chunk-3SHZ7PV2.cjs.map → chunk-GZ7HHI2D.cjs.map} +1 -1
- package/dist/{chunk-YTNCEXUX.mjs → chunk-KBSFVKUB.mjs} +2 -2
- package/dist/{chunk-G7VZ7E6W.mjs → chunk-LQXOM3TA.mjs} +3 -3
- package/dist/{chunk-7BEEGBA2.cjs → chunk-SZOX7K2V.cjs} +2 -2
- package/dist/{chunk-7BEEGBA2.cjs.map → chunk-SZOX7K2V.cjs.map} +1 -1
- package/dist/{chunk-ZA2XYCVX.mjs → chunk-Z4D7ZWVB.mjs} +2 -2
- package/dist/{chunk-ZA2XYCVX.mjs.map → chunk-Z4D7ZWVB.mjs.map} +1 -1
- package/dist/contracts/index.cjs +5 -5
- package/dist/contracts/index.mjs +4 -4
- package/dist/experimental/index.cjs +7 -7
- package/dist/experimental/index.mjs +1 -1
- package/dist/{index-Uj_xXVko.d.cts → index-BDC55AA9.d.cts} +5 -3
- package/dist/{index-D7fBuNV-.d.ts → index-DhG2lH80.d.ts} +5 -3
- package/dist/index.cjs +19 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +6 -6
- package/dist/utils/index.cjs +4 -4
- package/dist/utils/index.mjs +3 -3
- package/package.json +1 -1
- package/dist/chunk-734MOPHR.mjs.map +0 -1
- package/dist/chunk-T4IAMAB2.cjs.map +0 -1
- /package/dist/{chunk-L5DLMBDC.mjs.map → chunk-26PADMXR.mjs.map} +0 -0
- /package/dist/{chunk-VJXM3LWA.mjs.map → chunk-AC2BQSYP.mjs.map} +0 -0
- /package/dist/{chunk-YTNCEXUX.mjs.map → chunk-KBSFVKUB.mjs.map} +0 -0
- /package/dist/{chunk-G7VZ7E6W.mjs.map → chunk-LQXOM3TA.mjs.map} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkGZ7HHI2Dcjs = require('./chunk-GZ7HHI2D.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -21,11 +21,11 @@ var _chunkMOHCTPYQcjs = require('./chunk-MOHCTPYQ.cjs');
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _chunkSZOX7K2Vcjs = require('./chunk-SZOX7K2V.cjs');
|
|
25
25
|
|
|
26
26
|
// src/actions/index.ts
|
|
27
27
|
var actions_exports = {};
|
|
28
|
-
|
|
28
|
+
_chunkSZOX7K2Vcjs.__export.call(void 0, actions_exports, {
|
|
29
29
|
caveatEnforcerActions: () => caveatEnforcerActions,
|
|
30
30
|
erc7710BundlerActions: () => erc7710BundlerActions,
|
|
31
31
|
erc7710WalletActions: () => erc7710WalletActions,
|
|
@@ -49,7 +49,7 @@ _chunk7BEEGBA2cjs.__export.call(void 0, actions_exports, {
|
|
|
49
49
|
var _delegationabis = require('@metamask/delegation-abis');
|
|
50
50
|
var _viem = require('viem');
|
|
51
51
|
async function sendTransactionWithDelegationAction(client, args) {
|
|
52
|
-
|
|
52
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0, "sendTransactionWithDelegationAction", {
|
|
53
53
|
chainId: _nullishCoalesce(_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]), () => ( null))
|
|
54
54
|
});
|
|
55
55
|
if (!args.to) {
|
|
@@ -78,7 +78,7 @@ async function sendTransactionWithDelegationAction(client, args) {
|
|
|
78
78
|
abi: _delegationabis.DelegationManager,
|
|
79
79
|
functionName: "redeemDelegations",
|
|
80
80
|
args: [
|
|
81
|
-
[
|
|
81
|
+
[_chunkSZOX7K2Vcjs.encodeDelegations.call(void 0, args.permissionContext)],
|
|
82
82
|
["0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */],
|
|
83
83
|
_chunkMOHCTPYQcjs.encodeExecutionCalldatas.call(void 0, [executions])
|
|
84
84
|
]
|
|
@@ -97,7 +97,7 @@ async function sendTransactionWithDelegationAction(client, args) {
|
|
|
97
97
|
return hash;
|
|
98
98
|
}
|
|
99
99
|
async function sendUserOperationWithDelegationAction(client, parameters) {
|
|
100
|
-
|
|
100
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0, "sendUserOperationWithDelegationAction", {
|
|
101
101
|
chainId: _nullishCoalesce(_optionalChain([client, 'access', _5 => _5.chain, 'optionalAccess', _6 => _6.id]), () => ( null)),
|
|
102
102
|
callCount: parameters.calls.length,
|
|
103
103
|
hasDependencies: parameters.dependencies !== void 0
|
|
@@ -152,7 +152,7 @@ async function sendUserOperationWithDelegationAction(client, parameters) {
|
|
|
152
152
|
}
|
|
153
153
|
return {
|
|
154
154
|
...call,
|
|
155
|
-
permissionContext:
|
|
155
|
+
permissionContext: _chunkSZOX7K2Vcjs.encodeDelegations.call(void 0, permissionContext)
|
|
156
156
|
};
|
|
157
157
|
});
|
|
158
158
|
return client.sendUserOperation(
|
|
@@ -163,18 +163,37 @@ async function sendUserOperationWithDelegationAction(client, parameters) {
|
|
|
163
163
|
// src/actions/erc7715Mapping.ts
|
|
164
164
|
|
|
165
165
|
function permissionRequestToRpc(parameters) {
|
|
166
|
-
const { chainId, from, expiry } = parameters;
|
|
166
|
+
const { chainId, from, expiry, redeemer } = parameters;
|
|
167
167
|
const converter = getPermissionRequestToRpcConverter(
|
|
168
168
|
parameters.permission.type
|
|
169
169
|
);
|
|
170
|
-
const rules =
|
|
171
|
-
|
|
170
|
+
const rules = [];
|
|
171
|
+
if (_chunkSZOX7K2Vcjs.isDefined.call(void 0, expiry)) {
|
|
172
|
+
rules.push({
|
|
172
173
|
type: "expiry",
|
|
173
174
|
data: {
|
|
174
175
|
timestamp: expiry
|
|
175
176
|
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (_chunkSZOX7K2Vcjs.isDefined.call(void 0, redeemer)) {
|
|
180
|
+
if (redeemer.length === 0) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
"Invalid redeemers: must specify at least one redeemer address"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const addresses = [];
|
|
186
|
+
for (const addr of redeemer) {
|
|
187
|
+
if (!_viem.isAddress.call(void 0, addr)) {
|
|
188
|
+
throw new Error("Invalid redeemers: must be a valid address");
|
|
189
|
+
}
|
|
190
|
+
addresses.push(_viem.getAddress.call(void 0, addr));
|
|
176
191
|
}
|
|
177
|
-
|
|
192
|
+
rules.push({
|
|
193
|
+
type: "redeemer",
|
|
194
|
+
data: { addresses }
|
|
195
|
+
});
|
|
196
|
+
}
|
|
178
197
|
const optionalFields = {
|
|
179
198
|
...from ? { from } : {}
|
|
180
199
|
};
|
|
@@ -224,13 +243,13 @@ function nativeTokenStreamPermissionToRpc(permission) {
|
|
|
224
243
|
isAdjustmentAllowed
|
|
225
244
|
} = permission;
|
|
226
245
|
const optionalFields = {
|
|
227
|
-
...
|
|
228
|
-
initialAmount:
|
|
246
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, initialAmount) && {
|
|
247
|
+
initialAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
|
|
229
248
|
},
|
|
230
|
-
...
|
|
231
|
-
maxAmount:
|
|
249
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, maxAmount) && {
|
|
250
|
+
maxAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
|
|
232
251
|
},
|
|
233
|
-
...
|
|
252
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
|
|
234
253
|
startTime: Number(startTime)
|
|
235
254
|
},
|
|
236
255
|
...justification ? { justification } : {}
|
|
@@ -238,7 +257,7 @@ function nativeTokenStreamPermissionToRpc(permission) {
|
|
|
238
257
|
return {
|
|
239
258
|
type: "native-token-stream",
|
|
240
259
|
data: {
|
|
241
|
-
amountPerSecond:
|
|
260
|
+
amountPerSecond: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
|
|
242
261
|
...optionalFields
|
|
243
262
|
},
|
|
244
263
|
isAdjustmentAllowed
|
|
@@ -257,13 +276,13 @@ function erc20TokenStreamPermissionToRpc(permission) {
|
|
|
257
276
|
isAdjustmentAllowed
|
|
258
277
|
} = permission;
|
|
259
278
|
const optionalFields = {
|
|
260
|
-
...
|
|
261
|
-
initialAmount:
|
|
279
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, initialAmount) && {
|
|
280
|
+
initialAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
|
|
262
281
|
},
|
|
263
|
-
...
|
|
264
|
-
maxAmount:
|
|
282
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, maxAmount) && {
|
|
283
|
+
maxAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
|
|
265
284
|
},
|
|
266
|
-
...
|
|
285
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
|
|
267
286
|
startTime: Number(startTime)
|
|
268
287
|
},
|
|
269
288
|
...justification ? { justification } : {}
|
|
@@ -271,8 +290,8 @@ function erc20TokenStreamPermissionToRpc(permission) {
|
|
|
271
290
|
return {
|
|
272
291
|
type: "erc20-token-stream",
|
|
273
292
|
data: {
|
|
274
|
-
tokenAddress:
|
|
275
|
-
amountPerSecond:
|
|
293
|
+
tokenAddress: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
|
|
294
|
+
amountPerSecond: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
|
|
276
295
|
...optionalFields
|
|
277
296
|
},
|
|
278
297
|
isAdjustmentAllowed
|
|
@@ -284,7 +303,7 @@ function nativeTokenPeriodicPermissionToRpc(permission) {
|
|
|
284
303
|
isAdjustmentAllowed
|
|
285
304
|
} = permission;
|
|
286
305
|
const optionalFields = {
|
|
287
|
-
...
|
|
306
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
|
|
288
307
|
startTime: Number(startTime)
|
|
289
308
|
},
|
|
290
309
|
...justification ? { justification } : {}
|
|
@@ -292,7 +311,7 @@ function nativeTokenPeriodicPermissionToRpc(permission) {
|
|
|
292
311
|
return {
|
|
293
312
|
type: "native-token-periodic",
|
|
294
313
|
data: {
|
|
295
|
-
periodAmount:
|
|
314
|
+
periodAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
|
|
296
315
|
periodDuration: Number(periodDuration),
|
|
297
316
|
...optionalFields
|
|
298
317
|
},
|
|
@@ -311,7 +330,7 @@ function erc20TokenPeriodicPermissionToRpc(permission) {
|
|
|
311
330
|
isAdjustmentAllowed
|
|
312
331
|
} = permission;
|
|
313
332
|
const optionalFields = {
|
|
314
|
-
...
|
|
333
|
+
..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
|
|
315
334
|
startTime: Number(startTime)
|
|
316
335
|
},
|
|
317
336
|
...justification ? { justification } : {}
|
|
@@ -319,8 +338,8 @@ function erc20TokenPeriodicPermissionToRpc(permission) {
|
|
|
319
338
|
return {
|
|
320
339
|
type: "erc20-token-periodic",
|
|
321
340
|
data: {
|
|
322
|
-
tokenAddress:
|
|
323
|
-
periodAmount:
|
|
341
|
+
tokenAddress: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
|
|
342
|
+
periodAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
|
|
324
343
|
periodDuration: Number(periodDuration),
|
|
325
344
|
...optionalFields
|
|
326
345
|
},
|
|
@@ -345,9 +364,30 @@ function permissionResponsesFromRpc(result) {
|
|
|
345
364
|
return result.map((permission) => ({
|
|
346
365
|
...permission,
|
|
347
366
|
chainId: _viem.hexToNumber.call(void 0, permission.chainId),
|
|
348
|
-
permission: permissionTypeFromRpc(permission.permission)
|
|
367
|
+
permission: permissionTypeFromRpc(permission.permission),
|
|
368
|
+
rules: normalizeRulesFromRpc(permission.rules)
|
|
349
369
|
}));
|
|
350
370
|
}
|
|
371
|
+
function normalizeRulesFromRpc(rules) {
|
|
372
|
+
if (rules === void 0 || rules === null) {
|
|
373
|
+
return rules;
|
|
374
|
+
}
|
|
375
|
+
return rules.map((rule) => {
|
|
376
|
+
if (rule.type !== "redeemer") {
|
|
377
|
+
return rule;
|
|
378
|
+
}
|
|
379
|
+
const rawAddresses = _optionalChain([rule, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.addresses]);
|
|
380
|
+
if (!Array.isArray(rawAddresses)) {
|
|
381
|
+
return rule;
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
type: "redeemer",
|
|
385
|
+
data: {
|
|
386
|
+
addresses: rawAddresses.map((addr) => _viem.getAddress.call(void 0, addr))
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
}
|
|
351
391
|
function permissionTypeFromRpc(permission) {
|
|
352
392
|
const convertedData = { ...permission.data };
|
|
353
393
|
if ("amountPerSecond" in convertedData && convertedData.amountPerSecond) {
|
|
@@ -386,10 +426,10 @@ function rpcSupportedPermissionsToDeveloper(result) {
|
|
|
386
426
|
|
|
387
427
|
// src/actions/erc7715GetGrantedExecutionPermissionsAction.ts
|
|
388
428
|
async function erc7715GetGrantedExecutionPermissionsAction(client) {
|
|
389
|
-
|
|
429
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
390
430
|
"erc7715GetGrantedExecutionPermissionsAction",
|
|
391
431
|
{
|
|
392
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
432
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _11 => _11.chain, 'optionalAccess', _12 => _12.id]), () => ( null))
|
|
393
433
|
}
|
|
394
434
|
);
|
|
395
435
|
const result = await client.request(
|
|
@@ -407,10 +447,10 @@ async function erc7715GetGrantedExecutionPermissionsAction(client) {
|
|
|
407
447
|
|
|
408
448
|
// src/actions/erc7715GetSupportedExecutionPermissionsAction.ts
|
|
409
449
|
async function erc7715GetSupportedExecutionPermissionsAction(client) {
|
|
410
|
-
|
|
450
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
411
451
|
"erc7715GetSupportedExecutionPermissionsAction",
|
|
412
452
|
{
|
|
413
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
453
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _13 => _13.chain, 'optionalAccess', _14 => _14.id]), () => ( null))
|
|
414
454
|
}
|
|
415
455
|
);
|
|
416
456
|
const result = await client.request(
|
|
@@ -428,10 +468,10 @@ async function erc7715GetSupportedExecutionPermissionsAction(client) {
|
|
|
428
468
|
|
|
429
469
|
// src/actions/erc7715RequestExecutionPermissionsAction.ts
|
|
430
470
|
async function erc7715RequestExecutionPermissionsAction(client, parameters) {
|
|
431
|
-
|
|
471
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
432
472
|
"erc7715RequestExecutionPermissionsAction",
|
|
433
473
|
{
|
|
434
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
474
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _15 => _15.chain, 'optionalAccess', _16 => _16.id]), () => ( null)),
|
|
435
475
|
requestCount: parameters.length
|
|
436
476
|
}
|
|
437
477
|
);
|
|
@@ -489,10 +529,10 @@ function getEnforcerAddress({
|
|
|
489
529
|
return enforcerAddress;
|
|
490
530
|
}
|
|
491
531
|
async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment, params) {
|
|
492
|
-
|
|
532
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
493
533
|
"getErc20PeriodTransferEnforcerAvailableAmount",
|
|
494
534
|
{
|
|
495
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
535
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _17 => _17.chain, 'optionalAccess', _18 => _18.id]), () => ( null))
|
|
496
536
|
}
|
|
497
537
|
);
|
|
498
538
|
const enforcerName = "ERC20PeriodTransferEnforcer";
|
|
@@ -501,13 +541,13 @@ async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment
|
|
|
501
541
|
enforcerName,
|
|
502
542
|
environment
|
|
503
543
|
});
|
|
504
|
-
const delegationHash =
|
|
544
|
+
const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
|
|
505
545
|
const { terms } = findMatchingCaveat({
|
|
506
546
|
delegation: params.delegation,
|
|
507
547
|
enforcerAddress,
|
|
508
548
|
enforcerName
|
|
509
549
|
});
|
|
510
|
-
return
|
|
550
|
+
return _chunkGZ7HHI2Dcjs.read_exports.getAvailableAmount({
|
|
511
551
|
client,
|
|
512
552
|
contractAddress: enforcerAddress,
|
|
513
553
|
delegationHash,
|
|
@@ -516,10 +556,10 @@ async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment
|
|
|
516
556
|
});
|
|
517
557
|
}
|
|
518
558
|
async function getErc20StreamingEnforcerAvailableAmount(client, environment, params) {
|
|
519
|
-
|
|
559
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
520
560
|
"getErc20StreamingEnforcerAvailableAmount",
|
|
521
561
|
{
|
|
522
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
562
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _19 => _19.chain, 'optionalAccess', _20 => _20.id]), () => ( null))
|
|
523
563
|
}
|
|
524
564
|
);
|
|
525
565
|
const enforcerName = "ERC20StreamingEnforcer";
|
|
@@ -528,13 +568,13 @@ async function getErc20StreamingEnforcerAvailableAmount(client, environment, par
|
|
|
528
568
|
enforcerName,
|
|
529
569
|
environment
|
|
530
570
|
});
|
|
531
|
-
const delegationHash =
|
|
571
|
+
const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
|
|
532
572
|
const { terms } = findMatchingCaveat({
|
|
533
573
|
delegation: params.delegation,
|
|
534
574
|
enforcerAddress,
|
|
535
575
|
enforcerName
|
|
536
576
|
});
|
|
537
|
-
return
|
|
577
|
+
return _chunkGZ7HHI2Dcjs.read_exports2.getAvailableAmount({
|
|
538
578
|
client,
|
|
539
579
|
contractAddress: enforcerAddress,
|
|
540
580
|
delegationManager,
|
|
@@ -543,10 +583,10 @@ async function getErc20StreamingEnforcerAvailableAmount(client, environment, par
|
|
|
543
583
|
});
|
|
544
584
|
}
|
|
545
585
|
async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, params) {
|
|
546
|
-
|
|
586
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
547
587
|
"getMultiTokenPeriodEnforcerAvailableAmount",
|
|
548
588
|
{
|
|
549
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
589
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _21 => _21.chain, 'optionalAccess', _22 => _22.id]), () => ( null))
|
|
550
590
|
}
|
|
551
591
|
);
|
|
552
592
|
const enforcerName = "MultiTokenPeriodEnforcer";
|
|
@@ -555,13 +595,13 @@ async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, p
|
|
|
555
595
|
enforcerName,
|
|
556
596
|
environment
|
|
557
597
|
});
|
|
558
|
-
const delegationHash =
|
|
598
|
+
const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
|
|
559
599
|
const { terms, args } = findMatchingCaveat({
|
|
560
600
|
delegation: params.delegation,
|
|
561
601
|
enforcerAddress,
|
|
562
602
|
enforcerName
|
|
563
603
|
});
|
|
564
|
-
return
|
|
604
|
+
return _chunkGZ7HHI2Dcjs.read_exports3.getAvailableAmount({
|
|
565
605
|
client,
|
|
566
606
|
contractAddress: enforcerAddress,
|
|
567
607
|
delegationHash,
|
|
@@ -571,10 +611,10 @@ async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, p
|
|
|
571
611
|
});
|
|
572
612
|
}
|
|
573
613
|
async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, environment, params) {
|
|
574
|
-
|
|
614
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
575
615
|
"getNativeTokenPeriodTransferEnforcerAvailableAmount",
|
|
576
616
|
{
|
|
577
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
617
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _23 => _23.chain, 'optionalAccess', _24 => _24.id]), () => ( null))
|
|
578
618
|
}
|
|
579
619
|
);
|
|
580
620
|
const enforcerName = "NativeTokenPeriodTransferEnforcer";
|
|
@@ -583,13 +623,13 @@ async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, envir
|
|
|
583
623
|
enforcerName,
|
|
584
624
|
environment
|
|
585
625
|
});
|
|
586
|
-
const delegationHash =
|
|
626
|
+
const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
|
|
587
627
|
const { terms } = findMatchingCaveat({
|
|
588
628
|
delegation: params.delegation,
|
|
589
629
|
enforcerAddress,
|
|
590
630
|
enforcerName
|
|
591
631
|
});
|
|
592
|
-
return
|
|
632
|
+
return _chunkGZ7HHI2Dcjs.read_exports4.getAvailableAmount({
|
|
593
633
|
client,
|
|
594
634
|
contractAddress: enforcerAddress,
|
|
595
635
|
delegationHash,
|
|
@@ -598,10 +638,10 @@ async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, envir
|
|
|
598
638
|
});
|
|
599
639
|
}
|
|
600
640
|
async function getNativeTokenStreamingEnforcerAvailableAmount(client, environment, params) {
|
|
601
|
-
|
|
641
|
+
_chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
|
|
602
642
|
"getNativeTokenStreamingEnforcerAvailableAmount",
|
|
603
643
|
{
|
|
604
|
-
chainId: _nullishCoalesce(_optionalChain([client, 'access',
|
|
644
|
+
chainId: _nullishCoalesce(_optionalChain([client, 'access', _25 => _25.chain, 'optionalAccess', _26 => _26.id]), () => ( null))
|
|
605
645
|
}
|
|
606
646
|
);
|
|
607
647
|
const enforcerName = "NativeTokenStreamingEnforcer";
|
|
@@ -610,13 +650,13 @@ async function getNativeTokenStreamingEnforcerAvailableAmount(client, environmen
|
|
|
610
650
|
enforcerName,
|
|
611
651
|
environment
|
|
612
652
|
});
|
|
613
|
-
const delegationHash =
|
|
653
|
+
const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
|
|
614
654
|
const { terms } = findMatchingCaveat({
|
|
615
655
|
delegation: params.delegation,
|
|
616
656
|
enforcerAddress,
|
|
617
657
|
enforcerName
|
|
618
658
|
});
|
|
619
|
-
return
|
|
659
|
+
return _chunkGZ7HHI2Dcjs.read_exports5.getAvailableAmount({
|
|
620
660
|
client,
|
|
621
661
|
contractAddress: enforcerAddress,
|
|
622
662
|
delegationManager,
|
|
@@ -697,7 +737,7 @@ var caveatEnforcerActions = ({ environment }) => (client) => ({
|
|
|
697
737
|
var _actions = require('viem/actions');
|
|
698
738
|
var DELEGATION_PREFIX = "0xef0100";
|
|
699
739
|
function extractDelegatedAddress(code) {
|
|
700
|
-
if (_optionalChain([code, 'optionalAccess',
|
|
740
|
+
if (_optionalChain([code, 'optionalAccess', _27 => _27.length]) !== 48) {
|
|
701
741
|
return null;
|
|
702
742
|
}
|
|
703
743
|
if (!code.toLowerCase().startsWith(DELEGATION_PREFIX.toLowerCase())) {
|
|
@@ -746,7 +786,7 @@ async function signDelegation(client, parameters) {
|
|
|
746
786
|
throw new (0, _viem.BaseError)("Account not found. Please provide an account.");
|
|
747
787
|
}
|
|
748
788
|
const account = _accounts.parseAccount.call(void 0, accountParam);
|
|
749
|
-
const typedData =
|
|
789
|
+
const typedData = _chunkSZOX7K2Vcjs.prepareSignDelegationTypedData.call(void 0, {
|
|
750
790
|
delegation,
|
|
751
791
|
delegationManager,
|
|
752
792
|
chainId,
|
|
@@ -763,7 +803,7 @@ function signDelegationActions() {
|
|
|
763
803
|
return (client) => ({
|
|
764
804
|
signDelegation: async (parameters) => signDelegation(client, {
|
|
765
805
|
chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
|
|
766
|
-
if (!_optionalChain([client, 'access',
|
|
806
|
+
if (!_optionalChain([client, 'access', _28 => _28.chain, 'optionalAccess', _29 => _29.id])) {
|
|
767
807
|
throw new (0, _viem.BaseError)(
|
|
768
808
|
"Chain ID is required. Either provide it in parameters or configure the client with a chain."
|
|
769
809
|
);
|
|
@@ -809,7 +849,7 @@ function signUserOperationActions() {
|
|
|
809
849
|
return (client) => ({
|
|
810
850
|
signUserOperation: async (parameters) => signUserOperation(client, {
|
|
811
851
|
chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
|
|
812
|
-
if (!_optionalChain([client, 'access',
|
|
852
|
+
if (!_optionalChain([client, 'access', _30 => _30.chain, 'optionalAccess', _31 => _31.id])) {
|
|
813
853
|
throw new (0, _viem.BaseError)(
|
|
814
854
|
"Chain ID is required. Either provide it in parameters or configure the client with a chain."
|
|
815
855
|
);
|
|
@@ -867,4 +907,4 @@ var erc7710BundlerActions = () => (client) => ({
|
|
|
867
907
|
|
|
868
908
|
|
|
869
909
|
exports.isValid7702Implementation = isValid7702Implementation; exports.erc7715GetGrantedExecutionPermissionsAction = erc7715GetGrantedExecutionPermissionsAction; exports.erc7715GetSupportedExecutionPermissionsAction = erc7715GetSupportedExecutionPermissionsAction; exports.erc7715RequestExecutionPermissionsAction = erc7715RequestExecutionPermissionsAction; exports.getErc20PeriodTransferEnforcerAvailableAmount = getErc20PeriodTransferEnforcerAvailableAmount; exports.getErc20StreamingEnforcerAvailableAmount = getErc20StreamingEnforcerAvailableAmount; exports.getMultiTokenPeriodEnforcerAvailableAmount = getMultiTokenPeriodEnforcerAvailableAmount; exports.getNativeTokenPeriodTransferEnforcerAvailableAmount = getNativeTokenPeriodTransferEnforcerAvailableAmount; exports.getNativeTokenStreamingEnforcerAvailableAmount = getNativeTokenStreamingEnforcerAvailableAmount; exports.caveatEnforcerActions = caveatEnforcerActions; exports.signDelegation = signDelegation; exports.signDelegationActions = signDelegationActions; exports.signUserOperation = signUserOperation; exports.signUserOperationActions = signUserOperationActions; exports.erc7715ProviderActions = erc7715ProviderActions; exports.erc7710WalletActions = erc7710WalletActions; exports.erc7710BundlerActions = erc7710BundlerActions; exports.actions_exports = actions_exports;
|
|
870
|
-
//# sourceMappingURL=chunk-
|
|
910
|
+
//# sourceMappingURL=chunk-AJWMPR7X.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-AJWMPR7X.cjs","../src/actions/index.ts","../src/actions/erc7710RedeemDelegationAction.ts","../src/actions/erc7715Mapping.ts","../src/actions/erc7715GetGrantedExecutionPermissionsAction.ts","../src/actions/erc7715GetSupportedExecutionPermissionsAction.ts","../src/actions/erc7715RequestExecutionPermissionsAction.ts","../src/actions/getCaveatAvailableAmount.ts","../src/actions/isValid7702Implementation.ts","../src/actions/signDelegation.ts","../src/actions/signUserOperation.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACzBA,IAAA,gBAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,eAAA,EAAA;AAAA,EAAA,qBAAA,EAAA,CAAA,EAAA,GAAA,qBAAA;AAAA,EAAA,qBAAA,EAAA,CAAA,EAAA,GAAA,qBAAA;AAAA,EAAA,oBAAA,EAAA,CAAA,EAAA,GAAA,oBAAA;AAAA,EAAA,sBAAA,EAAA,CAAA,EAAA,GAAA,sBAAA;AAAA,EAAA,6CAAA,EAAA,CAAA,EAAA,GAAA,6CAAA;AAAA,EAAA,wCAAA,EAAA,CAAA,EAAA,GAAA,wCAAA;AAAA,EAAA,8BAAA,EAAA,CAAA,EAAA,GAAA,2CAAA;AAAA,EAAA,0CAAA,EAAA,CAAA,EAAA,GAAA,0CAAA;AAAA,EAAA,mDAAA,EAAA,CAAA,EAAA,GAAA,mDAAA;AAA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AAA;AAAU,YAAA;AACR,UAAA;AACF,QAAA;AAEF,QAAA;AAAoB,MAAA;AACnB,MAAA;AACF,IAAA;AACJ,EAAA;AAEP;AVktBA;AACA;AC3wBO;AAA0D,EAAA;AAI7D,IAAA;AAAO,MAAA;AACL,MAAA;AACA,IAAA;AACF,EAAA;AACF,EAAA;AAEE,IAAA;AAAO,MAAA;AACL,IAAA;AACF,EAAA;AACF,EAAA;AAEE,IAAA;AAAO,MAAA;AACL,IAAA;AACF,EAAA;AAEJ;AAqBO;AAA8D,EAAA;AAIrE;AAEO;AAAyD,EAAA;AAIhE;ADkvBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-AJWMPR7X.cjs","sourcesContent":[null,"import type { Client, WalletClient } from 'viem';\nimport type { BundlerClient } from 'viem/account-abstraction';\n\nimport type {\n SendTransactionWithDelegationParameters,\n SendUserOperationWithDelegationParameters,\n} from './erc7710RedeemDelegationAction';\nimport {\n sendTransactionWithDelegationAction,\n sendUserOperationWithDelegationAction,\n} from './erc7710RedeemDelegationAction';\nimport { erc7715GetGrantedExecutionPermissionsAction } from './erc7715GetGrantedExecutionPermissionsAction';\nimport { erc7715GetSupportedExecutionPermissionsAction } from './erc7715GetSupportedExecutionPermissionsAction';\nimport { erc7715RequestExecutionPermissionsAction } from './erc7715RequestExecutionPermissionsAction';\nimport type {\n MetaMaskExtensionClient,\n RequestExecutionPermissionsParameters,\n} from './erc7715RequestExecutionPermissionsAction';\n\nexport {\n // Individual action functions\n getErc20PeriodTransferEnforcerAvailableAmount,\n getErc20StreamingEnforcerAvailableAmount,\n getMultiTokenPeriodEnforcerAvailableAmount,\n getNativeTokenPeriodTransferEnforcerAvailableAmount,\n getNativeTokenStreamingEnforcerAvailableAmount,\n // Action builder\n caveatEnforcerActions,\n // Parameter types\n type CaveatEnforcerParams,\n // Result types\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\nexport { isValid7702Implementation } from './isValid7702Implementation';\n\n// Signing actions\nexport {\n signDelegation,\n signDelegationActions,\n type SignDelegationParameters,\n type SignDelegationReturnType,\n} from './signDelegation';\n\nexport {\n signUserOperation,\n signUserOperationActions,\n type SignUserOperationParameters,\n type SignUserOperationReturnType,\n} from './signUserOperation';\n\nexport {\n erc7715RequestExecutionPermissionsAction as requestExecutionPermissions,\n type MetaMaskExtensionClient,\n type MetaMaskExtensionSchema,\n type RequestExecutionPermissionsParameters,\n type RequestExecutionPermissionsReturnType,\n} from './erc7715RequestExecutionPermissionsAction';\n\nexport type { PermissionRequestParameter } from './erc7715Types';\n\nexport { erc7715GetSupportedExecutionPermissionsAction as getSupportedExecutionPermissions } from './erc7715GetSupportedExecutionPermissionsAction';\n\nexport { erc7715GetGrantedExecutionPermissionsAction as getGrantedExecutionPermissions } from './erc7715GetGrantedExecutionPermissionsAction';\n\nexport {\n type GetSupportedExecutionPermissionsResult,\n type GetGrantedExecutionPermissionsResult,\n type Rule,\n type SupportedPermissionInfo,\n type PermissionTypes,\n type NativeTokenStreamPermission,\n type NativeTokenPeriodicPermission,\n type Erc20TokenStreamPermission,\n type Erc20TokenPeriodicPermission,\n type Erc20TokenRevocationPermission,\n type RpcGetSupportedExecutionPermissionsResult,\n type RpcGetGrantedExecutionPermissionsResult,\n type RpcSupportedPermissionInfo,\n} from './erc7715Types';\n\nexport type { DelegatedCall } from './erc7710RedeemDelegationAction';\n\nexport const erc7715ProviderActions = () => (client: Client) => ({\n requestExecutionPermissions: async (\n parameters: RequestExecutionPermissionsParameters,\n ) => {\n return erc7715RequestExecutionPermissionsAction(\n client as MetaMaskExtensionClient,\n parameters,\n );\n },\n getSupportedExecutionPermissions: async () => {\n return erc7715GetSupportedExecutionPermissionsAction(\n client as MetaMaskExtensionClient,\n );\n },\n getGrantedExecutionPermissions: async () => {\n return erc7715GetGrantedExecutionPermissionsAction(\n client as MetaMaskExtensionClient,\n );\n },\n});\n\n/**\n * Type for a viem Client extended with ERC-7715 provider actions.\n * Use this to type variables that will be assigned an extended client later.\n *\n * @example\n * ```typescript\n * let client: Erc7715Client | null = null;\n *\n * function setupClient() {\n * client = createWalletClient({\n * chain: sepolia,\n * transport: custom(window.ethereum),\n * }).extend(erc7715ProviderActions());\n * }\n * ```\n */\nexport type Erc7715Client = Client &\n ReturnType<ReturnType<typeof erc7715ProviderActions>>;\n\nexport const erc7710WalletActions = () => (client: WalletClient) => ({\n sendTransactionWithDelegation: async (\n args: SendTransactionWithDelegationParameters,\n ) => sendTransactionWithDelegationAction(client, args),\n});\n\nexport const erc7710BundlerActions = () => (client: Client) => ({\n sendUserOperationWithDelegation: async (\n args: SendUserOperationWithDelegationParameters,\n ) => sendUserOperationWithDelegationAction(client as BundlerClient, args),\n});\n","import { DelegationManager } from '@metamask/delegation-abis';\nimport type {\n Account,\n Chain,\n Hex,\n OneOf,\n PublicClient,\n SendTransactionParameters,\n SendTransactionRequest,\n Transport,\n WalletClient,\n} from 'viem';\nimport { concat, encodeFunctionData, isAddressEqual } from 'viem';\nimport type {\n BundlerClient,\n SendUserOperationParameters,\n SmartAccount,\n} from 'viem/account-abstraction';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { encodeDelegations } from '../delegation';\nimport {\n createExecution,\n encodeExecutionCalldatas,\n ExecutionMode,\n} from '../executions';\nimport { getSmartAccountsEnvironment } from '../smartAccountsEnvironment';\nimport type { Call, PermissionContext } from '../types';\n\nexport type DelegatedCall = Call &\n OneOf<\n { permissionContext: PermissionContext; delegationManager: Hex } | object\n >;\n\nexport type SendTransactionWithDelegationParameters<\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n TChainOverride extends Chain | undefined = Chain | undefined,\n TRequest extends SendTransactionRequest<TChain, TChainOverride> =\n SendTransactionRequest<TChain, TChainOverride>,\n> = SendTransactionParameters<TChain, TAccount, TChainOverride, TRequest> & {\n permissionContext: PermissionContext;\n delegationManager: Hex;\n};\n\n/**\n * Sends a transaction using delegation to execute operations on behalf of another account.\n *\n * @param client - The wallet client to use for sending the transaction.\n * @param args - Transaction parameters with delegation details.\n * @returns Transaction hash of the executed transaction.\n */\nexport async function sendTransactionWithDelegationAction<\n TChain extends Chain | undefined,\n TAccount extends Account | undefined,\n>(\n client: WalletClient<Transport, TChain, TAccount>,\n args: SendTransactionWithDelegationParameters<TChain, TAccount>,\n) {\n trackSmartAccountsKitFunctionCall('sendTransactionWithDelegationAction', {\n chainId: client.chain?.id ?? null,\n });\n\n if (!args.to) {\n throw new Error(\n '`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts.',\n );\n }\n\n // Validate DelegationManager address\n const chainId = client.chain?.id;\n if (!chainId) {\n throw new Error('Chain ID is not set');\n }\n\n const { DelegationManager: expectedDelegationManager } =\n getSmartAccountsEnvironment(chainId);\n if (!isAddressEqual(args.delegationManager, expectedDelegationManager)) {\n throw new Error(\n `Invalid DelegationManager: expected ${expectedDelegationManager} for chain ${chainId}, but got ${args.delegationManager}`,\n );\n }\n\n const executions = [\n createExecution({\n target: args.to,\n value: args.value,\n callData: args.data,\n }),\n ];\n\n const calldata = encodeFunctionData({\n abi: DelegationManager,\n functionName: 'redeemDelegations',\n args: [\n [encodeDelegations(args.permissionContext)],\n [ExecutionMode.SingleDefault],\n encodeExecutionCalldatas([executions]),\n ],\n });\n\n const {\n value: _value,\n permissionContext: _permissionContext,\n delegationManager: _delegationManager,\n ...rest\n } = args;\n\n const hash = await client.sendTransaction({\n ...rest,\n to: args.delegationManager,\n data: calldata,\n } as unknown as SendTransactionParameters);\n\n return hash;\n}\n\nexport type SendUserOperationWithDelegationParameters<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n TAccountOverride extends SmartAccount | undefined = SmartAccount | undefined,\n> = SendUserOperationParameters<TAccount, TAccountOverride, DelegatedCall[]> & {\n dependencies?: { factory: Hex; factoryData: Hex }[];\n calls: DelegatedCall[];\n publicClient: PublicClient<Transport, Chain>;\n};\n\n/**\n * Broadcasts a User Operation with delegation to the Bundler.\n *\n * @param client - Client to use for sending the user operation.\n * @param parameters - Parameters for the user operation with delegation.\n * @returns The User Operation hash of the broadcasted operation.\n * @example\n * import { createBundlerClient, http } from 'viem'\n * import { mainnet } from 'viem/chains'\n *\n * const bundlerClient = createBundlerClient({\n * chain: mainnet,\n * transport: http(),\n * })\n *\n * const userOpHash = await sendUserOperationWithDelegationAction(bundlerClient, {\n * account: bobSmartAccount,\n * calls: [\n * {\n * to: aliceCounterContractAddress,\n * data: encodeFunctionData({\n * abi: CounterMetadata.abi,\n * functionName: 'increment',\n * }),\n * value: 0n,\n * permissionContext: '0x...',\n * delegationManager: '0x...',\n * },\n * ],\n * dependencies: [{ factory: '0x...', factoryData: '0x...' }], // Optional: for deploying accounts\n * })\n */\nexport async function sendUserOperationWithDelegationAction<\n TAccount extends SmartAccount | undefined,\n TAccountOverride extends SmartAccount | undefined = undefined,\n>(\n client: BundlerClient<Transport, Chain | undefined, TAccount>,\n parameters: SendUserOperationWithDelegationParameters<\n TAccount,\n TAccountOverride\n >,\n) {\n trackSmartAccountsKitFunctionCall('sendUserOperationWithDelegationAction', {\n chainId: client.chain?.id ?? null,\n callCount: parameters.calls.length,\n hasDependencies: parameters.dependencies !== undefined,\n });\n\n if (parameters.dependencies) {\n const { publicClient } = parameters;\n\n const includedAccountKeys: Record<Hex, boolean> = {};\n\n const chainId = publicClient.chain?.id;\n\n if (!chainId) {\n throw new Error('Chain ID is not set');\n }\n\n const { SimpleFactory } = getSmartAccountsEnvironment(chainId);\n\n const uniqueDependencies = parameters.dependencies.filter((dependency) => {\n if (!isAddressEqual(dependency.factory, SimpleFactory)) {\n throw new Error(\n `Invalid dependency: ${dependency.factory} is not allowed.`,\n );\n }\n\n // ensure that factory calls are not duplicated\n const accountKey = concat([dependency.factory, dependency.factoryData]);\n const isDuplicate = includedAccountKeys[accountKey];\n\n includedAccountKeys[accountKey] = true;\n return !isDuplicate;\n });\n\n const factoryCalls = (\n await Promise.all(\n uniqueDependencies.map(async ({ factory, factoryData }) => {\n const isDeployed = await publicClient\n .call({\n to: factory,\n data: factoryData,\n })\n .then(() => false)\n .catch(() => true);\n\n if (isDeployed) {\n return undefined;\n }\n return {\n to: factory,\n value: 0n,\n data: factoryData,\n };\n }),\n )\n ).filter((call: Call | undefined) => call !== undefined) as Call[];\n\n parameters.calls = [\n ...(factoryCalls as DelegatedCall[]),\n ...parameters.calls,\n ];\n }\n\n parameters.calls = parameters.calls.map((call) => {\n if (!('permissionContext' in call)) {\n return call;\n }\n\n const { permissionContext } = call;\n if (!permissionContext) {\n return call;\n }\n\n return {\n ...call,\n permissionContext: encodeDelegations(permissionContext),\n };\n });\n\n return client.sendUserOperation(\n parameters as unknown as SendUserOperationParameters,\n );\n}\n","import type {\n Erc20TokenPeriodicPermission as RpcErc20TokenPeriodicPermission,\n Erc20TokenStreamPermission as RpcErc20TokenStreamPermission,\n Erc20TokenRevocationPermission as RpcErc20TokenRevocationPermission,\n NativeTokenPeriodicPermission as RpcNativeTokenPeriodicPermission,\n NativeTokenStreamPermission as RpcNativeTokenStreamPermission,\n PermissionRequest,\n PermissionTypes as RpcPermissionTypes,\n Rule,\n} from '@metamask/7715-permission-types';\nimport { getAddress, hexToNumber, isAddress, toHex, type Hex } from 'viem';\n\nimport { isDefined, toHexOrThrow } from '../utils';\nimport type {\n Erc20TokenPeriodicPermission,\n Erc20TokenRevocationPermission,\n Erc20TokenStreamPermission,\n GetGrantedExecutionPermissionsResult,\n GetSupportedExecutionPermissionsResult,\n NativeTokenPeriodicPermission,\n NativeTokenStreamPermission,\n PermissionRequestParameter,\n PermissionTypes as DeveloperPermissionTypes,\n RpcGetGrantedExecutionPermissionsResult,\n RpcGetSupportedExecutionPermissionsResult,\n} from './erc7715Types';\n\n// =============================================================================\n// Developer → RPC (request formatting)\n// =============================================================================\n\n/**\n * Converts a developer permission request to RPC format for wallet submission.\n *\n * @param parameters the permission request parameters\n * @returns the permission request in RPC format\n */\nexport function permissionRequestToRpc(\n parameters: PermissionRequestParameter,\n): PermissionRequest<RpcPermissionTypes> {\n const { chainId, from, expiry, redeemer } = parameters;\n\n const converter = getPermissionRequestToRpcConverter(\n parameters.permission.type,\n );\n\n const rules: Rule[] = [];\n if (isDefined(expiry)) {\n rules.push({\n type: 'expiry',\n data: {\n timestamp: expiry,\n },\n });\n }\n if (isDefined(redeemer)) {\n if (redeemer.length === 0) {\n throw new Error(\n 'Invalid redeemers: must specify at least one redeemer address',\n );\n }\n const addresses: Hex[] = [];\n for (const addr of redeemer) {\n if (!isAddress(addr)) {\n throw new Error('Invalid redeemers: must be a valid address');\n }\n addresses.push(getAddress(addr));\n }\n rules.push({\n type: 'redeemer',\n data: { addresses },\n });\n }\n\n const optionalFields = {\n ...(from ? { from } : {}),\n };\n\n return {\n ...optionalFields,\n chainId: toHex(chainId),\n permission: converter(parameters.permission),\n to: parameters.to,\n rules,\n };\n}\n\ntype PermissionRequestToRpcConverter = (\n permission: DeveloperPermissionTypes,\n) => RpcPermissionTypes;\n\n/**\n * Get the permission request to RPC converter for the given permission type.\n *\n * @param permissionType the permission type\n * @returns the permission request to RPC converter for the given permission type\n */\nfunction getPermissionRequestToRpcConverter(\n permissionType: string,\n): PermissionRequestToRpcConverter {\n switch (permissionType) {\n case 'native-token-stream':\n return (permission) =>\n nativeTokenStreamPermissionToRpc(\n permission as NativeTokenStreamPermission,\n );\n case 'erc20-token-stream':\n return (permission) =>\n erc20TokenStreamPermissionToRpc(\n permission as Erc20TokenStreamPermission,\n );\n case 'native-token-periodic':\n return (permission) =>\n nativeTokenPeriodicPermissionToRpc(\n permission as NativeTokenPeriodicPermission,\n );\n case 'erc20-token-periodic':\n return (permission) =>\n erc20TokenPeriodicPermissionToRpc(\n permission as Erc20TokenPeriodicPermission,\n );\n case 'erc20-token-revocation':\n return (permission) =>\n erc20TokenRevocationPermissionToRpc(\n permission as Erc20TokenRevocationPermission,\n );\n default:\n throw new Error(`Unsupported permission type: ${permissionType}`);\n }\n}\n\n/**\n * Convert native token stream permission to RPC format.\n *\n * @param permission the native token stream permission\n * @returns the native token stream permission in RPC format\n */\nfunction nativeTokenStreamPermissionToRpc(\n permission: NativeTokenStreamPermission,\n): RpcNativeTokenStreamPermission {\n const {\n data: {\n initialAmount,\n justification,\n maxAmount,\n startTime,\n amountPerSecond,\n },\n isAdjustmentAllowed,\n } = permission;\n\n const optionalFields = {\n ...(isDefined(initialAmount) && {\n initialAmount: toHexOrThrow(initialAmount, 'initialAmount'),\n }),\n ...(isDefined(maxAmount) && {\n maxAmount: toHexOrThrow(maxAmount, 'maxAmount'),\n }),\n ...(isDefined(startTime) && {\n startTime: Number(startTime),\n }),\n ...(justification ? { justification } : {}),\n };\n\n return {\n type: 'native-token-stream',\n data: {\n amountPerSecond: toHexOrThrow(amountPerSecond, 'amountPerSecond'),\n ...optionalFields,\n },\n isAdjustmentAllowed,\n };\n}\n\n/**\n * Convert ERC20 token stream permission to RPC format.\n *\n * @param permission the erc20 token stream permission\n * @returns the erc20 token stream permission in RPC format\n */\nfunction erc20TokenStreamPermissionToRpc(\n permission: Erc20TokenStreamPermission,\n): RpcErc20TokenStreamPermission {\n const {\n data: {\n tokenAddress,\n amountPerSecond,\n initialAmount,\n startTime,\n maxAmount,\n justification,\n },\n isAdjustmentAllowed,\n } = permission;\n\n const optionalFields = {\n ...(isDefined(initialAmount) && {\n initialAmount: toHexOrThrow(initialAmount, 'initialAmount'),\n }),\n ...(isDefined(maxAmount) && {\n maxAmount: toHexOrThrow(maxAmount, 'maxAmount'),\n }),\n ...(isDefined(startTime) && {\n startTime: Number(startTime),\n }),\n ...(justification ? { justification } : {}),\n };\n\n return {\n type: 'erc20-token-stream',\n data: {\n tokenAddress: toHexOrThrow(tokenAddress, 'tokenAddress'),\n amountPerSecond: toHexOrThrow(amountPerSecond, 'amountPerSecond'),\n ...optionalFields,\n },\n isAdjustmentAllowed,\n };\n}\n\n/**\n * Convert native token periodic permission to RPC format.\n *\n * @param permission the native token periodic permission\n * @returns the native token periodic permission in RPC format\n */\nfunction nativeTokenPeriodicPermissionToRpc(\n permission: NativeTokenPeriodicPermission,\n): RpcNativeTokenPeriodicPermission {\n const {\n data: { periodAmount, periodDuration, startTime, justification },\n isAdjustmentAllowed,\n } = permission;\n\n const optionalFields = {\n ...(isDefined(startTime) && {\n startTime: Number(startTime),\n }),\n ...(justification ? { justification } : {}),\n };\n\n return {\n type: 'native-token-periodic',\n data: {\n periodAmount: toHexOrThrow(periodAmount, 'periodAmount'),\n periodDuration: Number(periodDuration),\n ...optionalFields,\n },\n isAdjustmentAllowed,\n };\n}\n\n/**\n * Convert ERC20 token periodic permission to RPC format.\n *\n * @param permission the erc20 token periodic permission\n * @returns the erc20 token periodic permission in RPC format\n */\nfunction erc20TokenPeriodicPermissionToRpc(\n permission: Erc20TokenPeriodicPermission,\n): RpcErc20TokenPeriodicPermission {\n const {\n data: {\n tokenAddress,\n periodAmount,\n periodDuration,\n startTime,\n justification,\n },\n isAdjustmentAllowed,\n } = permission;\n\n const optionalFields = {\n ...(isDefined(startTime) && {\n startTime: Number(startTime),\n }),\n ...(justification ? { justification } : {}),\n };\n\n return {\n type: 'erc20-token-periodic',\n data: {\n tokenAddress: toHexOrThrow(tokenAddress, 'tokenAddress'),\n periodAmount: toHexOrThrow(periodAmount, 'periodAmount'),\n periodDuration: Number(periodDuration),\n ...optionalFields,\n },\n isAdjustmentAllowed,\n };\n}\n\n/**\n * Convert ERC20 token revocation permission to RPC format.\n *\n * @param permission the erc20 token revocation permission\n * @returns the erc20 token revocation permission in RPC format\n */\nfunction erc20TokenRevocationPermissionToRpc(\n permission: Erc20TokenRevocationPermission,\n): RpcErc20TokenRevocationPermission {\n const {\n data: { justification },\n isAdjustmentAllowed,\n } = permission;\n\n const data = {\n ...(justification ? { justification } : {}),\n };\n return {\n type: 'erc20-token-revocation',\n data,\n isAdjustmentAllowed,\n };\n}\n\n// =============================================================================\n// RPC → Developer friendly types (response conversion)\n// =============================================================================\n\n/**\n * Converts RPC permission responses to developer-friendly types.\n * Converts chainId from hex to number, and token amounts from hex to bigint.\n *\n * @param result the RPC permission responses\n * @returns the developer-friendly permission responses\n */\nexport function permissionResponsesFromRpc(\n result: RpcGetGrantedExecutionPermissionsResult,\n): GetGrantedExecutionPermissionsResult {\n return result.map((permission) => ({\n ...permission,\n chainId: hexToNumber(permission.chainId),\n permission: permissionTypeFromRpc(permission.permission),\n rules: normalizeRulesFromRpc(permission.rules),\n }));\n}\n\n/**\n * Checksums addresses in `redeemer` rules; other rules are returned unchanged.\n *\n * @param rules - Rules from the wallet RPC response.\n * @returns The same list with normalized redeemer addresses, or null/undefined if that was the input.\n */\nfunction normalizeRulesFromRpc(\n rules: Rule[] | null | undefined,\n): Rule[] | null | undefined {\n if (rules === undefined || rules === null) {\n return rules;\n }\n return rules.map((rule) => {\n if (rule.type !== 'redeemer') {\n return rule;\n }\n const rawAddresses = (rule.data as { addresses?: unknown } | undefined)\n ?.addresses;\n if (!Array.isArray(rawAddresses)) {\n return rule;\n }\n return {\n type: 'redeemer',\n data: {\n addresses: rawAddresses.map((addr) => getAddress(addr as Hex)),\n },\n };\n });\n}\n\n/**\n * Converts RPC permission type data to developer-friendly types.\n * Converts hex amount fields to bigint.\n *\n * @param permission the RPC permission\n * @returns the developer-friendly permission\n */\nexport function permissionTypeFromRpc(\n permission: RpcPermissionTypes,\n): DeveloperPermissionTypes {\n const convertedData: Record<string, unknown> = { ...permission.data };\n\n if ('amountPerSecond' in convertedData && convertedData.amountPerSecond) {\n convertedData.amountPerSecond = BigInt(\n convertedData.amountPerSecond as `0x${string}`,\n );\n }\n\n if ('periodAmount' in convertedData && convertedData.periodAmount) {\n convertedData.periodAmount = BigInt(\n convertedData.periodAmount as `0x${string}`,\n );\n }\n\n if ('initialAmount' in convertedData && convertedData.initialAmount) {\n convertedData.initialAmount = BigInt(\n convertedData.initialAmount as `0x${string}`,\n );\n }\n\n if ('maxAmount' in convertedData && convertedData.maxAmount) {\n convertedData.maxAmount = BigInt(convertedData.maxAmount as `0x${string}`);\n }\n\n return {\n ...permission,\n data: convertedData,\n } as DeveloperPermissionTypes;\n}\n\n/**\n * Converts RPC supported permissions result to developer-friendly types.\n * Converts chain IDs from hex to numbers.\n *\n * @param result the RPC supported permissions result\n * @returns the developer-friendly supported permissions result\n */\nexport function rpcSupportedPermissionsToDeveloper(\n result: RpcGetSupportedExecutionPermissionsResult,\n): GetSupportedExecutionPermissionsResult {\n const converted: GetSupportedExecutionPermissionsResult = {};\n\n for (const [permissionType, permissionInfo] of Object.entries(result)) {\n converted[permissionType] = {\n chainIds: permissionInfo.chainIds.map((chainId) => hexToNumber(chainId)),\n ruleTypes: permissionInfo.ruleTypes,\n };\n }\n\n return converted;\n}\n","import { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { permissionResponsesFromRpc } from './erc7715Mapping';\nimport type {\n GetGrantedExecutionPermissionsResult,\n MetaMaskExtensionClient,\n} from './erc7715Types';\n\nexport type { GetGrantedExecutionPermissionsResult } from './erc7715Types';\n\n/**\n * Retrieves all previously granted execution permissions from the wallet according to EIP-7715 specification.\n *\n * @param client - The client to use for the request.\n * @returns A promise that resolves to an array of granted permission responses.\n * @description\n * This function queries the wallet for all granted permissions that are not yet revoked.\n * Each permission response includes the chain ID, address, signer, permission details,\n * context, and dependency information.\n * @example\n * ```typescript\n * const grantedPermissions = await erc7715GetGrantedExecutionPermissionsAction(client);\n * // Returns an array of PermissionResponse objects with user-friendly types\n * ```\n */\nexport async function erc7715GetGrantedExecutionPermissionsAction(\n client: MetaMaskExtensionClient,\n): Promise<GetGrantedExecutionPermissionsResult> {\n trackSmartAccountsKitFunctionCall(\n 'erc7715GetGrantedExecutionPermissionsAction',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n\n const result = await client.request(\n {\n method: 'wallet_getGrantedExecutionPermissions',\n params: [],\n },\n { retryCount: 0 },\n );\n\n if (!result) {\n throw new Error('Failed to get granted execution permissions');\n }\n\n return permissionResponsesFromRpc(result);\n}\n","import { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { rpcSupportedPermissionsToDeveloper } from './erc7715Mapping';\nimport type {\n GetSupportedExecutionPermissionsResult,\n MetaMaskExtensionClient,\n} from './erc7715Types';\n\nexport type { GetSupportedExecutionPermissionsResult } from './erc7715Types';\n\n/**\n * Retrieves the supported execution permission types from the wallet according to EIP-7715 specification.\n *\n * @param client - The client to use for the request.\n * @returns A promise that resolves to a record of supported permission types with their chain IDs and rule types.\n * @description\n * This function queries the wallet for the permission types it supports.\n * The result is keyed by permission type and includes the supported chain IDs and rule types.\n * @example\n * ```typescript\n * const supported = await erc7715GetSupportedExecutionPermissionsAction(client);\n * // Returns:\n * // {\n * // \"native-token-allowance\": {\n * // \"chainIds\": [1, 137],\n * // \"ruleTypes\": [\"expiry\", \"redeemer\"]\n * // },\n * // \"erc20-token-allowance\": {\n * // \"chainIds\": [1],\n * // \"ruleTypes\": [\"expiry\"]\n * // }\n * // }\n * //\n * // Which strings appear in `ruleTypes` is defined by the wallet; when supported,\n * // `\"redeemer\"` indicates the wallet accepts a redeemer execution rule.\n * ```\n */\nexport async function erc7715GetSupportedExecutionPermissionsAction(\n client: MetaMaskExtensionClient,\n): Promise<GetSupportedExecutionPermissionsResult> {\n trackSmartAccountsKitFunctionCall(\n 'erc7715GetSupportedExecutionPermissionsAction',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n\n const result = await client.request(\n {\n method: 'wallet_getSupportedExecutionPermissions',\n params: [],\n },\n { retryCount: 0 },\n );\n\n if (!result) {\n throw new Error('Failed to get supported execution permissions');\n }\n\n return rpcSupportedPermissionsToDeveloper(result);\n}\n","import { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport {\n permissionRequestToRpc,\n permissionResponsesFromRpc,\n} from './erc7715Mapping';\nimport type {\n GetGrantedExecutionPermissionsResult,\n MetaMaskExtensionClient,\n PermissionRequestParameter,\n} from './erc7715Types';\n\nexport type {\n GetGrantedExecutionPermissionsResult,\n GetSupportedExecutionPermissionsResult,\n MetaMaskExtensionClient,\n MetaMaskExtensionSchema,\n SupportedPermissionInfo,\n PermissionTypes,\n PermissionRequestParameter,\n} from './erc7715Types';\n\n/**\n * Parameters for the RequestExecutionPermissions action.\n *\n * @template Signer - The type of the signer, either an Address or Account.\n */\nexport type RequestExecutionPermissionsParameters =\n PermissionRequestParameter[];\n\n/**\n * Return type for the request execution permissions action.\n */\nexport type RequestExecutionPermissionsReturnType =\n GetGrantedExecutionPermissionsResult;\n\n/**\n * Grants permissions according to EIP-7715 specification.\n *\n * @template Signer - The type of the signer, either an Address or Account.\n * @param client - The client to use for the request.\n * @param parameters - The permissions requests to grant.\n * @returns A promise that resolves to the permission responses.\n * @description\n * This function formats the permissions requests and invokes the wallet method to grant permissions.\n * It will throw an error if the permissions could not be granted.\n */\nexport async function erc7715RequestExecutionPermissionsAction(\n client: MetaMaskExtensionClient,\n parameters: RequestExecutionPermissionsParameters,\n): Promise<RequestExecutionPermissionsReturnType> {\n trackSmartAccountsKitFunctionCall(\n 'erc7715RequestExecutionPermissionsAction',\n {\n chainId: client.chain?.id ?? null,\n requestCount: parameters.length,\n },\n );\n const formattedPermissionRequest = parameters.map(permissionRequestToRpc);\n\n const result = await client.request(\n {\n method: 'wallet_requestExecutionPermissions',\n params: formattedPermissionRequest,\n },\n { retryCount: 0 },\n );\n\n if (!result) {\n throw new Error('Failed to grant permissions');\n }\n\n return permissionResponsesFromRpc(result);\n}\n","import type { Address, Hex, Client } from 'viem';\n\nimport { trackSmartAccountsKitFunctionCall } from '../analytics';\nimport { hashDelegation } from '../delegation';\nimport * as ERC20PeriodTransferEnforcer from '../DelegationFramework/ERC20PeriodTransferEnforcer';\nimport * as ERC20StreamingEnforcer from '../DelegationFramework/ERC20StreamingEnforcer';\nimport * as MultiTokenPeriodEnforcer from '../DelegationFramework/MultiTokenPeriodEnforcer';\nimport * as NativeTokenPeriodTransferEnforcer from '../DelegationFramework/NativeTokenPeriodTransferEnforcer';\nimport * as NativeTokenStreamingEnforcer from '../DelegationFramework/NativeTokenStreamingEnforcer';\nimport type { SmartAccountsEnvironment, Delegation } from '../types';\n\n/**\n * Parameters for all caveat enforcer actions.\n */\nexport type CaveatEnforcerParams = {\n delegation: Delegation;\n};\n\n/**\n * Return type for period-based transfer enforcers\n */\nexport type PeriodTransferResult = {\n availableAmount: bigint;\n isNewPeriod: boolean;\n currentPeriod: bigint;\n};\n\n/**\n * Return type for streaming enforcers\n */\nexport type StreamingResult = {\n availableAmount: bigint;\n};\n\n/**\n * Finds a caveat that matches the specified enforcer address.\n *\n * @param config - The configuration object.\n * @param config.delegation - The delegation to search.\n * @param config.enforcerAddress - The enforcer address to match.\n * @param config.enforcerName - The name of the enforcer.\n * @returns The matching caveat.\n * @throws Error if no matching caveat is found.\n * @throws Error if multiple matching caveats are found.\n */\nfunction findMatchingCaveat({\n delegation,\n enforcerAddress,\n enforcerName,\n}: {\n delegation: Delegation;\n enforcerAddress: Address;\n enforcerName: keyof SmartAccountsEnvironment['caveatEnforcers'];\n}): { terms: Hex; args: Hex } {\n const matchingCaveats = delegation.caveats.filter(\n (caveat) => caveat.enforcer.toLowerCase() === enforcerAddress.toLowerCase(),\n );\n\n if (matchingCaveats.length === 0) {\n throw new Error(`No caveat found with enforcer matching ${enforcerName}`);\n }\n\n if (matchingCaveats.length > 1) {\n throw new Error(\n `Multiple caveats found with enforcer matching ${enforcerName}`,\n );\n }\n\n const [{ terms, args }] = matchingCaveats as unknown as [\n { terms: Hex; args: Hex },\n ];\n\n return {\n terms,\n args,\n };\n}\n\n/**\n * Gets the delegation manager address from environment.\n *\n * @param environment - The SmartAccountsEnvironment.\n * @returns The delegation manager address.\n */\nfunction getDelegationManager(environment: SmartAccountsEnvironment): Address {\n if (!environment.DelegationManager) {\n throw new Error('Delegation manager address not found');\n }\n\n return environment.DelegationManager;\n}\n\n/**\n * Gets the enforcer address from environment.\n *\n * @param config - The configuration object.\n * @param config.enforcerName - The name of the enforcer.\n * @param config.environment - The SmartAccountsEnvironment.\n * @returns The enforcer address.\n */\nfunction getEnforcerAddress({\n enforcerName,\n environment,\n}: {\n enforcerName: keyof SmartAccountsEnvironment['caveatEnforcers'];\n environment: SmartAccountsEnvironment;\n}): Address {\n const enforcerAddress = environment.caveatEnforcers[enforcerName];\n if (!enforcerAddress) {\n throw new Error(`${enforcerName} not found in environment`);\n }\n\n return enforcerAddress;\n}\n\n/**\n * Get available amount for ERC20 period transfer enforcer.\n *\n * @param client - The viem client.\n * @param environment - The SmartAccountsEnvironment.\n * @param params - The parameters for the ERC20 period transfer enforcer.\n * @returns Promise resolving to the period transfer result.\n */\nexport async function getErc20PeriodTransferEnforcerAvailableAmount(\n client: Client,\n environment: SmartAccountsEnvironment,\n params: CaveatEnforcerParams,\n): Promise<PeriodTransferResult> {\n trackSmartAccountsKitFunctionCall(\n 'getErc20PeriodTransferEnforcerAvailableAmount',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n const enforcerName = 'ERC20PeriodTransferEnforcer';\n\n const delegationManager = getDelegationManager(environment);\n const enforcerAddress = getEnforcerAddress({\n enforcerName,\n environment,\n });\n\n const delegationHash = hashDelegation(params.delegation);\n const { terms } = findMatchingCaveat({\n delegation: params.delegation,\n enforcerAddress,\n enforcerName,\n });\n\n return ERC20PeriodTransferEnforcer.read.getAvailableAmount({\n client,\n contractAddress: enforcerAddress,\n delegationHash,\n delegationManager,\n terms,\n });\n}\n\n/**\n * Get available amount for ERC20 streaming enforcer.\n *\n * @param client - The viem client.\n * @param environment - The SmartAccountsEnvironment.\n * @param params - The parameters for the ERC20 streaming enforcer.\n * @returns Promise resolving to the streaming result.\n */\nexport async function getErc20StreamingEnforcerAvailableAmount(\n client: Client,\n environment: SmartAccountsEnvironment,\n params: CaveatEnforcerParams,\n): Promise<StreamingResult> {\n trackSmartAccountsKitFunctionCall(\n 'getErc20StreamingEnforcerAvailableAmount',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n const enforcerName = 'ERC20StreamingEnforcer';\n const delegationManager = getDelegationManager(environment);\n const enforcerAddress = getEnforcerAddress({\n enforcerName,\n environment,\n });\n\n const delegationHash = hashDelegation(params.delegation);\n const { terms } = findMatchingCaveat({\n delegation: params.delegation,\n enforcerAddress,\n enforcerName,\n });\n\n return ERC20StreamingEnforcer.read.getAvailableAmount({\n client,\n contractAddress: enforcerAddress,\n delegationManager,\n delegationHash,\n terms,\n });\n}\n\n/**\n * Get available amount for multi-token period enforcer.\n *\n * @param client - The viem client.\n * @param environment - The SmartAccountsEnvironment.\n * @param params - The parameters for the multi-token period enforcer.\n * @returns Promise resolving to the period transfer result.\n */\nexport async function getMultiTokenPeriodEnforcerAvailableAmount(\n client: Client,\n environment: SmartAccountsEnvironment,\n params: CaveatEnforcerParams,\n): Promise<PeriodTransferResult> {\n trackSmartAccountsKitFunctionCall(\n 'getMultiTokenPeriodEnforcerAvailableAmount',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n const enforcerName = 'MultiTokenPeriodEnforcer';\n const delegationManager = getDelegationManager(environment);\n const enforcerAddress = getEnforcerAddress({\n enforcerName,\n environment,\n });\n\n const delegationHash = hashDelegation(params.delegation);\n const { terms, args } = findMatchingCaveat({\n delegation: params.delegation,\n enforcerAddress,\n enforcerName,\n });\n\n return MultiTokenPeriodEnforcer.read.getAvailableAmount({\n client,\n contractAddress: enforcerAddress,\n delegationHash,\n delegationManager,\n terms,\n args,\n });\n}\n\n/**\n * Get available amount for native token period transfer enforcer.\n *\n * @param client - The viem client.\n * @param environment - The SmartAccountsEnvironment.\n * @param params - The parameters for the native token period transfer enforcer.\n * @returns Promise resolving to the period transfer result.\n */\nexport async function getNativeTokenPeriodTransferEnforcerAvailableAmount(\n client: Client,\n environment: SmartAccountsEnvironment,\n params: CaveatEnforcerParams,\n): Promise<PeriodTransferResult> {\n trackSmartAccountsKitFunctionCall(\n 'getNativeTokenPeriodTransferEnforcerAvailableAmount',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n const enforcerName = 'NativeTokenPeriodTransferEnforcer';\n const delegationManager = getDelegationManager(environment);\n const enforcerAddress = getEnforcerAddress({\n enforcerName,\n environment,\n });\n\n const delegationHash = hashDelegation(params.delegation);\n const { terms } = findMatchingCaveat({\n delegation: params.delegation,\n enforcerAddress,\n enforcerName,\n });\n\n return NativeTokenPeriodTransferEnforcer.read.getAvailableAmount({\n client,\n contractAddress: enforcerAddress,\n delegationHash,\n delegationManager,\n terms,\n });\n}\n\n/**\n * Get available amount for native token streaming enforcer.\n *\n * @param client - The viem client.\n * @param environment - The SmartAccountsEnvironment.\n * @param params - The parameters for the native token streaming enforcer.\n * @returns Promise resolving to the streaming result.\n */\nexport async function getNativeTokenStreamingEnforcerAvailableAmount(\n client: Client,\n environment: SmartAccountsEnvironment,\n params: CaveatEnforcerParams,\n): Promise<StreamingResult> {\n trackSmartAccountsKitFunctionCall(\n 'getNativeTokenStreamingEnforcerAvailableAmount',\n {\n chainId: client.chain?.id ?? null,\n },\n );\n const enforcerName = 'NativeTokenStreamingEnforcer';\n const delegationManager = getDelegationManager(environment);\n const enforcerAddress = getEnforcerAddress({\n enforcerName,\n environment,\n });\n\n const delegationHash = hashDelegation(params.delegation);\n const { terms } = findMatchingCaveat({\n delegation: params.delegation,\n enforcerAddress,\n enforcerName,\n });\n\n return NativeTokenStreamingEnforcer.read.getAvailableAmount({\n client,\n contractAddress: enforcerAddress,\n delegationManager,\n delegationHash,\n terms,\n });\n}\n\n/**\n * Caveat enforcer actions for extending viem clients.\n *\n * @param params - The parameters object.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns A function that takes a client and returns the client extension with caveat enforcer actions.\n */\nexport const caveatEnforcerActions =\n ({ environment }: { environment: SmartAccountsEnvironment }) =>\n (client: Client) => ({\n /**\n * Get available amount for ERC20 period transfer enforcer.\n *\n * @param params - The parameters for the ERC20 period transfer enforcer.\n * @returns Promise resolving to the period transfer result.\n */\n getErc20PeriodTransferEnforcerAvailableAmount: async (\n params: CaveatEnforcerParams,\n ): Promise<PeriodTransferResult> => {\n return getErc20PeriodTransferEnforcerAvailableAmount(\n client,\n environment,\n params,\n );\n },\n\n /**\n * Get available amount for ERC20 streaming enforcer.\n *\n * @param params - The parameters for the ERC20 streaming enforcer.\n * @returns Promise resolving to the streaming result.\n */\n getErc20StreamingEnforcerAvailableAmount: async (\n params: CaveatEnforcerParams,\n ): Promise<StreamingResult> => {\n return getErc20StreamingEnforcerAvailableAmount(\n client,\n environment,\n params,\n );\n },\n\n /**\n * Get available amount for multi-token period enforcer.\n *\n * @param params - The parameters for the multi-token period enforcer.\n * @returns Promise resolving to the period transfer result.\n */\n getMultiTokenPeriodEnforcerAvailableAmount: async (\n params: CaveatEnforcerParams,\n ): Promise<PeriodTransferResult> => {\n return getMultiTokenPeriodEnforcerAvailableAmount(\n client,\n environment,\n params,\n );\n },\n\n /**\n * Get available amount for native token period transfer enforcer.\n *\n * @param params - The parameters for the native token period transfer enforcer.\n * @returns Promise resolving to the period transfer result.\n */\n getNativeTokenPeriodTransferEnforcerAvailableAmount: async (\n params: CaveatEnforcerParams,\n ): Promise<PeriodTransferResult> => {\n return getNativeTokenPeriodTransferEnforcerAvailableAmount(\n client,\n environment,\n params,\n );\n },\n\n /**\n * Get available amount for native token streaming enforcer.\n *\n * @param params - The parameters for the native token streaming enforcer.\n * @returns Promise resolving to the streaming result.\n */\n getNativeTokenStreamingEnforcerAvailableAmount: async (\n params: CaveatEnforcerParams,\n ): Promise<StreamingResult> => {\n return getNativeTokenStreamingEnforcerAvailableAmount(\n client,\n environment,\n params,\n );\n },\n });\n","import type { Client, Address, Hex } from 'viem';\nimport { isAddressEqual } from 'viem';\nimport { getCode } from 'viem/actions';\n\nimport type { SmartAccountsEnvironment } from '../types';\n\n// EIP-7702 delegation prefix (0xef0100)\nconst DELEGATION_PREFIX = '0xef0100' as const;\n\n/**\n * Parameters for checking if an account is delegated to the EIP-7702 implementation.\n */\nexport type IsValid7702ImplementationParameters = {\n /** The client to use for the query. */\n client: Client;\n /** The address to check for proper delegation. */\n accountAddress: Address;\n /** The SmartAccountsEnvironment containing contract addresses. */\n environment: SmartAccountsEnvironment;\n};\n\n/**\n * Extracts the delegated contract address from EIP-7702 delegation code.\n *\n * @param code - The code returned from getCode for a delegated account.\n * @returns The delegated contract address or null if not a valid delegation.\n */\nfunction extractDelegatedAddress(code: Hex | undefined): Address | null {\n if (code?.length !== 48) {\n // 0x (2 chars) + ef0100 (6 chars) + address (40 chars) = 48 chars\n return null;\n }\n\n if (!code.toLowerCase().startsWith(DELEGATION_PREFIX.toLowerCase())) {\n return null;\n }\n\n // Extract the 20-byte address after the delegation prefix\n const addressHex = code.slice(8); // Remove '0xef0100' prefix (8 chars)\n return `0x${addressHex}`;\n}\n\n/**\n * Checks if an account is properly delegated to the EIP-7702 implementation.\n *\n * This function validates EIP-7702 delegations by checking if the EOA has a 7702\n * contract assigned to it and comparing the delegated address against the 7702\n * implementation found in the environment.\n *\n * @param params - The parameters for checking the delegation.\n * @param params.client - The client to use for the query.\n * @param params.accountAddress - The address to check for proper delegation.\n * @param params.environment - The SmartAccountsEnvironment containing contract addresses.\n * @returns A promise that resolves to true if the account is properly delegated to the 7702 implementation, false otherwise.\n * @example\n * ```typescript\n * const isValid = await isValid7702Implementation({\n * client: publicClient,\n * accountAddress: '0x...',\n * environment: smartAccountEnvironment,\n * });\n *\n * if (isValid) {\n * console.log('Account is properly delegated to EIP-7702 implementation');\n * } else {\n * console.log('Account is not properly delegated');\n * }\n * ```\n */\nexport async function isValid7702Implementation({\n client,\n accountAddress,\n environment,\n}: IsValid7702ImplementationParameters): Promise<boolean> {\n try {\n // Get the code at the account address\n const code = await getCode(client, {\n address: accountAddress,\n });\n\n // Extract the delegated contract address from the EIP-7702 delegation code\n const delegatedAddress = extractDelegatedAddress(code);\n\n // If no valid delegation found, return false\n if (!delegatedAddress) {\n return false;\n }\n\n // Compare the delegated address with the 7702 implementation in the environment\n const expectedImplementation =\n environment.implementations.EIP7702StatelessDeleGatorImpl;\n if (!expectedImplementation) {\n return false;\n }\n\n return isAddressEqual(delegatedAddress, expectedImplementation);\n } catch {\n // If the call fails (e.g., no code at address, network error),\n // then it's not properly delegated to our implementation\n return false;\n }\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n Hex,\n Transport,\n WalletClient,\n} from 'viem';\nimport { BaseError } from 'viem';\nimport { parseAccount } from 'viem/accounts';\n\nimport { prepareSignDelegationTypedData } from '../delegation';\nimport type { Delegation } from '../types';\n\nexport type SignDelegationParameters = {\n /** Account to sign with */\n account?: Account | Address;\n /** The delegation to sign */\n delegation: Omit<Delegation, 'signature'>;\n /** The address of the delegation manager contract */\n delegationManager: Address;\n /** The chain ID for the signature */\n chainId: number;\n /** The name of the contract */\n name?: string;\n /** The version of the contract */\n version?: string;\n /** Whether to allow insecure unrestricted delegation */\n allowInsecureUnrestrictedDelegation?: boolean;\n};\n\nexport type SignDelegationReturnType = Hex;\n\n/**\n * Signs a delegation using a wallet client.\n *\n * @param client - The wallet client to use for signing.\n * @param parameters - The parameters for signing the delegation.\n * @returns The signature of the delegation.\n * @example\n * ```ts\n * const signature = await signDelegation(walletClient, {\n * delegation: {\n * delegate: '0x...',\n * delegator: '0x...',\n * authority: '0x...',\n * caveats: [],\n * salt: '0x'\n * },\n * delegationManager: '0x...',\n * chainId: 1\n * });\n * ```\n */\nexport async function signDelegation<\n TChain extends Chain | undefined,\n TAccount extends Account | undefined,\n>(\n client: Client<Transport, TChain, TAccount> & {\n signTypedData: WalletClient['signTypedData'];\n },\n parameters: SignDelegationParameters,\n): Promise<SignDelegationReturnType> {\n const {\n account: accountParam = client.account,\n delegation,\n delegationManager,\n chainId,\n name = 'DelegationManager',\n version = '1',\n allowInsecureUnrestrictedDelegation = false,\n } = parameters;\n\n if (!accountParam) {\n throw new BaseError('Account not found. Please provide an account.');\n }\n\n const account = parseAccount(accountParam);\n\n const typedData = prepareSignDelegationTypedData({\n delegation,\n delegationManager,\n chainId,\n name,\n version,\n allowInsecureUnrestrictedDelegation,\n });\n\n return client.signTypedData({\n account,\n ...typedData,\n });\n}\n\n/**\n * Creates a sign delegation action that can be used to extend a wallet client.\n *\n * @returns A function that can be used with wallet client extend method.\n * @example\n * ```ts\n * const walletClient = createWalletClient({\n * chain: mainnet,\n * transport: http()\n * }).extend(signDelegationActions());\n * ```\n */\nexport function signDelegationActions() {\n return <\n TChain extends Chain | undefined,\n TAccount extends Account | undefined,\n >(\n client: Client<Transport, TChain, TAccount> & {\n signTypedData: WalletClient['signTypedData'];\n },\n ) => ({\n signDelegation: async (\n parameters: Omit<SignDelegationParameters, 'chainId'> & {\n chainId?: number;\n },\n ) =>\n signDelegation(client, {\n chainId:\n parameters.chainId ??\n (() => {\n if (!client.chain?.id) {\n throw new BaseError(\n 'Chain ID is required. Either provide it in parameters or configure the client with a chain.',\n );\n }\n return client.chain.id;\n })(),\n ...parameters,\n }),\n });\n}\n","import type {\n Account,\n Address,\n Chain,\n Client,\n Hex,\n Transport,\n WalletClient,\n} from 'viem';\nimport { BaseError } from 'viem';\nimport { parseAccount } from 'viem/accounts';\n\nimport { prepareSignUserOperationTypedData } from '../userOp';\nimport type { UserOperationV07 } from '../userOp';\n\nexport type SignUserOperationParameters = {\n /** Account to sign with */\n account?: Account | Address;\n /** The user operation to sign */\n userOperation: Omit<UserOperationV07, 'signature'>;\n /** The entry point contract address */\n entryPoint: { address: Address };\n /** The chain ID that the entry point is deployed on */\n chainId: number;\n /** The address of the smart account */\n address: Address;\n /** The name of the domain of the implementation contract */\n name: 'HybridDeleGator' | 'MultiSigDeleGator';\n /** The version of the domain of the implementation contract */\n version?: string;\n};\n\nexport type SignUserOperationReturnType = Hex;\n\n/**\n * Signs a user operation using a wallet client.\n *\n * @param client - The wallet client to use for signing.\n * @param parameters - The parameters for signing the user operation.\n * @returns The signature of the user operation.\n * @example\n * ```ts\n * const signature = await signUserOperation(walletClient, {\n * userOperation: {\n * sender: '0x...',\n * nonce: 0n,\n * callData: '0x',\n * callGasLimit: 1000000n,\n * verificationGasLimit: 1000000n,\n * preVerificationGas: 21000n,\n * maxFeePerGas: 1000000000n,\n * maxPriorityFeePerGas: 1000000000n\n * },\n * entryPoint: { address: '0x...' },\n * chainId: 1,\n * address: '0x...',\n * name: 'HybridDeleGator'\n * });\n * ```\n */\nexport async function signUserOperation<\n TChain extends Chain | undefined,\n TAccount extends Account | undefined,\n>(\n client: Client<Transport, TChain, TAccount> & {\n signTypedData: WalletClient['signTypedData'];\n },\n parameters: SignUserOperationParameters,\n): Promise<SignUserOperationReturnType> {\n const {\n account: accountParam = client.account,\n userOperation,\n entryPoint,\n chainId,\n name,\n address,\n version = '1',\n } = parameters;\n\n if (!accountParam) {\n throw new BaseError('Account not found. Please provide an account.');\n }\n\n const account = parseAccount(accountParam);\n\n const typedData = prepareSignUserOperationTypedData({\n userOperation,\n entryPoint,\n chainId,\n name,\n address,\n version,\n });\n\n return client.signTypedData({\n account,\n ...typedData,\n });\n}\n\n/**\n * Creates a sign user operation action that can be used to extend a wallet client.\n *\n * @returns A function that can be used with wallet client extend method.\n * @example\n * ```ts\n * const walletClient = createWalletClient({\n * chain: mainnet,\n * transport: http()\n * }).extend(signUserOperationActions());\n * ```\n */\nexport function signUserOperationActions() {\n return <\n TChain extends Chain | undefined,\n TAccount extends Account | undefined,\n >(\n client: Client<Transport, TChain, TAccount> & {\n signTypedData: WalletClient['signTypedData'];\n },\n ) => ({\n signUserOperation: async (\n parameters: Omit<SignUserOperationParameters, 'chainId'> & {\n chainId?: number;\n },\n ) =>\n signUserOperation(client, {\n chainId:\n parameters.chainId ??\n (() => {\n if (!client.chain?.id) {\n throw new BaseError(\n 'Chain ID is required. Either provide it in parameters or configure the client with a chain.',\n );\n }\n return client.chain.id;\n })(),\n ...parameters,\n }),\n });\n}\n"]}
|