@pimlico/mock-paymaster 0.0.3 → 0.0.5

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/relay.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as util from "node:util"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import {
4
+ http,
4
5
  type Account,
5
6
  type Address,
6
7
  BaseError,
@@ -15,6 +16,7 @@ import {
15
16
  import {
16
17
  type BundlerClient,
17
18
  type UserOperation,
19
+ createBundlerClient,
18
20
  entryPoint06Address,
19
21
  entryPoint07Address,
20
22
  entryPoint08Address
@@ -40,6 +42,8 @@ import {
40
42
  } from "./helpers/schema.js"
41
43
  import {
42
44
  type PaymasterMode,
45
+ getChain,
46
+ getPublicClient,
43
47
  isTokenSupported,
44
48
  maxBigInt
45
49
  } from "./helpers/utils.js"
@@ -158,9 +162,9 @@ const handleMethod = async ({
158
162
  parsedBody,
159
163
  paymasterSigner,
160
164
  publicClient,
161
- bundler
165
+ bundlerClient
162
166
  }: {
163
- bundler: BundlerClient
167
+ bundlerClient: BundlerClient
164
168
  paymasterSigner: WalletClient<Transport, Chain, Account>
165
169
  publicClient: PublicClient
166
170
  parsedBody: JsonRpcSchema
@@ -196,7 +200,7 @@ const handleMethod = async ({
196
200
  entryPoint,
197
201
  userOperation,
198
202
  paymasterMode: { mode: "verifying" },
199
- bundler,
203
+ bundler: bundlerClient,
200
204
  paymaster: epToPaymaster[entryPoint],
201
205
  publicClient,
202
206
  paymasterSigner,
@@ -284,7 +288,7 @@ const handleMethod = async ({
284
288
  }
285
289
 
286
290
  if (parsedBody.method === "pimlico_getUserOperationGasPrice") {
287
- return await bundler.request({
291
+ return await bundlerClient.request({
288
292
  // @ts-ignore
289
293
  method: "pimlico_getUserOperationGasPrice",
290
294
  // @ts-ignore
@@ -340,15 +344,21 @@ const handleMethod = async ({
340
344
  }
341
345
 
342
346
  export const createRpcHandler = ({
343
- bundler,
344
- publicClient,
347
+ altoRpc,
348
+ anvilRpc,
345
349
  paymasterSigner
346
350
  }: {
347
- bundler: BundlerClient
348
- publicClient: PublicClient
351
+ altoRpc: string
352
+ anvilRpc: string
349
353
  paymasterSigner: WalletClient<Transport, Chain, Account>
350
354
  }) => {
351
355
  return async (request: FastifyRequest, _reply: FastifyReply) => {
356
+ const publicClient = await getPublicClient(anvilRpc)
357
+ const bundlerClient = createBundlerClient({
358
+ chain: await getChain(anvilRpc),
359
+ transport: http(altoRpc)
360
+ })
361
+
352
362
  const body = request.body
353
363
  const parsedBody = jsonRpcSchema.safeParse(body)
354
364
  if (!parsedBody.success) {
@@ -360,7 +370,7 @@ export const createRpcHandler = ({
360
370
 
361
371
  try {
362
372
  const result = await handleMethod({
363
- bundler,
373
+ bundlerClient,
364
374
  paymasterSigner,
365
375
  parsedBody: parsedBody.data,
366
376
  publicClient
@@ -30,7 +30,8 @@ import {
30
30
  singletonPaymaster07Abi,
31
31
  singletonPaymaster08Abi
32
32
  } from "./helpers/abi.js"
33
- import type { PaymasterMode } from "./helpers/utils.js"
33
+ import { getPaymasterUtilityWallet } from "./helpers/erc20-utils.js"
34
+ import { type PaymasterMode, getPublicClient } from "./helpers/utils.js"
34
35
 
35
36
  export const getDummyPaymasterData = ({
36
37
  is06,
@@ -240,13 +241,14 @@ export const getSignedPaymasterData = async ({
240
241
  }
241
242
 
242
243
  export const deployPaymasters = async ({
243
- walletClient,
244
- publicClient
244
+ anvilRpc,
245
+ paymasterSigner
245
246
  }: {
246
- walletClient: WalletClient<Transport, Chain, Account>
247
- publicClient: PublicClient<Transport, Chain>
247
+ anvilRpc: string
248
+ paymasterSigner: Address
248
249
  }) => {
249
- const owner = walletClient.account.address
250
+ const walletClient = await getPaymasterUtilityWallet(anvilRpc)
251
+ const publicClient = await getPublicClient(anvilRpc)
250
252
 
251
253
  let nonce = await publicClient.getTransactionCount({
252
254
  address: walletClient.account.address
@@ -257,7 +259,7 @@ export const deployPaymasters = async ({
257
259
  to: constants.deterministicDeployer,
258
260
  data: concat([
259
261
  constants.create2Salt,
260
- getSingletonPaymaster06InitCode(walletClient.account.address)
262
+ getSingletonPaymaster06InitCode(paymasterSigner)
261
263
  ]),
262
264
  nonce: nonce++
263
265
  })
@@ -267,7 +269,7 @@ export const deployPaymasters = async ({
267
269
  to: constants.deterministicDeployer,
268
270
  data: concat([
269
271
  constants.create2Salt,
270
- getSingletonPaymaster07InitCode(walletClient.account.address)
272
+ getSingletonPaymaster07InitCode(paymasterSigner)
271
273
  ]),
272
274
  nonce: nonce++
273
275
  })
@@ -277,7 +279,7 @@ export const deployPaymasters = async ({
277
279
  to: constants.deterministicDeployer,
278
280
  data: concat([
279
281
  constants.create2Salt,
280
- getSingletonPaymaster08InitCode(walletClient.account.address)
282
+ getSingletonPaymaster08InitCode(paymasterSigner)
281
283
  ]),
282
284
  nonce: nonce++
283
285
  })
@@ -285,17 +287,17 @@ export const deployPaymasters = async ({
285
287
  // Initialize contract instances.
286
288
  const [singletonPaymaster06, singletonPaymaster07, singletonPaymaster08] = [
287
289
  getContract({
288
- address: getSingletonPaymaster06Address(owner),
290
+ address: getSingletonPaymaster06Address(paymasterSigner),
289
291
  abi: singletonPaymaster06Abi,
290
292
  client: walletClient
291
293
  }),
292
294
  getContract({
293
- address: getSingletonPaymaster07Address(owner),
295
+ address: getSingletonPaymaster07Address(paymasterSigner),
294
296
  abi: singletonPaymaster07Abi,
295
297
  client: walletClient
296
298
  }),
297
299
  getContract({
298
- address: getSingletonPaymaster08Address(owner),
300
+ address: getSingletonPaymaster08Address(paymasterSigner),
299
301
  abi: singletonPaymaster08Abi,
300
302
  client: walletClient
301
303
  })