@account-kit/infra 4.13.1-alpha.0 → 4.15.0

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 (51) hide show
  1. package/dist/esm/actions/types.d.ts +14 -2
  2. package/dist/esm/actions/types.js.map +1 -1
  3. package/dist/esm/alchemyTransport.js +1 -0
  4. package/dist/esm/alchemyTransport.js.map +1 -1
  5. package/dist/esm/chains.d.ts +1 -0
  6. package/dist/esm/chains.js +17 -0
  7. package/dist/esm/chains.js.map +1 -1
  8. package/dist/esm/client/smartAccountClient.d.ts +1 -1
  9. package/dist/esm/client/smartAccountClient.js +11 -4
  10. package/dist/esm/client/smartAccountClient.js.map +1 -1
  11. package/dist/esm/client/types.d.ts +11 -2
  12. package/dist/esm/client/types.js.map +1 -1
  13. package/dist/esm/gas-manager.d.ts +2 -0
  14. package/dist/esm/gas-manager.js +2 -0
  15. package/dist/esm/gas-manager.js.map +1 -1
  16. package/dist/esm/index.d.ts +2 -2
  17. package/dist/esm/index.js +2 -2
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/middleware/gasManager.d.ts +43 -4
  20. package/dist/esm/middleware/gasManager.js +137 -3
  21. package/dist/esm/middleware/gasManager.js.map +1 -1
  22. package/dist/esm/version.d.ts +1 -1
  23. package/dist/esm/version.js +1 -1
  24. package/dist/esm/version.js.map +1 -1
  25. package/dist/types/actions/types.d.ts +14 -2
  26. package/dist/types/actions/types.d.ts.map +1 -1
  27. package/dist/types/alchemyTransport.d.ts.map +1 -1
  28. package/dist/types/chains.d.ts +1 -0
  29. package/dist/types/chains.d.ts.map +1 -1
  30. package/dist/types/client/smartAccountClient.d.ts +1 -1
  31. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  32. package/dist/types/client/types.d.ts +11 -2
  33. package/dist/types/client/types.d.ts.map +1 -1
  34. package/dist/types/gas-manager.d.ts +2 -0
  35. package/dist/types/gas-manager.d.ts.map +1 -1
  36. package/dist/types/index.d.ts +2 -2
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/middleware/gasManager.d.ts +43 -4
  39. package/dist/types/middleware/gasManager.d.ts.map +1 -1
  40. package/dist/types/version.d.ts +1 -1
  41. package/dist/types/version.d.ts.map +1 -1
  42. package/package.json +4 -4
  43. package/src/actions/types.ts +41 -2
  44. package/src/alchemyTransport.ts +1 -0
  45. package/src/chains.ts +18 -0
  46. package/src/client/smartAccountClient.ts +12 -5
  47. package/src/client/types.ts +13 -1
  48. package/src/gas-manager.ts +2 -0
  49. package/src/index.ts +5 -1
  50. package/src/middleware/gasManager.ts +234 -6
  51. package/src/version.ts +1 -1
@@ -6,6 +6,8 @@ import {
6
6
  import type {
7
7
  SimulateUserOperationAssetChangesRequest,
8
8
  SimulateUserOperationAssetChangesResponse,
9
+ RequestGasAndPaymasterAndDataRequest,
10
+ RequestGasAndPaymasterAndDataResponse,
9
11
  } from "../actions/types";
10
12
  import type { AlchemyTransport } from "../alchemyTransport";
11
13
 
@@ -20,7 +22,12 @@ export type AlchemyRpcSchema = [
20
22
  Parameters: [];
21
23
  ReturnType: UserOperationRequest["maxPriorityFeePerGas"];
22
24
  },
23
- ...Erc7677RpcSchema<{ policyId: string }>
25
+ ...Erc7677RpcSchema<{ policyId: string }>,
26
+ {
27
+ Method: "alchemy_requestGasAndPaymasterAndData";
28
+ Parameters: RequestGasAndPaymasterAndDataRequest;
29
+ ReturnType: RequestGasAndPaymasterAndDataResponse;
30
+ }
24
31
  ];
25
32
 
26
33
  export type ClientWithAlchemyMethods = BundlerClient<AlchemyTransport> & {
@@ -35,5 +42,10 @@ export type ClientWithAlchemyMethods = BundlerClient<AlchemyTransport> & {
35
42
  method: "rundler_maxPriorityFeePerGas";
36
43
  params: [];
37
44
  }): Promise<UserOperationRequest["maxPriorityFeePerGas"]>;
45
+
46
+ request(args: {
47
+ method: "alchemy_requestGasAndPaymasterAndData";
48
+ params: RequestGasAndPaymasterAndDataRequest;
49
+ }): Promise<RequestGasAndPaymasterAndDataResponse>;
38
50
  }["request"];
39
51
  };
@@ -38,6 +38,8 @@ export const AlchemyPaymasterAddressV1 =
38
38
  *
39
39
  * @param {Chain} chain The chain for which the paymaster address is required
40
40
  * @returns {Address} The Alchemy paymaster address corresponding to the specified chain
41
+ *
42
+ * @deprecated This chain list in this function is no longer maintained since the ERC-7677 middleware is typically used to resolve the paymaster address
41
43
  */
42
44
  export const getAlchemyPaymasterAddress = (chain: Chain): Address => {
43
45
  switch (chain.id) {
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export {
40
40
  inkMainnet,
41
41
  inkSepolia,
42
42
  mekong,
43
+ monadTestnet,
43
44
  } from "./chains.js";
44
45
  export type * from "./client/decorators/alchemyEnhancedApis.js";
45
46
  export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
@@ -55,6 +56,9 @@ export { getDefaultUserOperationFeeOptions } from "./defaults.js";
55
56
  export { getAlchemyPaymasterAddress } from "./gas-manager.js";
56
57
  export { alchemyFeeEstimator } from "./middleware/feeEstimator.js";
57
58
  export type * from "./middleware/gasManager.js";
58
- export { alchemyGasManagerMiddleware } from "./middleware/gasManager.js";
59
+ export {
60
+ alchemyGasManagerMiddleware,
61
+ alchemyGasAndPaymasterAndDataMiddleware,
62
+ } from "./middleware/gasManager.js";
59
63
  export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
60
64
  export type * from "./schema.js";
@@ -1,8 +1,32 @@
1
- import type { ClientMiddlewareConfig } from "@aa-sdk/core";
2
- import { erc7677Middleware } from "@aa-sdk/core";
1
+ import type {
2
+ ClientMiddlewareConfig,
3
+ ClientMiddlewareFn,
4
+ EntryPointVersion,
5
+ Multiplier,
6
+ UserOperationFeeOptions,
7
+ UserOperationOverrides,
8
+ UserOperationRequest,
9
+ } from "@aa-sdk/core";
10
+ import {
11
+ bypassPaymasterAndData,
12
+ ChainNotFoundError,
13
+ deepHexlify,
14
+ defaultGasEstimator,
15
+ erc7677Middleware,
16
+ filterUndefined,
17
+ isBigNumberish,
18
+ isMultiplier,
19
+ noopMiddleware,
20
+ resolveProperties,
21
+ } from "@aa-sdk/core";
22
+ import { fromHex, isHex, type Hex } from "viem";
23
+ import type { AlchemySmartAccountClient } from "../client/smartAccountClient.js";
24
+ import type { AlchemyTransport } from "../alchemyTransport.js";
25
+ import { alchemyFeeEstimator } from "./feeEstimator.js";
3
26
 
4
27
  /**
5
- * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring transactions.
28
+ * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
29
+ * transactions. Adheres to the ERC-7677 standardized communication protocol.
6
30
  *
7
31
  * @example
8
32
  * ```ts
@@ -16,13 +40,217 @@ import { erc7677Middleware } from "@aa-sdk/core";
16
40
  * });
17
41
  * ```
18
42
  *
19
- * @param {string} policyId the policyId for Alchemy's gas manager
43
+ * @param {string | string[]} policyId the policyId (or list of policyIds) for Alchemy's gas manager
20
44
  * @returns {Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData">} partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`
21
45
  */
22
46
  export function alchemyGasManagerMiddleware(
23
- policyId: string
47
+ policyId: string | string[]
24
48
  ): Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData"> {
25
- return erc7677Middleware<{ policyId: string }>({
49
+ return erc7677Middleware<{ policyId: string | string[] }>({
26
50
  context: { policyId: policyId },
27
51
  });
28
52
  }
53
+
54
+ interface AlchemyGasAndPaymasterAndDataMiddlewareParams {
55
+ policyId: string | string[];
56
+ transport: AlchemyTransport;
57
+ gasEstimatorOverride?: ClientMiddlewareFn;
58
+ feeEstimatorOverride?: ClientMiddlewareFn;
59
+ }
60
+
61
+ /**
62
+ * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
63
+ * transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`
64
+ * method instead of conforming to the standard ERC-7677 interface. Note that
65
+ * if you use `createAlchemySmartAccountClient`, this middleware is already
66
+ * used by default and you do not need to manually include it.
67
+ *
68
+ * @example
69
+ * ```ts twoslash
70
+ * import { sepolia, alchemy, alchemyGasAndPaymasterAndDataMiddleware } from "@account-kit/infra";
71
+ * import { createSmartAccountClient } from "@aa-sdk/core";
72
+ *
73
+ * const client = createSmartAccountClient({
74
+ * transport: alchemy({ apiKey: "your-api-key" }),
75
+ * chain: sepolia,
76
+ * ...alchemyGasAndPaymasterAndDataMiddleware({
77
+ * policyId: "policyId",
78
+ * transport: alchemy({ apiKey: "your-api-key" }),
79
+ * })
80
+ * });
81
+ * ```
82
+ *
83
+ * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams} params configuration params
84
+ * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.policyId} params.policyId the policyId for Alchemy's gas manager
85
+ * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.transport} params.transport fallback transport to use for fee estimation when not using the paymaster
86
+ * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.gasEstimatorOverride} params.gasEstimatorOverride custom gas estimator middleware
87
+ * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.feeEstimatorOverride} params.feeEstimatorOverride custom fee estimator middleware
88
+ * @returns {Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData">} partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`
89
+ */
90
+ export function alchemyGasAndPaymasterAndDataMiddleware(
91
+ params: AlchemyGasAndPaymasterAndDataMiddlewareParams
92
+ ): Pick<
93
+ ClientMiddlewareConfig,
94
+ "dummyPaymasterAndData" | "feeEstimator" | "gasEstimator" | "paymasterAndData"
95
+ > {
96
+ const { policyId, transport, gasEstimatorOverride, feeEstimatorOverride } =
97
+ params;
98
+ return {
99
+ dummyPaymasterAndData: async (uo, args) => {
100
+ if (
101
+ // No reason to generate dummy data if we are bypassing the paymaster.
102
+ bypassPaymasterAndData(args.overrides) ||
103
+ // When using alchemy_requestGasAndPaymasterAndData, there is generally no reason to generate dummy
104
+ // data. However, if the gas/feeEstimator is overriden, then this option should be enabled.
105
+ !(gasEstimatorOverride || feeEstimatorOverride)
106
+ ) {
107
+ return noopMiddleware(uo, args);
108
+ }
109
+
110
+ // Fall back to the default 7677 dummyPaymasterAndData middleware.
111
+ return alchemyGasManagerMiddleware(policyId).dummyPaymasterAndData!(
112
+ uo,
113
+ args
114
+ );
115
+ },
116
+ feeEstimator: (uo, args) => {
117
+ return feeEstimatorOverride
118
+ ? feeEstimatorOverride(uo, args)
119
+ : bypassPaymasterAndData(args.overrides)
120
+ ? alchemyFeeEstimator(transport)(uo, args)
121
+ : noopMiddleware(uo, args);
122
+ },
123
+ gasEstimator: (uo, args) => {
124
+ return gasEstimatorOverride
125
+ ? gasEstimatorOverride(uo, args)
126
+ : bypassPaymasterAndData(args.overrides)
127
+ ? defaultGasEstimator(args.client)(uo, args)
128
+ : noopMiddleware(uo, args);
129
+ },
130
+ paymasterAndData: async (
131
+ uo,
132
+ { account, client, feeOptions, overrides: overrides_ }
133
+ ) => {
134
+ if (!client.chain) {
135
+ throw new ChainNotFoundError();
136
+ }
137
+
138
+ const userOp = deepHexlify(await resolveProperties(uo));
139
+
140
+ const overrides: UserOperationOverrides = filterUndefined({
141
+ maxFeePerGas: overrideField(
142
+ "maxFeePerGas",
143
+ overrides_ as UserOperationOverrides,
144
+ feeOptions,
145
+ userOp
146
+ ),
147
+ maxPriorityFeePerGas: overrideField(
148
+ "maxPriorityFeePerGas",
149
+ overrides_ as UserOperationOverrides,
150
+ feeOptions,
151
+ userOp
152
+ ),
153
+ callGasLimit: overrideField(
154
+ "callGasLimit",
155
+ overrides_ as UserOperationOverrides,
156
+ feeOptions,
157
+ userOp
158
+ ),
159
+ verificationGasLimit: overrideField(
160
+ "verificationGasLimit",
161
+ overrides_ as UserOperationOverrides,
162
+ feeOptions,
163
+ userOp
164
+ ),
165
+ preVerificationGas: overrideField(
166
+ "preVerificationGas",
167
+ overrides_ as UserOperationOverrides,
168
+ feeOptions,
169
+ userOp
170
+ ),
171
+ ...(account.getEntryPoint().version === "0.7.0"
172
+ ? {
173
+ paymasterVerificationGasLimit: overrideField<"0.7.0">(
174
+ "paymasterVerificationGasLimit",
175
+ overrides_ as UserOperationOverrides<"0.7.0">,
176
+ feeOptions,
177
+ userOp
178
+ ),
179
+ paymasterPostOpGasLimit: overrideField<"0.7.0">(
180
+ "paymasterPostOpGasLimit",
181
+ overrides_ as UserOperationOverrides<"0.7.0">,
182
+ feeOptions,
183
+ userOp
184
+ ),
185
+ }
186
+ : {}),
187
+ });
188
+
189
+ const result = await (client as AlchemySmartAccountClient).request({
190
+ method: "alchemy_requestGasAndPaymasterAndData",
191
+ params: [
192
+ {
193
+ policyId,
194
+ entryPoint: account.getEntryPoint().address,
195
+ userOperation: userOp,
196
+ dummySignature: await account.getDummySignature(),
197
+ overrides,
198
+ },
199
+ ],
200
+ });
201
+
202
+ return {
203
+ ...uo,
204
+ ...result,
205
+ };
206
+ },
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Utility function to override a field in the user operation request with the overrides or fee options
212
+ *
213
+ * @template {EntryPointVersion} TEntryPointVersion
214
+ * @param {keyof UserOperationFeeOptions<TEntryPointVersion>} field the field to override
215
+ * @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the overrides object
216
+ * @param {UserOperationFeeOptions<TEntryPointVersion> | undefined} feeOptions the fee options object from the client
217
+ * @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request
218
+ * @returns {Hex | Multiplier | undefined} the overridden field value
219
+ */
220
+ const overrideField = <
221
+ TEntryPointVersion extends EntryPointVersion = EntryPointVersion
222
+ >(
223
+ field: keyof UserOperationFeeOptions<TEntryPointVersion>,
224
+ overrides: UserOperationOverrides<TEntryPointVersion> | undefined,
225
+ feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,
226
+ userOperation: UserOperationRequest<TEntryPointVersion>
227
+ ): Hex | Multiplier | undefined => {
228
+ let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;
229
+
230
+ if (overrides?.[_field] != null) {
231
+ // one-off absolute override
232
+ if (isBigNumberish(overrides[_field])) {
233
+ return deepHexlify(overrides[_field]);
234
+ }
235
+ // one-off multiplier overrides
236
+ else {
237
+ return {
238
+ multiplier: Number((overrides[_field] as Multiplier).multiplier),
239
+ };
240
+ }
241
+ }
242
+
243
+ // provider level fee options with multiplier
244
+ if (isMultiplier(feeOptions?.[field])) {
245
+ return {
246
+ multiplier: Number((feeOptions![field] as Multiplier).multiplier),
247
+ };
248
+ }
249
+
250
+ const userOpField =
251
+ userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];
252
+ if (isHex(userOpField) && fromHex(userOpField as Hex, "bigint") > 0n) {
253
+ return userOpField;
254
+ }
255
+ return undefined;
256
+ };
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.13.1-alpha.0";
3
+ export const VERSION = "4.15.0";