@across-protocol/sdk 4.3.2 → 4.3.3

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 (48) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +4 -1
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  3. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +8 -5
  4. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  5. package/dist/cjs/clients/HubPoolClient.d.ts +1 -1
  6. package/dist/cjs/clients/HubPoolClient.js +3 -3
  7. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  8. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +5 -5
  9. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  10. package/dist/cjs/typeguards/error.d.ts +2 -0
  11. package/dist/cjs/typeguards/error.js +4 -1
  12. package/dist/cjs/typeguards/error.js.map +1 -1
  13. package/dist/cjs/utils/TokenUtils.d.ts +5 -4
  14. package/dist/cjs/utils/TokenUtils.js +15 -23
  15. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  16. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +5 -2
  17. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  18. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +9 -6
  19. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  20. package/dist/esm/clients/HubPoolClient.d.ts +1 -1
  21. package/dist/esm/clients/HubPoolClient.js +3 -4
  22. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  23. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +11 -10
  24. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +6 -6
  25. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  26. package/dist/esm/typeguards/error.d.ts +2 -0
  27. package/dist/esm/typeguards/error.js +2 -0
  28. package/dist/esm/typeguards/error.js.map +1 -1
  29. package/dist/esm/utils/TokenUtils.d.ts +31 -10
  30. package/dist/esm/utils/TokenUtils.js +20 -28
  31. package/dist/esm/utils/TokenUtils.js.map +1 -1
  32. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  33. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  34. package/dist/types/clients/HubPoolClient.d.ts +1 -1
  35. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  36. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +11 -10
  37. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  38. package/dist/types/typeguards/error.d.ts +2 -0
  39. package/dist/types/typeguards/error.d.ts.map +1 -1
  40. package/dist/types/utils/TokenUtils.d.ts +31 -10
  41. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  42. package/package.json +3 -2
  43. package/src/clients/BundleDataClient/BundleDataClient.ts +4 -1
  44. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +10 -6
  45. package/src/clients/HubPoolClient.ts +3 -4
  46. package/src/relayFeeCalculator/relayFeeCalculator.ts +6 -5
  47. package/src/typeguards/error.ts +3 -0
  48. package/src/utils/TokenUtils.ts +30 -34
@@ -1 +1 @@
1
- {"version":3,"file":"TokenUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/TokenUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAY,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM7C,KAAK,gBAAgB,GAAG,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;AAEpD,wBAAsB,cAAc,CAAC,O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AE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAvC5E;;;;;;;WAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+DH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAjC6F,GAAG,SAAS,CAe3G;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAetF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "4.3.2",
4
+ "version": "4.3.3",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "files": [
@@ -33,7 +33,8 @@
33
33
  "bump-version:major": "yarn version --major --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
34
34
  "bump-version:minor": "yarn version --minor --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
35
35
  "bump-version:patch": "yarn version --patch --no-git-tag-version --no-commit-hooks && git commit -m 'chore: bump version' ./package.json --no-verify",
36
- "typechain": "typechain --target ethers-v5 --out-dir src/utils/abi/typechain 'src/utils/abi/contracts/*.json' && eslint --fix src/utils/abi/typechain && yarn prettier --write \"src/utils/abi/typechain/**/*.ts\""
36
+ "typechain": "typechain --target ethers-v5 --out-dir src/utils/abi/typechain 'src/utils/abi/contracts/*.json' && eslint --fix src/utils/abi/typechain && yarn prettier --write \"src/utils/abi/typechain/**/*.ts\"",
37
+ "yalc:watch": "nodemon --watch src --ext ts,tsx,json,js,jsx --exec 'yalc push'"
37
38
  },
38
39
  "lint-staged": {
39
40
  "*.ts": "yarn lint"
@@ -43,6 +43,7 @@ import {
43
43
  invalidOutputToken,
44
44
  Address,
45
45
  getNetworkName,
46
+ toBytes32,
46
47
  } from "../../utils";
47
48
  import winston from "winston";
48
49
  import {
@@ -327,7 +328,9 @@ export class BundleDataClient {
327
328
  Object.entries(tokenData).map(([token, data]) => [
328
329
  token,
329
330
  {
330
- refunds: data.refunds,
331
+ refunds: Object.fromEntries(
332
+ Object.entries(data.refunds).map(([refundAddress, refund]) => [toBytes32(refundAddress), refund])
333
+ ),
331
334
  totalRefundAmount: data.totalRefundAmount,
332
335
  realizedLpFees: data.realizedLpFees,
333
336
  fills: convertSortableEventFieldsIntoRequiredFields(data.fills),
@@ -15,10 +15,10 @@ import {
15
15
  type,
16
16
  } from "superstruct";
17
17
  import { CHAIN_IDs, UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
- import { BigNumber, EvmAddress, RawAddress, SvmAddress, toAddressType } from "../../../utils";
18
+ import { BigNumber, EvmAddress, RawAddress, SvmAddress, toAddressType, toBytes32 } from "../../../utils";
19
19
 
20
20
  const PositiveIntegerStringSS = pattern(string(), /\d+/);
21
- const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{40}$/);
21
+ const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{64}$/);
22
22
 
23
23
  const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (value) => {
24
24
  try {
@@ -43,6 +43,10 @@ const AddressType = coerce(AddressInstanceSS, string(), (value) => {
43
43
  return toAddressType(value, chainId);
44
44
  });
45
45
 
46
+ const Web3AddressType = coerce(Web3AddressSS, string(), (value) => {
47
+ return toBytes32(value);
48
+ });
49
+
46
50
  const FillTypeSS = number();
47
51
 
48
52
  const V3RelayDataSS = {
@@ -126,20 +130,20 @@ const BundleFillV3SS = object({
126
130
  lpFeePct: BigNumberType,
127
131
  });
128
132
 
129
- const nestedV3DepositRecordSS = record(PositiveIntegerStringSS, record(Web3AddressSS, array(V3DepositWithBlockSS)));
133
+ const nestedV3DepositRecordSS = record(PositiveIntegerStringSS, record(Web3AddressType, array(V3DepositWithBlockSS)));
130
134
  const nestedV3DepositRecordWithLpFeePctSS = record(
131
135
  PositiveIntegerStringSS,
132
- record(Web3AddressSS, array(V3DepositWithBlockLpFeeSS))
136
+ record(Web3AddressType, array(V3DepositWithBlockLpFeeSS))
133
137
  );
134
138
 
135
139
  const nestedV3BundleFillsSS = record(
136
140
  // Must be a chainId
137
141
  PositiveIntegerStringSS,
138
142
  record(
139
- Web3AddressSS,
143
+ Web3AddressType,
140
144
  object({
141
145
  fills: array(BundleFillV3SS),
142
- refunds: record(string(), BigNumberType),
146
+ refunds: record(Web3AddressType, BigNumberType),
143
147
  totalRefundAmount: BigNumberType,
144
148
  realizedLpFees: BigNumberType,
145
149
  })
@@ -281,13 +281,12 @@ export class HubPoolClient extends BaseAbstractClient {
281
281
  * @param chainId Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
282
282
  * @returns Token info for the given token address on the L2 chain including symbol and decimal.
283
283
  */
284
- // TODO: didn't change `tokenAddress` here to Address because of downstream getTokenInfo impl
285
- getTokenInfoForAddress(tokenAddress: string, chainId: number): TokenInfo {
286
- const tokenInfo = getTokenInfo(tokenAddress, chainId);
284
+ getTokenInfoForAddress(address: Address, chainId: number): TokenInfo {
285
+ const tokenInfo = getTokenInfo(address, chainId);
287
286
  // @dev Temporarily handle case where an L2 token for chain ID can map to more than one TOKEN_SYMBOLS_MAP
288
287
  // entry. For example, L2 Bridged USDC maps to both the USDC and USDC.e/USDbC entries in TOKEN_SYMBOLS_MAP.
289
288
  if (tokenInfo.symbol.toLowerCase() === "usdc" && chainId !== this.chainId) {
290
- tokenInfo.symbol = getUsdcSymbol(tokenAddress, chainId) ?? "UNKNOWN";
289
+ tokenInfo.symbol = getUsdcSymbol(address, chainId) ?? "UNKNOWN USDC";
291
290
  }
292
291
  return tokenInfo;
293
292
  }
@@ -27,6 +27,7 @@ import {
27
27
  Address,
28
28
  EvmAddress,
29
29
  SvmAddress,
30
+ toAddressType,
30
31
  } from "../utils";
31
32
 
32
33
  // This needs to be implemented for every chain and passed into RelayFeeCalculator
@@ -277,10 +278,10 @@ export class RelayFeeCalculator {
277
278
  isDefined(details.addresses[destinationChainId])
278
279
  );
279
280
  const outputToken = deposit.outputToken.isZeroAddress()
280
- ? destinationChainTokenDetails!.addresses[destinationChainId]
281
- : deposit.outputToken.toNative();
281
+ ? toAddressType(destinationChainTokenDetails!.addresses[destinationChainId], destinationChainId)
282
+ : deposit.outputToken;
282
283
  const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
283
- const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId, tokenMapping);
284
+ const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
284
285
  if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
285
286
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
286
287
  }
@@ -507,8 +508,8 @@ export class RelayFeeCalculator {
507
508
  const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
508
509
  // We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
509
510
  // resolve the L1 token symbol and not the L2 token decimals.
510
- const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId);
511
- const outputTokenInfo = getTokenInfo(outputToken.toNative(), destinationChainId);
511
+ const inputTokenInfo = getTokenInfo(inputToken, originChainId);
512
+ const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
512
513
  if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
513
514
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
514
515
  }
@@ -1,7 +1,10 @@
1
1
  import { ethers } from "ethers";
2
2
  import { EthersError } from "../interfaces";
3
+ import { BaseError } from "viem";
3
4
 
4
5
  export const isError = (error: unknown): error is Error => error instanceof Error;
5
6
 
6
7
  export const isEthersError = (error?: unknown): error is EthersError =>
7
8
  (error as EthersError)?.code in ethers.utils.Logger.errors;
9
+
10
+ export const isViemError = (error?: unknown): error is BaseError => error instanceof BaseError;
@@ -7,7 +7,7 @@ import { ERC20__factory } from "../typechain";
7
7
  import { BigNumber } from "./BigNumberUtils";
8
8
  import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
9
9
  import { isDefined } from "./TypeGuards";
10
- import { compareAddressesSimple, EvmAddress, toAddressType } from "./AddressUtils";
10
+ import { Address, EvmAddress, toAddressType } from "./AddressUtils";
11
11
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
12
12
 
13
13
  type SignerOrProvider = providers.Provider | Signer;
@@ -66,11 +66,8 @@ export const resolveContractFromSymbol = (
66
66
  })?.addresses[Number(chainId)];
67
67
  };
68
68
 
69
- export function getCoingeckoTokenIdByAddress(contractAddress: string, chainId: number): string {
70
- const token = getTokenInfo(contractAddress, chainId);
71
- if (!token) {
72
- throw new Error(`Token with address ${contractAddress} not found in token mapping`);
73
- }
69
+ export function getCoingeckoTokenIdByAddress(address: string, chainId: number): string {
70
+ const token = getTokenInfo(toAddressType(address, chainId), chainId);
74
71
  return TOKEN_SYMBOLS_MAP[token.symbol as keyof typeof TOKEN_SYMBOLS_MAP].coingeckoId;
75
72
  }
76
73
 
@@ -108,31 +105,26 @@ export function isStablecoin(tokenSymbol: string): boolean {
108
105
  * @notice Returns the Token info for the token mapping in TOKEN_SYMBOLS_MAP matching the given l2TokenAddress
109
106
  * and chainId. If the chain is the hub chain, then will remap the L1 token to its equivalent L1 token symbol for example
110
107
  * it will always return a token info with symbol USDC and never USDC.e if chainId = mainnet.
111
- * @param l2TokenAddress
112
- * @param chainId
113
- * @param tokenMapping
114
- * @returns
108
+ * @param l2Token Address instance.
109
+ * @param chainId ChainId for l2Token address.
110
+ * @param tokenMapping Optional custom token mapping.
111
+ * @returns TokenInfo object.
115
112
  */
116
- export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
117
- const parsedAddress = toAddressType(l2TokenAddress, chainId).toNative();
113
+ export function getTokenInfo(l2Token: Address, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
114
+ const address = l2Token.toNative();
118
115
 
119
116
  // @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
120
117
  // to get around this...
121
- let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === parsedAddress);
118
+ let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === address);
122
119
  if (!tokenObject) {
123
- throw new Error(
124
- `TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`
125
- );
120
+ throw new Error(`Unable to resolve token info for ${address} on chain ${chainId}`);
126
121
  }
127
122
  if (chainIsL1(chainId)) {
128
123
  const l1TokenSymbol = TOKEN_EQUIVALENCE_REMAPPING[tokenObject.symbol] ?? tokenObject.symbol;
129
124
  tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
130
125
  }
131
- return {
132
- address: toAddressType(l2TokenAddress, chainId),
133
- symbol: tokenObject.symbol,
134
- decimals: tokenObject.decimals,
135
- };
126
+
127
+ return { address: l2Token, symbol: tokenObject.symbol, decimals: tokenObject.decimals };
136
128
  }
137
129
 
138
130
  /**
@@ -141,26 +133,30 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
141
133
  * @param chainId A chain Id to reference
142
134
  * @returns Either USDC (if native) or USDbC/USDC.e (if bridged) or undefined if the token address is not recognized.
143
135
  */
144
- export function getUsdcSymbol(l2Token: string, chainId: number): string | undefined {
145
- const compareToken = (token?: string) => isDefined(token) && compareAddressesSimple(l2Token, token);
146
- return ["USDC", "USDbC", "USDC.e"].find((token) =>
147
- compareToken(
148
- (TOKEN_SYMBOLS_MAP as Record<string, { addresses?: Record<number, string> }>)[token]?.addresses?.[chainId]
149
- )
136
+ export function getUsdcSymbol(l2Token: Address, chainId: number): string | undefined {
137
+ type TokenRecord = Record<string, { addresses?: Record<number, string> }>;
138
+ const IterableTokenSymbolsMap = TOKEN_SYMBOLS_MAP as TokenRecord;
139
+ return ["USDC", "USDbC", "USDC.e"].find(
140
+ (token) => IterableTokenSymbolsMap[token]?.addresses?.[chainId] === l2Token.toNative()
150
141
  );
151
142
  }
152
143
 
153
144
  /**
154
145
  * @notice Returns the l1 token address matching the given l2TokenAddress and chainId.
155
146
  */
156
- export function getL1TokenAddress(l2TokenAddress: string, chainId: number): string {
157
- if (chainIsL1(chainId)) return l2TokenAddress;
158
- const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
147
+ export function getL1TokenAddress(l2TokenAddress: Address, chainId: number): EvmAddress {
148
+ if (chainIsL1(chainId)) {
149
+ assert(l2TokenAddress.isEVM());
150
+ return l2TokenAddress;
151
+ }
152
+
153
+ const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(
154
+ ({ addresses }) => l2TokenAddress.toNative() === addresses[chainId]
155
+ );
159
156
  const l1TokenAddress = tokenObject?.addresses[chainIsProd(chainId) ? CHAIN_IDs.MAINNET : CHAIN_IDs.SEPOLIA];
160
157
  if (!l1TokenAddress) {
161
- throw new Error(
162
- `TokenUtils#getL1TokenInfo: Unable to resolve l1 token address in TOKEN_SYMBOLS_MAP for L2 token ${l2TokenAddress} on chain ${chainId}`
163
- );
158
+ throw new Error(`getL1TokenAddress: Unable to resolve l1 token for L2 token ${l2TokenAddress} on chain ${chainId}`);
164
159
  }
165
- return l1TokenAddress;
160
+
161
+ return EvmAddress.from(l1TokenAddress);
166
162
  }