@account-kit/infra 4.0.0-alpha.0 → 4.0.0-alpha.2

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 (101) hide show
  1. package/dist/cjs/actions/simulateUserOperationChanges.js.map +1 -1
  2. package/dist/cjs/chains.d.ts +23 -0
  3. package/dist/cjs/chains.js +166 -1
  4. package/dist/cjs/chains.js.map +1 -1
  5. package/dist/cjs/client/decorators/alchemyEnhancedApis.d.ts +5537 -1
  6. package/dist/cjs/client/decorators/alchemyEnhancedApis.js.map +1 -1
  7. package/dist/cjs/client/decorators/smartAccount.js.map +1 -1
  8. package/dist/cjs/client/internal/smartAccountClientFromRpc.d.ts +2 -2
  9. package/dist/cjs/client/internal/smartAccountClientFromRpc.js +2 -1
  10. package/dist/cjs/client/internal/smartAccountClientFromRpc.js.map +1 -1
  11. package/dist/cjs/client/isAlchemySmartAccountClient.d.ts +128 -128
  12. package/dist/cjs/client/isAlchemySmartAccountClient.js.map +1 -1
  13. package/dist/cjs/client/rpcClient.js.map +1 -1
  14. package/dist/cjs/client/smartAccountClient.js.map +1 -1
  15. package/dist/cjs/defaults.js +7 -7
  16. package/dist/cjs/defaults.js.map +1 -1
  17. package/dist/cjs/gas-manager.js +16 -16
  18. package/dist/cjs/gas-manager.js.map +1 -1
  19. package/dist/cjs/index.d.ts +2 -1
  20. package/dist/cjs/index.js +20 -1
  21. package/dist/cjs/index.js.map +1 -1
  22. package/dist/cjs/middleware/feeEstimator.js.map +1 -1
  23. package/dist/cjs/middleware/gasManager.js.map +1 -1
  24. package/dist/cjs/middleware/userOperationSimulator.js.map +1 -1
  25. package/dist/cjs/schema.js +2 -9
  26. package/dist/cjs/schema.js.map +1 -1
  27. package/dist/cjs/version.d.ts +1 -1
  28. package/dist/cjs/version.js +1 -1
  29. package/dist/cjs/version.js.map +1 -1
  30. package/dist/esm/actions/simulateUserOperationChanges.js.map +1 -1
  31. package/dist/esm/chains.d.ts +23 -0
  32. package/dist/esm/chains.js +165 -0
  33. package/dist/esm/chains.js.map +1 -1
  34. package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +5537 -1
  35. package/dist/esm/client/decorators/alchemyEnhancedApis.js.map +1 -1
  36. package/dist/esm/client/decorators/smartAccount.js.map +1 -1
  37. package/dist/esm/client/internal/smartAccountClientFromRpc.d.ts +2 -2
  38. package/dist/esm/client/internal/smartAccountClientFromRpc.js +2 -1
  39. package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +1 -1
  40. package/dist/esm/client/isAlchemySmartAccountClient.d.ts +128 -128
  41. package/dist/esm/client/isAlchemySmartAccountClient.js.map +1 -1
  42. package/dist/esm/client/rpcClient.js.map +1 -1
  43. package/dist/esm/client/smartAccountClient.js.map +1 -1
  44. package/dist/esm/defaults.js +2 -1
  45. package/dist/esm/defaults.js.map +1 -1
  46. package/dist/esm/gas-manager.js +1 -1
  47. package/dist/esm/gas-manager.js.map +1 -1
  48. package/dist/esm/index.d.ts +2 -1
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/middleware/feeEstimator.js.map +1 -1
  52. package/dist/esm/middleware/gasManager.js.map +1 -1
  53. package/dist/esm/middleware/userOperationSimulator.js.map +1 -1
  54. package/dist/esm/schema.js +3 -10
  55. package/dist/esm/schema.js.map +1 -1
  56. package/dist/esm/version.d.ts +1 -1
  57. package/dist/esm/version.js +1 -1
  58. package/dist/esm/version.js.map +1 -1
  59. package/dist/types/actions/simulateUserOperationChanges.d.ts +17 -0
  60. package/dist/types/actions/simulateUserOperationChanges.d.ts.map +1 -1
  61. package/dist/types/chains.d.ts +42 -0
  62. package/dist/types/chains.d.ts.map +1 -1
  63. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +5554 -1
  64. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -1
  65. package/dist/types/client/decorators/smartAccount.d.ts +15 -0
  66. package/dist/types/client/decorators/smartAccount.d.ts.map +1 -1
  67. package/dist/types/client/internal/smartAccountClientFromRpc.d.ts +2 -2
  68. package/dist/types/client/internal/smartAccountClientFromRpc.d.ts.map +1 -1
  69. package/dist/types/client/isAlchemySmartAccountClient.d.ts +143 -128
  70. package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -1
  71. package/dist/types/client/rpcClient.d.ts +22 -0
  72. package/dist/types/client/rpcClient.d.ts.map +1 -1
  73. package/dist/types/defaults.d.ts +14 -0
  74. package/dist/types/defaults.d.ts.map +1 -1
  75. package/dist/types/gas-manager.d.ts +13 -0
  76. package/dist/types/gas-manager.d.ts.map +1 -1
  77. package/dist/types/index.d.ts +2 -1
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/types/middleware/feeEstimator.d.ts +19 -0
  80. package/dist/types/middleware/feeEstimator.d.ts.map +1 -1
  81. package/dist/types/middleware/userOperationSimulator.d.ts +19 -0
  82. package/dist/types/middleware/userOperationSimulator.d.ts.map +1 -1
  83. package/dist/types/schema.d.ts.map +1 -1
  84. package/dist/types/version.d.ts +1 -1
  85. package/package.json +3 -3
  86. package/src/actions/simulateUserOperationChanges.ts +17 -0
  87. package/src/chains.ts +219 -0
  88. package/src/client/decorators/alchemyEnhancedApis.ts +50 -33
  89. package/src/client/decorators/smartAccount.ts +15 -0
  90. package/src/client/internal/smartAccountClientFromRpc.ts +33 -13
  91. package/src/client/isAlchemySmartAccountClient.ts +15 -0
  92. package/src/client/rpcClient.ts +22 -0
  93. package/src/client/smartAccountClient.ts +17 -0
  94. package/src/defaults.ts +17 -3
  95. package/src/gas-manager.ts +17 -4
  96. package/src/index.ts +23 -1
  97. package/src/middleware/feeEstimator.ts +19 -0
  98. package/src/middleware/gasManager.ts +1 -1
  99. package/src/middleware/userOperationSimulator.ts +19 -0
  100. package/src/schema.ts +2 -10
  101. package/src/version.ts +1 -1
@@ -17,7 +17,7 @@ import type {
17
17
  } from "../smartAccountClient.js";
18
18
  import type { ClientWithAlchemyMethods } from "../types.js";
19
19
 
20
- export type CreateAlchemySmartAccountClientFromRpcClient<
20
+ export type CreateAlchemySmartAccountClientFromRpcClientParams<
21
21
  TAccount extends SmartContractAccount | undefined =
22
22
  | SmartContractAccount
23
23
  | undefined,
@@ -51,7 +51,7 @@ export function createAlchemySmartAccountClientFromRpcClient<
51
51
  | UserOperationContext
52
52
  | undefined
53
53
  >(
54
- args: CreateAlchemySmartAccountClientFromRpcClient<TAccount, TContext>
54
+ args: CreateAlchemySmartAccountClientFromRpcClientParams<TAccount, TContext>
55
55
  ): AlchemySmartAccountClient<
56
56
  CustomTransport,
57
57
  TChain,
@@ -60,17 +60,37 @@ export function createAlchemySmartAccountClientFromRpcClient<
60
60
  TContext
61
61
  >;
62
62
 
63
- export function createAlchemySmartAccountClientFromRpcClient({
64
- opts,
65
- account,
66
- useSimulation,
67
- gasManagerConfig,
68
- feeEstimator,
69
- gasEstimator,
70
- customMiddleware,
71
- signUserOperation,
72
- client,
73
- }: CreateAlchemySmartAccountClientFromRpcClient): AlchemySmartAccountClient {
63
+ /**
64
+ * Creates an AlchemySmartAccountClient using the provided RPC client configuration, including options, account, simulation settings, gas management, fee estimation, middleware and user operation signing.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { createAlchemySmartAccountClientFromRpcClient, createAlchemyPublicRpcClient } from "@account-kit/infra";
69
+ *
70
+ * const client = createAlchemyPublicRpcClient(...);
71
+ * const scaClient = createAlchemySmartAccountClientFromRpcClient({
72
+ * client,
73
+ * ...
74
+ * });
75
+ * ```
76
+ *
77
+ * @param {CreateAlchemySmartAccountClientFromRpcClientParams} args The configuration object containing all required parameters
78
+ * @returns {AlchemySmartAccountClient} An instance of AlchemySmartAccountClient
79
+ */
80
+ export function createAlchemySmartAccountClientFromRpcClient(
81
+ args: CreateAlchemySmartAccountClientFromRpcClientParams
82
+ ): AlchemySmartAccountClient {
83
+ const {
84
+ opts,
85
+ account,
86
+ useSimulation,
87
+ gasManagerConfig,
88
+ feeEstimator,
89
+ gasEstimator,
90
+ customMiddleware,
91
+ signUserOperation,
92
+ client,
93
+ } = args;
74
94
  const feeOptions =
75
95
  opts?.feeOptions ?? getDefaultUserOperationFeeOptions(client.chain);
76
96
 
@@ -2,6 +2,21 @@ import { isSmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
2
  import type { Chain, Client, Transport } from "viem";
3
3
  import type { AlchemySmartAccountClient } from "./smartAccountClient";
4
4
 
5
+ /**
6
+ * Checks if a given client is an Alchemy Smart Account Client. The goal of this check is to ensure that the client supports certain RPC methods.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { isAlchemySmartAccountClient } from "@account-kit/infra";
11
+ *
12
+ * if (isAlchemySmartAccountClient(client)) {
13
+ * // do things with the client as an Alchemy Smart Account Client
14
+ * }
15
+ * ```
16
+ *
17
+ * @param {Client<TTransport, TChain, TAccount>} client The client instance to be checked
18
+ * @returns {boolean} `true` if the client is an Alchemy Smart Account Client, otherwise `false`
19
+ */
5
20
  export const isAlchemySmartAccountClient = <
6
21
  TTransport extends Transport = Transport,
7
22
  TChain extends Chain | undefined = Chain | undefined,
@@ -8,6 +8,28 @@ import { AlchemyChainSchema } from "../schema.js";
8
8
  import { VERSION } from "../version.js";
9
9
  import type { ClientWithAlchemyMethods } from "./types.js";
10
10
 
11
+ /**
12
+ * Creates an Alchemy public RPC client with the provided chain, connection configuration, and optional fetch options. The client has alchemy methods and can dynamically update HTTP headers.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { createAlchemyPublicRpcClient } from "@account-kit/infra";
17
+ * import { sepolia } from "@account-kit/infra";
18
+ *
19
+ * const client = createAlchemyPublicRpcClient({
20
+ * chain: sepolia,
21
+ * connectionConfig: {
22
+ * apiKey: "your-api-key",
23
+ * }
24
+ * });
25
+ * ```
26
+ *
27
+ * @param {{connectionConfig: ConnectionConfig,chain: Chain,fetchOptions?: NoUndefined<HttpTransportConfig["fetchOptions"]>}} params The parameters for creating the Alchemy public RPC client
28
+ * @param {ConnectionConfig} params.connectionConfig The connection configuration containing the RPC URL and API key
29
+ * @param {Chain} params.chain The blockchain chain configuration
30
+ * @param {NoUndefined<HttpTransportConfig["fetchOptions"]>} [params.fetchOptions] Optional fetch configuration for HTTP transport
31
+ * @returns {ClientWithAlchemyMethods} A client object tailored with Alchemy methods and capabilities to interact with the blockchain
32
+ */
11
33
  export const createAlchemyPublicRpcClient = ({
12
34
  chain: chain_,
13
35
  connectionConfig,
@@ -115,6 +115,23 @@ export function createAlchemySmartAccountClient<
115
115
  TContext
116
116
  >;
117
117
 
118
+ /**
119
+ * Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { createAlchemySmartAccountClient } from "@account-kit/infra";
124
+ * import { sepolia } from "@account-kit/infra/chain";
125
+ *
126
+ * const client = createAlchemySmartAccountClient({
127
+ * chain: sepolia,
128
+ * apiKey: "your-api-key",
129
+ * });
130
+ * ```
131
+ *
132
+ * @param {AlchemySmartAccountClientConfig} config The configuration for creating the Alchemy smart account client
133
+ * @returns {AlchemySmartAccountClient} An instance of `AlchemySmartAccountClient` configured based on the provided options
134
+ */
118
135
  export function createAlchemySmartAccountClient({
119
136
  account,
120
137
  gasManagerConfig,
package/src/defaults.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { type UserOperationFeeOptions } from "@aa-sdk/core";
2
+ import type { Chain } from "viem";
1
3
  import {
2
4
  arbitrum,
3
5
  arbitrumGoerli,
@@ -5,10 +7,22 @@ import {
5
7
  optimism,
6
8
  optimismGoerli,
7
9
  optimismSepolia,
8
- type UserOperationFeeOptions,
9
- } from "@aa-sdk/core";
10
- import type { Chain } from "viem";
10
+ } from "./chains.js";
11
11
 
12
+ /**
13
+ * Retrieves the default user operation fee options for a given chain. Adjusts fees for specific chains like Arbitrum and Optimism.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { getDefaultUserOperationFeeOptions } from "@account-kit/infra";
18
+ * import { arbitrum } from "@account-kit/infra";
19
+ *
20
+ * const feeOpts = getDefaultUserOperationFeeOptions(arbitrum);
21
+ * ```
22
+ *
23
+ * @param {Chain} chain The blockchain chain for which to get the fee options
24
+ * @returns {UserOperationFeeOptions} An object containing the default fee options for user operations on the specified chain
25
+ */
12
26
  export const getDefaultUserOperationFeeOptions = (
13
27
  chain: Chain
14
28
  ): UserOperationFeeOptions => {
@@ -4,18 +4,18 @@ import {
4
4
  arbitrumSepolia,
5
5
  base,
6
6
  baseSepolia,
7
+ fraxtal,
8
+ fraxtalSepolia,
7
9
  mainnet,
8
- sepolia,
9
10
  optimism,
10
11
  optimismSepolia,
11
12
  polygon,
12
13
  polygonAmoy,
13
14
  polygonMumbai,
14
- fraxtal,
15
- fraxtalSepolia,
15
+ sepolia,
16
16
  zora,
17
17
  zoraSepolia,
18
- } from "@aa-sdk/core";
18
+ } from "./chains.js";
19
19
 
20
20
  export const AlchemyPaymasterAddressV3 =
21
21
  "0x4f84a207A80c39E9e8BaE717c1F25bA7AD1fB08F";
@@ -26,6 +26,19 @@ export const ArbSepoliaPaymasterAddress =
26
26
  export const AlchemyPaymasterAddressV1 =
27
27
  "0xc03aac639bb21233e0139381970328db8bceeb67";
28
28
 
29
+ /**
30
+ * Retrieves the Alchemy paymaster address for the given chain. Returns different addresses based on the chain ID.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { sepolia, getAlchemyPaymasterAddress } from "@account-kit/infra";
35
+ *
36
+ * const paymasterAddress = getAlchemyPaymasterAddress(sepolia);
37
+ * ```
38
+ *
39
+ * @param {Chain} chain The chain for which the paymaster address is required
40
+ * @returns {Address} The Alchemy paymaster address corresponding to the specified chain
41
+ */
29
42
  export const getAlchemyPaymasterAddress = (chain: Chain): Address => {
30
43
  switch (chain.id) {
31
44
  case polygonAmoy.id:
package/src/index.ts CHANGED
@@ -1,7 +1,29 @@
1
1
  export type * from "./actions/simulateUserOperationChanges.js";
2
2
  export { simulateUserOperationChanges } from "./actions/simulateUserOperationChanges.js";
3
3
  export type * from "./actions/types.js";
4
- export { defineAlchemyChain } from "./chains.js";
4
+ export type * from "./chains.js";
5
+ export {
6
+ arbitrum,
7
+ arbitrumGoerli,
8
+ arbitrumSepolia,
9
+ base,
10
+ baseGoerli,
11
+ baseSepolia,
12
+ defineAlchemyChain,
13
+ fraxtal,
14
+ fraxtalSepolia,
15
+ goerli,
16
+ mainnet,
17
+ optimism,
18
+ optimismGoerli,
19
+ optimismSepolia,
20
+ polygon,
21
+ polygonAmoy,
22
+ polygonMumbai,
23
+ sepolia,
24
+ zora,
25
+ zoraSepolia,
26
+ } from "./chains.js";
5
27
  export type * from "./client/decorators/alchemyEnhancedApis.js";
6
28
  export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
7
29
  export type * from "./client/decorators/smartAccount.js";
@@ -2,6 +2,25 @@ import type { ClientMiddlewareFn } from "@aa-sdk/core";
2
2
  import { applyUserOpOverrideOrFeeOption } from "@aa-sdk/core";
3
3
  import type { ClientWithAlchemyMethods } from "../client/types";
4
4
 
5
+ /**
6
+ * Function that estimates the transaction fees using Alchemy methods for a given client.
7
+ * It fetches the latest block and estimates the max priority fee per gas, applying any overrides or fee options provided.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { alchemyFeeEstimator, createAlchemyPublicRpcClient } from "@account-kit/infra";
12
+ * import { createSmartAccountClient } from "@aa-sdk/core";
13
+ *
14
+ * const bundlerClient = createAlchemyPublicRpcClient(...);
15
+ * const client = createSmartAccountClient({
16
+ * feeEstimator: alchemyFeeEstimator(bundlerClient),
17
+ * ...otherParams
18
+ * });
19
+ * ```
20
+ *
21
+ * @param {ClientWithAlchemyMethods} client The client with Alchemy methods
22
+ * @returns {ClientMiddlewareFn} A middleware function that takes a transaction structure and fee options, and returns the augmented structure with estimated fees
23
+ */
5
24
  export const alchemyFeeEstimator: <C extends ClientWithAlchemyMethods>(
6
25
  client: C
7
26
  ) => ClientMiddlewareFn =
@@ -145,7 +145,7 @@ export interface AlchemyGasEstimationOptions {
145
145
  }
146
146
 
147
147
  /**
148
- * dummy paymaster and data middleware for the alchemy gas manager
148
+ * Dummy paymaster and data middleware for the alchemy gas manager
149
149
  *
150
150
  * @template {ClientWithAlchemyMethods} C
151
151
  * @param client client with alchemy methods
@@ -5,6 +5,25 @@ import {
5
5
  } from "@aa-sdk/core";
6
6
  import type { ClientWithAlchemyMethods } from "../client/types";
7
7
 
8
+ /**
9
+ * A middleware function to be used during simulation of user operations which leverages Alchemy's RPC uo simulation method.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { alchemyUserOperationSimulator, createAlchemyPublicRpcClient } from "@account-kit/infra";
14
+ * import { createSmartAccountClient } from "@aa-sdk/core";
15
+ *
16
+ * const bundlerClient = createAlchemyPublicRpcClient(...);
17
+ * const client = createSmartAccountClient({
18
+ * userOperationSimulator: alchemyUserOperationSimulator(bundlerClient),
19
+ * ...otherParams
20
+ * });
21
+ * ```
22
+ *
23
+ * @template C The client object with Alchemy methods
24
+ * @param {C} client The client object with Alchemy methods
25
+ * @returns {ClientMiddlewareFn} A middleware function to simulate and process user operations
26
+ */
8
27
  export function alchemyUserOperationSimulator<
9
28
  C extends ClientWithAlchemyMethods
10
29
  >(client: C): ClientMiddlewareFn {
package/src/schema.ts CHANGED
@@ -2,23 +2,15 @@ import {
2
2
  ChainSchema,
3
3
  ConnectionConfigSchema,
4
4
  SmartAccountClientOptsSchema,
5
- getChain,
6
5
  } from "@aa-sdk/core";
7
6
  import { Alchemy } from "alchemy-sdk";
8
7
  import type { Chain } from "viem";
9
8
  import z from "zod";
10
9
 
11
10
  export const AlchemyChainSchema = z.custom<Chain>((chain) => {
12
- const _chain = ChainSchema.parse(chain);
11
+ const chain_ = ChainSchema.parse(chain);
13
12
 
14
- let chainObject;
15
- try {
16
- chainObject = getChain(_chain.id);
17
- } catch {
18
- return false;
19
- }
20
-
21
- return chainObject.rpcUrls.alchemy != null;
13
+ return chain_.rpcUrls.alchemy != null;
22
14
  }, "chain must include an alchemy rpc url. See `createAlchemyChain` or use the `AlchemyChainMap` exported from `@aa-sdk/core`");
23
15
 
24
16
  export const AlchemyProviderConfigSchema = ConnectionConfigSchema.and(
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.0";
3
+ export const VERSION = "4.0.0-alpha.2";