@account-kit/infra 4.0.0-beta.0 → 4.0.0-beta.10

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 (102) hide show
  1. package/dist/esm/alchemyTransport.d.ts +69 -0
  2. package/dist/esm/alchemyTransport.js +139 -0
  3. package/dist/esm/alchemyTransport.js.map +1 -0
  4. package/dist/esm/chains.d.ts +1 -0
  5. package/dist/esm/chains.js +17 -0
  6. package/dist/esm/chains.js.map +1 -1
  7. package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +2 -2
  8. package/dist/esm/client/decorators/alchemyEnhancedApis.js +3 -7
  9. package/dist/esm/client/decorators/alchemyEnhancedApis.js.map +1 -1
  10. package/dist/esm/client/decorators/smartAccount.d.ts +7 -4
  11. package/dist/esm/client/decorators/smartAccount.js +33 -0
  12. package/dist/esm/client/decorators/smartAccount.js.map +1 -1
  13. package/dist/esm/client/isAlchemySmartAccountClient.d.ts +1 -1
  14. package/dist/esm/client/isAlchemySmartAccountClient.js +2 -6
  15. package/dist/esm/client/isAlchemySmartAccountClient.js.map +1 -1
  16. package/dist/esm/client/rpcClient.d.ts +9 -10
  17. package/dist/esm/client/rpcClient.js +9 -33
  18. package/dist/esm/client/rpcClient.js.map +1 -1
  19. package/dist/esm/client/smartAccountClient.d.ts +12 -9
  20. package/dist/esm/client/smartAccountClient.js +34 -20
  21. package/dist/esm/client/smartAccountClient.js.map +1 -1
  22. package/dist/esm/client/types.d.ts +8 -7
  23. package/dist/esm/client/types.js.map +1 -1
  24. package/dist/esm/index.d.ts +3 -4
  25. package/dist/esm/index.js +2 -3
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/metrics.d.ts +12 -0
  28. package/dist/esm/metrics.js +7 -0
  29. package/dist/esm/metrics.js.map +1 -0
  30. package/dist/esm/middleware/feeEstimator.d.ts +10 -6
  31. package/dist/esm/middleware/feeEstimator.js +11 -6
  32. package/dist/esm/middleware/feeEstimator.js.map +1 -1
  33. package/dist/esm/middleware/gasManager.d.ts +5 -6
  34. package/dist/esm/middleware/gasManager.js +5 -6
  35. package/dist/esm/middleware/gasManager.js.map +1 -1
  36. package/dist/esm/middleware/userOperationSimulator.d.ts +11 -7
  37. package/dist/esm/middleware/userOperationSimulator.js +12 -8
  38. package/dist/esm/middleware/userOperationSimulator.js.map +1 -1
  39. package/dist/esm/schema.d.ts +0 -391
  40. package/dist/esm/schema.js +1 -5
  41. package/dist/esm/schema.js.map +1 -1
  42. package/dist/esm/version.d.ts +1 -1
  43. package/dist/esm/version.js +1 -1
  44. package/dist/esm/version.js.map +1 -1
  45. package/dist/types/alchemyTransport.d.ts +70 -0
  46. package/dist/types/alchemyTransport.d.ts.map +1 -0
  47. package/dist/types/chains.d.ts +1 -0
  48. package/dist/types/chains.d.ts.map +1 -1
  49. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +2 -2
  50. package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -1
  51. package/dist/types/client/decorators/smartAccount.d.ts +7 -4
  52. package/dist/types/client/decorators/smartAccount.d.ts.map +1 -1
  53. package/dist/types/client/isAlchemySmartAccountClient.d.ts +1 -1
  54. package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -1
  55. package/dist/types/client/rpcClient.d.ts +9 -10
  56. package/dist/types/client/rpcClient.d.ts.map +1 -1
  57. package/dist/types/client/smartAccountClient.d.ts +12 -9
  58. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  59. package/dist/types/client/types.d.ts +8 -7
  60. package/dist/types/client/types.d.ts.map +1 -1
  61. package/dist/types/index.d.ts +3 -4
  62. package/dist/types/index.d.ts.map +1 -1
  63. package/dist/types/metrics.d.ts +13 -0
  64. package/dist/types/metrics.d.ts.map +1 -0
  65. package/dist/types/middleware/feeEstimator.d.ts +10 -6
  66. package/dist/types/middleware/feeEstimator.d.ts.map +1 -1
  67. package/dist/types/middleware/gasManager.d.ts +5 -6
  68. package/dist/types/middleware/gasManager.d.ts.map +1 -1
  69. package/dist/types/middleware/userOperationSimulator.d.ts +11 -7
  70. package/dist/types/middleware/userOperationSimulator.d.ts.map +1 -1
  71. package/dist/types/schema.d.ts +0 -391
  72. package/dist/types/schema.d.ts.map +1 -1
  73. package/dist/types/version.d.ts +1 -1
  74. package/dist/types/version.d.ts.map +1 -1
  75. package/package.json +6 -10
  76. package/src/alchemyTransport.ts +214 -0
  77. package/src/chains.ts +18 -0
  78. package/src/client/decorators/alchemyEnhancedApis.ts +9 -16
  79. package/src/client/decorators/smartAccount.ts +77 -7
  80. package/src/client/isAlchemySmartAccountClient.ts +4 -9
  81. package/src/client/rpcClient.ts +14 -47
  82. package/src/client/smartAccountClient.ts +64 -57
  83. package/src/client/types.ts +10 -7
  84. package/src/index.ts +8 -8
  85. package/src/metrics.ts +19 -0
  86. package/src/middleware/feeEstimator.ts +15 -10
  87. package/src/middleware/gasManager.ts +5 -6
  88. package/src/middleware/userOperationSimulator.ts +13 -10
  89. package/src/schema.ts +1 -14
  90. package/src/version.ts +1 -1
  91. package/dist/esm/client/internal/smartAccountClientFromRpc.d.ts +0 -18
  92. package/dist/esm/client/internal/smartAccountClientFromRpc.js +0 -56
  93. package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +0 -1
  94. package/dist/esm/type.d.ts +0 -3
  95. package/dist/esm/type.js +0 -2
  96. package/dist/esm/type.js.map +0 -1
  97. package/dist/types/client/internal/smartAccountClientFromRpc.d.ts +0 -19
  98. package/dist/types/client/internal/smartAccountClientFromRpc.d.ts.map +0 -1
  99. package/dist/types/type.d.ts +0 -4
  100. package/dist/types/type.d.ts.map +0 -1
  101. package/src/client/internal/smartAccountClientFromRpc.ts +0 -125
  102. package/src/type.ts +0 -4
package/src/chains.ts CHANGED
@@ -310,6 +310,24 @@ export const shape: Chain = defineChain({
310
310
  },
311
311
  });
312
312
 
313
+ export const beraChainBartio: Chain = defineChain({
314
+ id: 80084,
315
+ name: "BeraChain Bartio",
316
+ network: "BeraChain Bartio",
317
+ nativeCurrency: { name: "Bera", symbol: "BERA", decimals: 18 },
318
+ rpcUrls: {
319
+ default: {
320
+ http: ["https://berachain-bartio.g.alchemy.com/v2"],
321
+ },
322
+ public: {
323
+ http: ["https://berachain-bartio.g.alchemy.com/v2"],
324
+ },
325
+ alchemy: {
326
+ http: ["https://berachain-bartio.g.alchemy.com/v2"],
327
+ },
328
+ },
329
+ });
330
+
313
331
  export const arbitrumNova: Chain = {
314
332
  ...vabn,
315
333
  rpcUrls: {
@@ -1,6 +1,6 @@
1
1
  import type { SmartContractAccount } from "@aa-sdk/core";
2
2
  import type { Alchemy } from "alchemy-sdk";
3
- import type { Chain, HttpTransport, Transport } from "viem";
3
+ import type { Chain } from "viem";
4
4
  import { AlchemySdkClientSchema } from "../../schema.js";
5
5
  import type { AlchemySmartAccountClient } from "../smartAccountClient.js";
6
6
 
@@ -34,30 +34,23 @@ export type AlchemyEnhancedApis = {
34
34
  export function alchemyEnhancedApiActions(
35
35
  alchemy: Alchemy
36
36
  ): <
37
- TTransport extends Transport = Transport,
38
37
  TChain extends Chain | undefined = Chain | undefined,
39
38
  TAccount extends SmartContractAccount | undefined =
40
39
  | SmartContractAccount
41
40
  | undefined
42
41
  >(
43
- client: AlchemySmartAccountClient<TTransport, TChain, TAccount>
42
+ client: AlchemySmartAccountClient<TChain, TAccount>
44
43
  ) => AlchemyEnhancedApis {
45
44
  return (client) => {
46
45
  const alchemySdk = AlchemySdkClientSchema.parse(alchemy);
47
46
 
48
- if (client.transport.type === "http") {
49
- const { url } = client.transport as ReturnType<HttpTransport>["config"] &
50
- ReturnType<HttpTransport>["value"];
51
-
52
- if (
53
- client.transport.type === "http" &&
54
- alchemy.config.url &&
55
- alchemy.config.url !== url
56
- ) {
57
- throw new Error(
58
- "Alchemy SDK client JSON-RPC URL must match AlchemyProvider JSON-RPC URL"
59
- );
60
- }
47
+ if (
48
+ alchemy.config.url &&
49
+ alchemy.config.url !== client.transport.alchemyRpcUrl
50
+ ) {
51
+ throw new Error(
52
+ "Alchemy SDK client JSON-RPC URL must match AlchemyProvider JSON-RPC URL"
53
+ );
61
54
  }
62
55
 
63
56
  return {
@@ -1,11 +1,26 @@
1
- import type {
2
- SendUserOperationParameters,
3
- SmartContractAccount,
4
- UserOperationContext,
1
+ import {
2
+ isSmartAccountWithSigner,
3
+ sendTransaction,
4
+ sendTransactions,
5
+ sendUserOperation,
6
+ type GetEntryPointFromAccount,
7
+ type SendTransactionsParameters,
8
+ type SendUserOperationParameters,
9
+ type SendUserOperationResult,
10
+ type SmartContractAccount,
11
+ type UserOperationContext,
12
+ type UserOperationOverrides,
5
13
  } from "@aa-sdk/core";
6
- import type { Chain, Client, Transport } from "viem";
14
+ import type {
15
+ Chain,
16
+ Client,
17
+ Hex,
18
+ SendTransactionParameters,
19
+ Transport,
20
+ } from "viem";
7
21
  import { simulateUserOperationChanges } from "../../actions/simulateUserOperationChanges.js";
8
22
  import type { SimulateUserOperationAssetChangesResponse } from "../../actions/types.js";
23
+ import { InfraLogger } from "../../metrics.js";
9
24
 
10
25
  export type AlchemySmartAccountClientActions<
11
26
  TAccount extends SmartContractAccount | undefined =
@@ -13,11 +28,28 @@ export type AlchemySmartAccountClientActions<
13
28
  | undefined,
14
29
  TContext extends UserOperationContext | undefined =
15
30
  | UserOperationContext
16
- | undefined
31
+ | undefined,
32
+ TChain extends Chain | undefined = Chain | undefined,
33
+ TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
17
34
  > = {
18
35
  simulateUserOperation: (
19
36
  args: SendUserOperationParameters<TAccount, TContext>
20
37
  ) => Promise<SimulateUserOperationAssetChangesResponse>;
38
+ sendUserOperation: (
39
+ args: SendUserOperationParameters<
40
+ TAccount,
41
+ TContext,
42
+ GetEntryPointFromAccount<TAccount>
43
+ >
44
+ ) => Promise<SendUserOperationResult<TEntryPointVersion>>;
45
+ sendTransaction: <TChainOverride extends Chain | undefined = undefined>(
46
+ args: SendTransactionParameters<TChain, TAccount, TChainOverride>,
47
+ overrides?: UserOperationOverrides<TEntryPointVersion>,
48
+ context?: TContext
49
+ ) => Promise<Hex>;
50
+ sendTransactions: (
51
+ args: SendTransactionsParameters<TAccount, TContext>
52
+ ) => Promise<Hex>;
21
53
  };
22
54
 
23
55
  /**
@@ -46,7 +78,45 @@ export const alchemyActions: <
46
78
  | undefined
47
79
  >(
48
80
  client: Client<TTransport, TChain, TAccount>
49
- ) => AlchemySmartAccountClientActions<TAccount, TContext> = (client) => ({
81
+ ) => AlchemySmartAccountClientActions<TAccount, TContext, TChain> = (
82
+ client
83
+ ) => ({
50
84
  simulateUserOperation: async (args) =>
51
85
  simulateUserOperationChanges(client, args),
86
+ sendUserOperation: async (args) => {
87
+ const { account = client.account } = args;
88
+
89
+ const result = sendUserOperation(client, args);
90
+ logSendUoEvent(client.chain!.id, account!);
91
+ return result;
92
+ },
93
+ sendTransaction: async (args, overrides, context) => {
94
+ const { account = client.account } = args;
95
+
96
+ const result = await sendTransaction(client, args, overrides, context);
97
+ logSendUoEvent(client.chain!.id, account as SmartContractAccount);
98
+ return result;
99
+ },
100
+ async sendTransactions(args) {
101
+ const { account = client.account } = args;
102
+
103
+ const result = sendTransactions(client, args);
104
+ logSendUoEvent(client.chain!.id, account!);
105
+ return result;
106
+ },
52
107
  });
108
+
109
+ function logSendUoEvent(chainId: number, account: SmartContractAccount) {
110
+ const signerType = isSmartAccountWithSigner(account)
111
+ ? account.getSigner().signerType
112
+ : "unknown";
113
+
114
+ InfraLogger.trackEvent({
115
+ name: "client_send_uo",
116
+ data: {
117
+ chainId,
118
+ signerType: signerType,
119
+ entryPoint: account.getEntryPoint().address,
120
+ },
121
+ });
122
+ }
@@ -1,4 +1,4 @@
1
- import { isSmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
1
+ import { type SmartContractAccount } from "@aa-sdk/core";
2
2
  import type { Chain, Client, Transport } from "viem";
3
3
  import type { AlchemySmartAccountClient } from "./smartAccountClient";
4
4
 
@@ -18,17 +18,12 @@ import type { AlchemySmartAccountClient } from "./smartAccountClient";
18
18
  * @returns {boolean} `true` if the client is an Alchemy Smart Account Client, otherwise `false`
19
19
  */
20
20
  export function isAlchemySmartAccountClient<
21
- TTransport extends Transport = Transport,
22
21
  TChain extends Chain | undefined = Chain | undefined,
23
22
  TAccount extends SmartContractAccount | undefined =
24
23
  | SmartContractAccount
25
24
  | undefined
26
25
  >(
27
- client: Client<TTransport, TChain, TAccount>
28
- ): client is AlchemySmartAccountClient<TTransport, TChain, TAccount> {
29
- // TODO: the goal of this check is to make sure that the client supports certain RPC methods
30
- // we should probably do this by checking the client's transport and configured URL, since alchemy
31
- // clients have to be RPC clients. this is difficult to do though because the transport might
32
- // point to a proxy url :/
33
- return isSmartAccountClient(client);
26
+ client: Client<Transport, TChain, TAccount>
27
+ ): client is AlchemySmartAccountClient<TChain, TAccount> {
28
+ return client.transport.type === "alchemy";
34
29
  }
@@ -1,11 +1,6 @@
1
- import {
2
- createBundlerClient,
3
- type ConnectionConfig,
4
- type NoUndefined,
5
- } from "@aa-sdk/core";
6
- import { http, type Chain, type HttpTransportConfig } from "viem";
7
- import { AlchemyChainSchema } from "../schema.js";
8
- import { VERSION } from "../version.js";
1
+ import { createBundlerClient } from "@aa-sdk/core";
2
+ import type { Chain } from "viem";
3
+ import type { AlchemyTransport } from "../alchemyTransport.js";
9
4
  import type { ClientWithAlchemyMethods } from "./types.js";
10
5
 
11
6
  /**
@@ -13,14 +8,14 @@ import type { ClientWithAlchemyMethods } from "./types.js";
13
8
  *
14
9
  * @example
15
10
  * ```ts
16
- * import { createAlchemyPublicRpcClient } from "@account-kit/infra";
11
+ * import { createAlchemyPublicRpcClient, alchemy } from "@account-kit/infra";
17
12
  * import { sepolia } from "@account-kit/infra";
18
13
  *
19
14
  * const client = createAlchemyPublicRpcClient({
15
+ * transport: alchemy({
16
+ * apiKey: "ALCHEMY_API_KEY"
17
+ * }),
20
18
  * chain: sepolia,
21
- * connectionConfig: {
22
- * apiKey: "your-api-key",
23
- * }
24
19
  * });
25
20
  * ```
26
21
  *
@@ -31,42 +26,14 @@ import type { ClientWithAlchemyMethods } from "./types.js";
31
26
  * @returns {ClientWithAlchemyMethods} A client object tailored with Alchemy methods and capabilities to interact with the blockchain
32
27
  */
33
28
  export const createAlchemyPublicRpcClient = ({
34
- chain: chain_,
35
- connectionConfig,
36
- fetchOptions = {},
29
+ transport,
30
+ chain,
37
31
  }: {
38
- connectionConfig: ConnectionConfig;
39
- chain: Chain;
40
- fetchOptions?: NoUndefined<HttpTransportConfig["fetchOptions"]>;
32
+ transport: AlchemyTransport;
33
+ chain: Chain | undefined;
41
34
  }): ClientWithAlchemyMethods => {
42
- const chain = AlchemyChainSchema.parse(chain_);
43
-
44
- const rpcUrl =
45
- connectionConfig.rpcUrl == null
46
- ? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}`
47
- : connectionConfig.rpcUrl;
48
-
49
- fetchOptions.headers = {
50
- ...fetchOptions.headers,
51
- "Alchemy-AA-Sdk-Version": VERSION,
52
- };
53
-
54
- if (connectionConfig.jwt != null) {
55
- fetchOptions.headers = {
56
- ...fetchOptions.headers,
57
- Authorization: `Bearer ${connectionConfig.jwt}`,
58
- };
59
- }
60
-
61
35
  return createBundlerClient({
62
- chain: chain,
63
- transport: http(rpcUrl, { fetchOptions }),
64
- }).extend(() => ({
65
- updateHeaders(newHeaders: HeadersInit) {
66
- fetchOptions.headers = {
67
- ...fetchOptions.headers,
68
- ...newHeaders,
69
- };
70
- },
71
- }));
36
+ chain,
37
+ transport,
38
+ });
72
39
  };
@@ -1,24 +1,36 @@
1
1
  import {
2
+ ChainNotFoundError,
3
+ createSmartAccountClient,
4
+ isSmartAccountWithSigner,
2
5
  type Prettify,
3
6
  type SmartAccountClient,
4
7
  type SmartAccountClientActions,
5
8
  type SmartAccountClientConfig,
6
9
  type SmartAccountClientRpcSchema,
7
10
  type SmartContractAccount,
11
+ type SmartContractAccountWithSigner,
8
12
  type UserOperationContext,
9
13
  } from "@aa-sdk/core";
10
- import { type Chain, type Transport } from "viem";
14
+ import { type Chain } from "viem";
15
+ import type { AlchemyTransport } from "../alchemyTransport.js";
11
16
  import { getDefaultUserOperationFeeOptions } from "../defaults.js";
12
- import { AlchemyProviderConfigSchema } from "../schema.js";
13
- import type { AlchemyProviderConfig } from "../type.js";
14
- import type { AlchemySmartAccountClientActions } from "./decorators/smartAccount.js";
15
- import { createAlchemySmartAccountClientFromRpcClient } from "./internal/smartAccountClientFromRpc.js";
16
- import { createAlchemyPublicRpcClient } from "./rpcClient.js";
17
+ import { alchemyFeeEstimator } from "../middleware/feeEstimator.js";
18
+ import { alchemyGasManagerMiddleware } from "../middleware/gasManager.js";
19
+ import { alchemyUserOperationSimulator } from "../middleware/userOperationSimulator.js";
20
+ import {
21
+ alchemyActions,
22
+ type AlchemySmartAccountClientActions,
23
+ } from "./decorators/smartAccount.js";
17
24
  import type { AlchemyRpcSchema } from "./types.js";
18
25
 
26
+ export function getSignerTypeHeader<
27
+ TAccount extends SmartContractAccountWithSigner
28
+ >(account: TAccount) {
29
+ return { "Alchemy-Aa-Sdk-Signer": account.getSigner().signerType };
30
+ }
31
+
19
32
  // #region AlchemySmartAccountClientConfig
20
33
  export type AlchemySmartAccountClientConfig<
21
- transport extends Transport = Transport,
22
34
  chain extends Chain | undefined = Chain | undefined,
23
35
  account extends SmartContractAccount | undefined =
24
36
  | SmartContractAccount
@@ -30,11 +42,16 @@ export type AlchemySmartAccountClientConfig<
30
42
  account?: account;
31
43
  useSimulation?: boolean;
32
44
  policyId?: string;
33
- } & AlchemyProviderConfig &
34
- Pick<
35
- SmartAccountClientConfig<transport, chain, account, context>,
36
- "customMiddleware" | "feeEstimator" | "gasEstimator" | "signUserOperation"
37
- >;
45
+ } & Pick<
46
+ SmartAccountClientConfig<AlchemyTransport, chain, account, context>,
47
+ | "customMiddleware"
48
+ | "feeEstimator"
49
+ | "gasEstimator"
50
+ | "signUserOperation"
51
+ | "transport"
52
+ | "chain"
53
+ | "opts"
54
+ >;
38
55
  // #endregion AlchemySmartAccountClientConfig
39
56
 
40
57
  export type BaseAlchemyActions<
@@ -49,7 +66,6 @@ export type BaseAlchemyActions<
49
66
  AlchemySmartAccountClientActions<account, context>;
50
67
 
51
68
  export type AlchemySmartAccountClient_Base<
52
- transport extends Transport = Transport,
53
69
  chain extends Chain | undefined = Chain | undefined,
54
70
  account extends SmartContractAccount | undefined =
55
71
  | SmartContractAccount
@@ -60,7 +76,7 @@ export type AlchemySmartAccountClient_Base<
60
76
  | undefined
61
77
  > = Prettify<
62
78
  SmartAccountClient<
63
- transport,
79
+ AlchemyTransport,
64
80
  chain,
65
81
  account,
66
82
  actions & BaseAlchemyActions<chain, account, context>,
@@ -70,7 +86,6 @@ export type AlchemySmartAccountClient_Base<
70
86
  >;
71
87
 
72
88
  export type AlchemySmartAccountClient<
73
- transport extends Transport = Transport,
74
89
  chain extends Chain | undefined = Chain | undefined,
75
90
  account extends SmartContractAccount | undefined =
76
91
  | SmartContractAccount
@@ -79,12 +94,9 @@ export type AlchemySmartAccountClient<
79
94
  context extends UserOperationContext | undefined =
80
95
  | UserOperationContext
81
96
  | undefined
82
- > = Prettify<
83
- AlchemySmartAccountClient_Base<transport, chain, account, actions, context>
84
- >;
97
+ > = Prettify<AlchemySmartAccountClient_Base<chain, account, actions, context>>;
85
98
 
86
99
  export function createAlchemySmartAccountClient<
87
- TTransport extends Transport = Transport,
88
100
  TChain extends Chain = Chain,
89
101
  TAccount extends SmartContractAccount | undefined =
90
102
  | SmartContractAccount
@@ -92,39 +104,21 @@ export function createAlchemySmartAccountClient<
92
104
  TContext extends UserOperationContext | undefined =
93
105
  | UserOperationContext
94
106
  | undefined
95
- >({
96
- account,
97
- policyId,
98
- useSimulation,
99
- feeEstimator,
100
- customMiddleware,
101
- gasEstimator,
102
- signUserOperation,
103
- ...config_
104
- }: AlchemySmartAccountClientConfig<
105
- TTransport,
106
- TChain,
107
- TAccount,
108
- TContext
109
- >): AlchemySmartAccountClient<
110
- TTransport,
111
- TChain,
112
- TAccount,
113
- Record<string, never>,
114
- TContext
115
- >;
107
+ >(
108
+ params: AlchemySmartAccountClientConfig<TChain, TAccount, TContext>
109
+ ): AlchemySmartAccountClient<TChain, TAccount, Record<string, never>, TContext>;
116
110
 
117
111
  /**
118
112
  * Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.
119
113
  *
120
114
  * @example
121
115
  * ```ts
122
- * import { createAlchemySmartAccountClient } from "@account-kit/infra";
116
+ * import { createAlchemySmartAccountClient, alchemy } from "@account-kit/infra";
123
117
  * import { sepolia } from "@account-kit/infra/chain";
124
118
  *
125
119
  * const client = createAlchemySmartAccountClient({
126
120
  * chain: sepolia,
127
- * apiKey: "your-api-key",
121
+ * transport: alchemy({ apiKey: "your-api-key" }),
128
122
  * });
129
123
  * ```
130
124
  *
@@ -139,31 +133,44 @@ export function createAlchemySmartAccountClient({
139
133
  customMiddleware,
140
134
  gasEstimator,
141
135
  signUserOperation,
142
- ...config_
136
+ transport,
137
+ chain,
138
+ opts,
143
139
  }: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {
144
- const config = AlchemyProviderConfigSchema.parse(config_);
145
- const { chain, opts, ...connectionConfig } = config;
146
-
147
- const client = createAlchemyPublicRpcClient({
148
- chain,
149
- connectionConfig,
150
- });
140
+ if (!chain) {
141
+ throw new ChainNotFoundError();
142
+ }
151
143
 
152
144
  const feeOptions =
153
145
  opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);
154
146
 
155
- return createAlchemySmartAccountClientFromRpcClient({
156
- client,
147
+ const scaClient = createSmartAccountClient({
157
148
  account,
149
+ transport,
150
+ chain,
151
+ type: "AlchemySmartAccountClient",
158
152
  opts: {
159
153
  ...opts,
160
154
  feeOptions,
161
155
  },
162
- policyId,
163
- useSimulation,
164
- feeEstimator,
165
- customMiddleware,
156
+ customMiddleware: async (struct, args) => {
157
+ if (isSmartAccountWithSigner(args.account)) {
158
+ transport.updateHeaders(getSignerTypeHeader(args.account));
159
+ }
160
+ return customMiddleware ? customMiddleware(struct, args) : struct;
161
+ },
162
+ feeEstimator: feeEstimator ?? alchemyFeeEstimator(transport),
163
+ userOperationSimulator: useSimulation
164
+ ? alchemyUserOperationSimulator(transport)
165
+ : undefined,
166
166
  gasEstimator,
167
+ ...(policyId && alchemyGasManagerMiddleware(policyId)),
167
168
  signUserOperation,
168
- });
169
+ }).extend(alchemyActions);
170
+
171
+ if (account && isSmartAccountWithSigner(account)) {
172
+ transport.updateHeaders(getSignerTypeHeader(account));
173
+ }
174
+
175
+ return scaClient;
169
176
  }
@@ -1,9 +1,13 @@
1
- import { type BundlerClient, type UserOperationRequest } from "@aa-sdk/core";
2
- import type { HttpTransport } from "viem";
1
+ import {
2
+ type BundlerClient,
3
+ type Erc7677RpcSchema,
4
+ type UserOperationRequest,
5
+ } from "@aa-sdk/core";
3
6
  import type {
4
7
  SimulateUserOperationAssetChangesRequest,
5
8
  SimulateUserOperationAssetChangesResponse,
6
9
  } from "../actions/types";
10
+ import type { AlchemyTransport } from "../alchemyTransport";
7
11
 
8
12
  export type AlchemyRpcSchema = [
9
13
  {
@@ -15,11 +19,12 @@ export type AlchemyRpcSchema = [
15
19
  Method: "rundler_maxPriorityFeePerGas";
16
20
  Parameters: [];
17
21
  ReturnType: UserOperationRequest["maxPriorityFeePerGas"];
18
- }
22
+ },
23
+ ...Erc7677RpcSchema<{ policyId: string }>
19
24
  ];
20
25
 
21
- export type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {
22
- request: BundlerClient<HttpTransport>["request"] &
26
+ export type ClientWithAlchemyMethods = BundlerClient<AlchemyTransport> & {
27
+ request: BundlerClient<AlchemyTransport>["request"] &
23
28
  {
24
29
  request(args: {
25
30
  method: "alchemy_simulateUserOperationAssetChanges";
@@ -31,6 +36,4 @@ export type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {
31
36
  params: [];
32
37
  }): Promise<UserOperationRequest["maxPriorityFeePerGas"]>;
33
38
  }["request"];
34
- } & {
35
- updateHeaders: (headers: HeadersInit) => void;
36
39
  };
package/src/index.ts CHANGED
@@ -1,12 +1,14 @@
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 type * from "./alchemyTransport.js";
5
+ export { alchemy } from "./alchemyTransport.js";
4
6
  export type * from "./chains.js";
5
7
  export {
6
8
  arbitrum,
7
9
  arbitrumGoerli,
8
- arbitrumSepolia,
9
10
  arbitrumNova,
11
+ arbitrumSepolia,
10
12
  base,
11
13
  baseGoerli,
12
14
  baseSepolia,
@@ -22,18 +24,18 @@ export {
22
24
  polygonAmoy,
23
25
  polygonMumbai,
24
26
  sepolia,
25
- zora,
26
- zoraSepolia,
27
- worldChain,
28
- worldChainSepolia,
29
27
  shape,
30
28
  shapeSepolia,
29
+ worldChain,
30
+ worldChainSepolia,
31
+ zora,
32
+ zoraSepolia,
33
+ beraChainBartio,
31
34
  } from "./chains.js";
32
35
  export type * from "./client/decorators/alchemyEnhancedApis.js";
33
36
  export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
34
37
  export type * from "./client/decorators/smartAccount.js";
35
38
  export { alchemyActions } from "./client/decorators/smartAccount.js";
36
- export { createAlchemySmartAccountClientFromRpcClient as createAlchemySmartAccountClientFromExisting } from "./client/internal/smartAccountClientFromRpc.js";
37
39
  export { isAlchemySmartAccountClient } from "./client/isAlchemySmartAccountClient.js";
38
40
  export type * from "./client/rpcClient.js";
39
41
  export { createAlchemyPublicRpcClient } from "./client/rpcClient.js";
@@ -47,5 +49,3 @@ export type * from "./middleware/gasManager.js";
47
49
  export { alchemyGasManagerMiddleware } from "./middleware/gasManager.js";
48
50
  export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
49
51
  export type * from "./schema.js";
50
- export { AlchemyProviderConfigSchema } from "./schema.js";
51
- export type { AlchemyProviderConfig } from "./type.js";
package/src/metrics.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { createLogger } from "@account-kit/logging";
2
+ import type { Address } from "viem";
3
+ import { VERSION } from "./version.js";
4
+
5
+ export type InfraEventsSchema = [
6
+ {
7
+ EventName: "client_send_uo";
8
+ EventData: {
9
+ signerType: string;
10
+ chainId: number;
11
+ entryPoint: Address;
12
+ };
13
+ }
14
+ ];
15
+
16
+ export const InfraLogger = createLogger<InfraEventsSchema>({
17
+ package: "@account-kit/infra",
18
+ version: VERSION,
19
+ });
@@ -1,6 +1,6 @@
1
1
  import type { ClientMiddlewareFn } from "@aa-sdk/core";
2
2
  import { applyUserOpOverrideOrFeeOption } from "@aa-sdk/core";
3
- import type { ClientWithAlchemyMethods } from "../client/types";
3
+ import type { AlchemyTransport } from "../alchemyTransport";
4
4
 
5
5
  /**
6
6
  * Function that estimates the transaction fees using Alchemy methods for a given client.
@@ -8,28 +8,33 @@ import type { ClientWithAlchemyMethods } from "../client/types";
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * import { alchemyFeeEstimator, createAlchemyPublicRpcClient } from "@account-kit/infra";
11
+ * import { alchemyFeeEstimator, alchemy } from "@account-kit/infra";
12
12
  * import { createSmartAccountClient } from "@aa-sdk/core";
13
13
  *
14
- * const bundlerClient = createAlchemyPublicRpcClient(...);
14
+ * const alchemyTransport = alchemy({
15
+ * chain: sepolia,
16
+ * apiKey: "your-api-key"
17
+ * });
18
+ *
15
19
  * const client = createSmartAccountClient({
16
- * feeEstimator: alchemyFeeEstimator(bundlerClient),
20
+ * feeEstimator: alchemyFeeEstimator(alchemyTransport),
17
21
  * ...otherParams
18
22
  * });
19
23
  * ```
20
24
  *
21
- * @param {ClientWithAlchemyMethods} client The client with Alchemy methods
25
+ * @param {AlchemyTransport} transport An alchemy transport for making Alchemy specific RPC calls
22
26
  * @returns {ClientMiddlewareFn} A middleware function that takes a transaction structure and fee options, and returns the augmented structure with estimated fees
23
27
  */
24
- export const alchemyFeeEstimator: <C extends ClientWithAlchemyMethods>(
25
- client: C
28
+ export const alchemyFeeEstimator: (
29
+ transport: AlchemyTransport
26
30
  ) => ClientMiddlewareFn =
27
- (client) =>
28
- async (struct, { overrides, feeOptions }) => {
31
+ (transport) =>
32
+ async (struct, { overrides, feeOptions, client }) => {
33
+ const transport_ = transport({ chain: client.chain });
29
34
  let [block, maxPriorityFeePerGasEstimate] = await Promise.all([
30
35
  client.getBlock({ blockTag: "latest" }),
31
36
  // it is a fair assumption that if someone is using this Alchemy Middleware, then they are using Alchemy RPC
32
- client.request({
37
+ transport_.request({
33
38
  method: "rundler_maxPriorityFeePerGas",
34
39
  params: [],
35
40
  }),
@@ -6,15 +6,14 @@ import { erc7677Middleware } from "@aa-sdk/core";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
- *
10
- * import { sepolia } from "@account-kit/infra";
9
+ * import { sepolia, alchemyErc7677Middleware } from "@account-kit/infra";
11
10
  * import { http } from "viem";
12
11
  *
13
12
  * const client = createSmartAccountClient({
14
- * http("rpc-url"),
15
- * sepolia,
16
- * alchemyErc7677Middleware("policyId")
17
- * );
13
+ * transport: http("rpc-url"),
14
+ * chain: sepolia,
15
+ * ...alchemyErc7677Middleware("policyId")
16
+ * });
18
17
  * ```
19
18
  *
20
19
  * @param {string} policyId the policyId for Alchemy's gas manager