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

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