@swapkit/helpers 1.0.0-rc.9 → 1.0.0-rc.90

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 (38) hide show
  1. package/dist/index.js +2065 -0
  2. package/dist/index.js.map +28 -0
  3. package/package.json +24 -37
  4. package/src/helpers/__tests__/asset.test.ts +126 -108
  5. package/src/helpers/__tests__/memo.test.ts +52 -40
  6. package/src/helpers/__tests__/others.test.ts +42 -37
  7. package/src/helpers/__tests__/validators.test.ts +24 -0
  8. package/src/helpers/asset.ts +119 -87
  9. package/src/helpers/liquidity.ts +50 -43
  10. package/src/helpers/memo.ts +31 -28
  11. package/src/helpers/others.ts +29 -12
  12. package/src/helpers/validators.ts +15 -6
  13. package/src/helpers/web3wallets.ts +178 -0
  14. package/src/index.ts +13 -9
  15. package/src/modules/__tests__/assetValue.test.ts +325 -116
  16. package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
  17. package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
  18. package/src/modules/assetValue.ts +216 -152
  19. package/src/modules/bigIntArithmetics.ts +214 -147
  20. package/src/modules/requestClient.ts +29 -0
  21. package/src/modules/swapKitError.ts +32 -5
  22. package/src/modules/swapKitNumber.ts +8 -1
  23. package/src/types/abis/erc20.ts +99 -0
  24. package/src/types/abis/tcEthVault.ts +496 -0
  25. package/src/types/chains.ts +220 -0
  26. package/src/types/commonTypes.ts +119 -0
  27. package/src/types/derivationPath.ts +56 -0
  28. package/src/types/index.ts +10 -0
  29. package/src/types/network.ts +43 -0
  30. package/src/types/sdk.ts +11 -0
  31. package/src/types/tokens.ts +30 -0
  32. package/src/types/transactions.ts +45 -0
  33. package/src/types/wallet.ts +39 -0
  34. package/LICENSE +0 -201
  35. package/dist/index.cjs +0 -1
  36. package/dist/index.d.ts +0 -354
  37. package/dist/index.es.js +0 -1054
  38. package/src/helpers/request.ts +0 -16
@@ -1,157 +1,175 @@
1
- import { BaseDecimal, Chain } from '@swapkit/types';
2
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from "bun:test";
2
+ import { BaseDecimal, Chain } from "@swapkit/helpers";
3
3
 
4
- import { getAssetType, getDecimal } from '../asset.ts';
4
+ import { getAssetType, getDecimal } from "../asset.ts";
5
5
 
6
6
  const tickerMap: Record<string, string> = {
7
- [Chain.THORChain]: 'RUNE',
8
- [Chain.Cosmos]: 'ATOM',
9
- [Chain.BinanceSmartChain]: 'BNB',
7
+ [Chain.THORChain]: "RUNE",
8
+ [Chain.Cosmos]: "ATOM",
9
+ [Chain.BinanceSmartChain]: "BNB",
10
10
  };
11
11
 
12
- describe('getAssetType', () => {
13
- describe('when isSynth is true', () => {
14
- it('should return "Synth"', () => {
15
- const result = getAssetType({ chain: Chain.Bitcoin, symbol: 'BTC/BTC' });
16
- expect(result).toBe('Synth');
12
+ describe("getAssetType", () => {
13
+ describe("when isSynth is true", () => {
14
+ test('should return "Synth"', () => {
15
+ const result = getAssetType({ chain: Chain.Bitcoin, symbol: "BTC/BTC" });
16
+ expect(result).toBe("Synth");
17
17
  });
18
18
  });
19
19
 
20
- describe('when isSynth is false', () => {
21
- describe('for native chains and their assets', () => {
22
- Object.values(Chain).forEach((chain) => {
23
- it(`should return "Native" for chain ${chain} asset`, () => {
20
+ describe("when isSynth is false", () => {
21
+ describe("for native chains and their assets", () => {
22
+ for (const chain of Object.values(Chain)) {
23
+ test(`should return "Native" for chain ${chain} asset`, () => {
24
24
  const ticker = tickerMap[chain] || chain;
25
25
  const result = getAssetType({ chain: chain as Chain, symbol: ticker });
26
26
 
27
- expect(result).toBe('Native');
27
+ expect(result).toBe("Native");
28
28
  });
29
- });
29
+ }
30
30
  });
31
31
 
32
- describe('for Cosmos chain', () => {
33
- it('should return "GAIA" for non-ATOM tickers', () => {
34
- const result = getAssetType({ chain: Chain.Cosmos, symbol: 'NOT_ATOM' });
35
- expect(result).toBe('GAIA');
32
+ describe("for Cosmos chain", () => {
33
+ test('should return "GAIA" for non-ATOM tickers', () => {
34
+ const result = getAssetType({ chain: Chain.Cosmos, symbol: "NOT_ATOM" });
35
+ expect(result).toBe("GAIA");
36
36
  });
37
37
  });
38
38
 
39
- describe('for Binance chain', () => {
40
- it('should return "BEP2" for non-BNB tickers', () => {
41
- const result = getAssetType({ chain: Chain.Binance, symbol: 'NOT_BNB' });
42
- expect(result).toBe('BEP2');
39
+ describe("for Binance chain", () => {
40
+ test('should return "BEP2" for non-BNB tickers', () => {
41
+ const result = getAssetType({ chain: Chain.Binance, symbol: "NOT_BNB" });
42
+ expect(result).toBe("BEP2");
43
43
  });
44
44
  });
45
45
 
46
- describe('for Binance Smart Chain', () => {
47
- it('should return "BEP20" for non-BNB tickers', () => {
48
- const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: 'NOT_BNB' });
49
- expect(result).toBe('BEP20');
46
+ describe("for Binance Smart Chain", () => {
47
+ test('should return "BEP20" for non-BNB tickers', () => {
48
+ const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: "NOT_BNB" });
49
+ expect(result).toBe("BEP20");
50
50
  });
51
51
  });
52
52
 
53
- describe('for Ethereum chain', () => {
54
- it('should return "ERC20" for non-ETH tickers', () => {
55
- const result = getAssetType({ chain: Chain.Ethereum, symbol: 'NOT_ETH' });
56
- expect(result).toBe('ERC20');
53
+ describe("for Ethereum chain", () => {
54
+ test('should return "ERC20" for non-ETH tickers', () => {
55
+ const result = getAssetType({ chain: Chain.Ethereum, symbol: "NOT_ETH" });
56
+ expect(result).toBe("ERC20");
57
57
  });
58
58
  });
59
59
 
60
- describe('for Avalanche chain', () => {
61
- it('should return "AVAX" for non-AVAX tickers', () => {
62
- const result = getAssetType({ chain: Chain.Avalanche, symbol: 'NOT_AVAX' });
63
- expect(result).toBe('AVAX');
60
+ describe("for Avalanche chain", () => {
61
+ test('should return "AVAX" for non-AVAX tickers', () => {
62
+ const result = getAssetType({ chain: Chain.Avalanche, symbol: "NOT_AVAX" });
63
+ expect(result).toBe("AVAX");
64
64
  });
65
65
  });
66
66
  });
67
67
  });
68
68
 
69
- describe('getDecimal', () => {
69
+ describe("getDecimal", () => {
70
70
  /**
71
71
  * Test out native
72
72
  */
73
- Object.values(Chain)
74
- .filter((c) => ![Chain.Ethereum, Chain.Avalanche].includes(c))
75
- .forEach((chain) => {
76
- describe(chain, () => {
77
- it(`returns proper decimal for native ${chain} asset`, async () => {
73
+ const filteredChains = Object.values(Chain).filter(
74
+ (c) => ![Chain.Ethereum, Chain.Avalanche].includes(c),
75
+ );
76
+
77
+ for (const chain of filteredChains) {
78
+ describe(chain, () => {
79
+ test(
80
+ `returns proper decimal for native ${chain} asset`,
81
+ async () => {
78
82
  const decimal = await getDecimal({ chain, symbol: chain });
79
83
  expect(decimal).toBe(BaseDecimal[chain]);
80
- });
81
- });
84
+ },
85
+ { retry: 3 },
86
+ );
82
87
  });
88
+ }
89
+
90
+ describe("ETH", () => {
91
+ test(
92
+ "returns proper decimal for eth and it's assets",
93
+ async () => {
94
+ const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: "ETH" });
95
+ expect(ethDecimal).toBe(BaseDecimal.ETH);
96
+ await Bun.sleep(500);
97
+
98
+ const usdcDecimal = await getDecimal({
99
+ chain: Chain.Ethereum,
100
+ symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
101
+ });
102
+ expect(usdcDecimal).toBe(6);
103
+ await Bun.sleep(500);
83
104
 
84
- describe('ETH', () => {
85
- it("returns proper decimal for eth and it's assets", async () => {
86
- const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: 'ETH' });
87
- expect(ethDecimal).toBe(BaseDecimal.ETH);
88
-
89
- const usdcDecimal = await getDecimal({
90
- chain: Chain.Ethereum,
91
- symbol: 'USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
92
- });
93
- expect(usdcDecimal).toBe(6);
94
-
95
- const wbtcDecimal = await getDecimal({
96
- chain: Chain.Ethereum,
97
- symbol: 'WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
98
- });
99
- expect(wbtcDecimal).toBe(8);
100
-
101
- const decDecimal = await getDecimal({
102
- chain: Chain.Ethereum,
103
- symbol: 'ZIL-0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27',
104
- });
105
- expect(decDecimal).toBe(12);
105
+ const wbtcDecimal = await getDecimal({
106
+ chain: Chain.Ethereum,
107
+ symbol: "WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
108
+ });
109
+ expect(wbtcDecimal).toBe(8);
110
+ await Bun.sleep(500);
106
111
 
107
- const kindDecimal = await getDecimal({
108
- chain: Chain.Ethereum,
109
- symbol: 'KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688',
110
- });
111
- expect(kindDecimal).toBe(8);
112
+ const kindDecimal = await getDecimal({
113
+ chain: Chain.Ethereum,
114
+ symbol: "KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688",
115
+ });
116
+ expect(kindDecimal).toBe(8);
117
+ await Bun.sleep(500);
112
118
 
113
- const shitcoinDecimal = await getDecimal({
114
- chain: Chain.Ethereum,
115
- symbol: 'HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078',
116
- });
117
- expect(shitcoinDecimal).toBe(0);
118
- });
119
+ const shitcoinDecimal = await getDecimal({
120
+ chain: Chain.Ethereum,
121
+ symbol: "HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
122
+ });
123
+ expect(shitcoinDecimal).toBe(0);
124
+ await Bun.sleep(500);
125
+ },
126
+ { retry: 3 },
127
+ );
119
128
  });
120
129
 
121
- describe('AVAX', () => {
122
- it("returns proper decimal for avax and it's assets", async () => {
123
- const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: 'AVAX' });
124
- expect(avaxDecimal).toBe(BaseDecimal.AVAX);
130
+ describe("AVAX", () => {
131
+ test(
132
+ "returns proper decimal for avax and it's assets",
133
+ async () => {
134
+ const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: "AVAX" });
135
+ expect(avaxDecimal).toBe(BaseDecimal.AVAX);
125
136
 
126
- const wbtceDecimal = await getDecimal({
127
- chain: Chain.Avalanche,
128
- symbol: 'WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218',
129
- });
130
- expect(wbtceDecimal).toBe(8);
137
+ const wbtceDecimal = await getDecimal({
138
+ chain: Chain.Avalanche,
139
+ symbol: "WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218",
140
+ });
141
+ expect(wbtceDecimal).toBe(8);
142
+ await Bun.sleep(500);
131
143
 
132
- const btcbDecimal = await getDecimal({
133
- chain: Chain.Avalanche,
134
- symbol: 'BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50',
135
- });
136
- expect(btcbDecimal).toBe(8);
144
+ const btcbDecimal = await getDecimal({
145
+ chain: Chain.Avalanche,
146
+ symbol: "BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
147
+ });
148
+ expect(btcbDecimal).toBe(8);
149
+ await Bun.sleep(500);
137
150
 
138
- const timeDecimal = await getDecimal({
139
- chain: Chain.Avalanche,
140
- symbol: 'TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3',
141
- });
142
- expect(timeDecimal).toBe(9);
151
+ const timeDecimal = await getDecimal({
152
+ chain: Chain.Avalanche,
153
+ symbol: "TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
154
+ });
155
+ expect(timeDecimal).toBe(9);
156
+ await Bun.sleep(500);
143
157
 
144
- const usdtDecimal = await getDecimal({
145
- chain: Chain.Avalanche,
146
- symbol: 'USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
147
- });
148
- expect(usdtDecimal).toBe(6);
158
+ const usdtDecimal = await getDecimal({
159
+ chain: Chain.Avalanche,
160
+ symbol: "USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
161
+ });
162
+ expect(usdtDecimal).toBe(6);
163
+ await Bun.sleep(500);
149
164
 
150
- const usdcDecimal = await getDecimal({
151
- chain: Chain.Avalanche,
152
- symbol: 'USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
153
- });
154
- expect(usdcDecimal).toBe(6);
155
- });
165
+ const usdcDecimal = await getDecimal({
166
+ chain: Chain.Avalanche,
167
+ symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
168
+ });
169
+ expect(usdcDecimal).toBe(6);
170
+ await Bun.sleep(500);
171
+ },
172
+ { retry: 3 },
173
+ );
156
174
  });
157
175
  });
@@ -1,79 +1,91 @@
1
- import { Chain, MemoType } from '@swapkit/types';
2
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from "bun:test";
2
+ import { Chain, MemoType } from "@swapkit/helpers";
3
3
 
4
- import { getMemoFor } from '../memo.ts';
4
+ import { getMemoFor } from "../memo.ts";
5
5
 
6
- describe('getMemoFor', () => {
7
- describe('for Leave, Upgrade, and Bond', () => {
8
- [
9
- [MemoType.LEAVE, 'LEAVE:ABC123'],
10
- [MemoType.BOND, 'BOND:ABC123'],
11
- ].forEach(([memoType, expected]) => {
12
- it(`returns correct memo for ${memoType}`, () => {
13
- const result = getMemoFor(memoType as MemoType, { address: 'ABC123' });
6
+ describe("getMemoFor", () => {
7
+ describe("for Leave, Upgrade, and Bond", () => {
8
+ const nodeMemos = [
9
+ [MemoType.LEAVE, "LEAVE:ABC123"],
10
+ [MemoType.BOND, "BOND:ABC123"],
11
+ ];
12
+
13
+ for (const [memoType, expected = ""] of nodeMemos) {
14
+ test(`returns correct memo for ${memoType}`, () => {
15
+ const result = getMemoFor(memoType as MemoType, { address: "ABC123" });
14
16
  expect(result).toBe(expected);
15
17
  });
16
- });
18
+ }
17
19
  });
18
20
 
19
- describe('for Unbond and Thorname Register', () => {
20
- it('returns correct memo for Unbond', () => {
21
- const result = getMemoFor(MemoType.UNBOND, { address: 'ABC123', unbondAmount: 10 });
22
- expect(result).toBe('UNBOND:ABC123:1000000000');
21
+ describe("for Unbond and Thorname/Mayaname Register", () => {
22
+ test("returns correct memo for Unbond", () => {
23
+ const result = getMemoFor(MemoType.UNBOND, { address: "ABC123", unbondAmount: 1000000000 });
24
+ expect(result).toBe("UNBOND:ABC123:1000000000");
25
+ });
26
+
27
+ test("returns correct memo for Thorname Register", () => {
28
+ const result = getMemoFor(MemoType.THORNAME_REGISTER, {
29
+ name: "thorname",
30
+ chain: "BNB",
31
+ address: "0xABC123",
32
+ owner: "0xDEF456",
33
+ });
34
+ expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
23
35
  });
24
36
 
25
- it('returns correct memo for Thorname Register', () => {
37
+ test("returns correct memo for Mayaname Register", () => {
26
38
  const result = getMemoFor(MemoType.THORNAME_REGISTER, {
27
- name: 'thorname',
28
- chain: 'BNB',
29
- address: '0xABC123',
30
- owner: '0xDEF456',
39
+ name: "mayaname",
40
+ chain: "BNB",
41
+ address: "0xABC123",
42
+ owner: "0xDEF456",
31
43
  });
32
- expect(result).toBe('~:thorname:BNB:0xABC123:0xDEF456');
44
+ expect(result).toBe("~:mayaname:BNB:0xABC123:0xDEF456");
33
45
  });
34
46
  });
35
47
 
36
- describe('for Deposit', () => {
37
- it('returns correct memo for Deposit (single side)', () => {
48
+ describe("for Deposit", () => {
49
+ test("returns correct memo for Deposit (single side)", () => {
38
50
  const result = getMemoFor(MemoType.DEPOSIT, {
39
51
  chain: Chain.Ethereum,
40
- symbol: 'ETH',
52
+ symbol: "ETH",
41
53
  singleSide: true,
42
54
  });
43
- expect(result).toBe('+:ETH/ETH::t:0');
55
+ expect(result).toBe("+:ETH/ETH");
44
56
  });
45
57
 
46
- it('returns correct memo for Deposit (dual side)', () => {
58
+ test("returns correct memo for Deposit (dual side)", () => {
47
59
  const result = getMemoFor(MemoType.DEPOSIT, {
48
60
  chain: Chain.Avalanche,
49
- symbol: 'AVAX',
50
- address: '0xABC123',
61
+ symbol: "AVAX",
62
+ address: "0xABC123",
51
63
  });
52
- expect(result).toBe('+:AVAX.AVAX:0xABC123:t:0');
64
+ expect(result).toBe("+:AVAX.AVAX:0xABC123");
53
65
  });
54
66
  });
55
67
 
56
- describe('for Withdraw', () => {
57
- it('returns correct memo for Withdraw (single side)', () => {
68
+ describe("for Withdraw", () => {
69
+ test("returns correct memo for Withdraw (single side)", () => {
58
70
  const result = getMemoFor(MemoType.WITHDRAW, {
59
71
  chain: Chain.Bitcoin,
60
- ticker: 'BTC',
61
- symbol: 'BTC',
72
+ ticker: "BTC",
73
+ symbol: "BTC",
62
74
  basisPoints: 10000,
63
75
  singleSide: true,
64
76
  });
65
- expect(result).toBe('-:BTC/BTC:10000');
77
+ expect(result).toBe("-:BTC/BTC:10000");
66
78
  });
67
79
 
68
- it('returns correct memo for Withdraw (dual side)', () => {
80
+ test("returns correct memo for Withdraw (dual side)", () => {
69
81
  const result = getMemoFor(MemoType.WITHDRAW, {
70
82
  chain: Chain.Ethereum,
71
- ticker: 'ETH',
72
- symbol: 'ETH',
83
+ ticker: "ETH",
84
+ symbol: "ETH",
73
85
  basisPoints: 100,
74
- targetAssetString: 'ETH.ETH',
86
+ targetAssetString: "ETH.ETH",
75
87
  });
76
- expect(result).toBe('-:ETH.ETH:100:ETH.ETH');
88
+ expect(result).toBe("-:ETH.ETH:100:ETH.ETH");
77
89
  });
78
90
  });
79
91
  });
@@ -1,59 +1,64 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from "bun:test";
2
+ import { Chain, type DerivationPathArray } from "@swapkit/helpers";
2
3
 
3
- import { derivationPathToString, getTHORNameCost, validateTHORName } from '../others.ts';
4
+ import { findAssetBy } from "../asset.ts";
5
+ import { derivationPathToString, getTHORNameCost } from "../others.ts";
4
6
 
5
- describe('derivationPathToString', () => {
6
- it('should return the correct string for a full path', () => {
7
- const path = [1, 2, 3, 4, 5];
8
- const result = derivationPathToString(path);
9
- expect(result).toEqual("1'/2'/3'/4/5");
7
+ describe("derivationPathToString", () => {
8
+ test("should return the correct string for a full path", () => {
9
+ const path = [1, 2, 3, 4, 5] as DerivationPathArray;
10
+ expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4/5");
10
11
  });
11
12
 
12
- it('should return the correct string for a short path', () => {
13
- const path = [1, 2, 3, 4];
14
- const result = derivationPathToString(path);
15
- expect(result).toEqual("1'/2'/3'/4");
13
+ test("should return the correct string for a short path", () => {
14
+ const path = [1, 2, 3, 4] as DerivationPathArray;
15
+ expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4");
16
16
  });
17
17
  });
18
18
 
19
- describe('getTHORNameCost', () => {
20
- describe('for correct values', () => {
21
- [
19
+ describe("getTHORNameCost", () => {
20
+ describe("for correct values", () => {
21
+ const costCases = [
22
22
  [1, 11],
23
23
  [2, 12],
24
24
  [3, 13],
25
25
  [10, 20],
26
- ].forEach(([years, expected]) => {
27
- it(`returns correct ${expected} cost for ${years} years`, () => {
26
+ ];
27
+
28
+ for (const [years = 0, expected = 10] of costCases) {
29
+ test(`returns correct ${expected} cost for ${years} years`, () => {
28
30
  const result = getTHORNameCost(years);
29
31
  expect(result).toBe(expected);
30
32
  });
31
- });
33
+ }
32
34
  });
33
35
 
34
- it('throws an error for negative years', () => {
35
- expect(() => getTHORNameCost(-1)).toThrowError('Invalid number of year');
36
+ test("throws an error for negative years", () => {
37
+ expect(() => getTHORNameCost(-1)).toThrow("Invalid number of year");
36
38
  });
37
39
  });
38
40
 
39
- describe('validateTHORName', () => {
40
- const casesWithExpectation: [string, boolean][] = [
41
- ['validname', true],
42
- ['valid-name', true],
43
- ['valid_name', true],
44
- ['valid+name', true],
45
- ['name_with_numbers123', true],
46
- ['UPPER_CASE', true],
47
- ['toolongname123456789012345678901', false],
48
- ['invalid@name', false],
49
- ['invalid!name', false],
50
- ['invalid#name', false],
51
- ];
52
-
53
- casesWithExpectation.forEach(([name, expected]) => {
54
- it(`returns ${expected} for THORName "${name}"`, () => {
55
- const result = validateTHORName(name);
56
- expect(result).toBe(expected);
41
+ describe("getAssetBy", () => {
42
+ test("find asset by identifier", async () => {
43
+ const assetByIdentifier = await findAssetBy({ identifier: "ETH.ETH" });
44
+ expect(assetByIdentifier).toBe("ETH.ETH");
45
+ });
46
+
47
+ test("find asset by chain and contract", async () => {
48
+ const assetByChainAndContract = await findAssetBy({
49
+ chain: Chain.Ethereum,
50
+ contract: "0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
51
+ });
52
+ expect(assetByChainAndContract).toBe("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48");
53
+ });
54
+
55
+ test("return undefined if asset can't be found", async () => {
56
+ const assetByIdentifier = await findAssetBy({ identifier: "ARB.NOTEXISTINGTOKEN" });
57
+ const assetByChainAndContract = await findAssetBy({
58
+ chain: Chain.Ethereum,
59
+ contract: "NOTFOUND",
57
60
  });
61
+ expect(assetByIdentifier).toBeUndefined();
62
+ expect(assetByChainAndContract).toBeUndefined();
58
63
  });
59
64
  });
@@ -0,0 +1,24 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { validateTNS } from "../validators";
3
+
4
+ describe("validateTNS", () => {
5
+ const casesWithExpectation: [string, boolean][] = [
6
+ ["validname", true],
7
+ ["valid-name", true],
8
+ ["valid_name", true],
9
+ ["valid+name", true],
10
+ ["name_with_numbers123", true],
11
+ ["UPPER_CASE", true],
12
+ ["toolongname123456789012345678901", false],
13
+ ["invalid@name", false],
14
+ ["invalid!name", false],
15
+ ["invalid#name", false],
16
+ ];
17
+
18
+ for (const [name, expected] of casesWithExpectation) {
19
+ test(`returns ${expected} for THORName "${name}"`, () => {
20
+ const result = validateTNS(name);
21
+ expect(result).toBe(expected);
22
+ });
23
+ }
24
+ });