permissionless 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/_cjs/actions/bundler.js +117 -0
- package/_cjs/actions/bundler.js.map +1 -0
- package/_cjs/actions/index.js +11 -0
- package/_cjs/actions/index.js.map +1 -0
- package/_cjs/actions/utils.js +27 -0
- package/_cjs/actions/utils.js.map +1 -0
- package/_cjs/index.js +6 -0
- package/_cjs/index.js.map +1 -0
- package/_cjs/package.json +1 -0
- package/_cjs/types/bundler.js +3 -0
- package/_cjs/types/bundler.js.map +1 -0
- package/_cjs/types/index.js +3 -0
- package/_cjs/types/index.js.map +1 -0
- package/_cjs/types/userOperation.js +3 -0
- package/_cjs/types/userOperation.js.map +1 -0
- package/_esm/actions/bundler.js +384 -0
- package/_esm/actions/bundler.js.map +1 -0
- package/_esm/actions/index.js +3 -0
- package/_esm/actions/index.js.map +1 -0
- package/_esm/actions/utils.js +24 -0
- package/_esm/actions/utils.js.map +1 -0
- package/_esm/index.js +3 -0
- package/_esm/index.js.map +1 -0
- package/_esm/package.json +1 -0
- package/_esm/types/bundler.js +2 -0
- package/_esm/types/bundler.js.map +1 -0
- package/_esm/types/index.js +2 -0
- package/_esm/types/index.js.map +1 -0
- package/_esm/types/userOperation.js +2 -0
- package/_esm/types/userOperation.js.map +1 -0
- package/_types/actions/bundler.d.ts +304 -0
- package/_types/actions/bundler.d.ts.map +1 -0
- package/_types/actions/index.d.ts +3 -0
- package/_types/actions/index.d.ts.map +1 -0
- package/_types/actions/utils.d.ts +2 -0
- package/_types/actions/utils.d.ts.map +1 -0
- package/_types/index.d.ts +3 -0
- package/_types/index.d.ts.map +1 -0
- package/_types/types/bundler.d.ts +115 -0
- package/_types/types/bundler.d.ts.map +1 -0
- package/_types/types/index.d.ts +4 -0
- package/_types/types/index.d.ts.map +1 -0
- package/_types/types/userOperation.d.ts +29 -0
- package/_types/types/userOperation.d.ts.map +1 -0
- package/actions/bundler.ts +446 -0
- package/actions/index.ts +22 -0
- package/actions/package.json +6 -0
- package/actions/utils.ts +25 -0
- package/index.ts +2 -0
- package/package.json +34 -11
- package/tsconfig.build.tsbuildinfo +1 -0
- package/types/bundler.ts +120 -0
- package/types/index.ts +4 -0
- package/types/package.json +6 -0
- package/types/userOperation.ts +30 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import type { Address } from "abitype"
|
|
2
|
+
import type { Client, Hash } from "viem"
|
|
3
|
+
import type { PartialBy } from "viem/types/utils"
|
|
4
|
+
import type { UserOperation, UserOperationReceipt } from "../types"
|
|
5
|
+
import type { BundlerClient } from "../types/bundler"
|
|
6
|
+
import type { UserOperationWithBigIntAsHex } from "../types/userOperation"
|
|
7
|
+
import { deepHexlify } from "./utils"
|
|
8
|
+
|
|
9
|
+
export type SendUserOperationParameters = {
|
|
10
|
+
userOperation: UserOperation
|
|
11
|
+
entryPoint: Address
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type EstimateUserOperationGasParameters = {
|
|
15
|
+
userOperation: PartialBy<UserOperation, "callGasLimit" | "preVerificationGas" | "verificationGasLimit">
|
|
16
|
+
entryPoint: Address
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type EstimateUserOperationGasReturnType = {
|
|
20
|
+
preVerificationGas: bigint
|
|
21
|
+
verificationGasLimit: bigint
|
|
22
|
+
callGasLimit: bigint
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type GetUserOperationByHash = {
|
|
26
|
+
hash: Hash
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type GetUserOperationReceipt = {
|
|
30
|
+
hash: Hash
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sends user operation to the bundler
|
|
35
|
+
*
|
|
36
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/sendUserOperation
|
|
37
|
+
*
|
|
38
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
39
|
+
* @param args {@link SendUserOperationParameters}.
|
|
40
|
+
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* import { createClient } from "viem"
|
|
45
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
46
|
+
*
|
|
47
|
+
* const bundlerClient = createClient({
|
|
48
|
+
* chain: goerli,
|
|
49
|
+
* transport: http(BUNDLER_URL)
|
|
50
|
+
* })
|
|
51
|
+
*
|
|
52
|
+
* const userOpHash = sendUserOperation(bundlerClient, {
|
|
53
|
+
* userOperation: signedUserOperation,
|
|
54
|
+
* entryPoint: entryPoint
|
|
55
|
+
* })
|
|
56
|
+
*
|
|
57
|
+
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
export const sendUserOperation = async (client: BundlerClient, args: SendUserOperationParameters): Promise<Hash> => {
|
|
61
|
+
const { userOperation, entryPoint } = args
|
|
62
|
+
|
|
63
|
+
return client.request({
|
|
64
|
+
method: "eth_sendUserOperation",
|
|
65
|
+
params: [deepHexlify(userOperation) as UserOperationWithBigIntAsHex, entryPoint as Address]
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Estimates preVerificationGas, verificationGasLimit and callGasLimit for user operation
|
|
71
|
+
*
|
|
72
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/estimateUserOperationGas
|
|
73
|
+
*
|
|
74
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
75
|
+
* @param args {@link EstimateUserOperationGasParameters}
|
|
76
|
+
* @returns preVerificationGas, verificationGasLimit and callGasLimit as {@link EstimateUserOperationGasReturnType}
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* import { createClient } from "viem"
|
|
81
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
82
|
+
*
|
|
83
|
+
* const bundlerClient = createClient({
|
|
84
|
+
* chain: goerli,
|
|
85
|
+
* transport: http(BUNDLER_URL)
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* const gasParameters = estimateUserOperationGas(bundlerClient, {
|
|
89
|
+
* serOperation: signedUserOperation,
|
|
90
|
+
* entryPoint: entryPoint
|
|
91
|
+
* })
|
|
92
|
+
*
|
|
93
|
+
* // Return {preVerificationGas: 43492n, verificationGasLimit: 59436n, callGasLimit: 9000n}
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
export const estimateUserOperationGas = async (
|
|
97
|
+
client: BundlerClient,
|
|
98
|
+
args: EstimateUserOperationGasParameters
|
|
99
|
+
): Promise<EstimateUserOperationGasReturnType> => {
|
|
100
|
+
const { userOperation, entryPoint } = args
|
|
101
|
+
|
|
102
|
+
const response = await client.request({
|
|
103
|
+
method: "eth_estimateUserOperationGas",
|
|
104
|
+
params: [deepHexlify(userOperation) as UserOperationWithBigIntAsHex, entryPoint as Address]
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
preVerificationGas: BigInt(response.preVerificationGas || 0n),
|
|
109
|
+
verificationGasLimit: BigInt(response.verificationGasLimit || 0n),
|
|
110
|
+
callGasLimit: BigInt(response.callGasLimit || 0n)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the supported entrypoints by the bundler service
|
|
116
|
+
*
|
|
117
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/supportedEntryPoints
|
|
118
|
+
*
|
|
119
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
120
|
+
* @returns Supported entryPoints
|
|
121
|
+
*
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* import { createClient } from "viem"
|
|
125
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
126
|
+
*
|
|
127
|
+
* const bundlerClient = createClient({
|
|
128
|
+
* chain: goerli,
|
|
129
|
+
* transport: http(BUNDLER_URL)
|
|
130
|
+
* })
|
|
131
|
+
*
|
|
132
|
+
* const entryPointsSupported = supportedEntryPoints(bundlerClient)
|
|
133
|
+
* // Return ['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']
|
|
134
|
+
*
|
|
135
|
+
*/
|
|
136
|
+
export const supportedEntryPoints = async (client: BundlerClient): Promise<Address[]> => {
|
|
137
|
+
return client.request({
|
|
138
|
+
method: "eth_supportedEntryPoints",
|
|
139
|
+
params: []
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns the supported chain id by the bundler service
|
|
145
|
+
*
|
|
146
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/chainId
|
|
147
|
+
*
|
|
148
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
149
|
+
* @returns Supported chain id
|
|
150
|
+
*
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* import { createClient } from "viem"
|
|
154
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
155
|
+
*
|
|
156
|
+
* const bundlerClient = createClient({
|
|
157
|
+
* chain: goerli,
|
|
158
|
+
* transport: http(BUNDLER_URL)
|
|
159
|
+
* })
|
|
160
|
+
*
|
|
161
|
+
* const chainId = chainId(bundlerClient)
|
|
162
|
+
* // Return 5n for Goerli
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
export const chainId = async (client: BundlerClient) => {
|
|
166
|
+
return BigInt(
|
|
167
|
+
await client.request({
|
|
168
|
+
method: "eth_chainId",
|
|
169
|
+
params: []
|
|
170
|
+
})
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Returns the user operation from userOpHash
|
|
176
|
+
*
|
|
177
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationByHash
|
|
178
|
+
*
|
|
179
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
180
|
+
* @param args {@link GetUserOperationByHash} UserOpHash that was returned by {@link sendUserOperation}
|
|
181
|
+
* @returns userOperation along with entryPoint, transactionHash, blockHash, blockNumber if found or null
|
|
182
|
+
*
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* import { createClient } from "viem"
|
|
186
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
187
|
+
*
|
|
188
|
+
* const bundlerClient = createClient({
|
|
189
|
+
* chain: goerli,
|
|
190
|
+
* transport: http(BUNDLER_URL)
|
|
191
|
+
* })
|
|
192
|
+
*
|
|
193
|
+
* getUserOperationByHash(bundlerClient, {hash: userOpHash})
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
export const getUserOperationByHash = async (
|
|
197
|
+
client: BundlerClient,
|
|
198
|
+
{ hash }: GetUserOperationByHash
|
|
199
|
+
): Promise<{
|
|
200
|
+
userOperation: UserOperation
|
|
201
|
+
entryPoint: Address
|
|
202
|
+
transactionHash: Hash
|
|
203
|
+
blockHash: Hash
|
|
204
|
+
blockNumber: bigint
|
|
205
|
+
} | null> => {
|
|
206
|
+
const params: [Hash] = [hash]
|
|
207
|
+
|
|
208
|
+
const response = await client.request({
|
|
209
|
+
method: "eth_getUserOperationByHash",
|
|
210
|
+
params
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
if (!response) return null
|
|
214
|
+
|
|
215
|
+
const { userOperation, entryPoint, transactionHash, blockHash, blockNumber } = response
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
userOperation: {
|
|
219
|
+
...userOperation,
|
|
220
|
+
nonce: BigInt(userOperation.nonce),
|
|
221
|
+
callGasLimit: BigInt(userOperation.callGasLimit),
|
|
222
|
+
verificationGasLimit: BigInt(userOperation.verificationGasLimit),
|
|
223
|
+
preVerificationGas: BigInt(userOperation.preVerificationGas),
|
|
224
|
+
maxFeePerGas: BigInt(userOperation.maxFeePerGas),
|
|
225
|
+
maxPriorityFeePerGas: BigInt(userOperation.maxPriorityFeePerGas)
|
|
226
|
+
} as UserOperation,
|
|
227
|
+
entryPoint: entryPoint,
|
|
228
|
+
transactionHash: transactionHash,
|
|
229
|
+
blockHash: blockHash,
|
|
230
|
+
blockNumber: BigInt(blockNumber)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Returns the user operation receipt from userOpHash
|
|
236
|
+
*
|
|
237
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt
|
|
238
|
+
*
|
|
239
|
+
* @param client {@link BundlerClient} that you created using viem's createClient and extended it with bundlerActions.
|
|
240
|
+
* @param args {@link GetUserOperationReceipt} UserOpHash that was returned by {@link sendUserOperation}
|
|
241
|
+
* @returns user operation receipt {@link UserOperationReceipt} if found or null
|
|
242
|
+
*
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* import { createClient } from "viem"
|
|
246
|
+
* import { sendUserOperation } from "permissionless/actions"
|
|
247
|
+
*
|
|
248
|
+
* const bundlerClient = createClient({
|
|
249
|
+
* chain: goerli,
|
|
250
|
+
* transport: http(BUNDLER_URL)
|
|
251
|
+
* })
|
|
252
|
+
*
|
|
253
|
+
* getUserOperationReceipt(bundlerClient, {hash: userOpHash})
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserOperationReceipt) => {
|
|
257
|
+
const params: [Hash] = [hash]
|
|
258
|
+
|
|
259
|
+
const response: UserOperationReceipt = await client.request({
|
|
260
|
+
method: "eth_getUserOperationReceipt",
|
|
261
|
+
params
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
if (!response) return null
|
|
265
|
+
|
|
266
|
+
const userOperationReceipt: UserOperationReceipt = {
|
|
267
|
+
userOpHash: response.userOpHash,
|
|
268
|
+
sender: response.sender,
|
|
269
|
+
nonce: BigInt(response.nonce),
|
|
270
|
+
actualGasUsed: BigInt(response.actualGasUsed),
|
|
271
|
+
actualGasCost: BigInt(response.actualGasCost),
|
|
272
|
+
success: response.success,
|
|
273
|
+
receipt: {
|
|
274
|
+
transactionHash: response.receipt.transactionHash,
|
|
275
|
+
transactionIndex: BigInt(response.receipt.transactionIndex),
|
|
276
|
+
blockHash: response.receipt.blockHash,
|
|
277
|
+
blockNumber: BigInt(response.receipt.blockNumber),
|
|
278
|
+
from: response.receipt.from,
|
|
279
|
+
to: response.receipt.to,
|
|
280
|
+
cumulativeGasUsed: BigInt(response.receipt.cumulativeGasUsed),
|
|
281
|
+
status: response.receipt.status ? BigInt(response.receipt.status) : null,
|
|
282
|
+
gasUsed: BigInt(response.receipt.gasUsed),
|
|
283
|
+
contractAddress: response.receipt.contractAddress,
|
|
284
|
+
logsBloom: response.receipt.logsBloom,
|
|
285
|
+
effectiveGasPrice: BigInt(response.receipt.effectiveGasPrice)
|
|
286
|
+
},
|
|
287
|
+
logs: response.logs.map((log) => ({
|
|
288
|
+
data: log.data,
|
|
289
|
+
blockNumber: BigInt(log.blockNumber),
|
|
290
|
+
blockHash: log.blockHash,
|
|
291
|
+
transactionHash: log.transactionHash,
|
|
292
|
+
logIndex: BigInt(log.logIndex),
|
|
293
|
+
transactionIndex: BigInt(log.transactionIndex),
|
|
294
|
+
address: log.address,
|
|
295
|
+
topics: log.topics
|
|
296
|
+
}))
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return userOperationReceipt
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const bundlerActions = (client: Client) => ({
|
|
303
|
+
/**
|
|
304
|
+
*
|
|
305
|
+
* Sends user operation to the bundler
|
|
306
|
+
*
|
|
307
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/sendUserOperation
|
|
308
|
+
*
|
|
309
|
+
* @param args {@link SendUserOperationParameters}.
|
|
310
|
+
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* import { createClient } from "viem"
|
|
314
|
+
* import { bundlerActions } from "permissionless"
|
|
315
|
+
*
|
|
316
|
+
* const bundlerClient = createClient({
|
|
317
|
+
* chain: goerli,
|
|
318
|
+
* transport: http(BUNDLER_URL)
|
|
319
|
+
* }).extend(bundlerActions)
|
|
320
|
+
*
|
|
321
|
+
* const userOpHash = await bundlerClient.sendUserOperation({
|
|
322
|
+
* userOperation: signedUserOperation,
|
|
323
|
+
* entryPoint: entryPoint
|
|
324
|
+
* })
|
|
325
|
+
*
|
|
326
|
+
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
|
|
327
|
+
*/
|
|
328
|
+
sendUserOperation: async (args: SendUserOperationParameters): Promise<Hash> =>
|
|
329
|
+
sendUserOperation(client as BundlerClient, args),
|
|
330
|
+
/**
|
|
331
|
+
*
|
|
332
|
+
* Estimates preVerificationGas, verificationGasLimit and callGasLimit for user operation
|
|
333
|
+
*
|
|
334
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/estimateUserOperationGas
|
|
335
|
+
*
|
|
336
|
+
* @param args {@link EstimateUserOperationGasParameters}
|
|
337
|
+
* @returns preVerificationGas, verificationGasLimit and callGasLimit as {@link EstimateUserOperationGasReturnType}
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* import { createClient } from "viem"
|
|
341
|
+
* import { bundlerActions } from "permissionless"
|
|
342
|
+
*
|
|
343
|
+
* const bundlerClient = createClient({
|
|
344
|
+
* chain: goerli,
|
|
345
|
+
* transport: http(BUNDLER_URL)
|
|
346
|
+
* }).extend(bundlerActions)
|
|
347
|
+
*
|
|
348
|
+
* const gasParameters = await bundlerClient.estimateUserOperationGas({
|
|
349
|
+
* userOperation: signedUserOperation,
|
|
350
|
+
* entryPoint: entryPoint
|
|
351
|
+
* })
|
|
352
|
+
*
|
|
353
|
+
* // Return {preVerificationGas: 43492n, verificationGasLimit: 59436n, callGasLimit: 9000n}
|
|
354
|
+
*/
|
|
355
|
+
estimateUserOperationGas: (args: EstimateUserOperationGasParameters) =>
|
|
356
|
+
estimateUserOperationGas(client as BundlerClient, args),
|
|
357
|
+
/**
|
|
358
|
+
*
|
|
359
|
+
* Returns the supported entrypoints by the bundler service
|
|
360
|
+
*
|
|
361
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/supportedEntryPoints
|
|
362
|
+
*
|
|
363
|
+
* @returns Supported entryPoints
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* import { createClient } from "viem"
|
|
367
|
+
* import { bundlerActions } from "permissionless"
|
|
368
|
+
*
|
|
369
|
+
* const bundlerClient = createClient({
|
|
370
|
+
* chain: goerli,
|
|
371
|
+
* transport: http(BUNDLER_URL)
|
|
372
|
+
* }).extend(bundlerActions)
|
|
373
|
+
*
|
|
374
|
+
* const supportedEntryPoints = await bundlerClient.supportedEntryPoints()
|
|
375
|
+
*
|
|
376
|
+
* // Return ['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']
|
|
377
|
+
*/
|
|
378
|
+
supportedEntryPoints: (): Promise<Address[]> => supportedEntryPoints(client as BundlerClient),
|
|
379
|
+
/**
|
|
380
|
+
*
|
|
381
|
+
* Returns the supported chain id by the bundler service
|
|
382
|
+
*
|
|
383
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/chainId
|
|
384
|
+
*
|
|
385
|
+
* @returns Supported chain id
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* import { createClient } from "viem"
|
|
389
|
+
* import { bundlerActions } from "permissionless"
|
|
390
|
+
*
|
|
391
|
+
* const bundlerClient = createClient({
|
|
392
|
+
* chain: goerli,
|
|
393
|
+
* transport: http(BUNDLER_URL)
|
|
394
|
+
* }).extend(bundlerActions)
|
|
395
|
+
*
|
|
396
|
+
* const chainId = await bundlerClient.chainId()
|
|
397
|
+
* // Return 5n for Goerli
|
|
398
|
+
*/
|
|
399
|
+
chainId: () => chainId(client as BundlerClient),
|
|
400
|
+
/**
|
|
401
|
+
*
|
|
402
|
+
* Returns the user operation from userOpHash
|
|
403
|
+
*
|
|
404
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationByHash
|
|
405
|
+
*
|
|
406
|
+
* @param args {@link GetUserOperationByHash} UserOpHash that was returned by {@link sendUserOperation}
|
|
407
|
+
* @returns userOperation along with entryPoint, transactionHash, blockHash, blockNumber if found or null
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* import { createClient } from "viem"
|
|
411
|
+
* import { bundlerActions } from "permissionless"
|
|
412
|
+
*
|
|
413
|
+
* const bundlerClient = createClient({
|
|
414
|
+
* chain: goerli,
|
|
415
|
+
* transport: http(BUNDLER_URL)
|
|
416
|
+
* }).extend(bundlerActions)
|
|
417
|
+
*
|
|
418
|
+
* await bundlerClient.getUserOperationByHash(userOpHash)
|
|
419
|
+
*
|
|
420
|
+
*/
|
|
421
|
+
getUserOperationByHash: (args: GetUserOperationByHash) => getUserOperationByHash(client as BundlerClient, args),
|
|
422
|
+
/**
|
|
423
|
+
*
|
|
424
|
+
* Returns the user operation receipt from userOpHash
|
|
425
|
+
*
|
|
426
|
+
* - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt
|
|
427
|
+
*
|
|
428
|
+
* @param args {@link GetUserOperationReceipt} UserOpHash that was returned by {@link sendUserOperation}
|
|
429
|
+
* @returns user operation receipt {@link UserOperationReceipt} if found or null
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* import { createClient } from "viem"
|
|
433
|
+
* import { bundlerActions } from "permissionless"
|
|
434
|
+
*
|
|
435
|
+
* const bundlerClient = createClient({
|
|
436
|
+
* chain: goerli,
|
|
437
|
+
* transport: http(BUNDLER_URL)
|
|
438
|
+
* }).extend(bundlerActions)
|
|
439
|
+
*
|
|
440
|
+
* await bundlerClient.getUserOperationReceipt({hash: userOpHash})
|
|
441
|
+
*
|
|
442
|
+
*/
|
|
443
|
+
getUserOperationReceipt: (args: GetUserOperationReceipt) => getUserOperationReceipt(client as BundlerClient, args)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
export default bundlerActions
|
package/actions/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import bundlerActions, {
|
|
2
|
+
type EstimateUserOperationGasParameters,
|
|
3
|
+
type EstimateUserOperationGasReturnType,
|
|
4
|
+
type SendUserOperationParameters,
|
|
5
|
+
chainId,
|
|
6
|
+
estimateUserOperationGas,
|
|
7
|
+
getUserOperationByHash,
|
|
8
|
+
sendUserOperation,
|
|
9
|
+
supportedEntryPoints
|
|
10
|
+
} from "./bundler"
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
bundlerActions,
|
|
14
|
+
type SendUserOperationParameters,
|
|
15
|
+
type EstimateUserOperationGasParameters,
|
|
16
|
+
type EstimateUserOperationGasReturnType,
|
|
17
|
+
sendUserOperation,
|
|
18
|
+
estimateUserOperationGas,
|
|
19
|
+
supportedEntryPoints,
|
|
20
|
+
chainId,
|
|
21
|
+
getUserOperationByHash
|
|
22
|
+
}
|
package/actions/utils.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { toHex } from "viem"
|
|
2
|
+
|
|
3
|
+
// biome-ignore lint/suspicious/noExplicitAny: it's a recursive function, so it's hard to type
|
|
4
|
+
export function deepHexlify(obj: any): any {
|
|
5
|
+
if (typeof obj === "function") {
|
|
6
|
+
return undefined
|
|
7
|
+
}
|
|
8
|
+
if (obj == null || typeof obj === "string" || typeof obj === "boolean") {
|
|
9
|
+
return obj
|
|
10
|
+
} else if (typeof obj === "bigint") {
|
|
11
|
+
return toHex(obj)
|
|
12
|
+
} else if (obj._isBigNumber != null || typeof obj !== "object") {
|
|
13
|
+
return toHex(obj).replace(/^0x0/, "0x")
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(obj)) {
|
|
16
|
+
return obj.map((member) => deepHexlify(member))
|
|
17
|
+
}
|
|
18
|
+
return Object.keys(obj).reduce(
|
|
19
|
+
(set, key) => ({
|
|
20
|
+
...set,
|
|
21
|
+
[key]: deepHexlify(obj[key])
|
|
22
|
+
}),
|
|
23
|
+
{}
|
|
24
|
+
)
|
|
25
|
+
}
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "permissionless",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"author": "Pimlico",
|
|
5
|
+
"main": "./_cjs/index.js",
|
|
6
|
+
"module": "./_esm/index.js",
|
|
7
|
+
"types": "./_types/index.d.ts",
|
|
8
|
+
"typings": "./_types/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"description": "A utility library for working with ERC-4337",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ethereum",
|
|
14
|
+
"erc-4337",
|
|
15
|
+
"eip-4337",
|
|
16
|
+
"paymaster",
|
|
17
|
+
"bundler"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./_types/index.d.ts",
|
|
23
|
+
"import": "./_esm/index.js",
|
|
24
|
+
"default": "./_cjs/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./actions": {
|
|
27
|
+
"types": "./_types/actions/index.d.ts",
|
|
28
|
+
"import": "./_esm/actions/index.js",
|
|
29
|
+
"default": "./_cjs/actions/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"viem": "^1.12.2"
|
|
34
|
+
}
|
|
35
|
+
}
|