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,133 @@
1
+ import {
2
+ type Address,
3
+ type Hex,
4
+ decodeAbiParameters,
5
+ decodeFunctionData,
6
+ getAddress,
7
+ size,
8
+ slice
9
+ } from "viem"
10
+ import type {
11
+ CallType,
12
+ ExecutionMode
13
+ } from "../actions/erc7579/supportsExecutionMode.js"
14
+
15
+ export type DecodeCallDataReturnType = {
16
+ mode: ExecutionMode<CallType>
17
+ callData: readonly {
18
+ to: Address
19
+ value?: bigint | undefined
20
+ data?: Hex | undefined
21
+ }[]
22
+ }
23
+
24
+ export function decode7579Calls(callData: Hex): DecodeCallDataReturnType {
25
+ const executeAbi = [
26
+ {
27
+ type: "function",
28
+ name: "execute",
29
+ inputs: [
30
+ {
31
+ name: "execMode",
32
+ type: "bytes32",
33
+ internalType: "ExecMode"
34
+ },
35
+ {
36
+ name: "executionCalldata",
37
+ type: "bytes",
38
+ internalType: "bytes"
39
+ }
40
+ ],
41
+ outputs: [],
42
+ stateMutability: "payable"
43
+ }
44
+ ] as const
45
+
46
+ const decoded = decodeFunctionData({
47
+ abi: executeAbi,
48
+ data: callData
49
+ })
50
+
51
+ const mode = decoded.args[0]
52
+ const executionCalldata = decoded.args[1]
53
+
54
+ const callType = slice(mode, 0, 1) // First byte
55
+ const revertOnError = slice(mode, 1, 2) // Second byte
56
+ const selector = slice(mode, 3, 7) as Hex // bytes 5-8
57
+ const context = slice(mode, 7) as Hex // bytes 9-32
58
+
59
+ let type: CallType
60
+ switch (BigInt(callType)) {
61
+ case BigInt(0x00):
62
+ type = "call"
63
+ break
64
+ case BigInt(0x01):
65
+ type = "batchcall"
66
+ break
67
+ case BigInt(0xff):
68
+ type = "delegatecall"
69
+ break
70
+ default:
71
+ throw new Error("Invalid call type")
72
+ }
73
+
74
+ const decodedMode: ExecutionMode<CallType> = {
75
+ type,
76
+ revertOnError: BigInt(revertOnError) === BigInt(1),
77
+ selector,
78
+ context
79
+ }
80
+
81
+ if (decodedMode.type === "batchcall") {
82
+ const [calls] = decodeAbiParameters(
83
+ [
84
+ {
85
+ name: "executionBatch",
86
+ type: "tuple[]",
87
+ components: [
88
+ {
89
+ name: "target",
90
+ type: "address"
91
+ },
92
+ {
93
+ name: "value",
94
+ type: "uint256"
95
+ },
96
+ {
97
+ name: "callData",
98
+ type: "bytes"
99
+ }
100
+ ]
101
+ }
102
+ ],
103
+ executionCalldata
104
+ )
105
+
106
+ return {
107
+ mode: decodedMode,
108
+ callData: calls.map((call) => ({
109
+ to: call.target,
110
+ value: call.value,
111
+ data: call.callData
112
+ }))
113
+ }
114
+ }
115
+
116
+ // Single call - calldata is encoded as concatenated (to, value, data)
117
+ const to = getAddress(slice(executionCalldata, 0, 20)) // 20 bytes address with 0x prefix
118
+ const value = BigInt(slice(executionCalldata, 20, 52)) // 32 bytes value
119
+
120
+ const data =
121
+ size(executionCalldata) > 52 ? slice(executionCalldata, 52) : "0x" // Remaining bytes are calldata
122
+
123
+ return {
124
+ mode: decodedMode,
125
+ callData: [
126
+ {
127
+ to,
128
+ value,
129
+ data
130
+ }
131
+ ]
132
+ }
133
+ }
@@ -0,0 +1,279 @@
1
+ import { type Address, type Hex, encodeFunctionData } from "viem"
2
+ import {
3
+ type UserOperation,
4
+ entryPoint06Abi,
5
+ toPackedUserOperation
6
+ } from "viem/account-abstraction"
7
+
8
+ function getPimlicoEstimationCallData06({
9
+ userOperation,
10
+ entrypoint
11
+ }: {
12
+ userOperation: UserOperation<"0.6">
13
+ entrypoint: {
14
+ address: Address
15
+ version: "0.6"
16
+ }
17
+ }): { to: Address; data: Hex } {
18
+ return {
19
+ to: entrypoint.address,
20
+ data: encodeFunctionData({
21
+ abi: entryPoint06Abi,
22
+ functionName: "simulateHandleOp",
23
+ args: [
24
+ {
25
+ callData: userOperation.callData,
26
+ callGasLimit: userOperation.callGasLimit,
27
+ initCode: userOperation.initCode ?? "0x",
28
+ maxFeePerGas: userOperation.maxFeePerGas,
29
+ maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
30
+ nonce: userOperation.nonce,
31
+ paymasterAndData: userOperation.paymasterAndData ?? "0x",
32
+ preVerificationGas: userOperation.preVerificationGas,
33
+ sender: userOperation.sender,
34
+ signature: userOperation.signature,
35
+ verificationGasLimit: userOperation.verificationGasLimit
36
+ },
37
+ "0x",
38
+ "0x"
39
+ ]
40
+ })
41
+ }
42
+ }
43
+
44
+ function encodeSimulateHandleOpLast({
45
+ userOperation
46
+ }: {
47
+ userOperation: UserOperation<"0.7">
48
+ }): Hex {
49
+ const userOperations = [userOperation]
50
+ const packedUserOperations = userOperations.map((uop) => ({
51
+ packedUserOperation: toPackedUserOperation(uop)
52
+ }))
53
+
54
+ const simulateHandleOpCallData = encodeFunctionData({
55
+ abi: [
56
+ {
57
+ type: "function",
58
+ name: "simulateHandleOpLast",
59
+ inputs: [
60
+ {
61
+ name: "ops",
62
+ type: "tuple[]",
63
+ internalType: "struct PackedUserOperation[]",
64
+ components: [
65
+ {
66
+ name: "sender",
67
+ type: "address",
68
+ internalType: "address"
69
+ },
70
+ {
71
+ name: "nonce",
72
+ type: "uint256",
73
+ internalType: "uint256"
74
+ },
75
+ {
76
+ name: "initCode",
77
+ type: "bytes",
78
+ internalType: "bytes"
79
+ },
80
+ {
81
+ name: "callData",
82
+ type: "bytes",
83
+ internalType: "bytes"
84
+ },
85
+ {
86
+ name: "accountGasLimits",
87
+ type: "bytes32",
88
+ internalType: "bytes32"
89
+ },
90
+ {
91
+ name: "preVerificationGas",
92
+ type: "uint256",
93
+ internalType: "uint256"
94
+ },
95
+ {
96
+ name: "gasFees",
97
+ type: "bytes32",
98
+ internalType: "bytes32"
99
+ },
100
+ {
101
+ name: "paymasterAndData",
102
+ type: "bytes",
103
+ internalType: "bytes"
104
+ },
105
+ {
106
+ name: "signature",
107
+ type: "bytes",
108
+ internalType: "bytes"
109
+ }
110
+ ]
111
+ }
112
+ ],
113
+ outputs: [
114
+ {
115
+ name: "",
116
+ type: "tuple",
117
+ internalType:
118
+ "struct IEntryPointSimulations.ExecutionResult",
119
+ components: [
120
+ {
121
+ name: "preOpGas",
122
+ type: "uint256",
123
+ internalType: "uint256"
124
+ },
125
+ {
126
+ name: "paid",
127
+ type: "uint256",
128
+ internalType: "uint256"
129
+ },
130
+ {
131
+ name: "accountValidationData",
132
+ type: "uint256",
133
+ internalType: "uint256"
134
+ },
135
+ {
136
+ name: "paymasterValidationData",
137
+ type: "uint256",
138
+ internalType: "uint256"
139
+ },
140
+ {
141
+ name: "paymasterVerificationGasLimit",
142
+ type: "uint256",
143
+ internalType: "uint256"
144
+ },
145
+ {
146
+ name: "paymasterPostOpGasLimit",
147
+ type: "uint256",
148
+ internalType: "uint256"
149
+ },
150
+ {
151
+ name: "targetSuccess",
152
+ type: "bool",
153
+ internalType: "bool"
154
+ },
155
+ {
156
+ name: "targetResult",
157
+ type: "bytes",
158
+ internalType: "bytes"
159
+ }
160
+ ]
161
+ }
162
+ ],
163
+ stateMutability: "nonpayable"
164
+ }
165
+ ],
166
+ functionName: "simulateHandleOpLast",
167
+ args: [packedUserOperations.map((uop) => uop.packedUserOperation)]
168
+ })
169
+
170
+ return simulateHandleOpCallData
171
+ }
172
+
173
+ const PIMLICO_ESTIMATION_ADDRESS = "0x949CeCa936909f75E5A40bD285d9985eFBb9B0D3"
174
+
175
+ function getPimlicoEstimationCallData07({
176
+ userOperation,
177
+ estimationAddress,
178
+ entrypoint
179
+ }: {
180
+ userOperation: UserOperation<"0.7">
181
+ estimationAddress?: Address
182
+ entrypoint: {
183
+ address: Address
184
+ version: "0.7"
185
+ }
186
+ }): { to: Address; data: Hex } {
187
+ const simulateHandleOpLast = encodeSimulateHandleOpLast({
188
+ userOperation
189
+ })
190
+
191
+ return {
192
+ to: estimationAddress ?? PIMLICO_ESTIMATION_ADDRESS,
193
+ data: encodeFunctionData({
194
+ abi: [
195
+ {
196
+ inputs: [
197
+ {
198
+ internalType: "address payable",
199
+ name: "ep",
200
+ type: "address"
201
+ },
202
+ {
203
+ internalType: "bytes[]",
204
+ name: "data",
205
+ type: "bytes[]"
206
+ }
207
+ ],
208
+ name: "simulateEntryPoint",
209
+ outputs: [
210
+ {
211
+ internalType: "bytes[]",
212
+ name: "",
213
+ type: "bytes[]"
214
+ }
215
+ ],
216
+ stateMutability: "nonpayable",
217
+ type: "function"
218
+ }
219
+ ],
220
+ functionName: "simulateEntryPoint",
221
+ args: [entrypoint.address, [simulateHandleOpLast]]
222
+ })
223
+ }
224
+ }
225
+
226
+ export type GetPimlicoEstimationCallDataParams<
227
+ entryPointVersion extends "0.6" | "0.7"
228
+ > = {
229
+ userOperation: UserOperation<entryPointVersion>
230
+ entrypoint: {
231
+ address: Address
232
+ version: entryPointVersion
233
+ }
234
+ } & (entryPointVersion extends "0.6"
235
+ ? {
236
+ estimationAddress: never
237
+ }
238
+ : { estimationAddress?: Address })
239
+
240
+ function isEntryPoint06(
241
+ args: GetPimlicoEstimationCallDataParams<"0.6" | "0.7">
242
+ ): args is GetPimlicoEstimationCallDataParams<"0.6"> {
243
+ return args.entrypoint.version === "0.6"
244
+ }
245
+
246
+ function isEntryPoint07(
247
+ args: GetPimlicoEstimationCallDataParams<"0.6" | "0.7">
248
+ ): args is GetPimlicoEstimationCallDataParams<"0.7"> {
249
+ return args.entrypoint.version === "0.7"
250
+ }
251
+
252
+ export function getPimlicoEstimationCallData<
253
+ entryPointVersion extends "0.6" | "0.7"
254
+ >(
255
+ args: GetPimlicoEstimationCallDataParams<entryPointVersion>
256
+ ): { to: Address; data: Hex } {
257
+ if (isEntryPoint06(args)) {
258
+ return getPimlicoEstimationCallData06({
259
+ userOperation: args.userOperation,
260
+ entrypoint: {
261
+ address: args.entrypoint.address,
262
+ version: "0.6"
263
+ }
264
+ })
265
+ }
266
+
267
+ if (isEntryPoint07(args)) {
268
+ return getPimlicoEstimationCallData07({
269
+ userOperation: args.userOperation,
270
+ estimationAddress: args.estimationAddress,
271
+ entrypoint: {
272
+ address: args.entrypoint.address,
273
+ version: "0.7"
274
+ }
275
+ })
276
+ }
277
+
278
+ throw new Error("Invalid entrypoint version")
279
+ }
package/utils/index.ts CHANGED
@@ -20,6 +20,12 @@ import {
20
20
  type EncodeCallDataParams,
21
21
  encode7579Calls
22
22
  } from "./encode7579Calls.js"
23
+
24
+ import {
25
+ type DecodeCallDataReturnType,
26
+ decode7579Calls
27
+ } from "./decode7579Calls.js"
28
+
23
29
  import {
24
30
  type Erc20AllowanceOverrideParameters,
25
31
  erc20AllowanceOverride
@@ -44,6 +50,8 @@ export {
44
50
  encodeInstallModule,
45
51
  type EncodeCallDataParams,
46
52
  encode7579Calls,
53
+ decode7579Calls,
54
+ type DecodeCallDataReturnType,
47
55
  erc20AllowanceOverride,
48
56
  erc20BalanceOverride,
49
57
  type Erc20AllowanceOverrideParameters,