@metamask/smart-accounts-kit 1.1.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +34 -2
  3. package/dist/actions/index.cjs +5 -5
  4. package/dist/actions/index.d.cts +2 -2
  5. package/dist/actions/index.d.ts +2 -2
  6. package/dist/actions/index.mjs +4 -4
  7. package/dist/{smartAccountsEnvironment-BIcho7e0.d.cts → caveats-CQbtzOKm.d.ts} +9 -2
  8. package/dist/{smartAccountsEnvironment-Bso0CIWt.d.ts → caveats-Cey0wm33.d.cts} +9 -2
  9. package/dist/{chunk-YSBBRLMT.mjs → chunk-26PADMXR.mjs} +5 -5
  10. package/dist/{chunk-BYWRJGSK.cjs → chunk-3PBVHNYP.cjs} +16 -16
  11. package/dist/{chunk-BYWRJGSK.cjs.map → chunk-3PBVHNYP.cjs.map} +1 -1
  12. package/dist/{chunk-TPBFVDVM.mjs → chunk-4QXIOE7F.mjs} +8 -6
  13. package/dist/chunk-4QXIOE7F.mjs.map +1 -0
  14. package/dist/{chunk-F2RG26RH.cjs → chunk-57I2FJY7.cjs} +105 -105
  15. package/dist/{chunk-F2RG26RH.cjs.map → chunk-57I2FJY7.cjs.map} +1 -1
  16. package/dist/{chunk-YTELOQ4I.mjs → chunk-AC2BQSYP.mjs} +2 -2
  17. package/dist/{chunk-QMRKCB7T.cjs → chunk-AJWMPR7X.cjs} +146 -48
  18. package/dist/chunk-AJWMPR7X.cjs.map +1 -0
  19. package/dist/{chunk-23YXLKTX.cjs → chunk-DLCTHNAE.cjs} +14 -14
  20. package/dist/{chunk-23YXLKTX.cjs.map → chunk-DLCTHNAE.cjs.map} +1 -1
  21. package/dist/{chunk-NOCLGZGB.mjs → chunk-FKI4OME5.mjs} +109 -11
  22. package/dist/chunk-FKI4OME5.mjs.map +1 -0
  23. package/dist/{chunk-UUOH2WAW.cjs → chunk-GZ7HHI2D.cjs} +12 -12
  24. package/dist/{chunk-UUOH2WAW.cjs.map → chunk-GZ7HHI2D.cjs.map} +1 -1
  25. package/dist/{chunk-WV2R7BXP.mjs → chunk-KBSFVKUB.mjs} +3 -3
  26. package/dist/{chunk-45GHWVQA.mjs → chunk-LQXOM3TA.mjs} +4 -4
  27. package/dist/{chunk-VLKX4BR6.cjs → chunk-MOHCTPYQ.cjs} +8 -6
  28. package/dist/chunk-MOHCTPYQ.cjs.map +1 -0
  29. package/dist/{chunk-YDLLC6PP.cjs → chunk-SZOX7K2V.cjs} +519 -16
  30. package/dist/chunk-SZOX7K2V.cjs.map +1 -0
  31. package/dist/{chunk-C5ZEEH2Z.mjs → chunk-Z4D7ZWVB.mjs} +517 -14
  32. package/dist/chunk-Z4D7ZWVB.mjs.map +1 -0
  33. package/dist/contracts/index.cjs +6 -6
  34. package/dist/contracts/index.d.cts +2 -2
  35. package/dist/contracts/index.d.ts +2 -2
  36. package/dist/contracts/index.mjs +5 -5
  37. package/dist/{delegation-DgmIOh21.d.ts → delegation-Bx4FEAIU.d.ts} +1 -1
  38. package/dist/{delegation-Ci3me5Rg.d.cts → delegation-KbWHzRxV.d.cts} +1 -1
  39. package/dist/experimental/index.cjs +36 -4
  40. package/dist/experimental/index.cjs.map +1 -1
  41. package/dist/experimental/index.d.cts +4 -1
  42. package/dist/experimental/index.d.ts +4 -1
  43. package/dist/experimental/index.mjs +35 -3
  44. package/dist/experimental/index.mjs.map +1 -1
  45. package/dist/{index-Uj_xXVko.d.cts → index-BDC55AA9.d.cts} +5 -3
  46. package/dist/{index-UF6eCzBC.d.ts → index-D2THBlfm.d.ts} +1 -1
  47. package/dist/{index-CSjEW7MJ.d.cts → index-DE87r5KY.d.cts} +1 -1
  48. package/dist/{index-D7fBuNV-.d.ts → index-DhG2lH80.d.ts} +5 -3
  49. package/dist/index.cjs +33 -17
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +9 -11
  52. package/dist/index.d.ts +9 -11
  53. package/dist/index.mjs +24 -8
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/utils/index.cjs +7 -5
  56. package/dist/utils/index.cjs.map +1 -1
  57. package/dist/utils/index.d.cts +2 -2
  58. package/dist/utils/index.d.ts +2 -2
  59. package/dist/utils/index.mjs +6 -4
  60. package/package.json +5 -4
  61. package/dist/chunk-C5ZEEH2Z.mjs.map +0 -1
  62. package/dist/chunk-NOCLGZGB.mjs.map +0 -1
  63. package/dist/chunk-QMRKCB7T.cjs.map +0 -1
  64. package/dist/chunk-TPBFVDVM.mjs.map +0 -1
  65. package/dist/chunk-VLKX4BR6.cjs.map +0 -1
  66. package/dist/chunk-YDLLC6PP.cjs.map +0 -1
  67. /package/dist/{chunk-YSBBRLMT.mjs.map → chunk-26PADMXR.mjs.map} +0 -0
  68. /package/dist/{chunk-YTELOQ4I.mjs.map → chunk-AC2BQSYP.mjs.map} +0 -0
  69. /package/dist/{chunk-WV2R7BXP.mjs.map → chunk-KBSFVKUB.mjs.map} +0 -0
  70. /package/dist/{chunk-45GHWVQA.mjs.map → chunk-LQXOM3TA.mjs.map} +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkUUOH2WAWcjs = require('./chunk-UUOH2WAW.cjs');
7
+ var _chunkGZ7HHI2Dcjs = require('./chunk-GZ7HHI2D.cjs');
8
8
 
9
9
 
10
10
 
@@ -12,7 +12,7 @@ var _chunkSOFB2MXGcjs = require('./chunk-SOFB2MXG.cjs');
12
12
 
13
13
 
14
14
 
15
- var _chunkVLKX4BR6cjs = require('./chunk-VLKX4BR6.cjs');
15
+ var _chunkMOHCTPYQcjs = require('./chunk-MOHCTPYQ.cjs');
16
16
 
17
17
 
18
18
 
@@ -20,11 +20,12 @@ var _chunkVLKX4BR6cjs = require('./chunk-VLKX4BR6.cjs');
20
20
 
21
21
 
22
22
 
23
- var _chunkYDLLC6PPcjs = require('./chunk-YDLLC6PP.cjs');
23
+
24
+ var _chunkSZOX7K2Vcjs = require('./chunk-SZOX7K2V.cjs');
24
25
 
25
26
  // src/actions/index.ts
26
27
  var actions_exports = {};
27
- _chunkYDLLC6PPcjs.__export.call(void 0, actions_exports, {
28
+ _chunkSZOX7K2Vcjs.__export.call(void 0, actions_exports, {
28
29
  caveatEnforcerActions: () => caveatEnforcerActions,
29
30
  erc7710BundlerActions: () => erc7710BundlerActions,
30
31
  erc7710WalletActions: () => erc7710WalletActions,
@@ -48,12 +49,15 @@ _chunkYDLLC6PPcjs.__export.call(void 0, actions_exports, {
48
49
  var _delegationabis = require('@metamask/delegation-abis');
49
50
  var _viem = require('viem');
50
51
  async function sendTransactionWithDelegationAction(client, args) {
52
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0, "sendTransactionWithDelegationAction", {
53
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]), () => ( null))
54
+ });
51
55
  if (!args.to) {
52
56
  throw new Error(
53
57
  "`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts."
54
58
  );
55
59
  }
56
- const chainId = _optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]);
60
+ const chainId = _optionalChain([client, 'access', _3 => _3.chain, 'optionalAccess', _4 => _4.id]);
57
61
  if (!chainId) {
58
62
  throw new Error("Chain ID is not set");
59
63
  }
@@ -64,7 +68,7 @@ async function sendTransactionWithDelegationAction(client, args) {
64
68
  );
65
69
  }
66
70
  const executions = [
67
- _chunkVLKX4BR6cjs.createExecution.call(void 0, {
71
+ _chunkMOHCTPYQcjs.createExecution.call(void 0, {
68
72
  target: args.to,
69
73
  value: args.value,
70
74
  callData: args.data
@@ -74,9 +78,9 @@ async function sendTransactionWithDelegationAction(client, args) {
74
78
  abi: _delegationabis.DelegationManager,
75
79
  functionName: "redeemDelegations",
76
80
  args: [
77
- [_chunkYDLLC6PPcjs.encodeDelegations.call(void 0, args.permissionContext)],
81
+ [_chunkSZOX7K2Vcjs.encodeDelegations.call(void 0, args.permissionContext)],
78
82
  ["0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */],
79
- _chunkVLKX4BR6cjs.encodeExecutionCalldatas.call(void 0, [executions])
83
+ _chunkMOHCTPYQcjs.encodeExecutionCalldatas.call(void 0, [executions])
80
84
  ]
81
85
  });
82
86
  const {
@@ -93,10 +97,15 @@ async function sendTransactionWithDelegationAction(client, args) {
93
97
  return hash;
94
98
  }
95
99
  async function sendUserOperationWithDelegationAction(client, parameters) {
100
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0, "sendUserOperationWithDelegationAction", {
101
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _5 => _5.chain, 'optionalAccess', _6 => _6.id]), () => ( null)),
102
+ callCount: parameters.calls.length,
103
+ hasDependencies: parameters.dependencies !== void 0
104
+ });
96
105
  if (parameters.dependencies) {
97
106
  const { publicClient } = parameters;
98
107
  const includedAccountKeys = {};
99
- const chainId = _optionalChain([publicClient, 'access', _3 => _3.chain, 'optionalAccess', _4 => _4.id]);
108
+ const chainId = _optionalChain([publicClient, 'access', _7 => _7.chain, 'optionalAccess', _8 => _8.id]);
100
109
  if (!chainId) {
101
110
  throw new Error("Chain ID is not set");
102
111
  }
@@ -143,7 +152,7 @@ async function sendUserOperationWithDelegationAction(client, parameters) {
143
152
  }
144
153
  return {
145
154
  ...call,
146
- permissionContext: _chunkYDLLC6PPcjs.encodeDelegations.call(void 0, permissionContext)
155
+ permissionContext: _chunkSZOX7K2Vcjs.encodeDelegations.call(void 0, permissionContext)
147
156
  };
148
157
  });
149
158
  return client.sendUserOperation(
@@ -154,18 +163,37 @@ async function sendUserOperationWithDelegationAction(client, parameters) {
154
163
  // src/actions/erc7715Mapping.ts
155
164
 
156
165
  function permissionRequestToRpc(parameters) {
157
- const { chainId, from, expiry } = parameters;
166
+ const { chainId, from, expiry, redeemer } = parameters;
158
167
  const converter = getPermissionRequestToRpcConverter(
159
168
  parameters.permission.type
160
169
  );
161
- const rules = _chunkYDLLC6PPcjs.isDefined.call(void 0, expiry) ? [
162
- {
170
+ const rules = [];
171
+ if (_chunkSZOX7K2Vcjs.isDefined.call(void 0, expiry)) {
172
+ rules.push({
163
173
  type: "expiry",
164
174
  data: {
165
175
  timestamp: expiry
166
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));
167
191
  }
168
- ] : [];
192
+ rules.push({
193
+ type: "redeemer",
194
+ data: { addresses }
195
+ });
196
+ }
169
197
  const optionalFields = {
170
198
  ...from ? { from } : {}
171
199
  };
@@ -215,13 +243,13 @@ function nativeTokenStreamPermissionToRpc(permission) {
215
243
  isAdjustmentAllowed
216
244
  } = permission;
217
245
  const optionalFields = {
218
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, initialAmount) && {
219
- initialAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
246
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, initialAmount) && {
247
+ initialAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
220
248
  },
221
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, maxAmount) && {
222
- maxAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
249
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, maxAmount) && {
250
+ maxAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
223
251
  },
224
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, startTime) && {
252
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
225
253
  startTime: Number(startTime)
226
254
  },
227
255
  ...justification ? { justification } : {}
@@ -229,7 +257,7 @@ function nativeTokenStreamPermissionToRpc(permission) {
229
257
  return {
230
258
  type: "native-token-stream",
231
259
  data: {
232
- amountPerSecond: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
260
+ amountPerSecond: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
233
261
  ...optionalFields
234
262
  },
235
263
  isAdjustmentAllowed
@@ -248,13 +276,13 @@ function erc20TokenStreamPermissionToRpc(permission) {
248
276
  isAdjustmentAllowed
249
277
  } = permission;
250
278
  const optionalFields = {
251
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, initialAmount) && {
252
- initialAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
279
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, initialAmount) && {
280
+ initialAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, initialAmount, "initialAmount")
253
281
  },
254
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, maxAmount) && {
255
- maxAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
282
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, maxAmount) && {
283
+ maxAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, maxAmount, "maxAmount")
256
284
  },
257
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, startTime) && {
285
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
258
286
  startTime: Number(startTime)
259
287
  },
260
288
  ...justification ? { justification } : {}
@@ -262,8 +290,8 @@ function erc20TokenStreamPermissionToRpc(permission) {
262
290
  return {
263
291
  type: "erc20-token-stream",
264
292
  data: {
265
- tokenAddress: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
266
- amountPerSecond: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
293
+ tokenAddress: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
294
+ amountPerSecond: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, amountPerSecond, "amountPerSecond"),
267
295
  ...optionalFields
268
296
  },
269
297
  isAdjustmentAllowed
@@ -275,7 +303,7 @@ function nativeTokenPeriodicPermissionToRpc(permission) {
275
303
  isAdjustmentAllowed
276
304
  } = permission;
277
305
  const optionalFields = {
278
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, startTime) && {
306
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
279
307
  startTime: Number(startTime)
280
308
  },
281
309
  ...justification ? { justification } : {}
@@ -283,7 +311,7 @@ function nativeTokenPeriodicPermissionToRpc(permission) {
283
311
  return {
284
312
  type: "native-token-periodic",
285
313
  data: {
286
- periodAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
314
+ periodAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
287
315
  periodDuration: Number(periodDuration),
288
316
  ...optionalFields
289
317
  },
@@ -302,7 +330,7 @@ function erc20TokenPeriodicPermissionToRpc(permission) {
302
330
  isAdjustmentAllowed
303
331
  } = permission;
304
332
  const optionalFields = {
305
- ..._chunkYDLLC6PPcjs.isDefined.call(void 0, startTime) && {
333
+ ..._chunkSZOX7K2Vcjs.isDefined.call(void 0, startTime) && {
306
334
  startTime: Number(startTime)
307
335
  },
308
336
  ...justification ? { justification } : {}
@@ -310,8 +338,8 @@ function erc20TokenPeriodicPermissionToRpc(permission) {
310
338
  return {
311
339
  type: "erc20-token-periodic",
312
340
  data: {
313
- tokenAddress: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
314
- periodAmount: _chunkYDLLC6PPcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
341
+ tokenAddress: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, tokenAddress, "tokenAddress"),
342
+ periodAmount: _chunkSZOX7K2Vcjs.toHexOrThrow.call(void 0, periodAmount, "periodAmount"),
315
343
  periodDuration: Number(periodDuration),
316
344
  ...optionalFields
317
345
  },
@@ -336,9 +364,30 @@ function permissionResponsesFromRpc(result) {
336
364
  return result.map((permission) => ({
337
365
  ...permission,
338
366
  chainId: _viem.hexToNumber.call(void 0, permission.chainId),
339
- permission: permissionTypeFromRpc(permission.permission)
367
+ permission: permissionTypeFromRpc(permission.permission),
368
+ rules: normalizeRulesFromRpc(permission.rules)
340
369
  }));
341
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
+ }
342
391
  function permissionTypeFromRpc(permission) {
343
392
  const convertedData = { ...permission.data };
344
393
  if ("amountPerSecond" in convertedData && convertedData.amountPerSecond) {
@@ -377,6 +426,12 @@ function rpcSupportedPermissionsToDeveloper(result) {
377
426
 
378
427
  // src/actions/erc7715GetGrantedExecutionPermissionsAction.ts
379
428
  async function erc7715GetGrantedExecutionPermissionsAction(client) {
429
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
430
+ "erc7715GetGrantedExecutionPermissionsAction",
431
+ {
432
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _11 => _11.chain, 'optionalAccess', _12 => _12.id]), () => ( null))
433
+ }
434
+ );
380
435
  const result = await client.request(
381
436
  {
382
437
  method: "wallet_getGrantedExecutionPermissions",
@@ -392,6 +447,12 @@ async function erc7715GetGrantedExecutionPermissionsAction(client) {
392
447
 
393
448
  // src/actions/erc7715GetSupportedExecutionPermissionsAction.ts
394
449
  async function erc7715GetSupportedExecutionPermissionsAction(client) {
450
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
451
+ "erc7715GetSupportedExecutionPermissionsAction",
452
+ {
453
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _13 => _13.chain, 'optionalAccess', _14 => _14.id]), () => ( null))
454
+ }
455
+ );
395
456
  const result = await client.request(
396
457
  {
397
458
  method: "wallet_getSupportedExecutionPermissions",
@@ -407,6 +468,13 @@ async function erc7715GetSupportedExecutionPermissionsAction(client) {
407
468
 
408
469
  // src/actions/erc7715RequestExecutionPermissionsAction.ts
409
470
  async function erc7715RequestExecutionPermissionsAction(client, parameters) {
471
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
472
+ "erc7715RequestExecutionPermissionsAction",
473
+ {
474
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _15 => _15.chain, 'optionalAccess', _16 => _16.id]), () => ( null)),
475
+ requestCount: parameters.length
476
+ }
477
+ );
410
478
  const formattedPermissionRequest = parameters.map(permissionRequestToRpc);
411
479
  const result = await client.request(
412
480
  {
@@ -461,19 +529,25 @@ function getEnforcerAddress({
461
529
  return enforcerAddress;
462
530
  }
463
531
  async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment, params) {
532
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
533
+ "getErc20PeriodTransferEnforcerAvailableAmount",
534
+ {
535
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _17 => _17.chain, 'optionalAccess', _18 => _18.id]), () => ( null))
536
+ }
537
+ );
464
538
  const enforcerName = "ERC20PeriodTransferEnforcer";
465
539
  const delegationManager = getDelegationManager(environment);
466
540
  const enforcerAddress = getEnforcerAddress({
467
541
  enforcerName,
468
542
  environment
469
543
  });
470
- const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, params.delegation);
544
+ const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
471
545
  const { terms } = findMatchingCaveat({
472
546
  delegation: params.delegation,
473
547
  enforcerAddress,
474
548
  enforcerName
475
549
  });
476
- return _chunkUUOH2WAWcjs.read_exports.getAvailableAmount({
550
+ return _chunkGZ7HHI2Dcjs.read_exports.getAvailableAmount({
477
551
  client,
478
552
  contractAddress: enforcerAddress,
479
553
  delegationHash,
@@ -482,19 +556,25 @@ async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment
482
556
  });
483
557
  }
484
558
  async function getErc20StreamingEnforcerAvailableAmount(client, environment, params) {
559
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
560
+ "getErc20StreamingEnforcerAvailableAmount",
561
+ {
562
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _19 => _19.chain, 'optionalAccess', _20 => _20.id]), () => ( null))
563
+ }
564
+ );
485
565
  const enforcerName = "ERC20StreamingEnforcer";
486
566
  const delegationManager = getDelegationManager(environment);
487
567
  const enforcerAddress = getEnforcerAddress({
488
568
  enforcerName,
489
569
  environment
490
570
  });
491
- const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, params.delegation);
571
+ const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
492
572
  const { terms } = findMatchingCaveat({
493
573
  delegation: params.delegation,
494
574
  enforcerAddress,
495
575
  enforcerName
496
576
  });
497
- return _chunkUUOH2WAWcjs.read_exports2.getAvailableAmount({
577
+ return _chunkGZ7HHI2Dcjs.read_exports2.getAvailableAmount({
498
578
  client,
499
579
  contractAddress: enforcerAddress,
500
580
  delegationManager,
@@ -503,19 +583,25 @@ async function getErc20StreamingEnforcerAvailableAmount(client, environment, par
503
583
  });
504
584
  }
505
585
  async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, params) {
586
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
587
+ "getMultiTokenPeriodEnforcerAvailableAmount",
588
+ {
589
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _21 => _21.chain, 'optionalAccess', _22 => _22.id]), () => ( null))
590
+ }
591
+ );
506
592
  const enforcerName = "MultiTokenPeriodEnforcer";
507
593
  const delegationManager = getDelegationManager(environment);
508
594
  const enforcerAddress = getEnforcerAddress({
509
595
  enforcerName,
510
596
  environment
511
597
  });
512
- const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, params.delegation);
598
+ const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
513
599
  const { terms, args } = findMatchingCaveat({
514
600
  delegation: params.delegation,
515
601
  enforcerAddress,
516
602
  enforcerName
517
603
  });
518
- return _chunkUUOH2WAWcjs.read_exports3.getAvailableAmount({
604
+ return _chunkGZ7HHI2Dcjs.read_exports3.getAvailableAmount({
519
605
  client,
520
606
  contractAddress: enforcerAddress,
521
607
  delegationHash,
@@ -525,19 +611,25 @@ async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, p
525
611
  });
526
612
  }
527
613
  async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, environment, params) {
614
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
615
+ "getNativeTokenPeriodTransferEnforcerAvailableAmount",
616
+ {
617
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _23 => _23.chain, 'optionalAccess', _24 => _24.id]), () => ( null))
618
+ }
619
+ );
528
620
  const enforcerName = "NativeTokenPeriodTransferEnforcer";
529
621
  const delegationManager = getDelegationManager(environment);
530
622
  const enforcerAddress = getEnforcerAddress({
531
623
  enforcerName,
532
624
  environment
533
625
  });
534
- const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, params.delegation);
626
+ const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
535
627
  const { terms } = findMatchingCaveat({
536
628
  delegation: params.delegation,
537
629
  enforcerAddress,
538
630
  enforcerName
539
631
  });
540
- return _chunkUUOH2WAWcjs.read_exports4.getAvailableAmount({
632
+ return _chunkGZ7HHI2Dcjs.read_exports4.getAvailableAmount({
541
633
  client,
542
634
  contractAddress: enforcerAddress,
543
635
  delegationHash,
@@ -546,19 +638,25 @@ async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, envir
546
638
  });
547
639
  }
548
640
  async function getNativeTokenStreamingEnforcerAvailableAmount(client, environment, params) {
641
+ _chunkSZOX7K2Vcjs.trackSmartAccountsKitFunctionCall.call(void 0,
642
+ "getNativeTokenStreamingEnforcerAvailableAmount",
643
+ {
644
+ chainId: _nullishCoalesce(_optionalChain([client, 'access', _25 => _25.chain, 'optionalAccess', _26 => _26.id]), () => ( null))
645
+ }
646
+ );
549
647
  const enforcerName = "NativeTokenStreamingEnforcer";
550
648
  const delegationManager = getDelegationManager(environment);
551
649
  const enforcerAddress = getEnforcerAddress({
552
650
  enforcerName,
553
651
  environment
554
652
  });
555
- const delegationHash = _chunkYDLLC6PPcjs.hashDelegation.call(void 0, params.delegation);
653
+ const delegationHash = _chunkSZOX7K2Vcjs.hashDelegation.call(void 0, params.delegation);
556
654
  const { terms } = findMatchingCaveat({
557
655
  delegation: params.delegation,
558
656
  enforcerAddress,
559
657
  enforcerName
560
658
  });
561
- return _chunkUUOH2WAWcjs.read_exports5.getAvailableAmount({
659
+ return _chunkGZ7HHI2Dcjs.read_exports5.getAvailableAmount({
562
660
  client,
563
661
  contractAddress: enforcerAddress,
564
662
  delegationManager,
@@ -639,7 +737,7 @@ var caveatEnforcerActions = ({ environment }) => (client) => ({
639
737
  var _actions = require('viem/actions');
640
738
  var DELEGATION_PREFIX = "0xef0100";
641
739
  function extractDelegatedAddress(code) {
642
- if (_optionalChain([code, 'optionalAccess', _5 => _5.length]) !== 48) {
740
+ if (_optionalChain([code, 'optionalAccess', _27 => _27.length]) !== 48) {
643
741
  return null;
644
742
  }
645
743
  if (!code.toLowerCase().startsWith(DELEGATION_PREFIX.toLowerCase())) {
@@ -688,7 +786,7 @@ async function signDelegation(client, parameters) {
688
786
  throw new (0, _viem.BaseError)("Account not found. Please provide an account.");
689
787
  }
690
788
  const account = _accounts.parseAccount.call(void 0, accountParam);
691
- const typedData = _chunkYDLLC6PPcjs.prepareSignDelegationTypedData.call(void 0, {
789
+ const typedData = _chunkSZOX7K2Vcjs.prepareSignDelegationTypedData.call(void 0, {
692
790
  delegation,
693
791
  delegationManager,
694
792
  chainId,
@@ -705,7 +803,7 @@ function signDelegationActions() {
705
803
  return (client) => ({
706
804
  signDelegation: async (parameters) => signDelegation(client, {
707
805
  chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
708
- if (!_optionalChain([client, 'access', _6 => _6.chain, 'optionalAccess', _7 => _7.id])) {
806
+ if (!_optionalChain([client, 'access', _28 => _28.chain, 'optionalAccess', _29 => _29.id])) {
709
807
  throw new (0, _viem.BaseError)(
710
808
  "Chain ID is required. Either provide it in parameters or configure the client with a chain."
711
809
  );
@@ -751,7 +849,7 @@ function signUserOperationActions() {
751
849
  return (client) => ({
752
850
  signUserOperation: async (parameters) => signUserOperation(client, {
753
851
  chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
754
- if (!_optionalChain([client, 'access', _8 => _8.chain, 'optionalAccess', _9 => _9.id])) {
852
+ if (!_optionalChain([client, 'access', _30 => _30.chain, 'optionalAccess', _31 => _31.id])) {
755
853
  throw new (0, _viem.BaseError)(
756
854
  "Chain ID is required. Either provide it in parameters or configure the client with a chain."
757
855
  );
@@ -809,4 +907,4 @@ var erc7710BundlerActions = () => (client) => ({
809
907
 
810
908
 
811
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;
812
- //# sourceMappingURL=chunk-QMRKCB7T.cjs.map
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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AAEP;AAcO;AACL,EAAA;AAOM,IAAA;AAMqB,MAAA;AAIjB,QAAA;AACE,UAAA;AAAU,YAAA;AACR,UAAA;AACF,QAAA;AAEF,QAAA;AAAoB,MAAA;AACnB,MAAA;AACF,IAAA;AACJ,EAAA;AAEP;ATyqBA;AACA;AUxyBA;AACA;AAkDA;AASE,EAAA;AAAM,IAAA;AAC2B,IAAA;AAC/B,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACU,EAAA;AAGZ,EAAA;AACE,IAAA;AAAmE,EAAA;AAGrE,EAAA;AAEA,EAAA;AAAoD,IAAA;AAClD,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAGF,EAAA;AAA4B,IAAA;AAC1B,IAAA;AACG,EAAA;AAEP;AAcO;AACL,EAAA;AAOM,IAAA;AAMwB,MAAA;AAIpB,QAAA;AACE,UAAA;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"]}