@across-protocol/sdk 3.1.25 → 3.1.27

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 (73) hide show
  1. package/dist/cjs/clients/HubPoolClient.d.ts +2 -0
  2. package/dist/cjs/clients/HubPoolClient.js +11 -0
  3. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  4. package/dist/cjs/providers/alchemy.d.ts +2 -0
  5. package/dist/cjs/providers/alchemy.js +28 -0
  6. package/dist/cjs/providers/alchemy.js.map +1 -0
  7. package/dist/cjs/providers/index.d.ts +1 -0
  8. package/dist/cjs/providers/index.js +1 -0
  9. package/dist/cjs/providers/index.js.map +1 -1
  10. package/dist/cjs/providers/infura.d.ts +2 -0
  11. package/dist/cjs/providers/infura.js +23 -0
  12. package/dist/cjs/providers/infura.js.map +1 -0
  13. package/dist/cjs/providers/types.d.ts +2 -0
  14. package/dist/cjs/providers/types.js +3 -0
  15. package/dist/cjs/providers/types.js.map +1 -0
  16. package/dist/cjs/providers/utils.d.ts +3 -0
  17. package/dist/cjs/providers/utils.js +33 -10
  18. package/dist/cjs/providers/utils.js.map +1 -1
  19. package/dist/cjs/utils/AddressUtils.d.ts +1 -0
  20. package/dist/cjs/utils/AddressUtils.js +8 -1
  21. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  22. package/dist/cjs/utils/TokenUtils.d.ts +3 -0
  23. package/dist/cjs/utils/TokenUtils.js +41 -1
  24. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  25. package/dist/esm/clients/HubPoolClient.d.ts +15 -0
  26. package/dist/esm/clients/HubPoolClient.js +27 -1
  27. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  28. package/dist/esm/providers/alchemy.d.ts +2 -0
  29. package/dist/esm/providers/alchemy.js +25 -0
  30. package/dist/esm/providers/alchemy.js.map +1 -0
  31. package/dist/esm/providers/index.d.ts +1 -0
  32. package/dist/esm/providers/index.js +1 -0
  33. package/dist/esm/providers/index.js.map +1 -1
  34. package/dist/esm/providers/infura.d.ts +2 -0
  35. package/dist/esm/providers/infura.js +20 -0
  36. package/dist/esm/providers/infura.js.map +1 -0
  37. package/dist/esm/providers/types.d.ts +2 -0
  38. package/dist/esm/providers/types.js +2 -0
  39. package/dist/esm/providers/types.js.map +1 -0
  40. package/dist/esm/providers/utils.d.ts +16 -0
  41. package/dist/esm/providers/utils.js +57 -16
  42. package/dist/esm/providers/utils.js.map +1 -1
  43. package/dist/esm/utils/AddressUtils.d.ts +1 -0
  44. package/dist/esm/utils/AddressUtils.js +6 -0
  45. package/dist/esm/utils/AddressUtils.js.map +1 -1
  46. package/dist/esm/utils/TokenUtils.d.ts +39 -16
  47. package/dist/esm/utils/TokenUtils.js +45 -0
  48. package/dist/esm/utils/TokenUtils.js.map +1 -1
  49. package/dist/types/clients/HubPoolClient.d.ts +15 -0
  50. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  51. package/dist/types/providers/alchemy.d.ts +3 -0
  52. package/dist/types/providers/alchemy.d.ts.map +1 -0
  53. package/dist/types/providers/index.d.ts +1 -0
  54. package/dist/types/providers/index.d.ts.map +1 -1
  55. package/dist/types/providers/infura.d.ts +3 -0
  56. package/dist/types/providers/infura.d.ts.map +1 -0
  57. package/dist/types/providers/types.d.ts +3 -0
  58. package/dist/types/providers/types.d.ts.map +1 -0
  59. package/dist/types/providers/utils.d.ts +16 -0
  60. package/dist/types/providers/utils.d.ts.map +1 -1
  61. package/dist/types/utils/AddressUtils.d.ts +1 -0
  62. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  63. package/dist/types/utils/TokenUtils.d.ts +39 -16
  64. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  65. package/package.json +1 -1
  66. package/src/clients/HubPoolClient.ts +30 -0
  67. package/src/providers/alchemy.ts +28 -0
  68. package/src/providers/index.ts +1 -0
  69. package/src/providers/infura.ts +23 -0
  70. package/src/providers/types.ts +2 -0
  71. package/src/providers/utils.ts +65 -16
  72. package/src/utils/AddressUtils.ts +7 -0
  73. package/src/utils/TokenUtils.ts +47 -0
@@ -0,0 +1,3 @@
1
+ import { RPCTransport } from "./types";
2
+ export declare function getURL(chainId: number, apiKey: string, transport: RPCTransport): string;
3
+ //# sourceMappingURL=alchemy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alchemy.d.ts","sourceRoot":"","sources":["../../../src/providers/alchemy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAcvC,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,MAAM,CAYvF"}
@@ -2,5 +2,6 @@ export * from "./rateLimitedProvider";
2
2
  export * from "./cachedProvider";
3
3
  export * from "./retryProvider";
4
4
  export * from "./constants";
5
+ export * from "./types";
5
6
  export * from "./utils";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { RPCTransport } from "./types";
2
+ export declare function getURL(chainId: number, apiKey: string, transport: RPCTransport): string;
3
+ //# sourceMappingURL=infura.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infura.d.ts","sourceRoot":"","sources":["../../../src/providers/infura.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,MAAM,CAYvF"}
@@ -0,0 +1,3 @@
1
+ export type RPCProvider = "INFURA" | "ALCHEMY";
2
+ export type RPCTransport = "https" | "wss";
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,CAAC"}
@@ -1,4 +1,20 @@
1
1
  import { providers } from "ethers";
2
+ import { RPCProvider, RPCTransport } from "./types";
3
+ /**
4
+ * Type predicate for RPCProvider type.
5
+ * @param provider Provider string (ALCHEMY, INFURA, ...).
6
+ * @returns True if the provider string is a supported provider.
7
+ */
8
+ export declare function isSupportedProvider(provider: string): provider is RPCProvider;
9
+ /**
10
+ * Produce an RPC for a given RPC provider, chainId API key and transport.
11
+ * @param provider RPC provider identifier (ALCHEMY, INFURA, ...)
12
+ * @param chainId Chain ID to obtain a URL for.
13
+ * @param apiKey API key for provider.
14
+ * @param transport Optional transport specifier (HTTPS or WSS).
15
+ * @returns An RPC URL confirming to the specified inputs.
16
+ */
17
+ export declare function getURL(provider: RPCProvider, chainId: number, apiKey: string, transport?: RPCTransport): string;
2
18
  export declare function compareResultsAndFilterIgnoredKeys(ignoredKeys: string[], _objA: Record<string, unknown>, _objB: Record<string, unknown>): boolean;
3
19
  export declare function compareArrayResultsWithIgnoredKeys(ignoredKeys: string[], objA: unknown[], objB: unknown[]): boolean;
4
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/providers/utils.ts"],"names":[],"mappings":"AAEA,OAA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"ethers";
6
6
  * @returns A boolean indicating if a contract is deployed at the given address or not (true = contract, false = no contract)
7
7
  */
8
8
  export declare function isContractDeployedToAddress(address: string, provider: providers.Provider): Promise<boolean>;
9
+ export declare function compareAddressesSimple(addressA?: string, addressB?: string): boolean;
9
10
  //# sourceMappingURL=AddressUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AddressUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/AddressUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,MAAM,QAAQ,CAAC;AAE1C;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CASjH"}
1
+ {"version":3,"file":"AddressUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/AddressUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,MAAM,QAAQ,CAAC;AAE1C;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CASjH;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAKpF"}
@@ -74,6 +74,13 @@ export declare const resolveContractFromSymbol: (symbol: string, chainId: string
74
74
  addresses: {
75
75
  [x: number]: string;
76
76
  };
77
+ /**
78
+ * Resolve a token symbol to an L1Token description on a particular chain ID.
79
+ * @notice Not to be confused with the HubPool's internal view on the supported origin/destination token for a chain.
80
+ * @param symbol Symbol to query.
81
+ * @param chainId Chain ID to query on.
82
+ * @returns Symbol, decimals and contract address on the requested chain.
83
+ */
77
84
  coingeckoId: string;
78
85
  };
79
86
  ETH: {
@@ -116,13 +123,6 @@ export declare const resolveContractFromSymbol: (symbol: string, chainId: string
116
123
  name: string;
117
124
  symbol: string;
118
125
  decimals: number;
119
- /**
120
- * Returns the contract address for a given token symbol and chainId.
121
- * @param symbol A case-insensitive token symbol.
122
- * @param chainId The chainId to resolve the contract address for.
123
- * @param tokenMapping A parameter to determine where to source token information. Defaults to the constants variant.
124
- * @returns The contract address for the given token symbol and chainId, or undefined if the token symbol is not supported.
125
- */
126
126
  addresses: {
127
127
  [x: number]: string;
128
128
  };
@@ -199,7 +199,14 @@ export declare const resolveContractFromSymbol: (symbol: string, chainId: string
199
199
  [x: number]: string;
200
200
  };
201
201
  coingeckoId: string;
202
- };
202
+ }; /**
203
+ * Retrieves the ERC20 balance for a given address and token address.
204
+ * @param address The address to retrieve the balance for.
205
+ * @param tokenAddress The token address
206
+ * @param signerOrProvider A valid ethers.js Signer or Provider object.
207
+ * @param blockTag The block tag to retrieve the balance at.
208
+ * @returns The balance of the given address for the given token address.
209
+ */
203
210
  WBTC: {
204
211
  name: string;
205
212
  symbol: string;
@@ -281,6 +288,13 @@ export declare function getTokenInformationFromAddress(address: string, tokenMap
281
288
  addresses: {
282
289
  [x: number]: string;
283
290
  };
291
+ /**
292
+ * Resolve a token symbol to an L1Token description on a particular chain ID.
293
+ * @notice Not to be confused with the HubPool's internal view on the supported origin/destination token for a chain.
294
+ * @param symbol Symbol to query.
295
+ * @param chainId Chain ID to query on.
296
+ * @returns Symbol, decimals and contract address on the requested chain.
297
+ */
284
298
  coingeckoId: string;
285
299
  };
286
300
  ETH: {
@@ -323,13 +337,6 @@ export declare function getTokenInformationFromAddress(address: string, tokenMap
323
337
  name: string;
324
338
  symbol: string;
325
339
  decimals: number;
326
- /**
327
- * Returns the contract address for a given token symbol and chainId.
328
- * @param symbol A case-insensitive token symbol.
329
- * @param chainId The chainId to resolve the contract address for.
330
- * @param tokenMapping A parameter to determine where to source token information. Defaults to the constants variant.
331
- * @returns The contract address for the given token symbol and chainId, or undefined if the token symbol is not supported.
332
- */
333
340
  addresses: {
334
341
  [x: number]: string;
335
342
  };
@@ -406,7 +413,14 @@ export declare function getTokenInformationFromAddress(address: string, tokenMap
406
413
  [x: number]: string;
407
414
  };
408
415
  coingeckoId: string;
409
- };
416
+ }; /**
417
+ * Retrieves the ERC20 balance for a given address and token address.
418
+ * @param address The address to retrieve the balance for.
419
+ * @param tokenAddress The token address
420
+ * @param signerOrProvider A valid ethers.js Signer or Provider object.
421
+ * @param blockTag The block tag to retrieve the balance at.
422
+ * @returns The balance of the given address for the given token address.
423
+ */
410
424
  WBTC: {
411
425
  name: string;
412
426
  symbol: string;
@@ -446,5 +460,14 @@ export declare function getCoingeckoTokenIdByAddress(contractAddress: string): s
446
460
  */
447
461
  export declare function getTokenBalance(address: string, tokenAddress: string, signerOrProvider: SignerOrProvider, blockTag?: BlockTag): Promise<BigNumber>;
448
462
  export declare function isBridgedUsdc(tokenSymbol: string): boolean;
463
+ export declare function getTokenInfo(l2TokenAddress: string, chainId: number): L1Token;
464
+ /**
465
+ * Get the USDC symbol for the given token address and chain ID.
466
+ * @param l2Token A Web3 token address (not case sensitive)
467
+ * @param chainId A chain Id to reference
468
+ * @returns Either USDC (if native) or USDbC/USDC.e (if bridged) or undefined if the token address is not recognized.
469
+ */
470
+ export declare function getUsdcSymbol(l2Token: string, chainId: number): string | undefined;
471
+ export declare function getL1TokenInfo(l2TokenAddress: string, chainId: number): L1Token;
449
472
  export {};
450
473
  //# sourceMappingURL=TokenUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TokenUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/TokenUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAY,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAMxC,KAAK,gBAAgB,GAAG,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;AAEpD,wBAAsB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA5B6F,GAAG,OAAO,GAAG,SAAS,CAWrH;AAED,wBAAgB,4BAA4B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAM5E;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,GAAE,QAAmB,GAC5B,OAAO,CAAC,SAAS,CAAC,CAGpB;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAI1D;AAED,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAc7E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOlF;AAED,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAa/E"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "3.1.25",
4
+ "version": "3.1.27",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "files": [
@@ -40,6 +40,9 @@ import {
40
40
  spreadEvent,
41
41
  spreadEventWithBlockNumber,
42
42
  toBN,
43
+ getTokenInfo,
44
+ getUsdcSymbol,
45
+ getL1TokenInfo,
43
46
  } from "../utils";
44
47
  import { AcrossConfigStoreClient as ConfigStoreClient } from "./AcrossConfigStoreClient/AcrossConfigStoreClient";
45
48
  import { BaseAbstractClient, isUpdateFailureReason, UpdateFailureReason } from "./BaseAbstractClient";
@@ -260,6 +263,33 @@ export class HubPoolClient extends BaseAbstractClient {
260
263
  return this.l1TokensToDestinationTokens?.[l1Token]?.[destinationChainId] != undefined;
261
264
  }
262
265
 
266
+ /**
267
+ * @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
268
+ * @param tokenAddress Token address on `chain`
269
+ * @param chain Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
270
+ * @returns Token info for the given token address on the L2 chain including symbol and decimal.
271
+ */
272
+ getTokenInfoForAddress(tokenAddress: string, chain: number): L1Token {
273
+ const tokenInfo = getTokenInfo(tokenAddress, chain);
274
+ // @dev Temporarily handle case where an L2 token for chain ID can map to more than one TOKEN_SYMBOLS_MAP
275
+ // entry. For example, L2 Bridged USDC maps to both the USDC and USDC.e/USDbC entries in TOKEN_SYMBOLS_MAP.
276
+ if (tokenInfo.symbol.toLowerCase() === "usdc" && chain !== this.chainId) {
277
+ tokenInfo.symbol = getUsdcSymbol(tokenAddress, chain) ?? "UNKNOWN";
278
+ }
279
+ return tokenInfo;
280
+ }
281
+
282
+ /**
283
+ * @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
284
+ * @dev if the token matched in TOKEN_SYMBOLS_MAP does not have an L1 token address then this will throw.
285
+ * @param tokenAddress Token address on `chain`
286
+ * @param chain Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
287
+ * @returns Token info for the given token address on the Hub chain including symbol and decimal and L1 address.
288
+ */
289
+ getL1TokenInfoForAddress(tokenAddress: string, chain: number): L1Token {
290
+ return getL1TokenInfo(tokenAddress, chain);
291
+ }
292
+
263
293
  getBlockNumber(timestamp: number): Promise<number | undefined> {
264
294
  const hints = { lowBlock: this.deploymentBlock };
265
295
  return getCachedBlockForTimestamp(this.chainId, timestamp, this.blockFinder, this.cachingMechanism, hints);
@@ -0,0 +1,28 @@
1
+ import { CHAIN_IDs, MAINNET_CHAIN_IDs as _MAINNET_CHAIN_IDs, PUBLIC_NETWORKS } from "../constants";
2
+ import { RPCTransport } from "./types";
3
+
4
+ const MAINNET_CHAIN_IDs = Object.values(_MAINNET_CHAIN_IDs);
5
+
6
+ // Chain-specific overrides for when the Alchemy endpoint does not match the canonical chain name.
7
+ const endpoints: { [chainId: string]: string } = {
8
+ [CHAIN_IDs.ARBITRUM]: "arb",
9
+ [CHAIN_IDs.ARBITRUM_SEPOLIA]: "arb-sepolia",
10
+ [CHAIN_IDs.MAINNET]: "eth",
11
+ [CHAIN_IDs.SEPOLIA]: "eth-sepolia",
12
+ [CHAIN_IDs.OPTIMISM]: "opt",
13
+ [CHAIN_IDs.OPTIMISM_SEPOLIA]: "opt-sepolia",
14
+ };
15
+
16
+ export function getURL(chainId: number, apiKey: string, transport: RPCTransport): string {
17
+ let host = endpoints[chainId] ?? PUBLIC_NETWORKS[chainId]?.name;
18
+ if (!host) {
19
+ throw new Error(`No known Alchemy provider for chainId ${chainId}`);
20
+ }
21
+
22
+ if (MAINNET_CHAIN_IDs.includes(chainId)) {
23
+ host = `${host}-mainnet`;
24
+ }
25
+ host = host.toLowerCase().replace(" ", "-");
26
+
27
+ return `${transport}://${host}.g.alchemy.com/v2/${apiKey}`;
28
+ }
@@ -2,4 +2,5 @@ export * from "./rateLimitedProvider";
2
2
  export * from "./cachedProvider";
3
3
  export * from "./retryProvider";
4
4
  export * from "./constants";
5
+ export * from "./types";
5
6
  export * from "./utils";
@@ -0,0 +1,23 @@
1
+ import { CHAIN_IDs, MAINNET_CHAIN_IDs as _MAINNET_CHAIN_IDs, PUBLIC_NETWORKS } from "../constants";
2
+ import { RPCTransport } from "./types";
3
+
4
+ const MAINNET_CHAIN_IDs = Object.values(_MAINNET_CHAIN_IDs);
5
+
6
+ // Chain-specific overrides for when the Infura endpoint does not match the canonical chain name.
7
+ const endpoints: { [chainId: string]: string } = {
8
+ [CHAIN_IDs.ARBITRUM]: "arbitrum",
9
+ };
10
+
11
+ export function getURL(chainId: number, apiKey: string, transport: RPCTransport): string {
12
+ let host = endpoints[chainId] ?? PUBLIC_NETWORKS[chainId]?.name;
13
+ if (!host) {
14
+ throw new Error(`No known Infura provider for chainId ${chainId}`);
15
+ }
16
+
17
+ if (chainId !== CHAIN_IDs.MAINNET && MAINNET_CHAIN_IDs.includes(chainId)) {
18
+ host = `${host}-mainnet`;
19
+ }
20
+ host = host.toLowerCase().replace(" ", "-");
21
+
22
+ return transport === "https" ? `https://${host}.infura.io/v3/${apiKey}` : `wss://${host}.infura.io/ws/v3/${apiKey}`;
23
+ }
@@ -0,0 +1,2 @@
1
+ export type RPCProvider = "INFURA" | "ALCHEMY";
2
+ export type RPCTransport = "https" | "wss";
@@ -1,8 +1,48 @@
1
1
  // The async/queue library has a task-based interface for building a concurrent queue.
2
-
2
+ import assert from "assert";
3
3
  import { providers } from "ethers";
4
- import { isDefined } from "../utils";
5
4
  import { isEqual } from "lodash";
5
+ import { isDefined } from "../utils";
6
+ import { RPCProvider, RPCTransport } from "./types";
7
+ import * as alchemy from "./alchemy";
8
+ import * as infura from "./infura";
9
+
10
+ /**
11
+ * Infura DIN is identified separately to allow it to be configured explicitly.
12
+ */
13
+ const PROVIDERS = {
14
+ ALCHEMY: alchemy.getURL,
15
+ INFURA: infura.getURL,
16
+ INFURA_DIN: infura.getURL,
17
+ };
18
+
19
+ /**
20
+ * Type predicate for RPCProvider type.
21
+ * @param provider Provider string (ALCHEMY, INFURA, ...).
22
+ * @returns True if the provider string is a supported provider.
23
+ */
24
+ export function isSupportedProvider(provider: string): provider is RPCProvider {
25
+ return ["ALCHEMY", "INFURA", "INFURA_DIN"].includes(provider);
26
+ }
27
+
28
+ /**
29
+ * Produce an RPC for a given RPC provider, chainId API key and transport.
30
+ * @param provider RPC provider identifier (ALCHEMY, INFURA, ...)
31
+ * @param chainId Chain ID to obtain a URL for.
32
+ * @param apiKey API key for provider.
33
+ * @param transport Optional transport specifier (HTTPS or WSS).
34
+ * @returns An RPC URL confirming to the specified inputs.
35
+ */
36
+ export function getURL(
37
+ provider: RPCProvider,
38
+ chainId: number,
39
+ apiKey: string,
40
+ transport: RPCTransport = "https"
41
+ ): string {
42
+ const getURL = PROVIDERS[provider];
43
+ assert(getURL, `Unsupported RPC provider (${provider})`);
44
+ return getURL(chainId, apiKey, transport);
45
+ }
6
46
 
7
47
  /**
8
48
  * Deletes keys from an object and returns new copy of object without ignored keys
@@ -43,6 +83,27 @@ export function compareArrayResultsWithIgnoredKeys(ignoredKeys: string[], objA:
43
83
  return isDefined(filteredA) && isDefined(filteredB) && isEqual(filteredA, filteredB);
44
84
  }
45
85
 
86
+ /**
87
+ * A record of error codes that correspond to fields that should be ignored when comparing RPC results.
88
+ * This is used to compare results from different providers that may have different, but still valid, results.
89
+ */
90
+ const IGNORED_FIELDS = {
91
+ // We've seen some RPC's like QuickNode add in transactionLogIndex which isn't in the
92
+ // JSON RPC spec: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterchanges
93
+ // Additional reference: https://github.com/ethers-io/ethers.js/issues/1721
94
+ // 2023-08-31 Added blockHash because of upstream zkSync provider disagreements. Consider removing later.
95
+ // 2024-05-07 Added l1BatchNumber and logType due to Alchemy. Consider removing later.
96
+ // 2024-07-11 Added blockTimestamp after zkSync rolled out a new node release.
97
+ eth_getBlockByNumber: [
98
+ "miner", // polygon (sometimes)
99
+ "l1BatchNumber", // zkSync
100
+ "l1BatchTimestamp", // zkSync
101
+ "size", // Alchemy/Arbitrum (temporary)
102
+ "totalDifficulty", // Quicknode/Alchemy (sometimes)
103
+ ],
104
+ eth_getLogs: ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
105
+ };
106
+
46
107
  /**
47
108
  * This is the type we pass to define a request "task".
48
109
  */
@@ -85,25 +146,13 @@ export function compareRpcResults(method: string, rpcResultA: unknown, rpcResult
85
146
  // We've seen RPC's disagree on the miner field, for example when Polygon nodes updated software that
86
147
  // led alchemy and quicknode to disagree on the miner field's value.
87
148
  return compareResultsAndFilterIgnoredKeys(
88
- [
89
- "miner", // polygon (sometimes)
90
- "l1BatchNumber", // zkSync
91
- "l1BatchTimestamp", // zkSync
92
- "size", // Alchemy/Arbitrum (temporary)
93
- "totalDifficulty", // Quicknode/Alchemy (sometimes)
94
- ],
149
+ IGNORED_FIELDS.eth_getBlockByNumber,
95
150
  rpcResultA as Record<string, unknown>,
96
151
  rpcResultB as Record<string, unknown>
97
152
  );
98
153
  } else if (method === "eth_getLogs") {
99
- // We've seen some RPC's like QuickNode add in transactionLogIndex which isn't in the
100
- // JSON RPC spec: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterchanges
101
- // Additional reference: https://github.com/ethers-io/ethers.js/issues/1721
102
- // 2023-08-31 Added blockHash because of upstream zkSync provider disagreements. Consider removing later.
103
- // 2024-05-07 Added l1BatchNumber and logType due to Alchemy. Consider removing later.
104
- // 2024-07-11 Added blockTimestamp after zkSync rolled out a new node release.
105
154
  return compareArrayResultsWithIgnoredKeys(
106
- ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
155
+ IGNORED_FIELDS.eth_getLogs,
107
156
  rpcResultA as unknown[],
108
157
  rpcResultB as unknown[]
109
158
  );
@@ -16,3 +16,10 @@ export async function isContractDeployedToAddress(address: string, provider: pro
16
16
  // If the code is not empty, then there is a contract at this address
17
17
  return code !== "0x";
18
18
  }
19
+
20
+ export function compareAddressesSimple(addressA?: string, addressB?: string): boolean {
21
+ if (addressA === undefined || addressB === undefined) {
22
+ return false;
23
+ }
24
+ return addressA.toLowerCase() === addressB.toLowerCase();
25
+ }
@@ -5,6 +5,7 @@ import { L1Token } from "../interfaces";
5
5
  import { ERC20__factory } from "../typechain";
6
6
  import { getNetworkName } from "./NetworkUtils";
7
7
  import { isDefined } from "./TypeGuards";
8
+ import { compareAddressesSimple } from "./AddressUtils";
8
9
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs } = constants;
9
10
 
10
11
  type SignerOrProvider = providers.Provider | Signer;
@@ -106,3 +107,49 @@ export function isBridgedUsdc(tokenSymbol: string): boolean {
106
107
  (bridgedUsdcSymbol) => bridgedUsdcSymbol.toLowerCase() === tokenSymbol.toLowerCase()
107
108
  );
108
109
  }
110
+
111
+ export function getTokenInfo(l2TokenAddress: string, chainId: number): L1Token {
112
+ // @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
113
+ // to get around this...
114
+ const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
115
+ if (!tokenObject) {
116
+ throw new Error(
117
+ `TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`
118
+ );
119
+ }
120
+ return {
121
+ address: l2TokenAddress,
122
+ symbol: tokenObject.symbol,
123
+ decimals: tokenObject.decimals,
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Get the USDC symbol for the given token address and chain ID.
129
+ * @param l2Token A Web3 token address (not case sensitive)
130
+ * @param chainId A chain Id to reference
131
+ * @returns Either USDC (if native) or USDbC/USDC.e (if bridged) or undefined if the token address is not recognized.
132
+ */
133
+ export function getUsdcSymbol(l2Token: string, chainId: number): string | undefined {
134
+ const compareToken = (token?: string) => isDefined(token) && compareAddressesSimple(l2Token, token);
135
+ return ["USDC", "USDbC", "USDC.e"].find((token) =>
136
+ compareToken(
137
+ (TOKEN_SYMBOLS_MAP as Record<string, { addresses?: Record<number, string> }>)[token]?.addresses?.[chainId]
138
+ )
139
+ );
140
+ }
141
+
142
+ export function getL1TokenInfo(l2TokenAddress: string, chainId: number): L1Token {
143
+ const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
144
+ const l1TokenAddress = tokenObject?.addresses[CHAIN_IDs.MAINNET];
145
+ if (!l1TokenAddress) {
146
+ throw new Error(
147
+ `TokenUtils#getL1TokenInfo: Unable to resolve l1 token address in TOKEN_SYMBOLS_MAP for L2 token ${l2TokenAddress} on chain ${chainId}`
148
+ );
149
+ }
150
+ return {
151
+ address: l1TokenAddress,
152
+ symbol: tokenObject.symbol,
153
+ decimals: tokenObject.decimals,
154
+ };
155
+ }