permissionless 0.2.25 → 0.2.27

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 (107) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/accounts/biconomy/toBiconomySmartAccount.js +27 -0
  3. package/_cjs/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
  4. package/_cjs/accounts/etherspot/toEtherspotSmartAccount.js +4 -0
  5. package/_cjs/accounts/etherspot/toEtherspotSmartAccount.js.map +1 -1
  6. package/_cjs/accounts/kernel/abi/KernelV3FactoryAbi.js +16 -0
  7. package/_cjs/accounts/kernel/abi/KernelV3FactoryAbi.js.map +1 -0
  8. package/_cjs/accounts/kernel/toKernelSmartAccount.js +17 -4
  9. package/_cjs/accounts/kernel/toKernelSmartAccount.js.map +1 -1
  10. package/_cjs/accounts/kernel/utils/decodeCallData.js +36 -0
  11. package/_cjs/accounts/kernel/utils/decodeCallData.js.map +1 -0
  12. package/_cjs/accounts/light/toLightSmartAccount.js +81 -0
  13. package/_cjs/accounts/light/toLightSmartAccount.js.map +1 -1
  14. package/_cjs/accounts/nexus/toNexusSmartAccount.js +4 -0
  15. package/_cjs/accounts/nexus/toNexusSmartAccount.js.map +1 -1
  16. package/_cjs/accounts/safe/toSafeSmartAccount.js +47 -0
  17. package/_cjs/accounts/safe/toSafeSmartAccount.js.map +1 -1
  18. package/_cjs/accounts/simple/toSimpleSmartAccount.js +114 -0
  19. package/_cjs/accounts/simple/toSimpleSmartAccount.js.map +1 -1
  20. package/_cjs/accounts/thirdweb/toThirdwebSmartAccount.js +4 -0
  21. package/_cjs/accounts/thirdweb/toThirdwebSmartAccount.js.map +1 -1
  22. package/_cjs/accounts/thirdweb/utils/decodeCallData.js +83 -0
  23. package/_cjs/accounts/thirdweb/utils/decodeCallData.js.map +1 -0
  24. package/_cjs/accounts/trust/toTrustSmartAccount.js +4 -0
  25. package/_cjs/accounts/trust/toTrustSmartAccount.js.map +1 -1
  26. package/_cjs/accounts/trust/utils/decodeCallData.js +83 -0
  27. package/_cjs/accounts/trust/utils/decodeCallData.js.map +1 -0
  28. package/_cjs/utils/decode7579Calls.js +100 -0
  29. package/_cjs/utils/decode7579Calls.js.map +1 -0
  30. package/_cjs/utils/getEstimationCallData.js +220 -0
  31. package/_cjs/utils/getEstimationCallData.js.map +1 -0
  32. package/_cjs/utils/index.js +3 -1
  33. package/_cjs/utils/index.js.map +1 -1
  34. package/_esm/accounts/biconomy/toBiconomySmartAccount.js +28 -1
  35. package/_esm/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
  36. package/_esm/accounts/etherspot/toEtherspotSmartAccount.js +4 -0
  37. package/_esm/accounts/etherspot/toEtherspotSmartAccount.js.map +1 -1
  38. package/_esm/accounts/kernel/abi/KernelV3FactoryAbi.js +13 -0
  39. package/_esm/accounts/kernel/abi/KernelV3FactoryAbi.js.map +1 -0
  40. package/_esm/accounts/kernel/toKernelSmartAccount.js +17 -4
  41. package/_esm/accounts/kernel/toKernelSmartAccount.js.map +1 -1
  42. package/_esm/accounts/kernel/utils/decodeCallData.js +32 -0
  43. package/_esm/accounts/kernel/utils/decodeCallData.js.map +1 -0
  44. package/_esm/accounts/light/toLightSmartAccount.js +82 -1
  45. package/_esm/accounts/light/toLightSmartAccount.js.map +1 -1
  46. package/_esm/accounts/nexus/toNexusSmartAccount.js +4 -0
  47. package/_esm/accounts/nexus/toNexusSmartAccount.js.map +1 -1
  48. package/_esm/accounts/safe/toSafeSmartAccount.js +56 -2
  49. package/_esm/accounts/safe/toSafeSmartAccount.js.map +1 -1
  50. package/_esm/accounts/simple/toSimpleSmartAccount.js +115 -1
  51. package/_esm/accounts/simple/toSimpleSmartAccount.js.map +1 -1
  52. package/_esm/accounts/thirdweb/toThirdwebSmartAccount.js +4 -0
  53. package/_esm/accounts/thirdweb/toThirdwebSmartAccount.js.map +1 -1
  54. package/_esm/accounts/thirdweb/utils/decodeCallData.js +79 -0
  55. package/_esm/accounts/thirdweb/utils/decodeCallData.js.map +1 -0
  56. package/_esm/accounts/trust/toTrustSmartAccount.js +4 -0
  57. package/_esm/accounts/trust/toTrustSmartAccount.js.map +1 -1
  58. package/_esm/accounts/trust/utils/decodeCallData.js +79 -0
  59. package/_esm/accounts/trust/utils/decodeCallData.js.map +1 -0
  60. package/_esm/utils/decode7579Calls.js +98 -0
  61. package/_esm/utils/decode7579Calls.js.map +1 -0
  62. package/_esm/utils/getEstimationCallData.js +217 -0
  63. package/_esm/utils/getEstimationCallData.js.map +1 -0
  64. package/_esm/utils/index.js +2 -1
  65. package/_esm/utils/index.js.map +1 -1
  66. package/_types/accounts/biconomy/toBiconomySmartAccount.d.ts.map +1 -1
  67. package/_types/accounts/etherspot/toEtherspotSmartAccount.d.ts.map +1 -1
  68. package/_types/accounts/kernel/abi/KernelV3FactoryAbi.d.ts +20 -0
  69. package/_types/accounts/kernel/abi/KernelV3FactoryAbi.d.ts.map +1 -0
  70. package/_types/accounts/kernel/toKernelSmartAccount.d.ts +1 -0
  71. package/_types/accounts/kernel/toKernelSmartAccount.d.ts.map +1 -1
  72. package/_types/accounts/kernel/utils/decodeCallData.d.ts +11 -0
  73. package/_types/accounts/kernel/utils/decodeCallData.d.ts.map +1 -0
  74. package/_types/accounts/light/toLightSmartAccount.d.ts.map +1 -1
  75. package/_types/accounts/nexus/toNexusSmartAccount.d.ts.map +1 -1
  76. package/_types/accounts/safe/toSafeSmartAccount.d.ts.map +1 -1
  77. package/_types/accounts/simple/toSimpleSmartAccount.d.ts.map +1 -1
  78. package/_types/accounts/thirdweb/toThirdwebSmartAccount.d.ts.map +1 -1
  79. package/_types/accounts/thirdweb/utils/decodeCallData.d.ts +7 -0
  80. package/_types/accounts/thirdweb/utils/decodeCallData.d.ts.map +1 -0
  81. package/_types/accounts/trust/toTrustSmartAccount.d.ts.map +1 -1
  82. package/_types/accounts/trust/utils/decodeCallData.d.ts +7 -0
  83. package/_types/accounts/trust/utils/decodeCallData.d.ts.map +1 -0
  84. package/_types/utils/decode7579Calls.d.ts +12 -0
  85. package/_types/utils/decode7579Calls.d.ts.map +1 -0
  86. package/_types/utils/getEstimationCallData.d.ts +18 -0
  87. package/_types/utils/getEstimationCallData.d.ts.map +1 -0
  88. package/_types/utils/index.d.ts +2 -1
  89. package/_types/utils/index.d.ts.map +1 -1
  90. package/accounts/biconomy/toBiconomySmartAccount.ts +30 -0
  91. package/accounts/decodeCalls.test.ts +340 -0
  92. package/accounts/etherspot/toEtherspotSmartAccount.ts +4 -0
  93. package/accounts/kernel/abi/KernelV3FactoryAbi.ts +12 -0
  94. package/accounts/kernel/toKernelSmartAccount.ts +22 -4
  95. package/accounts/kernel/utils/decodeCallData.ts +43 -0
  96. package/accounts/light/toLightSmartAccount.ts +90 -0
  97. package/accounts/nexus/toNexusSmartAccount.ts +4 -0
  98. package/accounts/safe/toSafeSmartAccount.ts +85 -0
  99. package/accounts/simple/toSimpleSmartAccount.ts +127 -0
  100. package/accounts/thirdweb/toThirdwebSmartAccount.ts +4 -0
  101. package/accounts/thirdweb/utils/decodeCallData.ts +87 -0
  102. package/accounts/trust/toTrustSmartAccount.ts +4 -0
  103. package/accounts/trust/utils/decodeCallData.ts +87 -0
  104. package/package.json +1 -1
  105. package/utils/decode7579Calls.ts +133 -0
  106. package/utils/getEstimationCallData.ts +279 -0
  107. package/utils/index.ts +8 -0
@@ -0,0 +1,43 @@
1
+ import { type Hex, decodeFunctionData } from "viem"
2
+ import { decode7579Calls } from "../../../utils/decode7579Calls.js"
3
+ import { KernelExecuteAbi } from "../abi/KernelAccountAbi.js"
4
+ import type { KernelVersion } from "../toKernelSmartAccount.js"
5
+ import { isKernelV2 } from "./isKernelV2.js"
6
+
7
+ export const decodeCallData = ({
8
+ kernelVersion,
9
+ callData
10
+ }: {
11
+ callData: Hex
12
+ kernelVersion: KernelVersion<"0.6" | "0.7">
13
+ }) => {
14
+ if (isKernelV2(kernelVersion)) {
15
+ const decoded = decodeFunctionData({
16
+ abi: KernelExecuteAbi,
17
+ data: callData
18
+ })
19
+
20
+ if (decoded.functionName === "executeBatch") {
21
+ return decoded.args[0].map((tx) => ({
22
+ to: tx.to,
23
+ value: tx.value,
24
+ data: tx.data
25
+ }))
26
+ }
27
+
28
+ if (decoded.functionName === "execute") {
29
+ const [to, value, data] = decoded.args
30
+ return [
31
+ {
32
+ to,
33
+ value,
34
+ data
35
+ }
36
+ ]
37
+ }
38
+
39
+ throw new Error("Invalid function name")
40
+ }
41
+
42
+ return decode7579Calls(callData).callData
43
+ }
@@ -10,6 +10,7 @@ import {
10
10
  type Transport,
11
11
  type WalletClient,
12
12
  concat,
13
+ decodeFunctionData,
13
14
  encodeFunctionData,
14
15
  hashMessage,
15
16
  hashTypedData
@@ -310,6 +311,95 @@ export async function toLightSmartAccount<
310
311
  args: [call.to, call.value ?? 0n, call.data ?? "0x"]
311
312
  })
312
313
  },
314
+ async decodeCalls(callData) {
315
+ try {
316
+ const decoded = decodeFunctionData({
317
+ abi: [
318
+ {
319
+ inputs: [
320
+ {
321
+ internalType: "address[]",
322
+ name: "dest",
323
+ type: "address[]"
324
+ },
325
+ {
326
+ internalType: "uint256[]",
327
+ name: "value",
328
+ type: "uint256[]"
329
+ },
330
+ {
331
+ internalType: "bytes[]",
332
+ name: "func",
333
+ type: "bytes[]"
334
+ }
335
+ ],
336
+ name: "executeBatch",
337
+ outputs: [],
338
+ stateMutability: "nonpayable",
339
+ type: "function"
340
+ }
341
+ ],
342
+ data: callData
343
+ })
344
+
345
+ if (decoded.functionName === "executeBatch") {
346
+ const calls: {
347
+ to: Address
348
+ value: bigint
349
+ data: Hex
350
+ }[] = []
351
+
352
+ for (let i = 0; i < decoded.args[0].length; i++) {
353
+ calls.push({
354
+ to: decoded.args[0][i],
355
+ value: decoded.args[1][i],
356
+ data: decoded.args[2][i]
357
+ })
358
+ }
359
+
360
+ return calls
361
+ }
362
+
363
+ throw new Error("Invalid function name")
364
+ } catch (_) {
365
+ const decoded = decodeFunctionData({
366
+ abi: [
367
+ {
368
+ inputs: [
369
+ {
370
+ internalType: "address",
371
+ name: "dest",
372
+ type: "address"
373
+ },
374
+ {
375
+ internalType: "uint256",
376
+ name: "value",
377
+ type: "uint256"
378
+ },
379
+ {
380
+ internalType: "bytes",
381
+ name: "func",
382
+ type: "bytes"
383
+ }
384
+ ],
385
+ name: "execute",
386
+ outputs: [],
387
+ stateMutability: "nonpayable",
388
+ type: "function"
389
+ }
390
+ ],
391
+ data: callData
392
+ })
393
+
394
+ return [
395
+ {
396
+ to: decoded.args[0],
397
+ value: decoded.args[1],
398
+ data: decoded.args[2]
399
+ }
400
+ ]
401
+ }
402
+ },
313
403
  async getNonce(args) {
314
404
  return getAccountNonce(client, {
315
405
  address: await this.getAddress(),
@@ -38,6 +38,7 @@ import {
38
38
  import { getChainId, readContract } from "viem/actions"
39
39
  import { getAction } from "viem/utils"
40
40
  import { getAccountNonce } from "../../actions/public/getAccountNonce.js"
41
+ import { decode7579Calls } from "../../utils/decode7579Calls.js"
41
42
  import { encode7579Calls } from "../../utils/encode7579Calls.js"
42
43
  import { type EthereumProvider, toOwner } from "../../utils/toOwner.js"
43
44
 
@@ -235,6 +236,9 @@ export async function toNexusSmartAccount(
235
236
  callData: calls
236
237
  })
237
238
  },
239
+ async decodeCalls(callData) {
240
+ return decode7579Calls(callData).callData
241
+ },
238
242
  async getStubSignature() {
239
243
  const dynamicPart = validatorAddress.substring(2).padEnd(40, "0")
240
244
  return `0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${dynamicPart}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000` as Hex
@@ -13,15 +13,19 @@ import {
13
13
  type TypedDataDefinition,
14
14
  type WalletClient,
15
15
  concat,
16
+ decodeFunctionData,
16
17
  encodeAbiParameters,
17
18
  encodeFunctionData,
18
19
  encodePacked,
20
+ getAddress,
19
21
  getContractAddress,
20
22
  hashMessage,
21
23
  hashTypedData,
22
24
  hexToBigInt,
23
25
  keccak256,
24
26
  pad,
27
+ size,
28
+ slice,
25
29
  toBytes,
26
30
  toHex,
27
31
  zeroAddress
@@ -38,6 +42,7 @@ import {
38
42
  import { getChainId, readContract } from "viem/actions"
39
43
  import { getAction } from "viem/utils"
40
44
  import { getAccountNonce } from "../../actions/public/getAccountNonce.js"
45
+ import { decode7579Calls } from "../../utils/decode7579Calls.js"
41
46
  import { encode7579Calls } from "../../utils/encode7579Calls.js"
42
47
  import { isSmartAccountDeployed } from "../../utils/isSmartAccountDeployed.js"
43
48
  import { type EthereumProvider, toOwner } from "../../utils/toOwner.js"
@@ -490,6 +495,11 @@ const encodeInternalTransaction = (tx: {
490
495
  operation: 0 | 1
491
496
  }): string => {
492
497
  const encoded = encodePacked(
498
+ // uint8 = 1 byte for operation
499
+ // address = 20 bytes for to address
500
+ // uint256 = 32 bytes for value
501
+ // uint256 = 32 bytes for data length
502
+ // bytes = dynamic length for data
493
503
  ["uint8", "address", "uint256", "uint256", "bytes"],
494
504
  [
495
505
  tx.operation,
@@ -1401,6 +1411,81 @@ export async function toSafeSmartAccount<
1401
1411
  args: [to, value, data, operationType]
1402
1412
  })
1403
1413
  },
1414
+ async decodeCalls(callData) {
1415
+ try {
1416
+ const decoded = decodeFunctionData({
1417
+ abi: setupSafeAbi,
1418
+ data: callData
1419
+ })
1420
+
1421
+ return decode7579Calls(decoded.args[0].callData).callData
1422
+ } catch (_) {}
1423
+
1424
+ try {
1425
+ return decode7579Calls(callData).callData
1426
+ } catch (_) {}
1427
+
1428
+ const decoded = decodeFunctionData({
1429
+ abi: executeUserOpWithErrorStringAbi,
1430
+ data: callData
1431
+ })
1432
+
1433
+ const to = decoded.args[0]
1434
+ const value = decoded.args[1]
1435
+ const data = decoded.args[2]
1436
+
1437
+ if (to === multiSendCallOnlyAddress) {
1438
+ const decodedMultiSend = decodeFunctionData({
1439
+ abi: multiSendAbi,
1440
+ data: data
1441
+ })
1442
+
1443
+ const dataToDecode = decodedMultiSend.args[0]
1444
+ const transactions: {
1445
+ to: Address
1446
+ value: bigint
1447
+ data: Hex
1448
+ }[] = []
1449
+
1450
+ let position = 0
1451
+ const dataLength = size(dataToDecode)
1452
+
1453
+ while (position < dataLength) {
1454
+ // skip the operation type
1455
+ position += 1
1456
+
1457
+ const to = getAddress(
1458
+ slice(dataToDecode, position, position + 20)
1459
+ )
1460
+ position += 20
1461
+
1462
+ const value = BigInt(
1463
+ slice(dataToDecode, position, position + 32)
1464
+ )
1465
+ position += 32
1466
+
1467
+ const dataLength = Number(
1468
+ BigInt(slice(dataToDecode, position, position + 32)) *
1469
+ BigInt(2)
1470
+ )
1471
+
1472
+ position += 32
1473
+
1474
+ const data = slice(
1475
+ dataToDecode,
1476
+ position,
1477
+ position + dataLength
1478
+ )
1479
+ position += dataLength
1480
+
1481
+ transactions.push({ to, value, data })
1482
+ }
1483
+
1484
+ return transactions
1485
+ }
1486
+
1487
+ return [{ to, value, data }]
1488
+ },
1404
1489
  async getNonce(args) {
1405
1490
  return getAccountNonce(client, {
1406
1491
  address: await this.getAddress(),
@@ -9,6 +9,7 @@ import {
9
9
  type OneOf,
10
10
  type Transport,
11
11
  type WalletClient,
12
+ decodeFunctionData,
12
13
  encodeFunctionData
13
14
  } from "viem"
14
15
  import {
@@ -291,6 +292,132 @@ export async function toSimpleSmartAccount<
291
292
  args: [call.to, call.value ?? 0n, call.data ?? "0x"]
292
293
  })
293
294
  },
295
+ decodeCalls: async (callData) => {
296
+ try {
297
+ const decodedV6 = decodeFunctionData({
298
+ abi: [
299
+ {
300
+ inputs: [
301
+ {
302
+ internalType: "address[]",
303
+ name: "dest",
304
+ type: "address[]"
305
+ },
306
+ {
307
+ internalType: "bytes[]",
308
+ name: "func",
309
+ type: "bytes[]"
310
+ }
311
+ ],
312
+ name: "executeBatch",
313
+ outputs: [],
314
+ stateMutability: "nonpayable",
315
+ type: "function"
316
+ }
317
+ ],
318
+ data: callData
319
+ })
320
+
321
+ const calls: {
322
+ to: Address
323
+ data: Hex
324
+ value?: bigint
325
+ }[] = []
326
+
327
+ for (let i = 0; i < decodedV6.args.length; i++) {
328
+ calls.push({
329
+ to: decodedV6.args[0][i],
330
+ data: decodedV6.args[1][i],
331
+ value: 0n
332
+ })
333
+ }
334
+
335
+ return calls
336
+ } catch (_) {
337
+ try {
338
+ const decodedV7 = decodeFunctionData({
339
+ abi: [
340
+ {
341
+ inputs: [
342
+ {
343
+ internalType: "address[]",
344
+ name: "dest",
345
+ type: "address[]"
346
+ },
347
+ {
348
+ internalType: "uint256[]",
349
+ name: "value",
350
+ type: "uint256[]"
351
+ },
352
+ {
353
+ internalType: "bytes[]",
354
+ name: "func",
355
+ type: "bytes[]"
356
+ }
357
+ ],
358
+ name: "executeBatch",
359
+ outputs: [],
360
+ stateMutability: "nonpayable",
361
+ type: "function"
362
+ }
363
+ ],
364
+ data: callData
365
+ })
366
+
367
+ const calls: {
368
+ to: Address
369
+ data: Hex
370
+ value?: bigint
371
+ }[] = []
372
+
373
+ for (let i = 0; i < decodedV7.args[0].length; i++) {
374
+ calls.push({
375
+ to: decodedV7.args[0][i],
376
+ value: decodedV7.args[1][i],
377
+ data: decodedV7.args[2][i]
378
+ })
379
+ }
380
+
381
+ return calls
382
+ } catch (_) {
383
+ const decodedSingle = decodeFunctionData({
384
+ abi: [
385
+ {
386
+ inputs: [
387
+ {
388
+ internalType: "address",
389
+ name: "dest",
390
+ type: "address"
391
+ },
392
+ {
393
+ internalType: "uint256",
394
+ name: "value",
395
+ type: "uint256"
396
+ },
397
+ {
398
+ internalType: "bytes",
399
+ name: "func",
400
+ type: "bytes"
401
+ }
402
+ ],
403
+ name: "execute",
404
+ outputs: [],
405
+ stateMutability: "nonpayable",
406
+ type: "function"
407
+ }
408
+ ],
409
+ data: callData
410
+ })
411
+ return [
412
+ {
413
+ to: decodedSingle.args[0],
414
+ value: decodedSingle.args[1],
415
+ data: decodedSingle.args[2]
416
+ }
417
+ ]
418
+ }
419
+ }
420
+ },
294
421
  async getNonce(args) {
295
422
  return getAccountNonce(client, {
296
423
  address: await this.getAddress(),
@@ -25,6 +25,7 @@ import {
25
25
  } from "viem/account-abstraction"
26
26
  import { getAction, toHex } from "viem/utils"
27
27
  import { type EthereumProvider, toOwner } from "../../utils/toOwner.js"
28
+ import { decodeCallData } from "./utils/decodeCallData.js"
28
29
  import { encodeCallData } from "./utils/encodeCallData.js"
29
30
  import { getAccountAddress } from "./utils/getAccountAddress.js"
30
31
  import { getFactoryData } from "./utils/getFactoryData.js"
@@ -158,6 +159,9 @@ export async function toThirdwebSmartAccount<
158
159
  async encodeCalls(calls) {
159
160
  return encodeCallData(calls)
160
161
  },
162
+ async decodeCalls(callData) {
163
+ return decodeCallData(callData)
164
+ },
161
165
  async getNonce(args) {
162
166
  return getAccountNonce(client, {
163
167
  address: await this.getAddress(),
@@ -0,0 +1,87 @@
1
+ import { type Address, type Hex, decodeFunctionData } from "viem"
2
+
3
+ export const decodeCallData = async (callData: `0x${string}`) => {
4
+ try {
5
+ const decodedBatch = decodeFunctionData({
6
+ abi: [
7
+ {
8
+ inputs: [
9
+ {
10
+ internalType: "address[]",
11
+ name: "dest",
12
+ type: "address[]"
13
+ },
14
+ {
15
+ internalType: "uint256[]",
16
+ name: "value",
17
+ type: "uint256[]"
18
+ },
19
+ {
20
+ internalType: "bytes[]",
21
+ name: "func",
22
+ type: "bytes[]"
23
+ }
24
+ ],
25
+ name: "executeBatch",
26
+ outputs: [],
27
+ stateMutability: "nonpayable",
28
+ type: "function"
29
+ }
30
+ ],
31
+ data: callData
32
+ })
33
+
34
+ const calls: {
35
+ to: Address
36
+ data: Hex
37
+ value?: bigint
38
+ }[] = []
39
+
40
+ for (let i = 0; i < decodedBatch.args[0].length; i++) {
41
+ calls.push({
42
+ to: decodedBatch.args[0][i],
43
+ value: decodedBatch.args[1][i],
44
+ data: decodedBatch.args[2][i]
45
+ })
46
+ }
47
+
48
+ return calls
49
+ } catch (_) {}
50
+
51
+ const decodedSingle = decodeFunctionData({
52
+ abi: [
53
+ {
54
+ inputs: [
55
+ {
56
+ internalType: "address",
57
+ name: "dest",
58
+ type: "address"
59
+ },
60
+ {
61
+ internalType: "uint256",
62
+ name: "value",
63
+ type: "uint256"
64
+ },
65
+ {
66
+ internalType: "bytes",
67
+ name: "func",
68
+ type: "bytes"
69
+ }
70
+ ],
71
+ name: "execute",
72
+ outputs: [],
73
+ stateMutability: "nonpayable",
74
+ type: "function"
75
+ }
76
+ ],
77
+ data: callData
78
+ })
79
+
80
+ return [
81
+ {
82
+ to: decodedSingle.args[0],
83
+ value: decodedSingle.args[1],
84
+ data: decodedSingle.args[2]
85
+ }
86
+ ]
87
+ }
@@ -27,6 +27,7 @@ import {
27
27
  import { getAction } from "viem/utils"
28
28
  import { getSenderAddress } from "../../actions/public/getSenderAddress.js"
29
29
  import { type EthereumProvider, toOwner } from "../../utils/toOwner.js"
30
+ import { decodeCallData } from "./utils/decodeCallData.js"
30
31
  import { encodeCallData } from "./utils/encodeCallData.js"
31
32
  import { getFactoryData } from "./utils/getFactoryData.js"
32
33
 
@@ -168,6 +169,9 @@ export async function toTrustSmartAccount(
168
169
  async encodeCalls(calls) {
169
170
  return encodeCallData(calls)
170
171
  },
172
+ async decodeCalls(callData) {
173
+ return decodeCallData(callData)
174
+ },
171
175
  async getNonce(args) {
172
176
  return getAccountNonce(client, {
173
177
  address: await this.getAddress(),
@@ -0,0 +1,87 @@
1
+ import { type Address, type Hex, decodeFunctionData } from "viem"
2
+
3
+ export const decodeCallData = async (callData: `0x${string}`) => {
4
+ try {
5
+ const decodedBatch = decodeFunctionData({
6
+ abi: [
7
+ {
8
+ inputs: [
9
+ {
10
+ internalType: "address[]",
11
+ name: "dest",
12
+ type: "address[]"
13
+ },
14
+ {
15
+ internalType: "uint256[]",
16
+ name: "value",
17
+ type: "uint256[]"
18
+ },
19
+ {
20
+ internalType: "bytes[]",
21
+ name: "func",
22
+ type: "bytes[]"
23
+ }
24
+ ],
25
+ name: "executeBatch",
26
+ outputs: [],
27
+ stateMutability: "nonpayable",
28
+ type: "function"
29
+ }
30
+ ],
31
+ data: callData
32
+ })
33
+
34
+ const calls: {
35
+ to: Address
36
+ data: Hex
37
+ value?: bigint
38
+ }[] = []
39
+
40
+ for (let i = 0; i < decodedBatch.args[0].length; i++) {
41
+ calls.push({
42
+ to: decodedBatch.args[0][i],
43
+ value: decodedBatch.args[1][i],
44
+ data: decodedBatch.args[2][i]
45
+ })
46
+ }
47
+
48
+ return calls
49
+ } catch (_) {}
50
+
51
+ const decodedSingle = decodeFunctionData({
52
+ abi: [
53
+ {
54
+ inputs: [
55
+ {
56
+ internalType: "address",
57
+ name: "dest",
58
+ type: "address"
59
+ },
60
+ {
61
+ internalType: "uint256",
62
+ name: "value",
63
+ type: "uint256"
64
+ },
65
+ {
66
+ internalType: "bytes",
67
+ name: "func",
68
+ type: "bytes"
69
+ }
70
+ ],
71
+ name: "execute",
72
+ outputs: [],
73
+ stateMutability: "nonpayable",
74
+ type: "function"
75
+ }
76
+ ],
77
+ data: callData
78
+ })
79
+
80
+ return [
81
+ {
82
+ to: decodedSingle.args[0],
83
+ value: decodedSingle.args[1],
84
+ data: decodedSingle.args[2]
85
+ }
86
+ ]
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",