@swapkit/helpers 1.0.0-rc.1 → 1.0.0-rc.100

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 (40) hide show
  1. package/dist/index.js +2452 -0
  2. package/dist/index.js.map +30 -0
  3. package/package.json +26 -36
  4. package/src/helpers/__tests__/asset.test.ts +149 -105
  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 +139 -91
  9. package/src/helpers/derivationPath.ts +53 -0
  10. package/src/helpers/liquidity.ts +50 -43
  11. package/src/helpers/memo.ts +31 -28
  12. package/src/helpers/others.ts +35 -57
  13. package/src/helpers/validators.ts +15 -6
  14. package/src/helpers/web3wallets.ts +177 -0
  15. package/src/index.ts +14 -8
  16. package/src/modules/__tests__/assetValue.test.ts +420 -117
  17. package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
  18. package/src/modules/__tests__/swapKitNumber.test.ts +351 -149
  19. package/src/modules/assetValue.ts +243 -171
  20. package/src/modules/bigIntArithmetics.ts +313 -153
  21. package/src/modules/requestClient.ts +39 -0
  22. package/src/modules/swapKitError.ts +33 -5
  23. package/src/modules/swapKitNumber.ts +6 -3
  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 +220 -0
  28. package/src/types/commonTypes.ts +119 -0
  29. package/src/types/derivationPath.ts +56 -0
  30. package/src/types/errors/apiV1.ts +0 -0
  31. package/src/types/index.ts +10 -0
  32. package/src/types/network.ts +43 -0
  33. package/src/types/sdk.ts +44 -0
  34. package/src/types/tokens.ts +30 -0
  35. package/src/types/wallet.ts +47 -0
  36. package/LICENSE +0 -201
  37. package/dist/index.cjs +0 -1
  38. package/dist/index.d.ts +0 -333
  39. package/dist/index.es.js +0 -661
  40. package/src/helpers/number.ts +0 -40
@@ -1,57 +1,96 @@
1
- import { BaseDecimal, Chain } from '@swapkit/types';
2
- import { describe, expect, test } from 'vitest';
1
+ import { describe, expect, test } from "bun:test";
3
2
 
4
- import { AssetValue } from '../assetValue.ts';
3
+ import { BaseDecimal, Chain } from "../../types/chains.ts";
4
+ import { AssetValue, getMinAmountByChain } from "../assetValue.ts";
5
5
 
6
- describe('AssetValue', () => {
7
- describe('assetValue', () => {
8
- test('returns asset ticker with value', () => {
6
+ describe("AssetValue", () => {
7
+ describe("assetValue", () => {
8
+ test("returns asset ticker with value", () => {
9
9
  const fakeAvaxUSDCAsset = new AssetValue({
10
10
  decimal: 6,
11
11
  value: 1234567890,
12
12
  chain: Chain.Avalanche,
13
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
13
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
14
14
  });
15
- expect(fakeAvaxUSDCAsset.assetValue).toBe('1234567890 USDC');
16
-
17
- const thor = AssetValue.fromChainOrSignature('ETH.THOR');
18
- expect(thor.assetValue).toBe('0 THOR');
15
+ expect(fakeAvaxUSDCAsset.toString()).toBe(
16
+ "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
17
+ );
19
18
 
20
19
  const ethSynth = new AssetValue({
21
20
  chain: Chain.THORChain,
22
- symbol: 'ETH/ETH',
21
+ symbol: "ETH/ETH",
23
22
  decimal: 8,
24
23
  value: 1234567890,
25
24
  });
26
25
 
27
- expect(ethSynth.assetValue).toBe('1234567890 ETH/ETH');
28
- expect(ethSynth.toString()).toBe('THOR.ETH/ETH');
26
+ expect(ethSynth.toString()).toBe("ETH/ETH");
27
+ expect(ethSynth.mul(21.37).getValue("string")).toBe("26382715809.3");
28
+
29
+ const ethThorSynth = new AssetValue({
30
+ chain: Chain.THORChain,
31
+ symbol: "ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
32
+ decimal: 8,
33
+ value: 1234567890,
34
+ });
35
+ expect(ethThorSynth.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
29
36
 
30
37
  const atomDerived = new AssetValue({
31
- identifier: 'THOR.ATOM',
38
+ identifier: "THOR.ATOM",
32
39
  decimal: 6,
33
40
  value: 123456789,
34
41
  });
35
42
 
36
- expect(atomDerived.assetValue).toBe('123456789 ATOM');
37
- expect(atomDerived.toString()).toBe('THOR.ATOM');
43
+ expect(atomDerived.toString()).toBe("THOR.ATOM");
44
+ });
45
+ });
46
+
47
+ describe("toUrl", () => {
48
+ test("returns asset compliance with url", () => {
49
+ const fakeAvaxUSDCAsset = new AssetValue({
50
+ decimal: 6,
51
+ value: 1234567890,
52
+ chain: Chain.Avalanche,
53
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
54
+ });
55
+ expect(fakeAvaxUSDCAsset.toUrl()).toBe(
56
+ "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
57
+ );
58
+
59
+ const thor = AssetValue.fromChainOrSignature("ETH.THOR");
60
+ expect(thor.toUrl()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
61
+
62
+ const ethSynth = new AssetValue({
63
+ chain: Chain.THORChain,
64
+ symbol: "ETH/ETH",
65
+ decimal: 8,
66
+ value: 1234567890,
67
+ });
68
+ expect(ethSynth.toUrl()).toBe("THOR.ETH.ETH");
69
+
70
+ const ethThorSynth = new AssetValue({
71
+ chain: Chain.THORChain,
72
+ symbol: "ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
73
+ decimal: 8,
74
+ value: 1234567890,
75
+ });
76
+ expect(ethThorSynth.toUrl()).toBe("THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
38
77
  });
39
78
  });
40
79
 
41
- describe('eq', () => {
42
- test('checks if assets are same chain and symbol', () => {
43
- const firstThor = AssetValue.fromChainOrSignature('ETH.THOR');
44
- const secondThor = AssetValue.fromChainOrSignature('ETH.THOR');
45
- const vThor = AssetValue.fromChainOrSignature('ETH.vTHOR');
80
+ describe("eq", () => {
81
+ test("checks if assets are same chain and symbol", () => {
82
+ const firstThor = AssetValue.fromChainOrSignature("ETH.THOR");
83
+ const secondThor = AssetValue.fromChainOrSignature("ETH.THOR");
84
+ const vThor = AssetValue.fromChainOrSignature("ETH.vTHOR");
46
85
  const firstUsdc = new AssetValue({
47
86
  chain: Chain.Avalanche,
48
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
87
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
49
88
  decimal: 6,
50
89
  value: 1234567890,
51
90
  });
52
91
  const secondUsdc = new AssetValue({
53
92
  chain: Chain.Avalanche,
54
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
93
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
55
94
  decimal: 6,
56
95
  value: 1234,
57
96
  });
@@ -70,136 +109,353 @@ describe('AssetValue', () => {
70
109
  });
71
110
  });
72
111
 
73
- describe('toString', () => {
74
- test('returns asset value string/identifier', async () => {
75
- const fakeAvaxUSDCAsset = new AssetValue({
112
+ describe("from bigint", () => {
113
+ test("returns asset value with correct decimal", async () => {
114
+ const avaxUSDCAsset = await AssetValue.fromIdentifier(
115
+ `${Chain.Avalanche}.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e`,
116
+ 1234567800n,
117
+ );
118
+ expect(avaxUSDCAsset.getValue("string")).toBe("1234.5678");
119
+ });
120
+ });
121
+
122
+ describe("toString", () => {
123
+ test("returns asset value string/identifier", async () => {
124
+ const avaxUSDCAsset = new AssetValue({
76
125
  decimal: 6,
77
126
  value: 1234567890,
78
127
  chain: Chain.Avalanche,
79
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
128
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
80
129
  });
81
- expect(fakeAvaxUSDCAsset.toString()).toBe(
82
- 'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
83
- );
130
+ expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
84
131
 
85
- const thor = AssetValue.fromChainOrSignature('ETH.THOR');
86
- expect(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
132
+ const thor = AssetValue.fromChainOrSignature("ETH.THOR");
133
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
87
134
 
88
- const ethSynth = await AssetValue.fromIdentifier('ETH/ETH');
89
- expect(ethSynth.toString()).toBe('THOR.ETH/ETH');
135
+ const ethSynth = await AssetValue.fromIdentifier("ETH/ETH");
136
+ expect(ethSynth.toString()).toBe("ETH/ETH");
90
137
  });
91
138
  });
92
139
 
93
- describe('fromIdentifier', () => {
94
- test('creates AssetValue from string', async () => {
95
- const fakeAvaxUSDCAssetString = 'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e';
96
- const fakeAvaxUSDCAsset = await AssetValue.fromIdentifier(fakeAvaxUSDCAssetString);
140
+ describe("fromIdentifier", () => {
141
+ test("creates AssetValue from string", async () => {
142
+ const avaxUSDCAsset = await AssetValue.fromIdentifier(
143
+ "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
144
+ );
97
145
 
98
- expect(fakeAvaxUSDCAsset).toEqual(
146
+ expect(avaxUSDCAsset).toEqual(
99
147
  expect.objectContaining({
100
- address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
148
+ address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
101
149
  chain: Chain.Avalanche,
102
150
  decimal: 6,
103
151
  isGasAsset: false,
104
152
  isSynthetic: false,
105
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
106
- ticker: 'USDC',
153
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
154
+ ticker: "USDC",
155
+ }),
156
+ );
157
+ });
158
+ test("creates AssetValue from string with multiple dashes", async () => {
159
+ const ethPendleLptAsset = await AssetValue.fromIdentifier("ETH.PENDLE-LPT-0x1234");
160
+
161
+ expect(ethPendleLptAsset).toEqual(
162
+ expect.objectContaining({
163
+ address: "0x1234",
164
+ chain: Chain.Ethereum,
165
+ decimal: 18,
166
+ isGasAsset: false,
167
+ isSynthetic: false,
168
+ symbol: "PENDLE-LPT-0x1234",
169
+ ticker: "PENDLE-LPT",
107
170
  }),
108
171
  );
109
172
  });
110
173
  });
111
174
 
112
- describe('fromString', () => {
113
- test('creates AssetValue from string', () => {
114
- test('creates AssetValue from string', async () => {
115
- const fakeAvaxAssetString = 'AVAX.ASDF-1234';
116
- const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
175
+ describe("fromString", () => {
176
+ test("creates AssetValue from string", async () => {
177
+ const fakeAvaxAssetString = "AVAX.ASDF-1234";
178
+ const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
117
179
 
118
- expect(fakeAvaxAsset).toEqual(
119
- expect.objectContaining({
120
- address: '1234',
121
- chain: Chain.Avalanche,
122
- decimal: 10,
123
- isGasAsset: false,
124
- isSynthetic: false,
125
- symbol: 'ASDF-1234',
126
- ticker: 'ASDF',
127
- }),
128
- );
129
- });
180
+ expect(fakeAvaxAsset).toEqual(
181
+ expect.objectContaining({
182
+ address: "1234",
183
+ chain: Chain.Avalanche,
184
+ decimal: 18,
185
+ isGasAsset: false,
186
+ isSynthetic: false,
187
+ symbol: "ASDF-1234",
188
+ ticker: "ASDF",
189
+ }),
190
+ );
191
+ });
192
+ test("creates AssetValue from string with multiple dashes", async () => {
193
+ const fakeAvaxAssetString = "AVAX.ASDF-LP-1234";
194
+ const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
195
+
196
+ expect(fakeAvaxAsset).toEqual(
197
+ expect.objectContaining({
198
+ address: "1234",
199
+ chain: Chain.Avalanche,
200
+ decimal: 18,
201
+ isGasAsset: false,
202
+ isSynthetic: false,
203
+ symbol: "ASDF-LP-1234",
204
+ ticker: "ASDF-LP",
205
+ }),
206
+ );
207
+ });
208
+ });
209
+
210
+ describe("fromStringWithBase", () => {
211
+ test("creates AssetValue from string with base", async () => {
212
+ const fakeAvaxAssetString = "AVAX.ASDF-1234";
213
+ const fakeAvaxAsset = await AssetValue.fromStringWithBase(fakeAvaxAssetString, 1, 8);
214
+
215
+ expect(fakeAvaxAsset).toEqual(
216
+ expect.objectContaining({
217
+ address: "1234",
218
+ chain: Chain.Avalanche,
219
+ decimal: 18,
220
+ isGasAsset: false,
221
+ isSynthetic: false,
222
+ symbol: "ASDF-1234",
223
+ ticker: "ASDF",
224
+ }),
225
+ );
226
+ expect(fakeAvaxAsset.getValue("string")).toBe("100000000");
227
+ expect(fakeAvaxAsset.getBaseValue("string")).toBe("100000000000000000000000000");
130
228
  });
131
229
  });
132
230
 
133
- describe('fromIdentifierSync', () => {
134
- test('(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists', async () => {
231
+ describe("fromUrl", () => {
232
+ test("creates AssetValue from url like format", async () => {
233
+ const synthETHString = "THOR.ETH.ETH";
234
+ const ethString = "ETH.ETH";
235
+ const thorString = "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
236
+ const synthThorString = "THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
237
+ const synthDashesString = "THOR.ETH.PENDLE-LPT-0x1234";
238
+
239
+ const synthETH = await AssetValue.fromUrl(synthETHString);
240
+ const eth = await AssetValue.fromUrl(ethString);
241
+ const thor = await AssetValue.fromUrl(thorString);
242
+ const synthThor = await AssetValue.fromUrl(synthThorString);
243
+ const synthDashes = await AssetValue.fromUrl(synthDashesString);
244
+
245
+ expect(synthETH.toString()).toBe("ETH/ETH");
246
+ expect(eth.toString()).toBe("ETH.ETH");
247
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
248
+ expect(synthThor.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
249
+ expect(synthDashes.toString()).toBe("ETH/PENDLE-LPT-0x1234");
250
+ });
251
+ });
252
+
253
+ describe("fromIdentifierSync", () => {
254
+ test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
135
255
  await AssetValue.loadStaticAssets();
136
256
  const thor = AssetValue.fromIdentifierSync(
137
- 'ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9',
257
+ "ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
138
258
  );
139
259
 
140
260
  expect(thor).toBeDefined();
141
261
  expect(thor).toEqual(
142
262
  expect.objectContaining({
143
- address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
263
+ address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
144
264
  chain: Chain.Arbitrum,
145
265
  decimal: 6,
146
266
  isGasAsset: false,
147
267
  isSynthetic: false,
148
- symbol: 'USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
149
- ticker: 'USDT',
268
+ symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
269
+ ticker: "USDT",
150
270
  }),
151
271
  );
152
272
  });
153
273
  });
154
274
 
155
- describe('fromStringSync', () => {
156
- test('creates AssetValue from string via `@swapkit/tokens` lists', async () => {
275
+ describe("fromStringSync", () => {
276
+ test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
157
277
  await AssetValue.loadStaticAssets();
158
- const thor = AssetValue.fromStringSync('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
278
+ const thor = AssetValue.fromStringSync("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
159
279
 
160
280
  expect(thor).toBeDefined();
161
281
  expect(thor).toEqual(
162
282
  expect.objectContaining({
163
- address: '0xa5f2211b9b8170f694421f2046281775e8468044',
283
+ address: "0xa5f2211b9b8170f694421f2046281775e8468044",
284
+ chain: Chain.Ethereum,
285
+ decimal: 18,
286
+ isGasAsset: false,
287
+ isSynthetic: false,
288
+ symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
289
+ ticker: "THOR",
290
+ }),
291
+ );
292
+
293
+ const usdc = AssetValue.fromStringSync("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48");
294
+ expect(usdc).toBeDefined();
295
+ expect(usdc).toEqual(
296
+ expect.objectContaining({
297
+ address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
164
298
  chain: Chain.Ethereum,
299
+ decimal: 6,
300
+ isGasAsset: false,
301
+ isSynthetic: false,
302
+ symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
303
+ ticker: "USDC",
304
+ }),
305
+ );
306
+ });
307
+
308
+ test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
309
+ await AssetValue.loadStaticAssets();
310
+ const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
311
+ const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
312
+
313
+ expect(fakeAvaxUSDCAsset).toBeDefined();
314
+ expect(fakeAvaxUSDCAsset).toEqual(
315
+ expect.objectContaining({
316
+ address: "1234",
317
+ chain: Chain.Avalanche,
165
318
  decimal: 18,
166
319
  isGasAsset: false,
167
320
  isSynthetic: false,
168
- symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
169
- ticker: 'THOR',
321
+ symbol: "USDC-1234",
322
+ ticker: "USDC",
170
323
  }),
171
324
  );
172
325
  });
173
326
 
174
- test('returns undefined if string is not in `@swapkit/tokens` lists', async () => {
327
+ test("returns safe decimals if string is not in `@swapkit/tokens` lists with multiple dashes", async () => {
175
328
  await AssetValue.loadStaticAssets();
176
- const fakeAvaxUSDCAssetString = 'AVAX.USDC-1234';
329
+ const fakeAvaxUSDCAssetString = "AVAX.USDC-LPT-1234";
177
330
  const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
178
331
 
179
- expect(fakeAvaxUSDCAsset).toBeUndefined();
332
+ expect(fakeAvaxUSDCAsset).toBeDefined();
333
+ expect(fakeAvaxUSDCAsset).toEqual(
334
+ expect.objectContaining({
335
+ address: "1234",
336
+ chain: Chain.Avalanche,
337
+ decimal: 18,
338
+ isGasAsset: false,
339
+ isSynthetic: false,
340
+ symbol: "USDC-LPT-1234",
341
+ ticker: "USDC-LPT",
342
+ }),
343
+ );
344
+ });
345
+
346
+ test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
347
+ await AssetValue.loadStaticAssets();
348
+ const avaxBTCb = "AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50";
349
+ const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
350
+
351
+ expect(AvaxBTCb).toBeDefined();
352
+ expect(AvaxBTCb).toEqual(
353
+ expect.objectContaining({
354
+ address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
355
+ chain: Chain.Avalanche,
356
+ decimal: 8,
357
+ isGasAsset: false,
358
+ isSynthetic: false,
359
+ symbol: "BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50",
360
+ ticker: "BTC.b",
361
+ }),
362
+ );
363
+ });
364
+ });
365
+
366
+ describe("fromStringWithBaseSync", () => {
367
+ test("creates AssetValue from string with base decimals via `@swapkit/tokens` lists", async () => {
368
+ await AssetValue.loadStaticAssets();
369
+ const btc = AssetValue.fromStringWithBaseSync("BTC.BTC", 5200000000000, 8);
370
+
371
+ expect(btc).toBeDefined();
372
+ expect(btc).toEqual(
373
+ expect.objectContaining({
374
+ chain: Chain.Bitcoin,
375
+ decimal: 8,
376
+ isGasAsset: true,
377
+ isSynthetic: false,
378
+ symbol: "BTC",
379
+ ticker: "BTC",
380
+ }),
381
+ );
382
+
383
+ expect(btc.getValue("string")).toBe("52000");
384
+ expect(btc.getBaseValue("string")).toBe("5200000000000");
385
+ });
386
+
387
+ test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
388
+ await AssetValue.loadStaticAssets();
389
+ const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
390
+ const fakeAvaxUSDCAsset = AssetValue.fromStringWithBaseSync(fakeAvaxUSDCAssetString, 1, 8);
391
+
392
+ expect(fakeAvaxUSDCAsset).toBeDefined();
393
+ expect(fakeAvaxUSDCAsset).toEqual(
394
+ expect.objectContaining({
395
+ address: "1234",
396
+ chain: Chain.Avalanche,
397
+ decimal: 18,
398
+ isGasAsset: false,
399
+ isSynthetic: false,
400
+ symbol: "USDC-1234",
401
+ ticker: "USDC",
402
+ }),
403
+ );
404
+
405
+ expect(fakeAvaxUSDCAsset.getValue("string")).toBe("0.00000001");
406
+ expect(fakeAvaxUSDCAsset.getBaseValue("string")).toBe("10000000000");
407
+ });
408
+
409
+ test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
410
+ await AssetValue.loadStaticAssets();
411
+ const avaxUSDC = "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e";
412
+ const AvaxUSDC = AssetValue.fromStringWithBaseSync(avaxUSDC, 100000000, 8);
413
+
414
+ expect(AvaxUSDC).toBeDefined();
415
+ expect(AvaxUSDC).toEqual(
416
+ expect.objectContaining({
417
+ address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
418
+ chain: Chain.Avalanche,
419
+ decimal: 6,
420
+ isGasAsset: false,
421
+ isSynthetic: false,
422
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
423
+ ticker: "USDC",
424
+ }),
425
+ );
426
+
427
+ expect(AvaxUSDC.getValue("string")).toBe("1");
428
+ expect(AvaxUSDC.getBaseValue("string")).toBe("1000000");
180
429
  });
181
430
  });
182
431
 
183
- describe('fromChainOrSignature', () => {
184
- test('creates AssetValue from common asset string or chain', () => {
185
- const customBaseAsset = [Chain.Cosmos, Chain.BinanceSmartChain, Chain.THORChain, Chain.Maya];
186
- Object.values(Chain)
187
- .filter((c) => !customBaseAsset.includes(c))
188
- .forEach((chain) => {
189
- const asset = AssetValue.fromChainOrSignature(chain);
190
- expect(asset).toEqual(
191
- expect.objectContaining({
192
- address: undefined,
193
- chain,
194
- decimal: BaseDecimal[chain],
195
- isGasAsset: ![Chain.Arbitrum, Chain.Optimism].includes(chain),
196
- isSynthetic: false,
197
- symbol: chain,
198
- ticker: chain,
199
- type: 'Native',
200
- }),
201
- );
202
- });
432
+ describe("fromChainOrSignature", () => {
433
+ test("creates AssetValue from common asset string or chain", () => {
434
+ const customBaseAsset = [
435
+ Chain.Cosmos,
436
+ Chain.BinanceSmartChain,
437
+ Chain.THORChain,
438
+ Chain.Maya,
439
+ Chain.Arbitrum,
440
+ Chain.Optimism,
441
+ ];
442
+ const filteredChains = Object.values(Chain).filter((c) => !customBaseAsset.includes(c));
443
+
444
+ for (const chain of filteredChains) {
445
+ const asset = AssetValue.fromChainOrSignature(chain);
446
+ expect(asset).toEqual(
447
+ expect.objectContaining({
448
+ address: undefined,
449
+ chain,
450
+ decimal: BaseDecimal[chain],
451
+ isGasAsset: true,
452
+ isSynthetic: false,
453
+ symbol: chain,
454
+ ticker: chain,
455
+ type: "Native",
456
+ }),
457
+ );
458
+ }
203
459
 
204
460
  const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
205
461
  expect(cosmosAsset).toEqual(
@@ -209,9 +465,9 @@ describe('AssetValue', () => {
209
465
  decimal: BaseDecimal.GAIA,
210
466
  isGasAsset: true,
211
467
  isSynthetic: false,
212
- symbol: 'ATOM',
213
- ticker: 'ATOM',
214
- type: 'Native',
468
+ symbol: "ATOM",
469
+ ticker: "ATOM",
470
+ type: "Native",
215
471
  }),
216
472
  );
217
473
 
@@ -223,9 +479,9 @@ describe('AssetValue', () => {
223
479
  decimal: BaseDecimal.BSC,
224
480
  isGasAsset: true,
225
481
  isSynthetic: false,
226
- symbol: 'BNB',
227
- ticker: 'BNB',
228
- type: 'Native',
482
+ symbol: "BNB",
483
+ ticker: "BNB",
484
+ type: "Native",
229
485
  }),
230
486
  );
231
487
 
@@ -237,9 +493,9 @@ describe('AssetValue', () => {
237
493
  decimal: BaseDecimal.THOR,
238
494
  isGasAsset: true,
239
495
  isSynthetic: false,
240
- symbol: 'RUNE',
241
- ticker: 'RUNE',
242
- type: 'Native',
496
+ symbol: "RUNE",
497
+ ticker: "RUNE",
498
+ type: "Native",
243
499
  }),
244
500
  );
245
501
 
@@ -251,45 +507,92 @@ describe('AssetValue', () => {
251
507
  decimal: BaseDecimal.MAYA,
252
508
  isGasAsset: true,
253
509
  isSynthetic: false,
254
- symbol: 'CACAO',
255
- ticker: 'CACAO',
256
- type: 'Native',
510
+ symbol: "CACAO",
511
+ ticker: "CACAO",
512
+ type: "Native",
257
513
  }),
258
514
  );
259
515
 
260
- const thor = AssetValue.fromChainOrSignature('ETH.THOR');
516
+ const thor = AssetValue.fromChainOrSignature("ETH.THOR");
261
517
  expect(thor).toEqual(
262
518
  expect.objectContaining({
263
- address: '0xa5f2211b9b8170f694421f2046281775e8468044',
519
+ address: "0xa5f2211b9b8170f694421f2046281775e8468044",
264
520
  chain: Chain.Ethereum,
265
521
  decimal: 18,
266
522
  isGasAsset: false,
267
523
  isSynthetic: false,
268
- symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
269
- ticker: 'THOR',
524
+ symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
525
+ ticker: "THOR",
270
526
  }),
271
527
  );
272
528
 
273
- const vthor = AssetValue.fromChainOrSignature('ETH.vTHOR');
529
+ const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
274
530
  expect(vthor).toEqual(
275
531
  expect.objectContaining({
276
- address: '0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
532
+ address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
277
533
  chain: Chain.Ethereum,
278
534
  decimal: 18,
279
535
  isGasAsset: false,
280
536
  isSynthetic: false,
281
- symbol: 'vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
282
- ticker: 'vTHOR',
537
+ symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
538
+ ticker: "vTHOR",
539
+ }),
540
+ );
541
+
542
+ const arbAsset = AssetValue.fromChainOrSignature(Chain.Arbitrum);
543
+ expect(arbAsset).toEqual(
544
+ expect.objectContaining({
545
+ address: undefined,
546
+ chain: Chain.Arbitrum,
547
+ decimal: BaseDecimal.ARB,
548
+ isGasAsset: true,
549
+ isSynthetic: false,
550
+ symbol: "ETH",
551
+ ticker: "ETH",
552
+ type: "Native",
553
+ }),
554
+ );
555
+
556
+ const opAsset = AssetValue.fromChainOrSignature(Chain.Optimism);
557
+ expect(opAsset).toEqual(
558
+ expect.objectContaining({
559
+ address: undefined,
560
+ chain: Chain.Optimism,
561
+ decimal: BaseDecimal.OP,
562
+ isGasAsset: true,
563
+ isSynthetic: false,
564
+ symbol: "ETH",
565
+ ticker: "ETH",
566
+ type: "Native",
283
567
  }),
284
568
  );
285
569
  });
286
570
  });
287
571
 
288
- describe('loadStaticAssets', () => {
289
- test('loads static assets from `@swapkit/tokens` lists', async () => {
572
+ describe("loadStaticAssets", () => {
573
+ test("loads static assets from `@swapkit/tokens` lists", async () => {
290
574
  // Dummy test - think of sth more meaningful
291
575
  const { ok } = await AssetValue.loadStaticAssets();
292
576
  expect(ok).toBe(true);
293
577
  });
294
578
  });
295
579
  });
580
+
581
+ describe("getMinAmountByChain", () => {
582
+ test("returns min amount for chain", () => {
583
+ expect(getMinAmountByChain(Chain.THORChain).getValue("string")).toBe("0");
584
+ expect(getMinAmountByChain(Chain.Maya).getValue("string")).toBe("0");
585
+ expect(getMinAmountByChain(Chain.Cosmos).getValue("string")).toBe("0.000001");
586
+
587
+ expect(getMinAmountByChain(Chain.Bitcoin).getValue("string")).toBe("0.00010001");
588
+ expect(getMinAmountByChain(Chain.Litecoin).getValue("string")).toBe("0.00010001");
589
+ expect(getMinAmountByChain(Chain.BitcoinCash).getValue("string")).toBe("0.00010001");
590
+ expect(getMinAmountByChain(Chain.Dogecoin).getValue("string")).toBe("1.00000001");
591
+
592
+ expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue("string")).toBe("0.00000001");
593
+ expect(getMinAmountByChain(Chain.Ethereum).getValue("string")).toBe("0.00000001");
594
+ expect(getMinAmountByChain(Chain.Avalanche).getValue("string")).toBe("0.00000001");
595
+ expect(getMinAmountByChain(Chain.Arbitrum).getValue("string")).toBe("0.00000001");
596
+ expect(getMinAmountByChain(Chain.Optimism).getValue("string")).toBe("0.00000001");
597
+ });
598
+ });