@account-kit/infra 4.20.1 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/esm/alchemyTrackerHeaders.d.ts +24 -0
  2. package/dist/esm/alchemyTrackerHeaders.js +60 -0
  3. package/dist/esm/alchemyTrackerHeaders.js.map +1 -0
  4. package/dist/esm/alchemyTransport.d.ts +2 -0
  5. package/dist/esm/alchemyTransport.js +4 -1
  6. package/dist/esm/alchemyTransport.js.map +1 -1
  7. package/dist/esm/chains.d.ts +3 -0
  8. package/dist/esm/chains.js +36 -1
  9. package/dist/esm/chains.js.map +1 -1
  10. package/dist/esm/client/decorators/smartAccount.d.ts +1 -1
  11. package/dist/esm/client/decorators/smartAccount.js +11 -5
  12. package/dist/esm/client/decorators/smartAccount.js.map +1 -1
  13. package/dist/esm/client/smartAccountClient.d.ts +1 -1
  14. package/dist/esm/client/smartAccountClient.js +43 -23
  15. package/dist/esm/client/smartAccountClient.js.map +1 -1
  16. package/dist/esm/index.d.ts +2 -1
  17. package/dist/esm/index.js +2 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/middleware/feeEstimator.js +3 -2
  20. package/dist/esm/middleware/feeEstimator.js.map +1 -1
  21. package/dist/esm/middleware/gasManager.js +3 -2
  22. package/dist/esm/middleware/gasManager.js.map +1 -1
  23. package/dist/esm/version.d.ts +1 -1
  24. package/dist/esm/version.js +1 -1
  25. package/dist/esm/version.js.map +1 -1
  26. package/dist/types/alchemyTrackerHeaders.d.ts +25 -0
  27. package/dist/types/alchemyTrackerHeaders.d.ts.map +1 -0
  28. package/dist/types/alchemyTransport.d.ts +2 -0
  29. package/dist/types/alchemyTransport.d.ts.map +1 -1
  30. package/dist/types/chains.d.ts +3 -0
  31. package/dist/types/chains.d.ts.map +1 -1
  32. package/dist/types/client/decorators/smartAccount.d.ts +1 -1
  33. package/dist/types/client/decorators/smartAccount.d.ts.map +1 -1
  34. package/dist/types/client/smartAccountClient.d.ts +1 -1
  35. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  36. package/dist/types/index.d.ts +2 -1
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/middleware/feeEstimator.d.ts.map +1 -1
  39. package/dist/types/middleware/gasManager.d.ts.map +1 -1
  40. package/dist/types/version.d.ts +1 -1
  41. package/package.json +4 -4
  42. package/src/alchemyTrackerHeaders.ts +61 -0
  43. package/src/alchemyTransport.ts +5 -1
  44. package/src/chains.ts +40 -0
  45. package/src/client/decorators/smartAccount.ts +11 -5
  46. package/src/client/smartAccountClient.ts +53 -34
  47. package/src/index.ts +4 -0
  48. package/src/middleware/feeEstimator.ts +7 -2
  49. package/src/middleware/gasManager.ts +3 -1
  50. package/src/version.ts +1 -1
package/src/chains.ts CHANGED
@@ -21,6 +21,8 @@ import {
21
21
  arbitrumNova as vabn,
22
22
  zora as vzora,
23
23
  zoraSepolia as vzoras,
24
+ sonic as vsonic,
25
+ sonicTestnet as vsonict,
24
26
  } from "viem/chains";
25
27
 
26
28
  export type AlchemyChainConfig = {
@@ -238,6 +240,20 @@ export const zoraSepolia: Chain = {
238
240
  },
239
241
  };
240
242
 
243
+ export const sonic: Chain = {
244
+ ...vsonic,
245
+ rpcUrls: {
246
+ ...vsonic.rpcUrls,
247
+ },
248
+ };
249
+
250
+ export const sonicTestnet: Chain = {
251
+ ...vsonict,
252
+ rpcUrls: {
253
+ ...vsonict.rpcUrls,
254
+ },
255
+ };
256
+
241
257
  export const worldChainSepolia: Chain = defineChain({
242
258
  id: 4801,
243
259
  name: "World Chain Sepolia",
@@ -562,3 +578,27 @@ export const gensynTestnet: Chain = defineChain({
562
578
  },
563
579
  testnet: true,
564
580
  });
581
+
582
+ export const riseTestnet: Chain = defineChain({
583
+ id: 11155931,
584
+ name: "Rise Testnet",
585
+ nativeCurrency: { name: "eth", symbol: "eth", decimals: 18 },
586
+ rpcUrls: {
587
+ default: {
588
+ http: ["https://rise-testnet.g.alchemy.com/v2"],
589
+ },
590
+ public: {
591
+ http: ["https://rise-testnet.g.alchemy.com/v2"],
592
+ },
593
+ alchemy: {
594
+ http: ["https://rise-testnet.g.alchemy.com/v2"],
595
+ },
596
+ },
597
+ blockExplorers: {
598
+ default: {
599
+ name: "Block Explorer",
600
+ url: "https://testnet-explorer.riselabs.xyz",
601
+ },
602
+ },
603
+ testnet: true,
604
+ });
@@ -10,6 +10,7 @@ import {
10
10
  type SmartContractAccount,
11
11
  type UserOperationContext,
12
12
  type UserOperationOverrides,
13
+ clientHeaderTrack,
13
14
  } from "@aa-sdk/core";
14
15
  import type {
15
16
  Chain,
@@ -64,7 +65,7 @@ export type AlchemySmartAccountClientActions<
64
65
  * const clientWithAlchemyActions = client.extend(alchemyActions);
65
66
  * ```
66
67
  *
67
- * @param {Client<TTransport, TChain, TAccount>} client The client instance used to perform actions
68
+ * @param {Client<TTransport, TChain, TAccount>} client_ The client instance used to perform actions
68
69
  * @returns {AlchemySmartAccountClientActions<TAccount, TContext>} An object containing Alchemy Smart Account client actions
69
70
  */
70
71
  export const alchemyActions: <
@@ -79,11 +80,14 @@ export const alchemyActions: <
79
80
  >(
80
81
  client: Client<TTransport, TChain, TAccount>
81
82
  ) => AlchemySmartAccountClientActions<TAccount, TContext, TChain> = (
82
- client
83
+ client_
83
84
  ) => ({
84
- simulateUserOperation: async (args) =>
85
- simulateUserOperationChanges(client, args),
86
- sendUserOperation: async (args) => {
85
+ simulateUserOperation: async (args) => {
86
+ const client = clientHeaderTrack(client_, "simulateUserOperation");
87
+ return simulateUserOperationChanges(client, args);
88
+ },
89
+ async sendUserOperation(args) {
90
+ const client = clientHeaderTrack(client_, "infraSendUserOperation");
87
91
  const { account = client.account } = args;
88
92
 
89
93
  const result = sendUserOperation(client, args);
@@ -91,6 +95,7 @@ export const alchemyActions: <
91
95
  return result;
92
96
  },
93
97
  sendTransaction: async (args, overrides, context) => {
98
+ const client = clientHeaderTrack(client_, "sendTransaction");
94
99
  const { account = client.account } = args;
95
100
 
96
101
  const result = await sendTransaction(client, args, overrides, context);
@@ -98,6 +103,7 @@ export const alchemyActions: <
98
103
  return result;
99
104
  },
100
105
  async sendTransactions(args) {
106
+ const client = clientHeaderTrack(client_, "sendTransactions");
101
107
  const { account = client.account } = args;
102
108
 
103
109
  const result = sendTransactions(client, args);
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ChainNotFoundError,
3
+ clientHeaderTrack,
3
4
  createSmartAccountClient,
4
5
  isSmartAccountWithSigner,
5
6
  type Prettify,
@@ -12,7 +13,11 @@ import {
12
13
  type UserOperationContext,
13
14
  } from "@aa-sdk/core";
14
15
  import { type Chain } from "viem";
15
- import type { AlchemyTransport } from "../alchemyTransport.js";
16
+ import {
17
+ alchemy,
18
+ convertHeadersToObject,
19
+ type AlchemyTransport,
20
+ } from "../alchemyTransport.js";
16
21
  import { getDefaultUserOperationFeeOptions } from "../defaults.js";
17
22
  import { alchemyFeeEstimator } from "../middleware/feeEstimator.js";
18
23
  import { alchemyGasAndPaymasterAndDataMiddleware } from "../middleware/gasManager.js";
@@ -22,6 +27,7 @@ import {
22
27
  type AlchemySmartAccountClientActions,
23
28
  } from "./decorators/smartAccount.js";
24
29
  import type { AlchemyRpcSchema } from "./types.js";
30
+ import { headersUpdate } from "../alchemyTrackerHeaders.js";
25
31
 
26
32
  export function getSignerTypeHeader<
27
33
  TAccount extends SmartContractAccountWithSigner
@@ -125,58 +131,71 @@ export function createAlchemySmartAccountClient<
125
131
  * @param {AlchemySmartAccountClientConfig} config The configuration for creating the Alchemy smart account client
126
132
  * @returns {AlchemySmartAccountClient} An instance of `AlchemySmartAccountClient` configured based on the provided options
127
133
  */
128
- export function createAlchemySmartAccountClient({
129
- account,
130
- policyId,
131
- useSimulation,
132
- feeEstimator,
133
- customMiddleware,
134
- gasEstimator,
135
- signUserOperation,
136
- transport,
137
- chain,
138
- opts,
139
- }: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {
140
- if (!chain) {
134
+ export function createAlchemySmartAccountClient(
135
+ config: AlchemySmartAccountClientConfig
136
+ ): AlchemySmartAccountClient {
137
+ if (!config.chain) {
141
138
  throw new ChainNotFoundError();
142
139
  }
143
140
 
144
141
  const feeOptions =
145
- opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);
142
+ config.opts?.feeOptions ?? getDefaultUserOperationFeeOptions(config.chain);
146
143
 
147
144
  const scaClient = createSmartAccountClient({
148
- account,
149
- transport,
150
- chain,
145
+ account: config.account,
146
+ transport: config.transport,
147
+ chain: config.chain,
151
148
  type: "AlchemySmartAccountClient",
152
149
  opts: {
153
- ...opts,
150
+ ...config.opts,
154
151
  feeOptions,
155
152
  },
156
- feeEstimator: feeEstimator ?? alchemyFeeEstimator(transport),
157
- gasEstimator,
153
+ feeEstimator: config.feeEstimator ?? alchemyFeeEstimator(config.transport),
154
+ gasEstimator: config.gasEstimator,
158
155
  customMiddleware: async (struct, args) => {
159
156
  if (isSmartAccountWithSigner(args.account)) {
160
- transport.updateHeaders(getSignerTypeHeader(args.account));
157
+ config.transport.updateHeaders(getSignerTypeHeader(args.account));
161
158
  }
162
- return customMiddleware ? customMiddleware(struct, args) : struct;
159
+ return config.customMiddleware
160
+ ? config.customMiddleware(struct, args)
161
+ : struct;
163
162
  },
164
- ...(policyId
163
+ ...(config.policyId
165
164
  ? alchemyGasAndPaymasterAndDataMiddleware({
166
- policyId,
167
- transport,
168
- gasEstimatorOverride: gasEstimator,
169
- feeEstimatorOverride: feeEstimator,
165
+ policyId: config.policyId,
166
+ transport: config.transport,
167
+ gasEstimatorOverride: config.gasEstimator,
168
+ feeEstimatorOverride: config.feeEstimator,
170
169
  })
171
170
  : {}),
172
- userOperationSimulator: useSimulation
173
- ? alchemyUserOperationSimulator(transport)
171
+ userOperationSimulator: config.useSimulation
172
+ ? alchemyUserOperationSimulator(config.transport)
174
173
  : undefined,
175
- signUserOperation,
176
- }).extend(alchemyActions);
174
+ signUserOperation: config.signUserOperation,
175
+ addBreadCrumb(breadcrumb: string) {
176
+ const oldConfig = config.transport.config;
177
+ const dynamicFetchOptions = config.transport.dynamicFetchOptions;
178
+ const newTransport = alchemy({ ...oldConfig });
179
+ newTransport.updateHeaders(
180
+ headersUpdate(breadcrumb)(
181
+ convertHeadersToObject(dynamicFetchOptions?.headers)
182
+ )
183
+ );
184
+ return createAlchemySmartAccountClient({
185
+ ...config,
186
+ transport: newTransport,
187
+ }) as any;
188
+ },
189
+ })
190
+ .extend(alchemyActions)
191
+ .extend((client_) => ({
192
+ addBreadcrumb(breadcrumb: string) {
193
+ return clientHeaderTrack(client_, breadcrumb);
194
+ },
195
+ }));
177
196
 
178
- if (account && isSmartAccountWithSigner(account)) {
179
- transport.updateHeaders(getSignerTypeHeader(account));
197
+ if (config.account && isSmartAccountWithSigner(config.account)) {
198
+ config.transport.updateHeaders(getSignerTypeHeader(config.account));
180
199
  }
181
200
 
182
201
  return scaClient;
package/src/index.ts CHANGED
@@ -43,6 +43,9 @@ export {
43
43
  monadTestnet,
44
44
  openlootSepolia,
45
45
  gensynTestnet,
46
+ riseTestnet,
47
+ sonic,
48
+ sonicTestnet,
46
49
  } from "./chains.js";
47
50
  export type * from "./client/decorators/alchemyEnhancedApis.js";
48
51
  export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
@@ -58,6 +61,7 @@ export { getDefaultUserOperationFeeOptions } from "./defaults.js";
58
61
  export { getAlchemyPaymasterAddress } from "./gas-manager.js";
59
62
  export { alchemyFeeEstimator } from "./middleware/feeEstimator.js";
60
63
  export type * from "./middleware/gasManager.js";
64
+ export * from "./alchemyTrackerHeaders.js";
61
65
  export {
62
66
  alchemyGasManagerMiddleware,
63
67
  alchemyGasAndPaymasterAndDataMiddleware,
@@ -1,5 +1,9 @@
1
1
  import type { ClientMiddlewareFn } from "@aa-sdk/core";
2
- import { applyUserOpOverrideOrFeeOption, bigIntMultiply } from "@aa-sdk/core";
2
+ import {
3
+ applyUserOpOverrideOrFeeOption,
4
+ bigIntMultiply,
5
+ clientHeaderTrack,
6
+ } from "@aa-sdk/core";
3
7
  import type { AlchemyTransport } from "../alchemyTransport";
4
8
 
5
9
  /**
@@ -29,7 +33,8 @@ export const alchemyFeeEstimator: (
29
33
  transport: AlchemyTransport
30
34
  ) => ClientMiddlewareFn =
31
35
  (transport) =>
32
- async (struct, { overrides, feeOptions, client }) => {
36
+ async (struct, { overrides, feeOptions, client: client_ }) => {
37
+ const client = clientHeaderTrack(client_, "alchemyFeeEstimator");
33
38
  const transport_ = transport({ chain: client.chain });
34
39
  let [block, maxPriorityFeePerGasEstimate] = await Promise.all([
35
40
  client.getBlock({ blockTag: "latest" }),
@@ -10,6 +10,7 @@ import type {
10
10
  import {
11
11
  bypassPaymasterAndData,
12
12
  ChainNotFoundError,
13
+ clientHeaderTrack,
13
14
  deepHexlify,
14
15
  defaultGasEstimator,
15
16
  erc7677Middleware,
@@ -129,8 +130,9 @@ export function alchemyGasAndPaymasterAndDataMiddleware(
129
130
  },
130
131
  paymasterAndData: async (
131
132
  uo,
132
- { account, client, feeOptions, overrides: overrides_ }
133
+ { account, client: client_, feeOptions, overrides: overrides_ }
133
134
  ) => {
135
+ const client = clientHeaderTrack(client_, "alchemyFeeEstimator");
134
136
  if (!client.chain) {
135
137
  throw new ChainNotFoundError();
136
138
  }
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.20.1";
3
+ export const VERSION = "4.22.0";