permissionless 0.0.2 → 0.0.3
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 +10 -0
- package/_cjs/actions/bundler.js +4 -3
- package/_cjs/actions/bundler.js.map +1 -1
- package/_cjs/actions/index.js +2 -1
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/pimlico.js +55 -0
- package/_cjs/actions/pimlico.js.map +1 -0
- package/_cjs/actions/utils.js +5 -1
- package/_cjs/actions/utils.js.map +1 -1
- package/_cjs/clients/bundler.js +17 -0
- package/_cjs/clients/bundler.js.map +1 -0
- package/_cjs/clients/index.js +6 -0
- package/_cjs/clients/index.js.map +1 -0
- package/_cjs/clients/pimlico.js +29 -0
- package/_cjs/clients/pimlico.js.map +1 -0
- package/_cjs/index.js +1 -0
- package/_cjs/index.js.map +1 -1
- package/_cjs/types/pimlico.js +3 -0
- package/_cjs/types/pimlico.js.map +1 -0
- package/_esm/actions/bundler.js +12 -145
- package/_esm/actions/bundler.js.map +1 -1
- package/_esm/actions/index.js +2 -2
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/pimlico.js +127 -0
- package/_esm/actions/pimlico.js.map +1 -0
- package/_esm/actions/utils.js +4 -0
- package/_esm/actions/utils.js.map +1 -1
- package/_esm/clients/bundler.js +33 -0
- package/_esm/clients/bundler.js.map +1 -0
- package/_esm/clients/index.js +3 -0
- package/_esm/clients/index.js.map +1 -0
- package/_esm/clients/pimlico.js +64 -0
- package/_esm/clients/pimlico.js.map +1 -0
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/types/pimlico.js +2 -0
- package/_esm/types/pimlico.js.map +1 -0
- package/_types/actions/bundler.d.ts +113 -24
- package/_types/actions/bundler.d.ts.map +1 -1
- package/_types/actions/index.d.ts +4 -2
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/pimlico.d.ts +184 -0
- package/_types/actions/pimlico.d.ts.map +1 -0
- package/_types/actions/utils.d.ts +4 -0
- package/_types/actions/utils.d.ts.map +1 -1
- package/_types/clients/bundler.d.ts +39 -0
- package/_types/clients/bundler.d.ts.map +1 -0
- package/_types/clients/index.d.ts +3 -0
- package/_types/clients/index.d.ts.map +1 -0
- package/_types/clients/pimlico.d.ts +75 -0
- package/_types/clients/pimlico.d.ts.map +1 -0
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/types/bundler.d.ts +4 -37
- package/_types/types/bundler.d.ts.map +1 -1
- package/_types/types/index.d.ts +1 -2
- package/_types/types/index.d.ts.map +1 -1
- package/_types/types/pimlico.d.ts +50 -0
- package/_types/types/pimlico.d.ts.map +1 -0
- package/_types/types/userOperation.d.ts +1 -0
- package/_types/types/userOperation.d.ts.map +1 -1
- package/actions/bundler.ts +85 -33
- package/actions/index.ts +23 -7
- package/actions/pimlico.ts +258 -0
- package/actions/utils.ts +5 -0
- package/clients/bundler.ts +39 -0
- package/clients/index.ts +3 -0
- package/clients/pimlico.ts +93 -0
- package/index.ts +1 -0
- package/package.json +18 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/bundler.ts +4 -39
- package/types/index.ts +1 -2
- package/types/pimlico.ts +55 -0
- package/types/userOperation.ts +2 -0
package/actions/bundler.ts
CHANGED
|
@@ -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 {
|
|
5
|
-
import type {
|
|
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
|
|
25
|
+
export type GetUserOperationByHashParameters = {
|
|
26
26
|
hash: Hash
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export type
|
|
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 {
|
|
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 {
|
|
166
|
+
* import { supportedEntryPoints } from "permissionless/actions"
|
|
126
167
|
*
|
|
127
168
|
* const bundlerClient = createClient({
|
|
128
169
|
* chain: goerli,
|
|
@@ -151,14 +192,14 @@ export const supportedEntryPoints = async (client: BundlerClient): Promise<Addre
|
|
|
151
192
|
*
|
|
152
193
|
* @example
|
|
153
194
|
* import { createClient } from "viem"
|
|
154
|
-
* import {
|
|
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
|
|
202
|
+
* const bundlerChainId = chainId(bundlerClient)
|
|
162
203
|
* // Return 5n for Goerli
|
|
163
204
|
*
|
|
164
205
|
*/
|
|
@@ -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
|
|
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 {
|
|
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 }:
|
|
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
|
|
241
|
-
* @returns user operation receipt {@link
|
|
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 {
|
|
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 }:
|
|
297
|
+
export const getUserOperationReceipt = async (client: BundlerClient, { hash }: GetUserOperationReceiptParameters) => {
|
|
257
298
|
const params: [Hash] = [hash]
|
|
258
299
|
|
|
259
|
-
const response
|
|
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:
|
|
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
|
|
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
|
-
|
|
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(
|
|
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:
|
|
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: ()
|
|
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: () =>
|
|
438
|
+
chainId: () => Promise<bigint>
|
|
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:
|
|
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
|
|
429
|
-
* @returns user operation receipt {@link
|
|
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:
|
|
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
498
|
export default bundlerActions
|
package/actions/index.ts
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EstimateUserOperationGasParameters,
|
|
3
|
+
EstimateUserOperationGasReturnType,
|
|
4
|
+
GetUserOperationByHashParameters,
|
|
5
|
+
GetUserOperationByHashReturnType,
|
|
6
|
+
GetUserOperationReceiptParameters,
|
|
7
|
+
GetUserOperationReceiptReturnType,
|
|
8
|
+
SendUserOperationParameters
|
|
9
|
+
} from "./bundler"
|
|
10
|
+
|
|
1
11
|
import bundlerActions, {
|
|
2
|
-
type EstimateUserOperationGasParameters,
|
|
3
|
-
type EstimateUserOperationGasReturnType,
|
|
4
|
-
type SendUserOperationParameters,
|
|
5
12
|
chainId,
|
|
6
13
|
estimateUserOperationGas,
|
|
7
14
|
getUserOperationByHash,
|
|
15
|
+
getUserOperationReceipt,
|
|
8
16
|
sendUserOperation,
|
|
9
17
|
supportedEntryPoints
|
|
10
18
|
} from "./bundler"
|
|
11
19
|
|
|
20
|
+
export type {
|
|
21
|
+
SendUserOperationParameters,
|
|
22
|
+
EstimateUserOperationGasParameters,
|
|
23
|
+
EstimateUserOperationGasReturnType,
|
|
24
|
+
GetUserOperationByHashParameters,
|
|
25
|
+
GetUserOperationByHashReturnType,
|
|
26
|
+
GetUserOperationReceiptParameters,
|
|
27
|
+
GetUserOperationReceiptReturnType
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
export {
|
|
13
31
|
bundlerActions,
|
|
14
|
-
type SendUserOperationParameters,
|
|
15
|
-
type EstimateUserOperationGasParameters,
|
|
16
|
-
type EstimateUserOperationGasReturnType,
|
|
17
32
|
sendUserOperation,
|
|
18
33
|
estimateUserOperationGas,
|
|
19
34
|
supportedEntryPoints,
|
|
20
35
|
chainId,
|
|
21
|
-
getUserOperationByHash
|
|
36
|
+
getUserOperationByHash,
|
|
37
|
+
getUserOperationReceipt
|
|
22
38
|
}
|
|
@@ -0,0 +1,258 @@
|
|
|
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: [TODO://add link]
|
|
48
|
+
* - Example: [TODO://add link]
|
|
49
|
+
*
|
|
50
|
+
* @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
|
|
51
|
+
* @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* import { createClient } from "viem"
|
|
56
|
+
* import { getUserOperationGasPrice } from "permissionless/actions"
|
|
57
|
+
*
|
|
58
|
+
* const bundlerClient = createClient({
|
|
59
|
+
* chain: goerli,
|
|
60
|
+
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* await getUserOperationGasPrice(bundlerClient)
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
export const getUserOperationGasPrice = async (
|
|
67
|
+
client: PimlicoBundlerClient
|
|
68
|
+
): Promise<GetUserOperationGasPriceReturnType> => {
|
|
69
|
+
const gasPrices = await client.request({
|
|
70
|
+
method: "pimlico_getUserOperationGasPrice",
|
|
71
|
+
params: []
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
slow: {
|
|
76
|
+
maxFeePerGas: BigInt(gasPrices.slow.maxFeePerGas),
|
|
77
|
+
maxPriorityFeePerGas: BigInt(gasPrices.slow.maxPriorityFeePerGas)
|
|
78
|
+
},
|
|
79
|
+
standard: {
|
|
80
|
+
maxFeePerGas: BigInt(gasPrices.standard.maxFeePerGas),
|
|
81
|
+
maxPriorityFeePerGas: BigInt(gasPrices.standard.maxPriorityFeePerGas)
|
|
82
|
+
},
|
|
83
|
+
fast: {
|
|
84
|
+
maxFeePerGas: BigInt(gasPrices.fast.maxFeePerGas),
|
|
85
|
+
maxPriorityFeePerGas: BigInt(gasPrices.fast.maxPriorityFeePerGas)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns the status of the userOperation that is pending in the mempool.
|
|
92
|
+
*
|
|
93
|
+
* - Docs: [TODO://add link]
|
|
94
|
+
* - Example: [TODO://add link]
|
|
95
|
+
*
|
|
96
|
+
* @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
|
|
97
|
+
* @param hash {@link Hash} UserOpHash that you must have received from sendUserOperation.
|
|
98
|
+
* @returns status & transaction hash if included {@link GetUserOperationStatusReturnType}
|
|
99
|
+
*
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* import { createClient } from "viem"
|
|
103
|
+
* import { getUserOperationStatus } from "permissionless/actions"
|
|
104
|
+
*
|
|
105
|
+
* const bundlerClient = createClient({
|
|
106
|
+
* chain: goerli,
|
|
107
|
+
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
108
|
+
* })
|
|
109
|
+
*
|
|
110
|
+
* await getUserOperationStatus(bundlerClient, { hash: userOpHash })
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
export const getUserOperationStatus = async (
|
|
114
|
+
client: PimlicoBundlerClient,
|
|
115
|
+
{ hash }: GetUserOperationStatusParameters
|
|
116
|
+
): Promise<GetUserOperationStatusReturnType> => {
|
|
117
|
+
return client.request({
|
|
118
|
+
method: "pimlico_getUserOperationStatus",
|
|
119
|
+
params: [hash]
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type PimlicoBundlerActions = {
|
|
124
|
+
/**
|
|
125
|
+
* Returns the live gas prices that you can use to send a user operation.
|
|
126
|
+
*
|
|
127
|
+
* - Docs: [TODO://add link]
|
|
128
|
+
* - Example: [TODO://add link]
|
|
129
|
+
*
|
|
130
|
+
* @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas {@link GetUserOperationGasPriceReturnType}
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* import { createClient } from "viem"
|
|
135
|
+
* import { pimlicoBundlerActions } from "permissionless/actions"
|
|
136
|
+
*
|
|
137
|
+
* const bundlerClient = createClient({
|
|
138
|
+
* chain: goerli,
|
|
139
|
+
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
140
|
+
* }).extend(pimlicoBundlerActions)
|
|
141
|
+
*
|
|
142
|
+
* await bundlerClient.getUserOperationGasPrice()
|
|
143
|
+
*/
|
|
144
|
+
getUserOperationGasPrice: () => Promise<GetUserOperationGasPriceReturnType>
|
|
145
|
+
/**
|
|
146
|
+
* Returns the status of the userOperation that is pending in the mempool.
|
|
147
|
+
*
|
|
148
|
+
* - Docs: [TODO://add link]
|
|
149
|
+
* - Example: [TODO://add link]
|
|
150
|
+
*
|
|
151
|
+
* @param hash {@link Hash} UserOpHash that you must have received from sendUserOperation.
|
|
152
|
+
* @returns status & transaction hash if included {@link GetUserOperationStatusReturnType}
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* import { createClient } from "viem"
|
|
156
|
+
* import { pimlicoBundlerActions } from "permissionless/actions"
|
|
157
|
+
*
|
|
158
|
+
* const bundlerClient = createClient({
|
|
159
|
+
* chain: goerli,
|
|
160
|
+
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
161
|
+
* }).extend(pimlicoBundlerActions)
|
|
162
|
+
*
|
|
163
|
+
* await bundlerClient.getUserOperationStatus({ hash: userOpHash })
|
|
164
|
+
*/
|
|
165
|
+
getUserOperationStatus: (args: GetUserOperationStatusParameters) => Promise<GetUserOperationStatusReturnType>
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const pimlicoBundlerActions = (client: Client): PimlicoBundlerActions => ({
|
|
169
|
+
getUserOperationGasPrice: async () => getUserOperationGasPrice(client as PimlicoBundlerClient),
|
|
170
|
+
getUserOperationStatus: async (args: GetUserOperationStatusParameters) =>
|
|
171
|
+
getUserOperationStatus(client as PimlicoBundlerClient, args)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
|
|
176
|
+
*
|
|
177
|
+
* - Docs: [TODO://add link]
|
|
178
|
+
* - Example: [TODO://add link]
|
|
179
|
+
*
|
|
180
|
+
* @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
|
|
181
|
+
* @param args {@link sponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
|
|
182
|
+
* @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
|
|
183
|
+
*
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* import { createClient } from "viem"
|
|
187
|
+
* import { sponsorUserOperation } from "permissionless/actions"
|
|
188
|
+
*
|
|
189
|
+
* const bundlerClient = createClient({
|
|
190
|
+
* chain: goerli,
|
|
191
|
+
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
192
|
+
* })
|
|
193
|
+
*
|
|
194
|
+
* await sponsorUserOperation(bundlerClient, {
|
|
195
|
+
* userOperation: userOperationWithDummySignature,
|
|
196
|
+
* entryPoint: entryPoint
|
|
197
|
+
* }})
|
|
198
|
+
*
|
|
199
|
+
*/
|
|
200
|
+
export const sponsorUserOperation = async (
|
|
201
|
+
client: PimlicoPaymasterClient,
|
|
202
|
+
args: SponsorUserOperationParameters
|
|
203
|
+
): Promise<SponsorUserOperationReturnType> => {
|
|
204
|
+
const response = await client.request({
|
|
205
|
+
method: "pm_sponsorUserOperation",
|
|
206
|
+
params: [deepHexlify(args.userOperation) as UserOperationWithBigIntAsHex, args.entryPoint]
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
paymasterAndData: response.paymasterAndData,
|
|
211
|
+
preVerificationGas: BigInt(response.preVerificationGas),
|
|
212
|
+
verificationGasLimit: BigInt(response.verificationGasLimit),
|
|
213
|
+
callGasLimit: BigInt(response.callGasLimit)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type PimlicoPaymasterClientActions = {
|
|
218
|
+
/**
|
|
219
|
+
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
|
|
220
|
+
*
|
|
221
|
+
* - Docs: [TODO://add link]
|
|
222
|
+
* - Example: [TODO://add link]
|
|
223
|
+
*
|
|
224
|
+
* @param args {@link SponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
|
|
225
|
+
* @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* import { createClient } from "viem"
|
|
229
|
+
* import { sponsorUserOperation } from "permissionless/actions"
|
|
230
|
+
*
|
|
231
|
+
* const bundlerClient = createClient({
|
|
232
|
+
* chain: goerli,
|
|
233
|
+
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
234
|
+
* }).extend(pimlicoPaymasterActions)
|
|
235
|
+
*
|
|
236
|
+
* await bundlerClient.sponsorUserOperation(bundlerClient, {
|
|
237
|
+
* userOperation: userOperationWithDummySignature,
|
|
238
|
+
* entryPoint: entryPoint
|
|
239
|
+
* }})
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
242
|
+
sponsorUserOperation: (args: SponsorUserOperationParameters) => Promise<SponsorUserOperationReturnType>
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const pimlicoPaymasterActions = (client: Client): PimlicoPaymasterClientActions => ({
|
|
246
|
+
sponsorUserOperation: async (args: SponsorUserOperationParameters) =>
|
|
247
|
+
sponsorUserOperation(client as PimlicoPaymasterClient, args)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* TODO: Add support for pimlicoActions after we support all the actions of v1 in v2 of the Pimlico API.
|
|
252
|
+
*/
|
|
253
|
+
// export const pimlicoActions = (client: Client) => {
|
|
254
|
+
// return {
|
|
255
|
+
// ...pimlicoBundlerActions(client),
|
|
256
|
+
// ...pimlicoPaymasterActions(client)
|
|
257
|
+
// }
|
|
258
|
+
// }
|
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,39 @@
|
|
|
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: [TODO://add link]
|
|
12
|
+
* - Example: [TODO://add link]
|
|
13
|
+
*
|
|
14
|
+
* 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](TODO://Add bundler action documentation link).
|
|
15
|
+
*
|
|
16
|
+
* @param config - {@link PublicClientConfig}
|
|
17
|
+
* @returns A Bundler Client. {@link BundlerClient}
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { createPublicClient, http } from 'viem'
|
|
21
|
+
* import { mainnet } from 'viem/chains'
|
|
22
|
+
*
|
|
23
|
+
* const bundlerClient = createBundlerClient({
|
|
24
|
+
* chain: mainnet,
|
|
25
|
+
* transport: http(BUNDLER_URL),
|
|
26
|
+
* })
|
|
27
|
+
*/
|
|
28
|
+
export const createBundlerClient = <transport extends Transport, chain extends Chain | undefined = undefined>(
|
|
29
|
+
parameters: PublicClientConfig<transport, chain>
|
|
30
|
+
): BundlerClient => {
|
|
31
|
+
const { key = "public", name = "Bundler Client" } = parameters
|
|
32
|
+
const client = createClient({
|
|
33
|
+
...parameters,
|
|
34
|
+
key,
|
|
35
|
+
name,
|
|
36
|
+
type: "bundlerClient"
|
|
37
|
+
})
|
|
38
|
+
return client.extend(bundlerActions)
|
|
39
|
+
}
|
package/clients/index.ts
ADDED