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

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,13 +1,12 @@
1
1
  import { type Prettify, type SmartAccountClient, type SmartAccountClientActions, type SmartAccountClientConfig, type SmartAccountClientRpcSchema, type SmartContractAccount, type UserOperationContext } from "@aa-sdk/core";
2
2
  import { type Chain, type Transport } from "viem";
3
- import { type AlchemyGasManagerConfig } from "../middleware/gasManager.js";
4
3
  import type { AlchemyProviderConfig } from "../type.js";
5
4
  import type { AlchemySmartAccountClientActions } from "./decorators/smartAccount.js";
6
5
  import type { AlchemyRpcSchema } from "./types.js";
7
6
  export type AlchemySmartAccountClientConfig<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, context extends UserOperationContext | undefined = UserOperationContext | undefined> = {
8
7
  account?: account;
9
8
  useSimulation?: boolean;
10
- gasManagerConfig?: AlchemyGasManagerConfig;
9
+ policyId?: string;
11
10
  } & AlchemyProviderConfig & Pick<SmartAccountClientConfig<transport, chain, account, context>, "customMiddleware" | "feeEstimator" | "gasEstimator" | "signUserOperation">;
12
11
  export type BaseAlchemyActions<chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, context extends UserOperationContext | undefined = UserOperationContext | undefined> = SmartAccountClientActions<chain, account, context> & AlchemySmartAccountClientActions<account, context>;
13
12
  export type AlchemySmartAccountClient_Base<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<string, unknown>, context extends UserOperationContext | undefined = UserOperationContext | undefined> = Prettify<SmartAccountClient<transport, chain, account, actions & BaseAlchemyActions<chain, account, context>, [
@@ -15,4 +14,4 @@ export type AlchemySmartAccountClient_Base<transport extends Transport = Transpo
15
14
  ...AlchemyRpcSchema
16
15
  ], context>>;
17
16
  export type AlchemySmartAccountClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<string, unknown>, context extends UserOperationContext | undefined = UserOperationContext | undefined> = Prettify<AlchemySmartAccountClient_Base<transport, chain, account, actions, context>>;
18
- export declare function createAlchemySmartAccountClient<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined>({ account, gasManagerConfig, useSimulation, feeEstimator, customMiddleware, gasEstimator, signUserOperation, ...config_ }: AlchemySmartAccountClientConfig<TTransport, TChain, TAccount, TContext>): AlchemySmartAccountClient<TTransport, TChain, TAccount, Record<string, never>, TContext>;
17
+ export declare function createAlchemySmartAccountClient<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined>({ account, policyId, useSimulation, feeEstimator, customMiddleware, gasEstimator, signUserOperation, ...config_ }: AlchemySmartAccountClientConfig<TTransport, TChain, TAccount, TContext>): AlchemySmartAccountClient<TTransport, TChain, TAccount, Record<string, never>, TContext>;
@@ -1,11 +1,10 @@
1
1
  import {} from "@aa-sdk/core";
2
2
  import {} from "viem";
3
3
  import { getDefaultUserOperationFeeOptions } from "../defaults.js";
4
- import {} from "../middleware/gasManager.js";
5
4
  import { AlchemyProviderConfigSchema } from "../schema.js";
6
5
  import { createAlchemySmartAccountClientFromRpcClient } from "./internal/smartAccountClientFromRpc.js";
7
6
  import { createAlchemyPublicRpcClient } from "./rpcClient.js";
8
- export function createAlchemySmartAccountClient({ account, gasManagerConfig, useSimulation, feeEstimator, customMiddleware, gasEstimator, signUserOperation, ...config_ }) {
7
+ export function createAlchemySmartAccountClient({ account, policyId, useSimulation, feeEstimator, customMiddleware, gasEstimator, signUserOperation, ...config_ }) {
9
8
  const config = AlchemyProviderConfigSchema.parse(config_);
10
9
  const { chain, opts, ...connectionConfig } = config;
11
10
  const client = createAlchemyPublicRpcClient({
@@ -20,7 +19,7 @@ export function createAlchemySmartAccountClient({ account, gasManagerConfig, use
20
19
  ...opts,
21
20
  feeOptions,
22
21
  },
23
- gasManagerConfig,
22
+ policyId,
24
23
  useSimulation,
25
24
  feeEstimator,
26
25
  customMiddleware,
@@ -1 +1 @@
1
- {"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,MAAM,cAAc,CAAC;AACtB,OAAO,EAA8B,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAgC,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAG3D,OAAO,EAAE,4CAA4C,EAAE,MAAM,yCAAyC,CAAC;AACvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAsH9D,MAAM,UAAU,+BAA+B,CAAC,EAC9C,OAAO,EACP,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,GAAG,OAAO,EACsB;IAChC,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAEpD,MAAM,MAAM,GAAG,4BAA4B,CAAC;QAC1C,KAAK;QACL,gBAAgB;KACjB,CAAC,CAAC;IAEH,MAAM,UAAU,GACd,IAAI,EAAE,UAAU,IAAI,iCAAiC,CAAC,KAAK,CAAC,CAAC;IAE/D,OAAO,4CAA4C,CAAC;QAClD,MAAM;QACN,OAAO;QACP,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,UAAU;SACX;QACD,gBAAgB;QAChB,aAAa;QACb,YAAY;QACZ,gBAAgB;QAChB,YAAY;QACZ,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Prettify,\n type SmartAccountClient,\n type SmartAccountClientActions,\n type SmartAccountClientConfig,\n type SmartAccountClientRpcSchema,\n type SmartContractAccount,\n type UserOperationContext,\n} from \"@aa-sdk/core\";\nimport { type Chain, type Transport } from \"viem\";\nimport { getDefaultUserOperationFeeOptions } from \"../defaults.js\";\nimport { type AlchemyGasManagerConfig } from \"../middleware/gasManager.js\";\nimport { AlchemyProviderConfigSchema } from \"../schema.js\";\nimport type { AlchemyProviderConfig } from \"../type.js\";\nimport type { AlchemySmartAccountClientActions } from \"./decorators/smartAccount.js\";\nimport { createAlchemySmartAccountClientFromRpcClient } from \"./internal/smartAccountClientFromRpc.js\";\nimport { createAlchemyPublicRpcClient } from \"./rpcClient.js\";\nimport type { AlchemyRpcSchema } from \"./types.js\";\n\n// #region AlchemySmartAccountClientConfig\nexport type AlchemySmartAccountClientConfig<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = {\n account?: account;\n useSimulation?: boolean;\n gasManagerConfig?: AlchemyGasManagerConfig;\n} & AlchemyProviderConfig &\n Pick<\n SmartAccountClientConfig<transport, chain, account, context>,\n \"customMiddleware\" | \"feeEstimator\" | \"gasEstimator\" | \"signUserOperation\"\n >;\n// #endregion AlchemySmartAccountClientConfig\n\nexport type BaseAlchemyActions<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = SmartAccountClientActions<chain, account, context> &\n AlchemySmartAccountClientActions<account, context>;\n\nexport type AlchemySmartAccountClient_Base<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n SmartAccountClient<\n transport,\n chain,\n account,\n actions & BaseAlchemyActions<chain, account, context>,\n [...SmartAccountClientRpcSchema, ...AlchemyRpcSchema],\n context\n >\n>;\n\nexport type AlchemySmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n AlchemySmartAccountClient_Base<transport, chain, account, actions, context>\n>;\n\nexport function createAlchemySmartAccountClient<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>({\n account,\n gasManagerConfig,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n ...config_\n}: AlchemySmartAccountClientConfig<\n TTransport,\n TChain,\n TAccount,\n TContext\n>): AlchemySmartAccountClient<\n TTransport,\n TChain,\n TAccount,\n Record<string, never>,\n TContext\n>;\n\n/**\n * Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.\n *\n * @example\n * ```ts\n * import { createAlchemySmartAccountClient } from \"@account-kit/infra\";\n * import { sepolia } from \"@account-kit/infra/chain\";\n *\n * const client = createAlchemySmartAccountClient({\n * chain: sepolia,\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * @param {AlchemySmartAccountClientConfig} config The configuration for creating the Alchemy smart account client\n * @returns {AlchemySmartAccountClient} An instance of `AlchemySmartAccountClient` configured based on the provided options\n */\nexport function createAlchemySmartAccountClient({\n account,\n gasManagerConfig,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n ...config_\n}: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {\n const config = AlchemyProviderConfigSchema.parse(config_);\n const { chain, opts, ...connectionConfig } = config;\n\n const client = createAlchemyPublicRpcClient({\n chain,\n connectionConfig,\n });\n\n const feeOptions =\n opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);\n\n return createAlchemySmartAccountClientFromRpcClient({\n client,\n account,\n opts: {\n ...opts,\n feeOptions,\n },\n gasManagerConfig,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n });\n}\n"]}
1
+ {"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,MAAM,cAAc,CAAC;AACtB,OAAO,EAA8B,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAG3D,OAAO,EAAE,4CAA4C,EAAE,MAAM,yCAAyC,CAAC;AACvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAsH9D,MAAM,UAAU,+BAA+B,CAAC,EAC9C,OAAO,EACP,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,GAAG,OAAO,EACsB;IAChC,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAEpD,MAAM,MAAM,GAAG,4BAA4B,CAAC;QAC1C,KAAK;QACL,gBAAgB;KACjB,CAAC,CAAC;IAEH,MAAM,UAAU,GACd,IAAI,EAAE,UAAU,IAAI,iCAAiC,CAAC,KAAK,CAAC,CAAC;IAE/D,OAAO,4CAA4C,CAAC;QAClD,MAAM;QACN,OAAO;QACP,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,UAAU;SACX;QACD,QAAQ;QACR,aAAa;QACb,YAAY;QACZ,gBAAgB;QAChB,YAAY;QACZ,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Prettify,\n type SmartAccountClient,\n type SmartAccountClientActions,\n type SmartAccountClientConfig,\n type SmartAccountClientRpcSchema,\n type SmartContractAccount,\n type UserOperationContext,\n} from \"@aa-sdk/core\";\nimport { type Chain, type Transport } from \"viem\";\nimport { getDefaultUserOperationFeeOptions } from \"../defaults.js\";\nimport { AlchemyProviderConfigSchema } from \"../schema.js\";\nimport type { AlchemyProviderConfig } from \"../type.js\";\nimport type { AlchemySmartAccountClientActions } from \"./decorators/smartAccount.js\";\nimport { createAlchemySmartAccountClientFromRpcClient } from \"./internal/smartAccountClientFromRpc.js\";\nimport { createAlchemyPublicRpcClient } from \"./rpcClient.js\";\nimport type { AlchemyRpcSchema } from \"./types.js\";\n\n// #region AlchemySmartAccountClientConfig\nexport type AlchemySmartAccountClientConfig<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = {\n account?: account;\n useSimulation?: boolean;\n policyId?: string;\n} & AlchemyProviderConfig &\n Pick<\n SmartAccountClientConfig<transport, chain, account, context>,\n \"customMiddleware\" | \"feeEstimator\" | \"gasEstimator\" | \"signUserOperation\"\n >;\n// #endregion AlchemySmartAccountClientConfig\n\nexport type BaseAlchemyActions<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = SmartAccountClientActions<chain, account, context> &\n AlchemySmartAccountClientActions<account, context>;\n\nexport type AlchemySmartAccountClient_Base<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n SmartAccountClient<\n transport,\n chain,\n account,\n actions & BaseAlchemyActions<chain, account, context>,\n [...SmartAccountClientRpcSchema, ...AlchemyRpcSchema],\n context\n >\n>;\n\nexport type AlchemySmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n AlchemySmartAccountClient_Base<transport, chain, account, actions, context>\n>;\n\nexport function createAlchemySmartAccountClient<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>({\n account,\n policyId,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n ...config_\n}: AlchemySmartAccountClientConfig<\n TTransport,\n TChain,\n TAccount,\n TContext\n>): AlchemySmartAccountClient<\n TTransport,\n TChain,\n TAccount,\n Record<string, never>,\n TContext\n>;\n\n/**\n * Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.\n *\n * @example\n * ```ts\n * import { createAlchemySmartAccountClient } from \"@account-kit/infra\";\n * import { sepolia } from \"@account-kit/infra/chain\";\n *\n * const client = createAlchemySmartAccountClient({\n * chain: sepolia,\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * @param {AlchemySmartAccountClientConfig} config The configuration for creating the Alchemy smart account client\n * @returns {AlchemySmartAccountClient} An instance of `AlchemySmartAccountClient` configured based on the provided options\n */\nexport function createAlchemySmartAccountClient({\n account,\n policyId,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n ...config_\n}: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {\n const config = AlchemyProviderConfigSchema.parse(config_);\n const { chain, opts, ...connectionConfig } = config;\n\n const client = createAlchemyPublicRpcClient({\n chain,\n connectionConfig,\n });\n\n const feeOptions =\n opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);\n\n return createAlchemySmartAccountClientFromRpcClient({\n client,\n account,\n opts: {\n ...opts,\n feeOptions,\n },\n policyId,\n useSimulation,\n feeEstimator,\n customMiddleware,\n gasEstimator,\n signUserOperation,\n });\n}\n"]}
@@ -1,32 +1,7 @@
1
1
  import { type BundlerClient, type UserOperationRequest } from "@aa-sdk/core";
2
- import type { Address, Hex, HttpTransport } from "viem";
2
+ import type { HttpTransport } from "viem";
3
3
  import type { SimulateUserOperationAssetChangesRequest, SimulateUserOperationAssetChangesResponse } from "../actions/types";
4
- import type { RequestGasAndPaymasterAndDataOverrides, RequestGasAndPaymasterAndDataResponse, RequestPaymasterAndDataResponse } from "../middleware/gasManager";
5
4
  export type AlchemyRpcSchema = [
6
- {
7
- Method: "alchemy_requestPaymasterAndData";
8
- Parameters: [
9
- {
10
- policyId: string;
11
- entryPoint: Address;
12
- userOperation: UserOperationRequest;
13
- }
14
- ];
15
- ReturnType: RequestPaymasterAndDataResponse;
16
- },
17
- {
18
- Method: "alchemy_requestGasAndPaymasterAndData";
19
- Parameters: [
20
- {
21
- policyId: string;
22
- entryPoint: Address;
23
- userOperation: UserOperationRequest;
24
- dummySignature: Hex;
25
- overrides?: RequestGasAndPaymasterAndDataOverrides;
26
- }
27
- ];
28
- ReturnType: RequestGasAndPaymasterAndDataResponse;
29
- },
30
5
  {
31
6
  Method: "alchemy_simulateUserOperationAssetChanges";
32
7
  Parameters: SimulateUserOperationAssetChangesRequest;
@@ -40,28 +15,6 @@ export type AlchemyRpcSchema = [
40
15
  ];
41
16
  export type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {
42
17
  request: BundlerClient<HttpTransport>["request"] & {
43
- request(args: {
44
- method: "alchemy_requestPaymasterAndData";
45
- params: [
46
- {
47
- policyId: string;
48
- entryPoint: Address;
49
- userOperation: UserOperationRequest;
50
- }
51
- ];
52
- }): Promise<RequestPaymasterAndDataResponse>;
53
- request(args: {
54
- method: "alchemy_requestGasAndPaymasterAndData";
55
- params: [
56
- {
57
- policyId: string;
58
- entryPoint: Address;
59
- userOperation: UserOperationRequest;
60
- dummySignature: Hex;
61
- overrides?: RequestGasAndPaymasterAndDataOverrides;
62
- }
63
- ];
64
- }): Promise<RequestGasAndPaymasterAndDataResponse>;
65
18
  request(args: {
66
19
  method: "alchemy_simulateUserOperationAssetChanges";
67
20
  params: SimulateUserOperationAssetChangesRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,MAAM,cAAc,CAAC","sourcesContent":["import { type BundlerClient, type UserOperationRequest } from \"@aa-sdk/core\";\nimport type { Address, Hex, HttpTransport } from \"viem\";\nimport type {\n SimulateUserOperationAssetChangesRequest,\n SimulateUserOperationAssetChangesResponse,\n} from \"../actions/types\";\nimport type {\n RequestGasAndPaymasterAndDataOverrides,\n RequestGasAndPaymasterAndDataResponse,\n RequestPaymasterAndDataResponse,\n} from \"../middleware/gasManager\";\n\nexport type AlchemyRpcSchema = [\n {\n Method: \"alchemy_requestPaymasterAndData\";\n Parameters: [\n {\n policyId: string;\n entryPoint: Address;\n userOperation: UserOperationRequest;\n }\n ];\n ReturnType: RequestPaymasterAndDataResponse;\n },\n {\n Method: \"alchemy_requestGasAndPaymasterAndData\";\n Parameters: [\n {\n policyId: string;\n entryPoint: Address;\n userOperation: UserOperationRequest;\n dummySignature: Hex;\n overrides?: RequestGasAndPaymasterAndDataOverrides;\n }\n ];\n ReturnType: RequestGasAndPaymasterAndDataResponse;\n },\n {\n Method: \"alchemy_simulateUserOperationAssetChanges\";\n Parameters: SimulateUserOperationAssetChangesRequest;\n ReturnType: SimulateUserOperationAssetChangesResponse;\n },\n {\n Method: \"rundler_maxPriorityFeePerGas\";\n Parameters: [];\n ReturnType: UserOperationRequest[\"maxPriorityFeePerGas\"];\n }\n];\n\nexport type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {\n request: BundlerClient<HttpTransport>[\"request\"] &\n {\n request(args: {\n method: \"alchemy_requestPaymasterAndData\";\n params: [\n {\n policyId: string;\n entryPoint: Address;\n userOperation: UserOperationRequest;\n }\n ];\n }): Promise<RequestPaymasterAndDataResponse>;\n\n request(args: {\n method: \"alchemy_requestGasAndPaymasterAndData\";\n params: [\n {\n policyId: string;\n entryPoint: Address;\n userOperation: UserOperationRequest;\n dummySignature: Hex;\n overrides?: RequestGasAndPaymasterAndDataOverrides;\n }\n ];\n }): Promise<RequestGasAndPaymasterAndDataResponse>;\n\n request(args: {\n method: \"alchemy_simulateUserOperationAssetChanges\";\n params: SimulateUserOperationAssetChangesRequest;\n }): Promise<SimulateUserOperationAssetChangesResponse>;\n\n request(args: {\n method: \"rundler_maxPriorityFeePerGas\";\n params: [];\n }): Promise<UserOperationRequest[\"maxPriorityFeePerGas\"]>;\n }[\"request\"];\n} & {\n updateHeaders: (headers: HeadersInit) => void;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,MAAM,cAAc,CAAC","sourcesContent":["import { type BundlerClient, type UserOperationRequest } from \"@aa-sdk/core\";\nimport type { HttpTransport } from \"viem\";\nimport type {\n SimulateUserOperationAssetChangesRequest,\n SimulateUserOperationAssetChangesResponse,\n} from \"../actions/types\";\n\nexport type AlchemyRpcSchema = [\n {\n Method: \"alchemy_simulateUserOperationAssetChanges\";\n Parameters: SimulateUserOperationAssetChangesRequest;\n ReturnType: SimulateUserOperationAssetChangesResponse;\n },\n {\n Method: \"rundler_maxPriorityFeePerGas\";\n Parameters: [];\n ReturnType: UserOperationRequest[\"maxPriorityFeePerGas\"];\n }\n];\n\nexport type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {\n request: BundlerClient<HttpTransport>[\"request\"] &\n {\n request(args: {\n method: \"alchemy_simulateUserOperationAssetChanges\";\n params: SimulateUserOperationAssetChangesRequest;\n }): Promise<SimulateUserOperationAssetChangesResponse>;\n\n request(args: {\n method: \"rundler_maxPriorityFeePerGas\";\n params: [];\n }): Promise<UserOperationRequest[\"maxPriorityFeePerGas\"]>;\n }[\"request\"];\n} & {\n updateHeaders: (headers: HeadersInit) => void;\n};\n"]}
@@ -1,29 +1,2 @@
1
- import type { Address, ClientMiddlewareConfig, ClientMiddlewareFn, EntryPointVersion, Multiplier, UserOperationRequest } from "@aa-sdk/core";
2
- import { type Hex } from "viem";
3
- import type { ClientWithAlchemyMethods } from "../client/types";
4
- export type RequestGasAndPaymasterAndDataOverrides<TEntryPointVersion extends EntryPointVersion = EntryPointVersion> = Partial<{
5
- maxFeePerGas: UserOperationRequest<TEntryPointVersion>["maxFeePerGas"] | Multiplier;
6
- maxPriorityFeePerGas: UserOperationRequest<TEntryPointVersion>["maxPriorityFeePerGas"] | Multiplier;
7
- callGasLimit: UserOperationRequest<TEntryPointVersion>["callGasLimit"] | Multiplier;
8
- verificationGasLimit: UserOperationRequest<TEntryPointVersion>["verificationGasLimit"] | Multiplier;
9
- preVerificationGas: UserOperationRequest<TEntryPointVersion>["preVerificationGas"] | Multiplier;
10
- } & TEntryPointVersion extends "0.7.0" ? {
11
- paymasterVerificationGasLimit: UserOperationRequest<"0.7.0">["paymasterVerificationGasLimit"] | Multiplier;
12
- paymasterPostOpGasLimit: UserOperationRequest<"0.7.0">["paymasterPostOpGasLimit"] | Multiplier;
13
- } : {}>;
14
- export type RequestPaymasterAndDataResponse<TEntryPointVersion extends EntryPointVersion = EntryPointVersion> = TEntryPointVersion extends "0.6.0" ? {
15
- paymasterAndData: UserOperationRequest<"0.6.0">["paymasterAndData"];
16
- } : TEntryPointVersion extends "0.7.0" ? Pick<UserOperationRequest<"0.7.0">, "paymaster" | "paymasterData"> : {};
17
- export type RequestGasAndPaymasterAndDataResponse<TEntryPointVersion extends EntryPointVersion = EntryPointVersion> = Pick<UserOperationRequest, "callGasLimit" | "preVerificationGas" | "verificationGasLimit" | "maxFeePerGas" | "maxPriorityFeePerGas"> & RequestPaymasterAndDataResponse<TEntryPointVersion>;
18
- export interface AlchemyGasManagerConfig {
19
- policyId: string;
20
- gasEstimationOptions?: AlchemyGasEstimationOptions;
21
- paymasterAddress?: Address;
22
- dummyData?: Hex;
23
- }
24
- export interface AlchemyGasEstimationOptions {
25
- disableGasEstimation: boolean;
26
- fallbackGasEstimator?: ClientMiddlewareFn;
27
- fallbackFeeDataGetter?: ClientMiddlewareFn;
28
- }
29
- export declare function alchemyGasManagerMiddleware<C extends ClientWithAlchemyMethods>(client: C, config: AlchemyGasManagerConfig): Pick<ClientMiddlewareConfig, "paymasterAndData" | "feeEstimator" | "gasEstimator">;
1
+ import type { ClientMiddlewareConfig } from "@aa-sdk/core";
2
+ export declare function alchemyGasManagerMiddleware(policyId: string): Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData">;
@@ -1,149 +1,7 @@
1
- import { bypassPaymasterAndDataEmptyHex, deepHexlify, defaultGasEstimator, filterUndefined, isBigNumberish, isMultiplier, resolveProperties, } from "@aa-sdk/core";
2
- import { concat, fromHex, isHex } from "viem";
3
- import { getAlchemyPaymasterAddress } from "../gas-manager.js";
4
- import { alchemyFeeEstimator } from "./feeEstimator.js";
5
- const dummyPaymasterAndData = (client, config) => async (uo) => {
6
- const paymaster = config.paymasterAddress ?? getAlchemyPaymasterAddress(client.chain);
7
- const paymasterData = config.dummyData ??
8
- "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
9
- return {
10
- ...uo,
11
- paymaster,
12
- paymasterData,
13
- paymasterAndData: concat([paymaster, paymasterData]),
14
- };
15
- };
16
- export function alchemyGasManagerMiddleware(client, config) {
17
- const gasEstimationOptions = config.gasEstimationOptions;
18
- const disableGasEstimation = gasEstimationOptions?.disableGasEstimation ?? false;
19
- const fallbackFeeDataGetter = gasEstimationOptions?.fallbackFeeDataGetter ?? alchemyFeeEstimator(client);
20
- const fallbackGasEstimator = gasEstimationOptions?.fallbackGasEstimator ??
21
- defaultGasEstimator(client);
22
- return {
23
- gasEstimator: disableGasEstimation
24
- ? fallbackGasEstimator
25
- : async (struct, { overrides, account, feeOptions }) => {
26
- if (bypassPaymasterAndDataEmptyHex(overrides)) {
27
- return {
28
- ...struct,
29
- ...(await fallbackGasEstimator(struct, {
30
- overrides,
31
- account,
32
- feeOptions,
33
- client,
34
- })),
35
- };
36
- }
37
- return struct;
38
- },
39
- feeEstimator: disableGasEstimation
40
- ? fallbackFeeDataGetter
41
- : async (struct, { overrides, account, feeOptions }) => {
42
- let maxFeePerGas = await struct.maxFeePerGas;
43
- let maxPriorityFeePerGas = await struct.maxPriorityFeePerGas;
44
- if (bypassPaymasterAndDataEmptyHex(overrides)) {
45
- const result = await fallbackFeeDataGetter(struct, {
46
- overrides,
47
- feeOptions,
48
- account,
49
- client,
50
- });
51
- maxFeePerGas = (await result.maxFeePerGas) ?? maxFeePerGas;
52
- maxPriorityFeePerGas =
53
- (await result.maxPriorityFeePerGas) ?? maxPriorityFeePerGas;
54
- }
55
- return {
56
- ...struct,
57
- maxFeePerGas,
58
- maxPriorityFeePerGas,
59
- };
60
- },
61
- ...(disableGasEstimation
62
- ? requestPaymasterAndData(client, config)
63
- : requestGasAndPaymasterData(client, config)),
64
- };
1
+ import { erc7677Middleware } from "@aa-sdk/core";
2
+ export function alchemyGasManagerMiddleware(policyId) {
3
+ return erc7677Middleware({
4
+ context: { policyId: policyId },
5
+ });
65
6
  }
66
- const overrideField = (field, overrides, feeOptions, userOperation) => {
67
- let _field = field;
68
- if (overrides?.[_field] != null) {
69
- if (isBigNumberish(overrides[_field])) {
70
- return deepHexlify(overrides[_field]);
71
- }
72
- else {
73
- return {
74
- multiplier: Number(overrides[_field].multiplier),
75
- };
76
- }
77
- }
78
- if (isMultiplier(feeOptions?.[field])) {
79
- return {
80
- multiplier: Number(feeOptions[field].multiplier),
81
- };
82
- }
83
- const userOpField = userOperation[field];
84
- if (isHex(userOpField) && fromHex(userOpField, "bigint") > 0n) {
85
- return userOpField;
86
- }
87
- return undefined;
88
- };
89
- function requestGasAndPaymasterData(client, config) {
90
- return {
91
- dummyPaymasterAndData: dummyPaymasterAndData(client, config),
92
- paymasterAndData: async (struct, { overrides: overrides_, feeOptions, account }) => {
93
- const userOperation = deepHexlify(await resolveProperties(struct));
94
- const overrides = filterUndefined({
95
- maxFeePerGas: overrideField("maxFeePerGas", overrides_, feeOptions, userOperation),
96
- maxPriorityFeePerGas: overrideField("maxPriorityFeePerGas", overrides_, feeOptions, userOperation),
97
- callGasLimit: overrideField("callGasLimit", overrides_, feeOptions, userOperation),
98
- verificationGasLimit: overrideField("verificationGasLimit", overrides_, feeOptions, userOperation),
99
- preVerificationGas: overrideField("preVerificationGas", overrides_, feeOptions, userOperation),
100
- });
101
- if (account.getEntryPoint().version === "0.7.0") {
102
- const paymasterVerificationGasLimit = overrideField("paymasterVerificationGasLimit", overrides_, feeOptions, userOperation);
103
- if (paymasterVerificationGasLimit != null) {
104
- overrides.paymasterVerificationGasLimit = paymasterVerificationGasLimit;
105
- }
106
- const paymasterPostOpGasLimit = overrideField("paymasterPostOpGasLimit", overrides_, feeOptions, userOperation);
107
- if (paymasterPostOpGasLimit != null) {
108
- overrides.paymasterPostOpGasLimit = paymasterPostOpGasLimit;
109
- }
110
- }
111
- const result = await client.request({
112
- method: "alchemy_requestGasAndPaymasterAndData",
113
- params: [
114
- {
115
- policyId: config.policyId,
116
- entryPoint: account.getEntryPoint().address,
117
- userOperation,
118
- dummySignature: userOperation.signature,
119
- overrides,
120
- },
121
- ],
122
- });
123
- return {
124
- ...struct,
125
- ...result,
126
- };
127
- },
128
- };
129
- }
130
- const requestPaymasterAndData = (client, config) => ({
131
- dummyPaymasterAndData: dummyPaymasterAndData(client, config),
132
- paymasterAndData: async (struct, { account }) => {
133
- const result = await client.request({
134
- method: "alchemy_requestPaymasterAndData",
135
- params: [
136
- {
137
- policyId: config.policyId,
138
- entryPoint: account.getEntryPoint().address,
139
- userOperation: deepHexlify(await resolveProperties(struct)),
140
- },
141
- ],
142
- });
143
- return {
144
- ...struct,
145
- ...result,
146
- };
147
- },
148
- });
149
7
  //# sourceMappingURL=gasManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gasManager.js","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,8BAA8B,EAC9B,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAY,MAAM,MAAM,CAAC;AAExD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CA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AAU,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,OAAO;oBAC3C,aAAa,EAAE,WAAW,CAAC,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;iBAC5D;aACF;SACF,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,MAAM;YACT,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type {\n Address,\n ClientMiddlewareConfig,\n ClientMiddlewareFn,\n EntryPointVersion,\n Multiplier,\n UserOperationFeeOptions,\n UserOperationOverrides,\n UserOperationRequest,\n} from \"@aa-sdk/core\";\nimport {\n bypassPaymasterAndDataEmptyHex,\n deepHexlify,\n defaultGasEstimator,\n filterUndefined,\n isBigNumberish,\n isMultiplier,\n resolveProperties,\n} from \"@aa-sdk/core\";\nimport { concat, fromHex, isHex, type Hex } from \"viem\";\nimport type { ClientWithAlchemyMethods } from \"../client/types\";\nimport { getAlchemyPaymasterAddress } from \"../gas-manager.js\";\nimport { alchemyFeeEstimator } from \"./feeEstimator.js\";\n\n/**\n * overrides value for [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)\n *\n * @template {EntryPointVersion} TEntryPointVersion entry point version type\n */\nexport type RequestGasAndPaymasterAndDataOverrides<\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion\n> = Partial<\n {\n maxFeePerGas:\n | UserOperationRequest<TEntryPointVersion>[\"maxFeePerGas\"]\n | Multiplier;\n maxPriorityFeePerGas:\n | UserOperationRequest<TEntryPointVersion>[\"maxPriorityFeePerGas\"]\n | Multiplier;\n callGasLimit:\n | UserOperationRequest<TEntryPointVersion>[\"callGasLimit\"]\n | Multiplier;\n verificationGasLimit:\n | UserOperationRequest<TEntryPointVersion>[\"verificationGasLimit\"]\n | Multiplier;\n preVerificationGas:\n | UserOperationRequest<TEntryPointVersion>[\"preVerificationGas\"]\n | Multiplier;\n } & TEntryPointVersion extends \"0.7.0\"\n ? {\n paymasterVerificationGasLimit:\n | UserOperationRequest<\"0.7.0\">[\"paymasterVerificationGasLimit\"]\n | Multiplier;\n paymasterPostOpGasLimit:\n | UserOperationRequest<\"0.7.0\">[\"paymasterPostOpGasLimit\"]\n | Multiplier;\n }\n : {}\n>;\n\n/**\n * [`alchemy-requestpaymasteranddata`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)\n * response type\n *\n * @template {EntryPointVersion} TEntryPointVersion entry point version type\n */\nexport type RequestPaymasterAndDataResponse<\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion\n> = TEntryPointVersion extends \"0.6.0\"\n ? {\n paymasterAndData: UserOperationRequest<\"0.6.0\">[\"paymasterAndData\"];\n }\n : TEntryPointVersion extends \"0.7.0\"\n ? Pick<UserOperationRequest<\"0.7.0\">, \"paymaster\" | \"paymasterData\">\n : {};\n\n/**\n * [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)\n * response type\n *\n * @template {EntryPointVersion} TEntryPointVersion entry point version type\n */\nexport type RequestGasAndPaymasterAndDataResponse<\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion\n> = Pick<\n UserOperationRequest,\n | \"callGasLimit\"\n | \"preVerificationGas\"\n | \"verificationGasLimit\"\n | \"maxFeePerGas\"\n | \"maxPriorityFeePerGas\"\n> &\n RequestPaymasterAndDataResponse<TEntryPointVersion>;\n\n/**\n * Alchemy gas manager configuration with gas policy id and optional gas estimation options\n *\n * To create a Gas Manager Policy, go to the [gas manager](https://dashboard.alchemy.com/gas-manager?a=embedded-accounts-get-started)\n * page of the Alchemy dashboard and click the “Create new policy” button.\n */\nexport interface AlchemyGasManagerConfig {\n /**\n * the policy id of the gas manager you want to use.\n *\n */\n policyId: string;\n /**\n * optional option configurable for the gas estimation portion of the Alchemy gas manager\n *\n */\n gasEstimationOptions?: AlchemyGasEstimationOptions;\n /**\n * paymaster address to use for the gas estimation.\n * If not provided, the default paymaster address for the chain will be used.\n *\n */\n paymasterAddress?: Address;\n /**\n * dummy paymaster data to use for the gas estimation.\n *\n */\n dummyData?: Hex;\n}\n\n/**\n * Alchemy gas manager configuration option configurable for the gas estimation portion of the Alchemy gas manager\n *\n */\nexport interface AlchemyGasEstimationOptions {\n /**\n * disable gas estimation and fallback to the default gas estimation.\n *\n */\n disableGasEstimation: boolean;\n /**\n * optional fallback gas estimator to use when gas estimation is disabled.\n *\n */\n fallbackGasEstimator?: ClientMiddlewareFn;\n /**\n * optional fallback fee estimator to use when gas estimation is disabled.\n *\n */\n fallbackFeeDataGetter?: ClientMiddlewareFn;\n}\n\n/**\n * Dummy paymaster and data middleware for the alchemy gas manager\n *\n * NOTE: right now, this only really works for 0.6.0 unless you pass in overrides in the config for 0.7.0\n *\n * @template {ClientWithAlchemyMethods} C\n * @param {ClientWithAlchemyMethods} client client with alchemy methods\n * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration\n * @returns {() => Hex} the dummyPaymasterAndData middleware for Alchemy gas manager\n */\nconst dummyPaymasterAndData =\n <C extends ClientWithAlchemyMethods>(\n client: C,\n config: AlchemyGasManagerConfig\n ): ClientMiddlewareFn =>\n async (uo) => {\n const paymaster =\n config.paymasterAddress ?? getAlchemyPaymasterAddress(client.chain);\n const paymasterData =\n config.dummyData ??\n \"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n return {\n ...uo,\n paymaster,\n paymasterData,\n paymasterAndData: concat([paymaster, paymasterData]),\n };\n };\n\n/**\n * Alchemy gas manager middleware used as the paymaster middleware overrides param to the client middleware config\n *\n * @template {ClientWithAlchemyMethods} C\n * @param {ClientWithAlchemyMethods} client client with alchemy methods\n * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration\n * @returns {Pick<ClientMiddlewareConfig,\"paymasterAndData\" | \"feeEstimator\" | \"gasEstimator\">} the gas estimator, fee estimator, and paymasterAndData middleware for Alchemy gas manager\n */\nexport function alchemyGasManagerMiddleware<C extends ClientWithAlchemyMethods>(\n client: C,\n config: AlchemyGasManagerConfig\n): Pick<\n ClientMiddlewareConfig,\n \"paymasterAndData\" | \"feeEstimator\" | \"gasEstimator\"\n> {\n const gasEstimationOptions = config.gasEstimationOptions;\n const disableGasEstimation =\n gasEstimationOptions?.disableGasEstimation ?? false;\n const fallbackFeeDataGetter =\n gasEstimationOptions?.fallbackFeeDataGetter ?? alchemyFeeEstimator(client);\n const fallbackGasEstimator =\n gasEstimationOptions?.fallbackGasEstimator ??\n defaultGasEstimator<C>(client);\n\n return {\n gasEstimator: disableGasEstimation\n ? fallbackGasEstimator\n : async (struct, { overrides, account, feeOptions }) => {\n // if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),\n // we cannot delegate gas estimation to the bundler because paymaster middleware will not be called\n if (bypassPaymasterAndDataEmptyHex(overrides)) {\n return {\n ...struct,\n ...(await fallbackGasEstimator(struct, {\n overrides,\n account,\n feeOptions,\n client,\n })),\n };\n }\n\n // essentially noop, because the gas estimation will happen in the backend\n return struct;\n },\n feeEstimator: disableGasEstimation\n ? fallbackFeeDataGetter\n : async (struct, { overrides, account, feeOptions }) => {\n let maxFeePerGas = await struct.maxFeePerGas;\n let maxPriorityFeePerGas = await struct.maxPriorityFeePerGas;\n\n // if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),\n // we cannot delegate gas estimation to the bundler because paymaster middleware will not be called\n if (bypassPaymasterAndDataEmptyHex(overrides)) {\n const result = await fallbackFeeDataGetter(struct, {\n overrides,\n feeOptions,\n account,\n client,\n });\n maxFeePerGas = (await result.maxFeePerGas) ?? maxFeePerGas;\n maxPriorityFeePerGas =\n (await result.maxPriorityFeePerGas) ?? maxPriorityFeePerGas;\n }\n\n return {\n ...struct,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n },\n ...(disableGasEstimation\n ? requestPaymasterAndData(client, config)\n : requestGasAndPaymasterData(client, config)),\n };\n}\n\n/**\n * Utility function to override a field in the user operation request with the overrides or fee options\n *\n * @template {EntryPointVersion} TEntryPointVersion\n * @param {keyof UserOperationFeeOptions<TEntryPointVersion>} field the field to override\n * @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the overrides object\n * @param {UserOperationFeeOptions<TEntryPointVersion> | undefined} feeOptions the fee options object from the client\n * @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request\n * @returns {Hex | Multiplier | undefine} the overridden field value\n */\nconst overrideField = <\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion\n>(\n field: keyof UserOperationFeeOptions<TEntryPointVersion>,\n overrides: UserOperationOverrides<TEntryPointVersion> | undefined,\n feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,\n userOperation: UserOperationRequest<TEntryPointVersion>\n): Hex | Multiplier | undefined => {\n let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;\n\n if (overrides?.[_field] != null) {\n // one-off absolute override\n if (isBigNumberish(overrides[_field])) {\n return deepHexlify(overrides[_field]);\n }\n // one-off multiplier overrides\n else {\n return {\n multiplier: Number((overrides[_field] as Multiplier).multiplier),\n };\n }\n }\n\n // provider level fee options with multiplier\n if (isMultiplier(feeOptions?.[field])) {\n return {\n multiplier: Number((feeOptions![field] as Multiplier).multiplier),\n };\n }\n\n const userOpField =\n userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];\n if (isHex(userOpField) && fromHex(userOpField as Hex, \"bigint\") > 0n) {\n return userOpField;\n }\n return undefined;\n};\n\n/**\n * Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config\n * that calls the [`alchemy_requestGasAndPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)\n *\n * @template {ClientWithAlchemyMethods} C\n * @param {ClientWithAlchemyMethods} client client with alchemy methods\n * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration\n * @returns {ClientMiddlewareConfig[\"paymasterAndData\"]} the paymasterAndData middleware for Alchemy gas manager\n */\nfunction requestGasAndPaymasterData<C extends ClientWithAlchemyMethods>(\n client: C,\n config: AlchemyGasManagerConfig\n): Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\"> {\n return {\n dummyPaymasterAndData: dummyPaymasterAndData(client, config),\n paymasterAndData: async (\n struct,\n { overrides: overrides_, feeOptions, account }\n ) => {\n const userOperation: UserOperationRequest = deepHexlify(\n await resolveProperties(struct)\n );\n\n const overrides: RequestGasAndPaymasterAndDataOverrides = filterUndefined(\n {\n maxFeePerGas: overrideField(\n \"maxFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOperation\n ),\n maxPriorityFeePerGas: overrideField(\n \"maxPriorityFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOperation\n ),\n callGasLimit: overrideField(\n \"callGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOperation\n ),\n verificationGasLimit: overrideField(\n \"verificationGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOperation\n ),\n preVerificationGas: overrideField(\n \"preVerificationGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOperation\n ),\n }\n );\n\n if (account.getEntryPoint().version === \"0.7.0\") {\n const paymasterVerificationGasLimit = overrideField<\"0.7.0\">(\n \"paymasterVerificationGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOperation\n );\n if (paymasterVerificationGasLimit != null) {\n (\n overrides as RequestGasAndPaymasterAndDataOverrides<\"0.7.0\">\n ).paymasterVerificationGasLimit = paymasterVerificationGasLimit;\n }\n\n const paymasterPostOpGasLimit = overrideField<\"0.7.0\">(\n \"paymasterPostOpGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOperation\n );\n if (paymasterPostOpGasLimit != null) {\n (\n overrides as RequestGasAndPaymasterAndDataOverrides<\"0.7.0\">\n ).paymasterPostOpGasLimit = paymasterPostOpGasLimit;\n }\n }\n\n const result = await client.request({\n method: \"alchemy_requestGasAndPaymasterAndData\",\n params: [\n {\n policyId: config.policyId,\n entryPoint: account.getEntryPoint().address,\n userOperation,\n dummySignature: userOperation.signature,\n overrides,\n },\n ],\n });\n\n return {\n ...struct,\n ...result,\n };\n },\n };\n}\n\n/**\n * Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config\n * that calls the [`alchemy_requestPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)\n * with gas estimation disabled.\n *\n * @param {ClientWithAlchemyMethods} client client with alchemy methods\n * @param {AlchemyGasManagerConfig} config alchemy gas manager configuration\n * @returns {ClientMiddlewareConfig[\"paymasterAndData\"]} the paymasterAndData middleware for Alchemy gas manager with gas estimation disabled\n */\nconst requestPaymasterAndData: <C extends ClientWithAlchemyMethods>(\n client: C,\n config: AlchemyGasManagerConfig\n) => Pick<\n ClientMiddlewareConfig,\n \"dummyPaymasterAndData\" | \"paymasterAndData\"\n> = (client, config) => ({\n dummyPaymasterAndData: dummyPaymasterAndData(client, config),\n paymasterAndData: async (struct, { account }) => {\n const result = await client.request({\n method: \"alchemy_requestPaymasterAndData\",\n params: [\n {\n policyId: config.policyId,\n entryPoint: account.getEntryPoint().address,\n userOperation: deepHexlify(await resolveProperties(struct)),\n },\n ],\n });\n\n return {\n ...struct,\n ...result,\n };\n },\n});\n"]}
1
+ {"version":3,"file":"gasManager.js","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAqBjD,MAAM,UAAU,2BAA2B,CACzC,QAAgB;IAEhB,OAAO,iBAAiB,CAAuB;QAC7C,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;KAChC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ClientMiddlewareConfig } from \"@aa-sdk/core\";\nimport { erc7677Middleware } from \"@aa-sdk/core\";\n\n/**\n * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring transactions.\n *\n * @example\n * ```ts\n *\n * import { sepolia } from \"@account-kit/infra\";\n * import { http } from \"viem\";\n *\n * const client = createSmartAccountClient({\n * http(\"rpc-url\"),\n * sepolia,\n * alchemyErc7677Middleware(\"policyId\")\n * );\n * ```\n *\n * @param {string} policyId the policyId for Alchemy's gas manager\n * @returns {Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\">} partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`\n */\nexport function alchemyGasManagerMiddleware(\n policyId: string\n): Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\"> {\n return erc7677Middleware<{ policyId: string }>({\n context: { policyId: policyId },\n });\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.0-alpha.6";
1
+ export declare const VERSION = "4.0.0-alpha.8";
@@ -1,2 +1,2 @@
1
- export const VERSION = "4.0.0-alpha.6";
1
+ export const VERSION = "4.0.0-alpha.8";
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.0.0-alpha.6\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.0.0-alpha.8\";\n"]}