@account-kit/infra 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (47) hide show
  1. package/dist/cjs/client/decorators/alchemyEnhancedApis.d.ts +1132 -1276
  2. package/dist/cjs/client/internal/smartAccountClientFromRpc.js +2 -14
  3. package/dist/cjs/client/internal/smartAccountClientFromRpc.js.map +1 -1
  4. package/dist/cjs/client/isAlchemySmartAccountClient.d.ts +1132 -1276
  5. package/dist/cjs/client/smartAccountClient.d.ts +2 -3
  6. package/dist/cjs/client/smartAccountClient.js +2 -2
  7. package/dist/cjs/client/smartAccountClient.js.map +1 -1
  8. package/dist/cjs/client/types.d.ts +1 -48
  9. package/dist/cjs/client/types.js.map +1 -1
  10. package/dist/cjs/middleware/gasManager.d.ts +2 -29
  11. package/dist/cjs/middleware/gasManager.js +4 -146
  12. package/dist/cjs/middleware/gasManager.js.map +1 -1
  13. package/dist/cjs/version.d.ts +1 -1
  14. package/dist/cjs/version.js +1 -1
  15. package/dist/cjs/version.js.map +1 -1
  16. package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +1132 -1276
  17. package/dist/esm/client/internal/smartAccountClientFromRpc.js +2 -14
  18. package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +1 -1
  19. package/dist/esm/client/isAlchemySmartAccountClient.d.ts +1132 -1276
  20. package/dist/esm/client/smartAccountClient.d.ts +2 -3
  21. package/dist/esm/client/smartAccountClient.js +2 -3
  22. package/dist/esm/client/smartAccountClient.js.map +1 -1
  23. package/dist/esm/client/types.d.ts +1 -48
  24. package/dist/esm/client/types.js.map +1 -1
  25. package/dist/esm/middleware/gasManager.d.ts +2 -29
  26. package/dist/esm/middleware/gasManager.js +5 -147
  27. package/dist/esm/middleware/gasManager.js.map +1 -1
  28. package/dist/esm/version.d.ts +1 -1
  29. package/dist/esm/version.js +1 -1
  30. package/dist/esm/version.js.map +1 -1
  31. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +1132 -1276
  32. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -1
  33. package/dist/types/client/isAlchemySmartAccountClient.d.ts +1132 -1276
  34. package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -1
  35. package/dist/types/client/smartAccountClient.d.ts +2 -3
  36. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  37. package/dist/types/client/types.d.ts +1 -48
  38. package/dist/types/client/types.d.ts.map +1 -1
  39. package/dist/types/middleware/gasManager.d.ts +15 -87
  40. package/dist/types/middleware/gasManager.d.ts.map +1 -1
  41. package/dist/types/version.d.ts +1 -1
  42. package/package.json +3 -3
  43. package/src/client/internal/smartAccountClientFromRpc.ts +2 -18
  44. package/src/client/smartAccountClient.ts +4 -5
  45. package/src/client/types.ts +1 -54
  46. package/src/middleware/gasManager.ts +20 -432
  47. package/src/version.ts +1 -1
@@ -1,441 +1,29 @@
1
- import type {
2
- Address,
3
- ClientMiddlewareConfig,
4
- ClientMiddlewareFn,
5
- EntryPointVersion,
6
- Multiplier,
7
- UserOperationFeeOptions,
8
- UserOperationOverrides,
9
- UserOperationRequest,
10
- } from "@aa-sdk/core";
11
- import {
12
- bypassPaymasterAndDataEmptyHex,
13
- deepHexlify,
14
- defaultGasEstimator,
15
- filterUndefined,
16
- isBigNumberish,
17
- isMultiplier,
18
- resolveProperties,
19
- } from "@aa-sdk/core";
20
- import { concat, fromHex, isHex, type Hex } from "viem";
21
- import type { ClientWithAlchemyMethods } from "../client/types";
22
- import { getAlchemyPaymasterAddress } from "../gas-manager.js";
23
- import { alchemyFeeEstimator } from "./feeEstimator.js";
1
+ import type { ClientMiddlewareConfig } from "@aa-sdk/core";
2
+ import { erc7677Middleware } from "@aa-sdk/core";
24
3
 
25
4
  /**
26
- * overrides value for [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
5
+ * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring transactions.
27
6
  *
28
- * @template {EntryPointVersion} TEntryPointVersion entry point version type
29
- */
30
- export type RequestGasAndPaymasterAndDataOverrides<
31
- TEntryPointVersion extends EntryPointVersion = EntryPointVersion
32
- > = Partial<
33
- {
34
- maxFeePerGas:
35
- | UserOperationRequest<TEntryPointVersion>["maxFeePerGas"]
36
- | Multiplier;
37
- maxPriorityFeePerGas:
38
- | UserOperationRequest<TEntryPointVersion>["maxPriorityFeePerGas"]
39
- | Multiplier;
40
- callGasLimit:
41
- | UserOperationRequest<TEntryPointVersion>["callGasLimit"]
42
- | Multiplier;
43
- verificationGasLimit:
44
- | UserOperationRequest<TEntryPointVersion>["verificationGasLimit"]
45
- | Multiplier;
46
- preVerificationGas:
47
- | UserOperationRequest<TEntryPointVersion>["preVerificationGas"]
48
- | Multiplier;
49
- } & TEntryPointVersion extends "0.7.0"
50
- ? {
51
- paymasterVerificationGasLimit:
52
- | UserOperationRequest<"0.7.0">["paymasterVerificationGasLimit"]
53
- | Multiplier;
54
- paymasterPostOpGasLimit:
55
- | UserOperationRequest<"0.7.0">["paymasterPostOpGasLimit"]
56
- | Multiplier;
57
- }
58
- : {}
59
- >;
60
-
61
- /**
62
- * [`alchemy-requestpaymasteranddata`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)
63
- * response type
64
- *
65
- * @template {EntryPointVersion} TEntryPointVersion entry point version type
66
- */
67
- export type RequestPaymasterAndDataResponse<
68
- TEntryPointVersion extends EntryPointVersion = EntryPointVersion
69
- > = TEntryPointVersion extends "0.6.0"
70
- ? {
71
- paymasterAndData: UserOperationRequest<"0.6.0">["paymasterAndData"];
72
- }
73
- : TEntryPointVersion extends "0.7.0"
74
- ? Pick<UserOperationRequest<"0.7.0">, "paymaster" | "paymasterData">
75
- : {};
76
-
77
- /**
78
- * [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
79
- * response type
80
- *
81
- * @template {EntryPointVersion} TEntryPointVersion entry point version type
82
- */
83
- export type RequestGasAndPaymasterAndDataResponse<
84
- TEntryPointVersion extends EntryPointVersion = EntryPointVersion
85
- > = Pick<
86
- UserOperationRequest,
87
- | "callGasLimit"
88
- | "preVerificationGas"
89
- | "verificationGasLimit"
90
- | "maxFeePerGas"
91
- | "maxPriorityFeePerGas"
92
- > &
93
- RequestPaymasterAndDataResponse<TEntryPointVersion>;
94
-
95
- /**
96
- * Alchemy gas manager configuration with gas policy id and optional gas estimation options
97
- *
98
- * To create a Gas Manager Policy, go to the [gas manager](https://dashboard.alchemy.com/gas-manager?a=embedded-accounts-get-started)
99
- * page of the Alchemy dashboard and click the “Create new policy” button.
100
- */
101
- export interface AlchemyGasManagerConfig {
102
- /**
103
- * the policy id of the gas manager you want to use.
104
- *
105
- */
106
- policyId: string;
107
- /**
108
- * optional option configurable for the gas estimation portion of the Alchemy gas manager
109
- *
110
- */
111
- gasEstimationOptions?: AlchemyGasEstimationOptions;
112
- /**
113
- * paymaster address to use for the gas estimation.
114
- * If not provided, the default paymaster address for the chain will be used.
115
- *
116
- */
117
- paymasterAddress?: Address;
118
- /**
119
- * dummy paymaster data to use for the gas estimation.
120
- *
121
- */
122
- dummyData?: Hex;
123
- }
124
-
125
- /**
126
- * Alchemy gas manager configuration option configurable for the gas estimation portion of the Alchemy gas manager
7
+ * @example
8
+ * ```ts
127
9
  *
128
- */
129
- export interface AlchemyGasEstimationOptions {
130
- /**
131
- * disable gas estimation and fallback to the default gas estimation.
132
- *
133
- */
134
- disableGasEstimation: boolean;
135
- /**
136
- * optional fallback gas estimator to use when gas estimation is disabled.
137
- *
138
- */
139
- fallbackGasEstimator?: ClientMiddlewareFn;
140
- /**
141
- * optional fallback fee estimator to use when gas estimation is disabled.
142
- *
143
- */
144
- fallbackFeeDataGetter?: ClientMiddlewareFn;
145
- }
146
-
147
- /**
148
- * Dummy paymaster and data middleware for the alchemy gas manager
10
+ * import { sepolia } from "@account-kit/infra";
11
+ * import { http } from "viem";
149
12
  *
150
- * NOTE: right now, this only really works for 0.6.0 unless you pass in overrides in the config for 0.7.0
13
+ * const client = createSmartAccountClient({
14
+ * http("rpc-url"),
15
+ * sepolia,
16
+ * alchemyErc7677Middleware("policyId")
17
+ * );
18
+ * ```
151
19
  *
152
- * @template {ClientWithAlchemyMethods} C
153
- * @param {ClientWithAlchemyMethods} client client with alchemy methods
154
- * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration
155
- * @returns {() => Hex} the dummyPaymasterAndData middleware for Alchemy gas manager
20
+ * @param {string} policyId the policyId for Alchemy's gas manager
21
+ * @returns {Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData">} partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`
156
22
  */
157
- const dummyPaymasterAndData =
158
- <C extends ClientWithAlchemyMethods>(
159
- client: C,
160
- config: AlchemyGasManagerConfig
161
- ): ClientMiddlewareFn =>
162
- async (uo) => {
163
- const paymaster =
164
- config.paymasterAddress ?? getAlchemyPaymasterAddress(client.chain);
165
- const paymasterData =
166
- config.dummyData ??
167
- "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
168
-
169
- return {
170
- ...uo,
171
- paymaster,
172
- paymasterData,
173
- paymasterAndData: concat([paymaster, paymasterData]),
174
- };
175
- };
176
-
177
- /**
178
- * Alchemy gas manager middleware used as the paymaster middleware overrides param to the client middleware config
179
- *
180
- * @template {ClientWithAlchemyMethods} C
181
- * @param {ClientWithAlchemyMethods} client client with alchemy methods
182
- * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration
183
- * @returns {Pick<ClientMiddlewareConfig,"paymasterAndData" | "feeEstimator" | "gasEstimator">} the gas estimator, fee estimator, and paymasterAndData middleware for Alchemy gas manager
184
- */
185
- export function alchemyGasManagerMiddleware<C extends ClientWithAlchemyMethods>(
186
- client: C,
187
- config: AlchemyGasManagerConfig
188
- ): Pick<
189
- ClientMiddlewareConfig,
190
- "paymasterAndData" | "feeEstimator" | "gasEstimator"
191
- > {
192
- const gasEstimationOptions = config.gasEstimationOptions;
193
- const disableGasEstimation =
194
- gasEstimationOptions?.disableGasEstimation ?? false;
195
- const fallbackFeeDataGetter =
196
- gasEstimationOptions?.fallbackFeeDataGetter ?? alchemyFeeEstimator(client);
197
- const fallbackGasEstimator =
198
- gasEstimationOptions?.fallbackGasEstimator ??
199
- defaultGasEstimator<C>(client);
200
-
201
- return {
202
- gasEstimator: disableGasEstimation
203
- ? fallbackGasEstimator
204
- : async (struct, { overrides, account, feeOptions }) => {
205
- // if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
206
- // we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
207
- if (bypassPaymasterAndDataEmptyHex(overrides)) {
208
- return {
209
- ...struct,
210
- ...(await fallbackGasEstimator(struct, {
211
- overrides,
212
- account,
213
- feeOptions,
214
- client,
215
- })),
216
- };
217
- }
218
-
219
- // essentially noop, because the gas estimation will happen in the backend
220
- return struct;
221
- },
222
- feeEstimator: disableGasEstimation
223
- ? fallbackFeeDataGetter
224
- : async (struct, { overrides, account, feeOptions }) => {
225
- let maxFeePerGas = await struct.maxFeePerGas;
226
- let maxPriorityFeePerGas = await struct.maxPriorityFeePerGas;
227
-
228
- // if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
229
- // we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
230
- if (bypassPaymasterAndDataEmptyHex(overrides)) {
231
- const result = await fallbackFeeDataGetter(struct, {
232
- overrides,
233
- feeOptions,
234
- account,
235
- client,
236
- });
237
- maxFeePerGas = (await result.maxFeePerGas) ?? maxFeePerGas;
238
- maxPriorityFeePerGas =
239
- (await result.maxPriorityFeePerGas) ?? maxPriorityFeePerGas;
240
- }
241
-
242
- return {
243
- ...struct,
244
- maxFeePerGas,
245
- maxPriorityFeePerGas,
246
- };
247
- },
248
- ...(disableGasEstimation
249
- ? requestPaymasterAndData(client, config)
250
- : requestGasAndPaymasterData(client, config)),
251
- };
252
- }
253
-
254
- /**
255
- * Utility function to override a field in the user operation request with the overrides or fee options
256
- *
257
- * @template {EntryPointVersion} TEntryPointVersion
258
- * @param {keyof UserOperationFeeOptions<TEntryPointVersion>} field the field to override
259
- * @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the overrides object
260
- * @param {UserOperationFeeOptions<TEntryPointVersion> | undefined} feeOptions the fee options object from the client
261
- * @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request
262
- * @returns {Hex | Multiplier | undefine} the overridden field value
263
- */
264
- const overrideField = <
265
- TEntryPointVersion extends EntryPointVersion = EntryPointVersion
266
- >(
267
- field: keyof UserOperationFeeOptions<TEntryPointVersion>,
268
- overrides: UserOperationOverrides<TEntryPointVersion> | undefined,
269
- feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,
270
- userOperation: UserOperationRequest<TEntryPointVersion>
271
- ): Hex | Multiplier | undefined => {
272
- let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;
273
-
274
- if (overrides?.[_field] != null) {
275
- // one-off absolute override
276
- if (isBigNumberish(overrides[_field])) {
277
- return deepHexlify(overrides[_field]);
278
- }
279
- // one-off multiplier overrides
280
- else {
281
- return {
282
- multiplier: Number((overrides[_field] as Multiplier).multiplier),
283
- };
284
- }
285
- }
286
-
287
- // provider level fee options with multiplier
288
- if (isMultiplier(feeOptions?.[field])) {
289
- return {
290
- multiplier: Number((feeOptions![field] as Multiplier).multiplier),
291
- };
292
- }
293
-
294
- const userOpField =
295
- userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];
296
- if (isHex(userOpField) && fromHex(userOpField as Hex, "bigint") > 0n) {
297
- return userOpField;
298
- }
299
- return undefined;
300
- };
301
-
302
- /**
303
- * Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config
304
- * that calls the [`alchemy_requestGasAndPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
305
- *
306
- * @template {ClientWithAlchemyMethods} C
307
- * @param {ClientWithAlchemyMethods} client client with alchemy methods
308
- * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration
309
- * @returns {ClientMiddlewareConfig["paymasterAndData"]} the paymasterAndData middleware for Alchemy gas manager
310
- */
311
- function requestGasAndPaymasterData<C extends ClientWithAlchemyMethods>(
312
- client: C,
313
- config: AlchemyGasManagerConfig
23
+ export function alchemyGasManagerMiddleware(
24
+ policyId: string
314
25
  ): Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData"> {
315
- return {
316
- dummyPaymasterAndData: dummyPaymasterAndData(client, config),
317
- paymasterAndData: async (
318
- struct,
319
- { overrides: overrides_, feeOptions, account }
320
- ) => {
321
- const userOperation: UserOperationRequest = deepHexlify(
322
- await resolveProperties(struct)
323
- );
324
-
325
- const overrides: RequestGasAndPaymasterAndDataOverrides = filterUndefined(
326
- {
327
- maxFeePerGas: overrideField(
328
- "maxFeePerGas",
329
- overrides_ as UserOperationOverrides,
330
- feeOptions,
331
- userOperation
332
- ),
333
- maxPriorityFeePerGas: overrideField(
334
- "maxPriorityFeePerGas",
335
- overrides_ as UserOperationOverrides,
336
- feeOptions,
337
- userOperation
338
- ),
339
- callGasLimit: overrideField(
340
- "callGasLimit",
341
- overrides_ as UserOperationOverrides,
342
- feeOptions,
343
- userOperation
344
- ),
345
- verificationGasLimit: overrideField(
346
- "verificationGasLimit",
347
- overrides_ as UserOperationOverrides,
348
- feeOptions,
349
- userOperation
350
- ),
351
- preVerificationGas: overrideField(
352
- "preVerificationGas",
353
- overrides_ as UserOperationOverrides,
354
- feeOptions,
355
- userOperation
356
- ),
357
- }
358
- );
359
-
360
- if (account.getEntryPoint().version === "0.7.0") {
361
- const paymasterVerificationGasLimit = overrideField<"0.7.0">(
362
- "paymasterVerificationGasLimit",
363
- overrides_ as UserOperationOverrides<"0.7.0">,
364
- feeOptions,
365
- userOperation
366
- );
367
- if (paymasterVerificationGasLimit != null) {
368
- (
369
- overrides as RequestGasAndPaymasterAndDataOverrides<"0.7.0">
370
- ).paymasterVerificationGasLimit = paymasterVerificationGasLimit;
371
- }
372
-
373
- const paymasterPostOpGasLimit = overrideField<"0.7.0">(
374
- "paymasterPostOpGasLimit",
375
- overrides_ as UserOperationOverrides<"0.7.0">,
376
- feeOptions,
377
- userOperation
378
- );
379
- if (paymasterPostOpGasLimit != null) {
380
- (
381
- overrides as RequestGasAndPaymasterAndDataOverrides<"0.7.0">
382
- ).paymasterPostOpGasLimit = paymasterPostOpGasLimit;
383
- }
384
- }
385
-
386
- const result = await client.request({
387
- method: "alchemy_requestGasAndPaymasterAndData",
388
- params: [
389
- {
390
- policyId: config.policyId,
391
- entryPoint: account.getEntryPoint().address,
392
- userOperation,
393
- dummySignature: userOperation.signature,
394
- overrides,
395
- },
396
- ],
397
- });
398
-
399
- return {
400
- ...struct,
401
- ...result,
402
- };
403
- },
404
- };
26
+ return erc7677Middleware<{ policyId: string }>({
27
+ context: { policyId: policyId },
28
+ });
405
29
  }
406
-
407
- /**
408
- * Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config
409
- * that calls the [`alchemy_requestPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)
410
- * with gas estimation disabled.
411
- *
412
- * @param {ClientWithAlchemyMethods} client client with alchemy methods
413
- * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration
414
- * @returns {ClientMiddlewareConfig["paymasterAndData"]} the paymasterAndData middleware for Alchemy gas manager with gas estimation disabled
415
- */
416
- const requestPaymasterAndData: <C extends ClientWithAlchemyMethods>(
417
- client: C,
418
- config: AlchemyGasManagerConfig
419
- ) => Pick<
420
- ClientMiddlewareConfig,
421
- "dummyPaymasterAndData" | "paymasterAndData"
422
- > = (client, config) => ({
423
- dummyPaymasterAndData: dummyPaymasterAndData(client, config),
424
- paymasterAndData: async (struct, { account }) => {
425
- const result = await client.request({
426
- method: "alchemy_requestPaymasterAndData",
427
- params: [
428
- {
429
- policyId: config.policyId,
430
- entryPoint: account.getEntryPoint().address,
431
- userOperation: deepHexlify(await resolveProperties(struct)),
432
- },
433
- ],
434
- });
435
-
436
- return {
437
- ...struct,
438
- ...result,
439
- };
440
- },
441
- });
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.0.0-alpha.6";
3
+ export const VERSION = "4.0.0-alpha.7";