@swapkit/helpers 1.0.0-rc.11 → 1.0.0-rc.111

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 (42) hide show
  1. package/dist/index.js +2900 -0
  2. package/dist/index.js.map +31 -0
  3. package/package.json +26 -37
  4. package/src/helpers/__tests__/asset.test.ts +186 -103
  5. package/src/helpers/__tests__/memo.test.ts +53 -41
  6. package/src/helpers/__tests__/others.test.ts +44 -37
  7. package/src/helpers/__tests__/validators.test.ts +24 -0
  8. package/src/helpers/asset.ts +184 -95
  9. package/src/helpers/derivationPath.ts +53 -0
  10. package/src/helpers/liquidity.ts +50 -43
  11. package/src/helpers/memo.ts +34 -31
  12. package/src/helpers/others.ts +46 -12
  13. package/src/helpers/validators.ts +15 -6
  14. package/src/helpers/web3wallets.ts +200 -0
  15. package/src/index.ts +14 -9
  16. package/src/modules/__tests__/assetValue.test.ts +486 -129
  17. package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
  18. package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
  19. package/src/modules/assetValue.ts +220 -162
  20. package/src/modules/bigIntArithmetics.ts +214 -165
  21. package/src/modules/requestClient.ts +38 -0
  22. package/src/modules/swapKitError.ts +41 -5
  23. package/src/modules/swapKitNumber.ts +1 -1
  24. package/src/types/abis/erc20.ts +99 -0
  25. package/src/types/abis/mayaEvmVaults.ts +331 -0
  26. package/src/types/abis/tcEthVault.ts +496 -0
  27. package/src/types/chains.ts +226 -0
  28. package/src/types/commonTypes.ts +123 -0
  29. package/src/types/derivationPath.ts +58 -0
  30. package/src/types/errors/apiV1.ts +0 -0
  31. package/src/types/index.ts +12 -0
  32. package/src/types/network.ts +45 -0
  33. package/src/types/quotes.ts +391 -0
  34. package/src/types/radix.ts +14 -0
  35. package/src/types/sdk.ts +126 -0
  36. package/src/types/tokens.ts +30 -0
  37. package/src/types/wallet.ts +72 -0
  38. package/LICENSE +0 -201
  39. package/dist/index.cjs +0 -1
  40. package/dist/index.d.ts +0 -356
  41. package/dist/index.es.js +0 -1071
  42. package/src/helpers/request.ts +0 -16
@@ -1,157 +1,240 @@
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 "../../types";
3
3
 
4
- import { getAssetType, getDecimal } from '../asset.ts';
4
+ import { assetFromString, 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
+ }
30
+ });
31
+
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");
29
36
  });
30
37
  });
31
38
 
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');
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");
36
43
  });
37
44
  });
38
45
 
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');
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");
43
50
  });
44
51
  });
45
52
 
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');
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");
50
57
  });
51
58
  });
52
59
 
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');
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");
57
64
  });
58
65
  });
59
66
 
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');
67
+ describe("for Radix chain", () => {
68
+ test('should return "RADIX" for non-XRD tickers', () => {
69
+ const result = getAssetType({ chain: Chain.Radix, symbol: "NOT_XRD" });
70
+ expect(result).toBe("RADIX");
64
71
  });
65
72
  });
66
73
  });
67
74
  });
68
75
 
69
- describe('getDecimal', () => {
76
+ describe("getDecimal", () => {
70
77
  /**
71
78
  * Test out native
72
79
  */
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 () => {
80
+ const filteredChains = Object.values(Chain).filter(
81
+ (c) => ![Chain.Ethereum, Chain.Avalanche].includes(c),
82
+ );
83
+
84
+ for (const chain of filteredChains) {
85
+ describe(chain, () => {
86
+ test(
87
+ `returns proper decimal for native ${chain} asset`,
88
+ async () => {
78
89
  const decimal = await getDecimal({ chain, symbol: chain });
79
90
  expect(decimal).toBe(BaseDecimal[chain]);
80
- });
81
- });
91
+ },
92
+ { retry: 3 },
93
+ );
82
94
  });
95
+ }
96
+
97
+ describe("ETH", () => {
98
+ test(
99
+ "returns proper decimal for eth and it's assets",
100
+ async () => {
101
+ const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: "ETH" });
102
+ expect(ethDecimal).toBe(BaseDecimal.ETH);
103
+ await Bun.sleep(500);
104
+
105
+ const usdcDecimal = await getDecimal({
106
+ chain: Chain.Ethereum,
107
+ symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
108
+ });
109
+ expect(usdcDecimal).toBe(6);
110
+ await Bun.sleep(500);
83
111
 
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);
112
+ const wbtcDecimal = await getDecimal({
113
+ chain: Chain.Ethereum,
114
+ symbol: "WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
115
+ });
116
+ expect(wbtcDecimal).toBe(8);
117
+ await Bun.sleep(500);
88
118
 
89
- const usdcDecimal = await getDecimal({
90
- chain: Chain.Ethereum,
91
- symbol: 'USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
92
- });
93
- expect(usdcDecimal).toBe(6);
119
+ const kindDecimal = await getDecimal({
120
+ chain: Chain.Ethereum,
121
+ symbol: "KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688",
122
+ });
123
+ expect(kindDecimal).toBe(8);
124
+ await Bun.sleep(500);
94
125
 
95
- const wbtcDecimal = await getDecimal({
96
- chain: Chain.Ethereum,
97
- symbol: 'WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
98
- });
99
- expect(wbtcDecimal).toBe(8);
126
+ const shitcoinDecimal = await getDecimal({
127
+ chain: Chain.Ethereum,
128
+ symbol: "HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
129
+ });
130
+ expect(shitcoinDecimal).toBe(0);
131
+ await Bun.sleep(500);
132
+ },
133
+ { retry: 3 },
134
+ );
135
+ });
100
136
 
101
- const decDecimal = await getDecimal({
102
- chain: Chain.Ethereum,
103
- symbol: 'ZIL-0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27',
104
- });
105
- expect(decDecimal).toBe(12);
137
+ describe("AVAX", () => {
138
+ test(
139
+ "returns proper decimal for avax and it's assets",
140
+ async () => {
141
+ const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: "AVAX" });
142
+ expect(avaxDecimal).toBe(BaseDecimal.AVAX);
106
143
 
107
- const kindDecimal = await getDecimal({
108
- chain: Chain.Ethereum,
109
- symbol: 'KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688',
110
- });
111
- expect(kindDecimal).toBe(8);
144
+ const wbtceDecimal = await getDecimal({
145
+ chain: Chain.Avalanche,
146
+ symbol: "WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218",
147
+ });
148
+ expect(wbtceDecimal).toBe(8);
149
+ await Bun.sleep(500);
112
150
 
113
- const shitcoinDecimal = await getDecimal({
114
- chain: Chain.Ethereum,
115
- symbol: 'HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078',
116
- });
117
- expect(shitcoinDecimal).toBe(0);
118
- });
151
+ const btcbDecimal = await getDecimal({
152
+ chain: Chain.Avalanche,
153
+ symbol: "BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
154
+ });
155
+ expect(btcbDecimal).toBe(8);
156
+ await Bun.sleep(500);
157
+
158
+ const timeDecimal = await getDecimal({
159
+ chain: Chain.Avalanche,
160
+ symbol: "TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
161
+ });
162
+ expect(timeDecimal).toBe(9);
163
+ await Bun.sleep(500);
164
+
165
+ const usdtDecimal = await getDecimal({
166
+ chain: Chain.Avalanche,
167
+ symbol: "USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
168
+ });
169
+ expect(usdtDecimal).toBe(6);
170
+ await Bun.sleep(500);
171
+
172
+ const usdcDecimal = await getDecimal({
173
+ chain: Chain.Avalanche,
174
+ symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
175
+ });
176
+ expect(usdcDecimal).toBe(6);
177
+ await Bun.sleep(500);
178
+ },
179
+ { retry: 3 },
180
+ );
119
181
  });
120
182
 
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);
183
+ describe("Radix", () => {
184
+ test(
185
+ "returns proper decimal for radix and it's assets",
186
+ async () => {
187
+ const radixDecimal = await getDecimal({ chain: Chain.Radix, symbol: "XRD" });
188
+ expect(radixDecimal).toBe(BaseDecimal.XRD);
189
+ await Bun.sleep(500);
190
+
191
+ const xwBTCDecimal = await getDecimal({
192
+ chain: Chain.Radix,
193
+ symbol: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
194
+ });
195
+ expect(xwBTCDecimal).toBe(8);
196
+ await Bun.sleep(500);
197
+ },
198
+ { retry: 3 },
199
+ );
200
+ });
201
+ });
125
202
 
126
- const wbtceDecimal = await getDecimal({
127
- chain: Chain.Avalanche,
128
- symbol: 'WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218',
129
- });
130
- expect(wbtceDecimal).toBe(8);
203
+ describe("assetFromString", () => {
204
+ test("should return the correct object", () => {
205
+ const assetString = "THOR.RUNE";
206
+ const result = assetFromString(assetString);
131
207
 
132
- const btcbDecimal = await getDecimal({
133
- chain: Chain.Avalanche,
134
- symbol: 'BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50',
135
- });
136
- expect(btcbDecimal).toBe(8);
208
+ expect(result).toEqual({
209
+ chain: Chain.THORChain,
210
+ symbol: "RUNE",
211
+ ticker: "RUNE",
212
+ synth: false,
213
+ });
214
+ });
137
215
 
138
- const timeDecimal = await getDecimal({
139
- chain: Chain.Avalanche,
140
- symbol: 'TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3',
141
- });
142
- expect(timeDecimal).toBe(9);
216
+ test("should return the correct object for multiple dashes", () => {
217
+ const assetString = "ETH.PENDLE-LPT-0x1234";
218
+ const result = assetFromString(assetString);
143
219
 
144
- const usdtDecimal = await getDecimal({
145
- chain: Chain.Avalanche,
146
- symbol: 'USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
147
- });
148
- expect(usdtDecimal).toBe(6);
220
+ expect(result).toEqual({
221
+ chain: Chain.Ethereum,
222
+ symbol: "PENDLE-LPT-0x1234",
223
+ ticker: "PENDLE-LPT",
224
+ synth: false,
225
+ });
226
+ });
149
227
 
150
- const usdcDecimal = await getDecimal({
151
- chain: Chain.Avalanche,
152
- symbol: 'USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
153
- });
154
- expect(usdcDecimal).toBe(6);
228
+ test("should return the correct object for Radix resource", () => {
229
+ const assetString =
230
+ "XRD.xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75";
231
+ const result = assetFromString(assetString);
232
+
233
+ expect(result).toEqual({
234
+ chain: Chain.Radix,
235
+ symbol: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
236
+ ticker: "xwBTC",
237
+ synth: false,
155
238
  });
156
239
  });
157
240
  });
@@ -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 "../../types";
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.NAME_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', () => {
26
- const result = getMemoFor(MemoType.THORNAME_REGISTER, {
27
- name: 'thorname',
28
- chain: 'BNB',
29
- address: '0xABC123',
30
- owner: '0xDEF456',
37
+ test("returns correct memo for Mayaname Register", () => {
38
+ const result = getMemoFor(MemoType.NAME_REGISTER, {
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,66 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from "bun:test";
2
+ import { Chain, type DerivationPathArray } from "../../types";
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?.toUpperCase()).toBe(
53
+ "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
54
+ );
55
+ });
56
+
57
+ test("return undefined if asset can't be found", async () => {
58
+ const assetByIdentifier = await findAssetBy({ identifier: "ARB.NOTEXISTINGTOKEN" });
59
+ const assetByChainAndContract = await findAssetBy({
60
+ chain: Chain.Ethereum,
61
+ contract: "NOTFOUND",
57
62
  });
63
+ expect(assetByIdentifier).toBeUndefined();
64
+ expect(assetByChainAndContract).toBeUndefined();
58
65
  });
59
66
  });
@@ -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
+ });