permissionless 0.0.2 → 0.0.4

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 (82) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/_cjs/actions/bundler.js +6 -5
  3. package/_cjs/actions/bundler.js.map +1 -1
  4. package/_cjs/actions/index.js +3 -2
  5. package/_cjs/actions/index.js.map +1 -1
  6. package/_cjs/actions/pimlico.js +55 -0
  7. package/_cjs/actions/pimlico.js.map +1 -0
  8. package/_cjs/actions/utils.js +5 -1
  9. package/_cjs/actions/utils.js.map +1 -1
  10. package/_cjs/clients/bundler.js +17 -0
  11. package/_cjs/clients/bundler.js.map +1 -0
  12. package/_cjs/clients/index.js +6 -0
  13. package/_cjs/clients/index.js.map +1 -0
  14. package/_cjs/clients/pimlico.js +29 -0
  15. package/_cjs/clients/pimlico.js.map +1 -0
  16. package/_cjs/index.js +2 -0
  17. package/_cjs/index.js.map +1 -1
  18. package/_cjs/types/pimlico.js +3 -0
  19. package/_cjs/types/pimlico.js.map +1 -0
  20. package/_cjs/utils/index.js +38 -0
  21. package/_cjs/utils/index.js.map +1 -0
  22. package/_esm/actions/bundler.js +14 -147
  23. package/_esm/actions/bundler.js.map +1 -1
  24. package/_esm/actions/index.js +2 -2
  25. package/_esm/actions/index.js.map +1 -1
  26. package/_esm/actions/pimlico.js +124 -0
  27. package/_esm/actions/pimlico.js.map +1 -0
  28. package/_esm/actions/utils.js +4 -0
  29. package/_esm/actions/utils.js.map +1 -1
  30. package/_esm/clients/bundler.js +32 -0
  31. package/_esm/clients/bundler.js.map +1 -0
  32. package/_esm/clients/index.js +3 -0
  33. package/_esm/clients/index.js.map +1 -0
  34. package/_esm/clients/pimlico.js +62 -0
  35. package/_esm/clients/pimlico.js.map +1 -0
  36. package/_esm/index.js +2 -0
  37. package/_esm/index.js.map +1 -1
  38. package/_esm/types/pimlico.js +2 -0
  39. package/_esm/types/pimlico.js.map +1 -0
  40. package/_esm/utils/index.js +56 -0
  41. package/_esm/utils/index.js.map +1 -0
  42. package/_types/actions/bundler.d.ts +116 -27
  43. package/_types/actions/bundler.d.ts.map +1 -1
  44. package/_types/actions/index.d.ts +4 -2
  45. package/_types/actions/index.d.ts.map +1 -1
  46. package/_types/actions/pimlico.d.ts +178 -0
  47. package/_types/actions/pimlico.d.ts.map +1 -0
  48. package/_types/actions/utils.d.ts +4 -0
  49. package/_types/actions/utils.d.ts.map +1 -1
  50. package/_types/clients/bundler.d.ts +38 -0
  51. package/_types/clients/bundler.d.ts.map +1 -0
  52. package/_types/clients/index.d.ts +3 -0
  53. package/_types/clients/index.d.ts.map +1 -0
  54. package/_types/clients/pimlico.d.ts +73 -0
  55. package/_types/clients/pimlico.d.ts.map +1 -0
  56. package/_types/index.d.ts +2 -0
  57. package/_types/index.d.ts.map +1 -1
  58. package/_types/types/bundler.d.ts +4 -37
  59. package/_types/types/bundler.d.ts.map +1 -1
  60. package/_types/types/index.d.ts +1 -2
  61. package/_types/types/index.d.ts.map +1 -1
  62. package/_types/types/pimlico.d.ts +50 -0
  63. package/_types/types/pimlico.d.ts.map +1 -0
  64. package/_types/types/userOperation.d.ts +1 -0
  65. package/_types/types/userOperation.d.ts.map +1 -1
  66. package/_types/utils/index.d.ts +31 -0
  67. package/_types/utils/index.d.ts.map +1 -0
  68. package/actions/bundler.ts +87 -35
  69. package/actions/index.ts +25 -8
  70. package/actions/pimlico.ts +252 -0
  71. package/actions/utils.ts +5 -0
  72. package/clients/bundler.ts +38 -0
  73. package/clients/index.ts +3 -0
  74. package/clients/pimlico.ts +91 -0
  75. package/index.ts +2 -0
  76. package/package.json +23 -3
  77. package/tsconfig.build.tsbuildinfo +1 -1
  78. package/types/bundler.ts +4 -39
  79. package/types/index.ts +1 -2
  80. package/types/pimlico.ts +55 -0
  81. package/types/userOperation.ts +2 -0
  82. package/utils/index.ts +70 -0
@@ -1,10 +1,10 @@
1
1
  import type { Address } from "abitype"
2
- import type { Client, Hash } from "viem"
2
+ import type { Client, Hash, Hex } from "viem"
3
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"
4
+ import type { BundlerClient } from "../clients/bundler"
5
+ import type { UserOperation } from "../types"
6
+ import type { TStatus, UserOperationWithBigIntAsHex } from "../types/userOperation"
7
+ import { deepHexlify, transactionReceiptStatus } from "./utils"
8
8
 
9
9
  export type SendUserOperationParameters = {
10
10
  userOperation: UserOperation
@@ -22,14 +22,55 @@ export type EstimateUserOperationGasReturnType = {
22
22
  callGasLimit: bigint
23
23
  }
24
24
 
25
- export type GetUserOperationByHash = {
25
+ export type GetUserOperationByHashParameters = {
26
26
  hash: Hash
27
27
  }
28
28
 
29
- export type GetUserOperationReceipt = {
29
+ export type GetUserOperationByHashReturnType = {
30
+ userOperation: UserOperation
31
+ entryPoint: Address
32
+ transactionHash: Hash
33
+ blockHash: Hash
34
+ blockNumber: bigint
35
+ } | null
36
+
37
+ export type GetUserOperationReceiptParameters = {
30
38
  hash: Hash
31
39
  }
32
40
 
41
+ export type GetUserOperationReceiptReturnType = {
42
+ userOpHash: Hash
43
+ sender: Address
44
+ nonce: bigint
45
+ actualGasUsed: bigint
46
+ actualGasCost: bigint
47
+ success: boolean
48
+ receipt: {
49
+ transactionHash: Hex
50
+ transactionIndex: bigint
51
+ blockHash: Hash
52
+ blockNumber: bigint
53
+ from: Address
54
+ to: Address | null
55
+ cumulativeGasUsed: bigint
56
+ status: TStatus
57
+ gasUsed: bigint
58
+ contractAddress: Address | null
59
+ logsBloom: Hex
60
+ effectiveGasPrice: bigint
61
+ }
62
+ logs: {
63
+ data: Hex
64
+ blockNumber: bigint
65
+ blockHash: Hash
66
+ transactionHash: Hash
67
+ logIndex: bigint
68
+ transactionIndex: bigint
69
+ address: Address
70
+ topics: Hex[]
71
+ }[]
72
+ } | null
73
+
33
74
  /**
34
75
  * Sends user operation to the bundler
35
76
  *
@@ -78,7 +119,7 @@ export const sendUserOperation = async (client: BundlerClient, args: SendUserOpe
78
119
  *
79
120
  * @example
80
121
  * import { createClient } from "viem"
81
- * import { sendUserOperation } from "permissionless/actions"
122
+ * import { estimateUserOperationGas } from "permissionless/actions"
82
123
  *
83
124
  * const bundlerClient = createClient({
84
125
  * chain: goerli,
@@ -122,7 +163,7 @@ export const estimateUserOperationGas = async (
122
163
  *
123
164
  * @example
124
165
  * import { createClient } from "viem"
125
- * import { sendUserOperation } from "permissionless/actions"
166
+ * import { supportedEntryPoints } from "permissionless/actions"
126
167
  *
127
168
  * const bundlerClient = createClient({
128
169
  * chain: goerli,
@@ -151,19 +192,19 @@ export const supportedEntryPoints = async (client: BundlerClient): Promise<Addre
151
192
  *
152
193
  * @example
153
194
  * import { createClient } from "viem"
154
- * import { sendUserOperation } from "permissionless/actions"
195
+ * import { chainId } from "permissionless/actions"
155
196
  *
156
197
  * const bundlerClient = createClient({
157
198
  * chain: goerli,
158
199
  * transport: http(BUNDLER_URL)
159
200
  * })
160
201
  *
161
- * const chainId = chainId(bundlerClient)
202
+ * const bundlerChainId = chainId(bundlerClient)
162
203
  * // Return 5n for Goerli
163
204
  *
164
205
  */
165
206
  export const chainId = async (client: BundlerClient) => {
166
- return BigInt(
207
+ return Number(
167
208
  await client.request({
168
209
  method: "eth_chainId",
169
210
  params: []
@@ -177,13 +218,13 @@ export const chainId = async (client: BundlerClient) => {
177
218
  * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationByHash
178
219
  *
179
220
  * @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}
221
+ * @param args {@link GetUserOperationByHashParameters} UserOpHash that was returned by {@link sendUserOperation}
181
222
  * @returns userOperation along with entryPoint, transactionHash, blockHash, blockNumber if found or null
182
223
  *
183
224
  *
184
225
  * @example
185
226
  * import { createClient } from "viem"
186
- * import { sendUserOperation } from "permissionless/actions"
227
+ * import { getUserOperationByHash } from "permissionless/actions"
187
228
  *
188
229
  * const bundlerClient = createClient({
189
230
  * chain: goerli,
@@ -195,7 +236,7 @@ export const chainId = async (client: BundlerClient) => {
195
236
  */
196
237
  export const getUserOperationByHash = async (
197
238
  client: BundlerClient,
198
- { hash }: GetUserOperationByHash
239
+ { hash }: GetUserOperationByHashParameters
199
240
  ): Promise<{
200
241
  userOperation: UserOperation
201
242
  entryPoint: Address
@@ -237,13 +278,13 @@ export const getUserOperationByHash = async (
237
278
  * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt
238
279
  *
239
280
  * @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
281
+ * @param args {@link GetUserOperationReceiptParameters} UserOpHash that was returned by {@link sendUserOperation}
282
+ * @returns user operation receipt {@link GetUserOperationReceiptReturnType} if found or null
242
283
  *
243
284
  *
244
285
  * @example
245
286
  * import { createClient } from "viem"
246
- * import { sendUserOperation } from "permissionless/actions"
287
+ * import { getUserOperationReceipt } from "permissionless/actions"
247
288
  *
248
289
  * const bundlerClient = createClient({
249
290
  * chain: goerli,
@@ -253,17 +294,17 @@ export const getUserOperationByHash = async (
253
294
  * getUserOperationReceipt(bundlerClient, {hash: userOpHash})
254
295
  *
255
296
  */
256
- const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserOperationReceipt) => {
297
+ export const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserOperationReceiptParameters) => {
257
298
  const params: [Hash] = [hash]
258
299
 
259
- const response: UserOperationReceipt = await client.request({
300
+ const response = await client.request({
260
301
  method: "eth_getUserOperationReceipt",
261
302
  params
262
303
  })
263
304
 
264
305
  if (!response) return null
265
306
 
266
- const userOperationReceipt: UserOperationReceipt = {
307
+ const userOperationReceipt: GetUserOperationReceiptReturnType = {
267
308
  userOpHash: response.userOpHash,
268
309
  sender: response.sender,
269
310
  nonce: BigInt(response.nonce),
@@ -278,7 +319,7 @@ const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserO
278
319
  from: response.receipt.from,
279
320
  to: response.receipt.to,
280
321
  cumulativeGasUsed: BigInt(response.receipt.cumulativeGasUsed),
281
- status: response.receipt.status ? BigInt(response.receipt.status) : null,
322
+ status: transactionReceiptStatus[response.receipt.status],
282
323
  gasUsed: BigInt(response.receipt.gasUsed),
283
324
  contractAddress: response.receipt.contractAddress,
284
325
  logsBloom: response.receipt.logsBloom,
@@ -299,7 +340,7 @@ const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserO
299
340
  return userOperationReceipt
300
341
  }
301
342
 
302
- const bundlerActions = (client: Client) => ({
343
+ export type BundlerActions = {
303
344
  /**
304
345
  *
305
346
  * Sends user operation to the bundler
@@ -315,7 +356,7 @@ const bundlerActions = (client: Client) => ({
315
356
  *
316
357
  * const bundlerClient = createClient({
317
358
  * chain: goerli,
318
- * transport: http(BUNDLER_URL)
359
+ * transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
319
360
  * }).extend(bundlerActions)
320
361
  *
321
362
  * const userOpHash = await bundlerClient.sendUserOperation({
@@ -325,8 +366,7 @@ const bundlerActions = (client: Client) => ({
325
366
  *
326
367
  * // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
327
368
  */
328
- sendUserOperation: async (args: SendUserOperationParameters): Promise<Hash> =>
329
- sendUserOperation(client as BundlerClient, args),
369
+ sendUserOperation: (args: SendUserOperationParameters) => Promise<Hash>
330
370
  /**
331
371
  *
332
372
  * Estimates preVerificationGas, verificationGasLimit and callGasLimit for user operation
@@ -352,8 +392,7 @@ const bundlerActions = (client: Client) => ({
352
392
  *
353
393
  * // Return {preVerificationGas: 43492n, verificationGasLimit: 59436n, callGasLimit: 9000n}
354
394
  */
355
- estimateUserOperationGas: (args: EstimateUserOperationGasParameters) =>
356
- estimateUserOperationGas(client as BundlerClient, args),
395
+ estimateUserOperationGas: (args: EstimateUserOperationGasParameters) => Promise<EstimateUserOperationGasReturnType>
357
396
  /**
358
397
  *
359
398
  * Returns the supported entrypoints by the bundler service
@@ -375,7 +414,7 @@ const bundlerActions = (client: Client) => ({
375
414
  *
376
415
  * // Return ['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']
377
416
  */
378
- supportedEntryPoints: (): Promise<Address[]> => supportedEntryPoints(client as BundlerClient),
417
+ supportedEntryPoints: () => Promise<Address[]>
379
418
  /**
380
419
  *
381
420
  * Returns the supported chain id by the bundler service
@@ -396,7 +435,7 @@ const bundlerActions = (client: Client) => ({
396
435
  * const chainId = await bundlerClient.chainId()
397
436
  * // Return 5n for Goerli
398
437
  */
399
- chainId: () => chainId(client as BundlerClient),
438
+ chainId: () => Promise<number>
400
439
  /**
401
440
  *
402
441
  * Returns the user operation from userOpHash
@@ -418,15 +457,15 @@ const bundlerActions = (client: Client) => ({
418
457
  * await bundlerClient.getUserOperationByHash(userOpHash)
419
458
  *
420
459
  */
421
- getUserOperationByHash: (args: GetUserOperationByHash) => getUserOperationByHash(client as BundlerClient, args),
460
+ getUserOperationByHash: (args: GetUserOperationByHashParameters) => Promise<GetUserOperationByHashReturnType>
422
461
  /**
423
462
  *
424
463
  * Returns the user operation receipt from userOpHash
425
464
  *
426
465
  * - Docs: https://docs.pimlico.io/permissionless/reference/bundler-actions/getUserOperationReceipt
427
466
  *
428
- * @param args {@link GetUserOperationReceipt} UserOpHash that was returned by {@link sendUserOperation}
429
- * @returns user operation receipt {@link UserOperationReceipt} if found or null
467
+ * @param args {@link GetUserOperationReceiptParameters} UserOpHash that was returned by {@link sendUserOperation}
468
+ * @returns user operation receipt {@link GetUserOperationReceiptReturnType} if found or null
430
469
  *
431
470
  * @example
432
471
  * import { createClient } from "viem"
@@ -440,7 +479,20 @@ const bundlerActions = (client: Client) => ({
440
479
  * await bundlerClient.getUserOperationReceipt({hash: userOpHash})
441
480
  *
442
481
  */
443
- getUserOperationReceipt: (args: GetUserOperationReceipt) => getUserOperationReceipt(client as BundlerClient, args)
482
+ getUserOperationReceipt: (args: GetUserOperationReceiptParameters) => Promise<GetUserOperationReceiptReturnType>
483
+ }
484
+
485
+ const bundlerActions = (client: Client): BundlerActions => ({
486
+ sendUserOperation: async (args: SendUserOperationParameters): Promise<Hash> =>
487
+ sendUserOperation(client as BundlerClient, args),
488
+ estimateUserOperationGas: (args: EstimateUserOperationGasParameters) =>
489
+ estimateUserOperationGas(client as BundlerClient, args),
490
+ supportedEntryPoints: (): Promise<Address[]> => supportedEntryPoints(client as BundlerClient),
491
+ chainId: () => chainId(client as BundlerClient),
492
+ getUserOperationByHash: (args: GetUserOperationByHashParameters) =>
493
+ getUserOperationByHash(client as BundlerClient, args),
494
+ getUserOperationReceipt: (args: GetUserOperationReceiptParameters) =>
495
+ getUserOperationReceipt(client as BundlerClient, args)
444
496
  })
445
497
 
446
- export default bundlerActions
498
+ export { bundlerActions }
package/actions/index.ts CHANGED
@@ -1,22 +1,39 @@
1
- import bundlerActions, {
2
- type EstimateUserOperationGasParameters,
3
- type EstimateUserOperationGasReturnType,
4
- type SendUserOperationParameters,
1
+ import type {
2
+ EstimateUserOperationGasParameters,
3
+ EstimateUserOperationGasReturnType,
4
+ GetUserOperationByHashParameters,
5
+ GetUserOperationByHashReturnType,
6
+ GetUserOperationReceiptParameters,
7
+ GetUserOperationReceiptReturnType,
8
+ SendUserOperationParameters
9
+ } from "./bundler"
10
+
11
+ import {
12
+ bundlerActions,
5
13
  chainId,
6
14
  estimateUserOperationGas,
7
15
  getUserOperationByHash,
16
+ getUserOperationReceipt,
8
17
  sendUserOperation,
9
18
  supportedEntryPoints
10
19
  } from "./bundler"
11
20
 
21
+ export type {
22
+ SendUserOperationParameters,
23
+ EstimateUserOperationGasParameters,
24
+ EstimateUserOperationGasReturnType,
25
+ GetUserOperationByHashParameters,
26
+ GetUserOperationByHashReturnType,
27
+ GetUserOperationReceiptParameters,
28
+ GetUserOperationReceiptReturnType
29
+ }
30
+
12
31
  export {
13
32
  bundlerActions,
14
- type SendUserOperationParameters,
15
- type EstimateUserOperationGasParameters,
16
- type EstimateUserOperationGasReturnType,
17
33
  sendUserOperation,
18
34
  estimateUserOperationGas,
19
35
  supportedEntryPoints,
20
36
  chainId,
21
- getUserOperationByHash
37
+ getUserOperationByHash,
38
+ getUserOperationReceipt
22
39
  }
@@ -0,0 +1,252 @@
1
+ import type { Address, Client, Hash, Hex } from "viem"
2
+ import type { PartialBy } from "viem/types/utils"
3
+ import type { PimlicoBundlerClient, PimlicoPaymasterClient } from "../clients/pimlico"
4
+ import type { PimlicoUserOperationStatus } from "../types/pimlico"
5
+ import type { UserOperation, UserOperationWithBigIntAsHex } from "../types/userOperation"
6
+ import { deepHexlify } from "./utils"
7
+
8
+ export type SponsorUserOperationParameters = {
9
+ userOperation: PartialBy<
10
+ UserOperation,
11
+ "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "paymasterAndData"
12
+ >
13
+ entryPoint: Address
14
+ }
15
+
16
+ export type SponsorUserOperationReturnType = {
17
+ paymasterAndData: Hex
18
+ preVerificationGas: bigint
19
+ verificationGasLimit: bigint
20
+ callGasLimit: bigint
21
+ }
22
+
23
+ export type GetUserOperationGasPriceReturnType = {
24
+ slow: {
25
+ maxFeePerGas: bigint
26
+ maxPriorityFeePerGas: bigint
27
+ }
28
+ standard: {
29
+ maxFeePerGas: bigint
30
+ maxPriorityFeePerGas: bigint
31
+ }
32
+ fast: {
33
+ maxFeePerGas: bigint
34
+ maxPriorityFeePerGas: bigint
35
+ }
36
+ }
37
+
38
+ export type GetUserOperationStatusParameters = {
39
+ hash: Hash
40
+ }
41
+
42
+ export type GetUserOperationStatusReturnType = PimlicoUserOperationStatus
43
+
44
+ /**
45
+ * Returns the live gas prices that you can use to send a user operation.
46
+ *
47
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationGasPrice
48
+ *
49
+ * @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
50
+ * @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas
51
+ *
52
+ *
53
+ * @example
54
+ * import { createClient } from "viem"
55
+ * import { getUserOperationGasPrice } from "permissionless/actions"
56
+ *
57
+ * const bundlerClient = createClient({
58
+ * chain: goerli,
59
+ * transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
60
+ * })
61
+ *
62
+ * await getUserOperationGasPrice(bundlerClient)
63
+ *
64
+ */
65
+ export const getUserOperationGasPrice = async (
66
+ client: PimlicoBundlerClient
67
+ ): Promise<GetUserOperationGasPriceReturnType> => {
68
+ const gasPrices = await client.request({
69
+ method: "pimlico_getUserOperationGasPrice",
70
+ params: []
71
+ })
72
+
73
+ return {
74
+ slow: {
75
+ maxFeePerGas: BigInt(gasPrices.slow.maxFeePerGas),
76
+ maxPriorityFeePerGas: BigInt(gasPrices.slow.maxPriorityFeePerGas)
77
+ },
78
+ standard: {
79
+ maxFeePerGas: BigInt(gasPrices.standard.maxFeePerGas),
80
+ maxPriorityFeePerGas: BigInt(gasPrices.standard.maxPriorityFeePerGas)
81
+ },
82
+ fast: {
83
+ maxFeePerGas: BigInt(gasPrices.fast.maxFeePerGas),
84
+ maxPriorityFeePerGas: BigInt(gasPrices.fast.maxPriorityFeePerGas)
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Returns the status of the userOperation that is pending in the mempool.
91
+ *
92
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationStatus
93
+ *
94
+ * @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
95
+ * @param hash {@link Hash} UserOpHash that you must have received from sendUserOperation.
96
+ * @returns status & transaction hash if included {@link GetUserOperationStatusReturnType}
97
+ *
98
+ *
99
+ * @example
100
+ * import { createClient } from "viem"
101
+ * import { getUserOperationStatus } from "permissionless/actions"
102
+ *
103
+ * const bundlerClient = createClient({
104
+ * chain: goerli,
105
+ * transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
106
+ * })
107
+ *
108
+ * await getUserOperationStatus(bundlerClient, { hash: userOpHash })
109
+ *
110
+ */
111
+ export const getUserOperationStatus = async (
112
+ client: PimlicoBundlerClient,
113
+ { hash }: GetUserOperationStatusParameters
114
+ ): Promise<GetUserOperationStatusReturnType> => {
115
+ return client.request({
116
+ method: "pimlico_getUserOperationStatus",
117
+ params: [hash]
118
+ })
119
+ }
120
+
121
+ export type PimlicoBundlerActions = {
122
+ /**
123
+ * Returns the live gas prices that you can use to send a user operation.
124
+ *
125
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationGasPrice
126
+ *
127
+ * @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas {@link GetUserOperationGasPriceReturnType}
128
+ *
129
+ * @example
130
+ *
131
+ * import { createClient } from "viem"
132
+ * import { pimlicoBundlerActions } from "permissionless/actions"
133
+ *
134
+ * const bundlerClient = createClient({
135
+ * chain: goerli,
136
+ * transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
137
+ * }).extend(pimlicoBundlerActions)
138
+ *
139
+ * await bundlerClient.getUserOperationGasPrice()
140
+ */
141
+ getUserOperationGasPrice: () => Promise<GetUserOperationGasPriceReturnType>
142
+ /**
143
+ * Returns the status of the userOperation that is pending in the mempool.
144
+ *
145
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationStatus
146
+ *
147
+ * @param hash {@link Hash} UserOpHash that you must have received from sendUserOperation.
148
+ * @returns status & transaction hash if included {@link GetUserOperationStatusReturnType}
149
+ *
150
+ * @example
151
+ * import { createClient } from "viem"
152
+ * import { pimlicoBundlerActions } from "permissionless/actions"
153
+ *
154
+ * const bundlerClient = createClient({
155
+ * chain: goerli,
156
+ * transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
157
+ * }).extend(pimlicoBundlerActions)
158
+ *
159
+ * await bundlerClient.getUserOperationStatus({ hash: userOpHash })
160
+ */
161
+ getUserOperationStatus: (args: GetUserOperationStatusParameters) => Promise<GetUserOperationStatusReturnType>
162
+ }
163
+
164
+ export const pimlicoBundlerActions = (client: Client): PimlicoBundlerActions => ({
165
+ getUserOperationGasPrice: async () => getUserOperationGasPrice(client as PimlicoBundlerClient),
166
+ getUserOperationStatus: async (args: GetUserOperationStatusParameters) =>
167
+ getUserOperationStatus(client as PimlicoBundlerClient, args)
168
+ })
169
+
170
+ /**
171
+ * Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
172
+ *
173
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-paymaster-actions/sponsorUserOperation
174
+ *
175
+ * @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
176
+ * @param args {@link sponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
177
+ * @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
178
+ *
179
+ *
180
+ * @example
181
+ * import { createClient } from "viem"
182
+ * import { sponsorUserOperation } from "permissionless/actions"
183
+ *
184
+ * const bundlerClient = createClient({
185
+ * chain: goerli,
186
+ * transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
187
+ * })
188
+ *
189
+ * await sponsorUserOperation(bundlerClient, {
190
+ * userOperation: userOperationWithDummySignature,
191
+ * entryPoint: entryPoint
192
+ * }})
193
+ *
194
+ */
195
+ export const sponsorUserOperation = async (
196
+ client: PimlicoPaymasterClient,
197
+ args: SponsorUserOperationParameters
198
+ ): Promise<SponsorUserOperationReturnType> => {
199
+ const response = await client.request({
200
+ method: "pm_sponsorUserOperation",
201
+ params: [deepHexlify(args.userOperation) as UserOperationWithBigIntAsHex, args.entryPoint]
202
+ })
203
+
204
+ return {
205
+ paymasterAndData: response.paymasterAndData,
206
+ preVerificationGas: BigInt(response.preVerificationGas),
207
+ verificationGasLimit: BigInt(response.verificationGasLimit),
208
+ callGasLimit: BigInt(response.callGasLimit)
209
+ }
210
+ }
211
+
212
+ export type PimlicoPaymasterClientActions = {
213
+ /**
214
+ * Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
215
+ *
216
+ * https://docs.pimlico.io/permissionless/reference/pimlico-paymaster-actions/sponsorUserOperation
217
+ *
218
+ * @param args {@link SponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
219
+ * @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
220
+ *
221
+ * @example
222
+ * import { createClient } from "viem"
223
+ * import { sponsorUserOperation } from "permissionless/actions"
224
+ *
225
+ * const bundlerClient = createClient({
226
+ * chain: goerli,
227
+ * transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
228
+ * }).extend(pimlicoPaymasterActions)
229
+ *
230
+ * await bundlerClient.sponsorUserOperation(bundlerClient, {
231
+ * userOperation: userOperationWithDummySignature,
232
+ * entryPoint: entryPoint
233
+ * }})
234
+ *
235
+ */
236
+ sponsorUserOperation: (args: SponsorUserOperationParameters) => Promise<SponsorUserOperationReturnType>
237
+ }
238
+
239
+ export const pimlicoPaymasterActions = (client: Client): PimlicoPaymasterClientActions => ({
240
+ sponsorUserOperation: async (args: SponsorUserOperationParameters) =>
241
+ sponsorUserOperation(client as PimlicoPaymasterClient, args)
242
+ })
243
+
244
+ /**
245
+ * TODO: Add support for pimlicoActions after we support all the actions of v1 in v2 of the Pimlico API.
246
+ */
247
+ // export const pimlicoActions = (client: Client) => {
248
+ // return {
249
+ // ...pimlicoBundlerActions(client),
250
+ // ...pimlicoPaymasterActions(client)
251
+ // }
252
+ // }
package/actions/utils.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { toHex } from "viem"
2
2
 
3
+ export const transactionReceiptStatus = {
4
+ "0x0": "reverted",
5
+ "0x1": "success"
6
+ } as const
7
+
3
8
  // biome-ignore lint/suspicious/noExplicitAny: it's a recursive function, so it's hard to type
4
9
  export function deepHexlify(obj: any): any {
5
10
  if (typeof obj === "function") {
@@ -0,0 +1,38 @@
1
+ import type { Account, Chain, Client, PublicClientConfig, Transport } from "viem"
2
+ import { createClient } from "viem"
3
+ import { bundlerActions } from "../actions"
4
+ import type { BundlerActions } from "../actions/bundler"
5
+ import type { BundlerRpcSchema } from "../types/bundler"
6
+
7
+ export type BundlerClient = Client<Transport, Chain | undefined, Account | undefined, BundlerRpcSchema, BundlerActions>
8
+ /**
9
+ * Creates a EIP-4337 compliant Bundler Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html).
10
+ *
11
+ * - Docs: https://docs.pimlico.io/permissionless/reference/clients/bundlerClient
12
+ *
13
+ * A Bundler Client is an interface to "erc 4337" [JSON-RPC API](https://eips.ethereum.org/EIPS/eip-4337#rpc-methods-eth-namespace) methods such as sending user operation, estimating gas for a user operation, get user operation receipt, etc through Bundler Actions.
14
+ *
15
+ * @param config - {@link PublicClientConfig}
16
+ * @returns A Bundler Client. {@link BundlerClient}
17
+ *
18
+ * @example
19
+ * import { createPublicClient, http } from 'viem'
20
+ * import { mainnet } from 'viem/chains'
21
+ *
22
+ * const bundlerClient = createBundlerClient({
23
+ * chain: mainnet,
24
+ * transport: http(BUNDLER_URL),
25
+ * })
26
+ */
27
+ export const createBundlerClient = <transport extends Transport, chain extends Chain | undefined = undefined>(
28
+ parameters: PublicClientConfig<transport, chain>
29
+ ): BundlerClient => {
30
+ const { key = "public", name = "Bundler Client" } = parameters
31
+ const client = createClient({
32
+ ...parameters,
33
+ key,
34
+ name,
35
+ type: "bundlerClient"
36
+ })
37
+ return client.extend(bundlerActions)
38
+ }
@@ -0,0 +1,3 @@
1
+ import { type BundlerClient, createBundlerClient } from "./bundler"
2
+
3
+ export { createBundlerClient, type BundlerClient }