@swapkit/helpers 3.0.0-beta.7 → 3.0.0-beta.8

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.
@@ -13,7 +13,7 @@ describe("AssetValue", () => {
13
13
  symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
14
14
  });
15
15
  expect(fakeAvaxUSDCAsset.toString()).toBe(
16
- "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
16
+ "AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
17
17
  );
18
18
 
19
19
  const ethSynth = new AssetValue({
@@ -115,20 +115,20 @@ describe("AssetValue", () => {
115
115
  const arbWeth = AssetValue.from({
116
116
  asset: "ARB.WETH-0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
117
117
  });
118
- expect(arbWeth.toString()).toBe("ARB.WETH-0x82af49447d8a07e3bd95bd0d56f35241523fbab1");
118
+ expect(arbWeth.toString()).toBe("ARB.WETH-0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
119
119
 
120
120
  const baseAssetFromString = AssetValue.from({
121
121
  asset: "BASE.USDC-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
122
122
  });
123
123
  expect(baseAssetFromString.toString()).toBe(
124
- "BASE.USDC-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
124
+ "BASE.USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
125
125
  );
126
126
 
127
127
  const avaxSolanaAsset = AssetValue.from({
128
128
  asset: "AVAX.SOL-0XFE6B19286885A4F7F55ADAD09C3CD1F906D2478F",
129
129
  });
130
130
  expect(avaxSolanaAsset.toString()).toBe(
131
- "AVAX.SOL-0xfe6b19286885a4f7f55adad09c3cd1f906d2478f",
131
+ "AVAX.SOL-0xFE6B19286885a4F7F55AdAD09C3Cd1f906D2478F",
132
132
  );
133
133
  });
134
134
  });
@@ -190,11 +190,11 @@ describe("AssetValue", () => {
190
190
  symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
191
191
  });
192
192
  expect(fakeAvaxUSDCAsset.toUrl()).toBe(
193
- "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
193
+ "AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
194
194
  );
195
195
 
196
196
  const thor = AssetValue.from({ asset: "ETH.THOR" });
197
- expect(thor.toUrl()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
197
+ expect(thor.toUrl()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
198
198
 
199
199
  const ethSynth = new AssetValue({
200
200
  chain: Chain.THORChain,
@@ -299,10 +299,10 @@ describe("AssetValue", () => {
299
299
  chain: Chain.Avalanche,
300
300
  symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
301
301
  });
302
- expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
302
+ expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E");
303
303
 
304
304
  const thor = AssetValue.from({ asset: "ETH.THOR" });
305
- expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
305
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
306
306
 
307
307
  const ethSynth = await AssetValue.from({
308
308
  asset: "ETH/ETH",
@@ -331,12 +331,12 @@ describe("AssetValue", () => {
331
331
 
332
332
  expect(avaxUSDCAsset).toEqual(
333
333
  expect.objectContaining({
334
- address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
334
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
335
335
  chain: Chain.Avalanche,
336
336
  decimal: 6,
337
337
  isGasAsset: false,
338
338
  isSynthetic: false,
339
- symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
339
+ symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
340
340
  ticker: "USDC",
341
341
  }),
342
342
  );
@@ -465,7 +465,7 @@ describe("AssetValue", () => {
465
465
 
466
466
  expect(synthETH.toString()).toBe("ETH/ETH");
467
467
  expect(eth.toString()).toBe("ETH.ETH");
468
- expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
468
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
469
469
  expect(synthThor.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
470
470
  expect(synthDashes.toString()).toBe("ETH/PENDLE-LPT-0x1234");
471
471
  });
@@ -481,12 +481,12 @@ describe("AssetValue", () => {
481
481
  expect(thor).toBeDefined();
482
482
  expect(thor).toEqual(
483
483
  expect.objectContaining({
484
- address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
484
+ address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
485
485
  chain: Chain.Arbitrum,
486
486
  decimal: 6,
487
487
  isGasAsset: false,
488
488
  isSynthetic: false,
489
- symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
489
+ symbol: "USDT-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
490
490
  ticker: "USDT",
491
491
  }),
492
492
  );
@@ -503,12 +503,12 @@ describe("AssetValue", () => {
503
503
  expect(thor).toBeDefined();
504
504
  expect(thor).toEqual(
505
505
  expect.objectContaining({
506
- address: "0xa5f2211b9b8170f694421f2046281775e8468044",
506
+ address: "0xa5f2211B9b8170F694421f2046281775E8468044",
507
507
  chain: Chain.Ethereum,
508
508
  decimal: 18,
509
509
  isGasAsset: false,
510
510
  isSynthetic: false,
511
- symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
511
+ symbol: "THOR-0xa5f2211B9b8170F694421f2046281775E8468044",
512
512
  ticker: "THOR",
513
513
  }),
514
514
  );
@@ -519,12 +519,12 @@ describe("AssetValue", () => {
519
519
  expect(usdc).toBeDefined();
520
520
  expect(usdc).toEqual(
521
521
  expect.objectContaining({
522
- address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
522
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
523
523
  chain: Chain.Ethereum,
524
524
  decimal: 6,
525
525
  isGasAsset: false,
526
526
  isSynthetic: false,
527
- symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
527
+ symbol: "USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
528
528
  ticker: "USDC",
529
529
  }),
530
530
  );
@@ -580,12 +580,12 @@ describe("AssetValue", () => {
580
580
  expect(AvaxBTCb).toBeDefined();
581
581
  expect(AvaxBTCb).toEqual(
582
582
  expect.objectContaining({
583
- address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
583
+ address: "0x152b9d0FdC40C096757F570A51E494bd4b943E50",
584
584
  chain: Chain.Avalanche,
585
585
  decimal: 8,
586
586
  isGasAsset: false,
587
587
  isSynthetic: false,
588
- symbol: "BTC.B-0x152b9d0fdc40c096757f570a51e494bd4b943e50",
588
+ symbol: "BTC.B-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
589
589
  ticker: "BTC.B",
590
590
  }),
591
591
  );
@@ -655,12 +655,12 @@ describe("AssetValue", () => {
655
655
  expect(AvaxUSDC).toBeDefined();
656
656
  expect(AvaxUSDC).toEqual(
657
657
  expect.objectContaining({
658
- address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
658
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
659
659
  chain: Chain.Avalanche,
660
660
  decimal: 6,
661
661
  isGasAsset: false,
662
662
  isSynthetic: false,
663
- symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
663
+ symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
664
664
  ticker: "USDC",
665
665
  }),
666
666
  );
@@ -731,12 +731,12 @@ describe("AssetValue", () => {
731
731
  const thor = AssetValue.from({ asset: "ETH.THOR" });
732
732
  expect(thor).toEqual(
733
733
  expect.objectContaining({
734
- address: "0xa5f2211b9b8170f694421f2046281775e8468044",
734
+ address: "0xa5f2211B9b8170F694421f2046281775E8468044",
735
735
  chain: Chain.Ethereum,
736
736
  decimal: 18,
737
737
  isGasAsset: false,
738
738
  isSynthetic: false,
739
- symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
739
+ symbol: "THOR-0xa5f2211B9b8170F694421f2046281775E8468044",
740
740
  ticker: "THOR",
741
741
  }),
742
742
  );
@@ -1,4 +1,11 @@
1
- import { BaseDecimal, Chain, type ChainId, ChainToChainId } from "../types/chains";
1
+ import {
2
+ BaseDecimal,
3
+ Chain,
4
+ type ChainId,
5
+ ChainToChainId,
6
+ type EVMChain,
7
+ EVMChains,
8
+ } from "../types/chains";
2
9
  import type { TokenNames, TokenTax } from "../types/tokens";
3
10
  import {
4
11
  type CommonAssetString,
@@ -12,6 +19,7 @@ import { warnOnce } from "../utils/others";
12
19
  import { type TokenListName, loadTokenLists } from "../utils/tokens";
13
20
  import { validateIdentifier } from "../utils/validators";
14
21
 
22
+ import { getAddress } from "ethers";
15
23
  import type { NumberPrimitives } from "./bigIntArithmetics";
16
24
  import { BigIntArithmetics, formatBigIntToSafeValue } from "./bigIntArithmetics";
17
25
  import { SwapKitError } from "./swapKitError";
@@ -345,12 +353,23 @@ function getAssetInfo(identifier: string) {
345
353
  const assetSymbol = isSynthOrTrade ? synthSymbol : rest.join(".");
346
354
 
347
355
  const { address, ticker } = getAssetBaseInfo({ symbol: assetSymbol, chain });
356
+
357
+ let formattedAddress: string | undefined;
358
+ try {
359
+ formattedAddress =
360
+ address && EVMChains.includes(chain as EVMChain) && getAddress(address)
361
+ ? getAddress(address)
362
+ : address;
363
+ } catch (_error) {
364
+ formattedAddress = address;
365
+ }
366
+
348
367
  const symbol =
349
368
  (isSynthOrTrade ? `${synthChain}${assetSeparator}` : "") +
350
- (address ? `${ticker}-${address ?? ""}` : assetSymbol);
369
+ (formattedAddress ? `${ticker}-${formattedAddress ?? ""}` : assetSymbol);
351
370
 
352
371
  return {
353
- address,
372
+ address: formattedAddress,
354
373
  chain,
355
374
  isSynthOrTrade,
356
375
  isSynthetic,