@across-protocol/sdk 3.1.24 → 3.1.26

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 (46) 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/constants.d.ts +1 -1
  5. package/dist/cjs/constants.js +1 -1
  6. package/dist/cjs/providers/utils.js +12 -8
  7. package/dist/cjs/providers/utils.js.map +1 -1
  8. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +0 -1
  9. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  10. package/dist/cjs/utils/AddressUtils.d.ts +1 -0
  11. package/dist/cjs/utils/AddressUtils.js +8 -1
  12. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  13. package/dist/cjs/utils/TokenUtils.d.ts +3 -0
  14. package/dist/cjs/utils/TokenUtils.js +41 -1
  15. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  16. package/dist/esm/clients/HubPoolClient.d.ts +15 -0
  17. package/dist/esm/clients/HubPoolClient.js +27 -1
  18. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  19. package/dist/esm/constants.d.ts +1 -1
  20. package/dist/esm/constants.js +1 -1
  21. package/dist/esm/providers/utils.js +22 -14
  22. package/dist/esm/providers/utils.js.map +1 -1
  23. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +0 -1
  24. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  25. package/dist/esm/utils/AddressUtils.d.ts +1 -0
  26. package/dist/esm/utils/AddressUtils.js +6 -0
  27. package/dist/esm/utils/AddressUtils.js.map +1 -1
  28. package/dist/esm/utils/TokenUtils.d.ts +39 -16
  29. package/dist/esm/utils/TokenUtils.js +45 -0
  30. package/dist/esm/utils/TokenUtils.js.map +1 -1
  31. package/dist/types/clients/HubPoolClient.d.ts +15 -0
  32. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  33. package/dist/types/constants.d.ts +1 -1
  34. package/dist/types/providers/utils.d.ts.map +1 -1
  35. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  36. package/dist/types/utils/AddressUtils.d.ts +1 -0
  37. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  38. package/dist/types/utils/TokenUtils.d.ts +39 -16
  39. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/src/clients/HubPoolClient.ts +30 -0
  42. package/src/constants.ts +1 -1
  43. package/src/providers/utils.ts +23 -14
  44. package/src/relayFeeCalculator/relayFeeCalculator.ts +0 -1
  45. package/src/utils/AddressUtils.ts +7 -0
  46. package/src/utils/TokenUtils.ts +47 -0
@@ -43,6 +43,27 @@ export function compareArrayResultsWithIgnoredKeys(ignoredKeys: string[], objA:
43
43
  return isDefined(filteredA) && isDefined(filteredB) && isEqual(filteredA, filteredB);
44
44
  }
45
45
 
46
+ /**
47
+ * A record of error codes that correspond to fields that should be ignored when comparing RPC results.
48
+ * This is used to compare results from different providers that may have different, but still valid, results.
49
+ */
50
+ const IGNORED_FIELDS = {
51
+ // We've seen some RPC's like QuickNode add in transactionLogIndex which isn't in the
52
+ // JSON RPC spec: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterchanges
53
+ // Additional reference: https://github.com/ethers-io/ethers.js/issues/1721
54
+ // 2023-08-31 Added blockHash because of upstream zkSync provider disagreements. Consider removing later.
55
+ // 2024-05-07 Added l1BatchNumber and logType due to Alchemy. Consider removing later.
56
+ // 2024-07-11 Added blockTimestamp after zkSync rolled out a new node release.
57
+ eth_getBlockByNumber: [
58
+ "miner", // polygon (sometimes)
59
+ "l1BatchNumber", // zkSync
60
+ "l1BatchTimestamp", // zkSync
61
+ "size", // Alchemy/Arbitrum (temporary)
62
+ "totalDifficulty", // Quicknode/Alchemy (sometimes)
63
+ ],
64
+ eth_getLogs: ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
65
+ };
66
+
46
67
  /**
47
68
  * This is the type we pass to define a request "task".
48
69
  */
@@ -85,25 +106,13 @@ export function compareRpcResults(method: string, rpcResultA: unknown, rpcResult
85
106
  // We've seen RPC's disagree on the miner field, for example when Polygon nodes updated software that
86
107
  // led alchemy and quicknode to disagree on the miner field's value.
87
108
  return compareResultsAndFilterIgnoredKeys(
88
- [
89
- "miner", // polygon (sometimes)
90
- "l1BatchNumber", // zkSync
91
- "l1BatchTimestamp", // zkSync
92
- "size", // Alchemy/Arbitrum (temporary)
93
- "totalDifficulty", // Quicknode/Alchemy (sometimes)
94
- ],
109
+ IGNORED_FIELDS.eth_getBlockByNumber,
95
110
  rpcResultA as Record<string, unknown>,
96
111
  rpcResultB as Record<string, unknown>
97
112
  );
98
113
  } 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
114
  return compareArrayResultsWithIgnoredKeys(
106
- ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
115
+ IGNORED_FIELDS.eth_getLogs,
107
116
  rpcResultA as unknown[],
108
117
  rpcResultB as unknown[]
109
118
  );
@@ -196,7 +196,6 @@ export class RelayFeeCalculator {
196
196
  */
197
197
  static validateCapitalCostsConfig(capitalCosts: CapitalCostConfig): void {
198
198
  assert(toBN(capitalCosts.upperBound).lt(toBNWei("0.01")), "upper bound must be < 1%");
199
- assert(toBN(capitalCosts.lowerBound).lte(capitalCosts.upperBound), "lower bound must be <= upper bound");
200
199
  assert(capitalCosts.decimals > 0 && capitalCosts.decimals <= 18, "invalid decimals");
201
200
  }
202
201
 
@@ -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
+ }