@across-protocol/sdk 4.1.46-beta.3 → 4.1.46

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 (47) hide show
  1. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +2 -2
  2. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  3. package/dist/cjs/clients/HubPoolClient.d.ts +3 -0
  4. package/dist/cjs/clients/HubPoolClient.js +10 -0
  5. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  6. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +3 -0
  7. package/dist/cjs/clients/mocks/MockHubPoolClient.js +7 -0
  8. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  9. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -0
  10. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +5 -0
  11. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  12. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
  13. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  14. package/dist/cjs/utils/TokenUtils.js +0 -2
  15. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  16. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +2 -2
  17. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  18. package/dist/esm/clients/HubPoolClient.d.ts +10 -0
  19. package/dist/esm/clients/HubPoolClient.js +18 -1
  20. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  21. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +3 -0
  22. package/dist/esm/clients/mocks/MockHubPoolClient.js +7 -0
  23. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  24. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -0
  25. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +10 -0
  26. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  27. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
  28. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  29. package/dist/esm/utils/TokenUtils.js +0 -2
  30. package/dist/esm/utils/TokenUtils.js.map +1 -1
  31. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  32. package/dist/types/clients/HubPoolClient.d.ts +10 -0
  33. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  34. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +3 -0
  35. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  36. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -0
  37. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  38. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
  39. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  40. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/clients/BundleDataClient/utils/FillUtils.ts +9 -5
  43. package/src/clients/HubPoolClient.ts +23 -0
  44. package/src/clients/mocks/MockHubPoolClient.ts +9 -0
  45. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +10 -0
  46. package/src/relayFeeCalculator/relayFeeCalculator.ts +1 -0
  47. package/src/utils/TokenUtils.ts +0 -2
@@ -43,6 +43,7 @@ import {
43
43
  toBN,
44
44
  getTokenInfo,
45
45
  getUsdcSymbol,
46
+ getL1TokenInfo,
46
47
  compareAddressesSimple,
47
48
  chainIsSvm,
48
49
  getDeployedAddress,
@@ -284,6 +285,17 @@ export class HubPoolClient extends BaseAbstractClient {
284
285
  return tokenInfo;
285
286
  }
286
287
 
288
+ /**
289
+ * @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
290
+ * @dev if the token matched in TOKEN_SYMBOLS_MAP does not have an L1 token address then this will throw.
291
+ * @param tokenAddress Token address on `chain`
292
+ * @param chain Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
293
+ * @returns Token info for the given token address on the Hub chain including symbol and decimal and L1 address.
294
+ */
295
+ getL1TokenInfoForAddress(tokenAddress: string, chain: number): L1Token {
296
+ return getL1TokenInfo(tokenAddress, chain);
297
+ }
298
+
287
299
  /**
288
300
  * Resolve a given timestamp to a block number on the HubPool chain.
289
301
  * @param timestamp A single timestamp to be resolved to a block number on the HubPool chain.
@@ -503,6 +515,17 @@ export class HubPoolClient extends BaseAbstractClient {
503
515
  return this.getTokenInfoForL1Token(l1TokenCounterpart);
504
516
  }
505
517
 
518
+ getTokenInfoForDeposit(deposit: Pick<Deposit, "inputToken" | "originChainId">): L1Token | undefined {
519
+ return this.getTokenInfoForL1Token(
520
+ this.getL1TokenForL2TokenAtBlock(deposit.inputToken, deposit.originChainId, this.latestBlockSearched)
521
+ );
522
+ }
523
+
524
+ getTokenInfo(chainId: number | string, tokenAddress: string): L1Token | undefined {
525
+ const deposit = { originChainId: parseInt(chainId.toString()), inputToken: tokenAddress };
526
+ return this.getTokenInfoForDeposit(deposit);
527
+ }
528
+
506
529
  areTokensEquivalent(
507
530
  tokenA: string,
508
531
  chainIdA: number,
@@ -23,6 +23,7 @@ export class MockHubPoolClient extends HubPoolClient {
23
23
  private realizedLpFeePctOverride = false;
24
24
 
25
25
  private l1TokensMock: L1Token[] = []; // L1Tokens and their associated info.
26
+ private tokenInfoToReturn: L1Token = { address: "", decimals: 0, symbol: "" };
26
27
 
27
28
  private spokePoolTokens: { [l1Token: string]: { [chainId: number]: string } } = {};
28
29
 
@@ -90,6 +91,10 @@ export class MockHubPoolClient extends HubPoolClient {
90
91
  return this.l1TokensMock;
91
92
  }
92
93
 
94
+ getTokenInfoForDeposit() {
95
+ return this.tokenInfoToReturn;
96
+ }
97
+
93
98
  setTokenMapping(l1Token: string, chainId: number, l2Token: string) {
94
99
  this.spokePoolTokens[l1Token] ??= {};
95
100
  this.spokePoolTokens[l1Token][chainId] = l2Token;
@@ -131,6 +136,10 @@ export class MockHubPoolClient extends HubPoolClient {
131
136
  return this.l1TokensMock.find((token) => token.address === l1Token);
132
137
  }
133
138
 
139
+ setTokenInfoToReturn(tokenInfo: L1Token) {
140
+ this.tokenInfoToReturn = tokenInfo;
141
+ }
142
+
134
143
  _update(eventNames: string[]): Promise<HubPoolUpdate> {
135
144
  // Generate new "on chain" responses.
136
145
  const latestBlockSearched = this.eventManager.blockNumber;
@@ -252,4 +252,14 @@ export class QueryBase implements QueryInterface {
252
252
  );
253
253
  return price;
254
254
  }
255
+
256
+ /**
257
+ * Resolves the number of decimal places a token can have
258
+ * @param tokenSymbol A valid Across-Enabled Token ID
259
+ * @returns The number of decimals of precision for the corresponding tokenSymbol
260
+ */
261
+ getTokenDecimals(tokenSymbol: string): number {
262
+ if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
263
+ return this.symbolMapping[tokenSymbol].decimals;
264
+ }
255
265
  }
@@ -34,6 +34,7 @@ export interface QueryInterface {
34
34
  }>
35
35
  ) => Promise<TransactionCostEstimate>;
36
36
  getTokenPrice: (tokenSymbol: string) => Promise<number>;
37
+ getTokenDecimals: (tokenSymbol: string) => number;
37
38
  }
38
39
 
39
40
  export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
@@ -147,8 +147,6 @@ export function getUsdcSymbol(l2Token: string, chainId: number): string | undefi
147
147
  }
148
148
 
149
149
  export function getL1TokenInfo(l2TokenAddress: string, chainId: number): L1Token {
150
- if (chainId === CHAIN_IDs.MAINNET)
151
- throw new Error("chainId should be an L2 chainId because many mappings re-use the same L1 token address");
152
150
  const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
153
151
  const l1TokenAddress = tokenObject?.addresses[CHAIN_IDs.MAINNET];
154
152
  if (!l1TokenAddress) {