@swapkit/helpers 1.0.0-rc.8 → 1.0.0-rc.80

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.
@@ -1,64 +1,96 @@
1
- import { BaseDecimal, Chain } from '@swapkit/types';
2
- import { describe, expect, test } from 'vitest';
1
+ import { BaseDecimal, Chain } from "@swapkit/types";
2
+ import { describe, expect, test } from "vitest";
3
3
 
4
- import { AssetValue } from '../assetValue.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
+ });
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");
45
77
  });
46
78
  });
47
79
 
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');
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");
53
85
  const firstUsdc = new AssetValue({
54
86
  chain: Chain.Avalanche,
55
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
87
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
56
88
  decimal: 6,
57
89
  value: 1234567890,
58
90
  });
59
91
  const secondUsdc = new AssetValue({
60
92
  chain: Chain.Avalanche,
61
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
93
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
62
94
  decimal: 6,
63
95
  value: 1234,
64
96
  });
@@ -77,136 +109,293 @@ describe('AssetValue', () => {
77
109
  });
78
110
  });
79
111
 
80
- describe('toString', () => {
81
- test('returns asset value string/identifier', async () => {
82
- const fakeAvaxUSDCAsset = new AssetValue({
112
+ describe("from bigint", () => {
113
+ test.todo("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({
83
125
  decimal: 6,
84
126
  value: 1234567890,
85
127
  chain: Chain.Avalanche,
86
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
128
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
87
129
  });
88
- expect(fakeAvaxUSDCAsset.toString()).toBe(
89
- 'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
90
- );
130
+ expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
91
131
 
92
- const thor = AssetValue.fromChainOrSignature('ETH.THOR');
93
- expect(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
132
+ const thor = AssetValue.fromChainOrSignature("ETH.THOR");
133
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
94
134
 
95
- const ethSynth = await AssetValue.fromIdentifier('ETH/ETH');
96
- expect(ethSynth.toString()).toBe('THOR.ETH/ETH');
135
+ const ethSynth = await AssetValue.fromIdentifier("ETH/ETH");
136
+ expect(ethSynth.toString()).toBe("ETH/ETH");
97
137
  });
98
138
  });
99
139
 
100
- describe('fromIdentifier', () => {
101
- test('creates AssetValue from string', async () => {
102
- const fakeAvaxUSDCAssetString = 'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e';
103
- const fakeAvaxUSDCAsset = await AssetValue.fromIdentifier(fakeAvaxUSDCAssetString);
140
+ describe("fromIdentifier", () => {
141
+ test.skip("creates AssetValue from string", async () => {
142
+ const avaxUSDCAsset = await AssetValue.fromIdentifier(
143
+ "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
144
+ );
104
145
 
105
- expect(fakeAvaxUSDCAsset).toEqual(
146
+ expect(avaxUSDCAsset).toEqual(
106
147
  expect.objectContaining({
107
- address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
148
+ address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
108
149
  chain: Chain.Avalanche,
109
150
  decimal: 6,
110
151
  isGasAsset: false,
111
152
  isSynthetic: false,
112
- symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
113
- ticker: 'USDC',
153
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
154
+ ticker: "USDC",
114
155
  }),
115
156
  );
116
157
  });
117
158
  });
118
159
 
119
- describe('fromString', () => {
120
- test('creates AssetValue from string', () => {
121
- test('creates AssetValue from string', async () => {
122
- const fakeAvaxAssetString = 'AVAX.ASDF-1234';
123
- const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
160
+ describe("fromString", () => {
161
+ test("creates AssetValue from string", async () => {
162
+ const fakeAvaxAssetString = "AVAX.ASDF-1234";
163
+ const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
124
164
 
125
- expect(fakeAvaxAsset).toEqual(
126
- expect.objectContaining({
127
- address: '1234',
128
- chain: Chain.Avalanche,
129
- decimal: 10,
130
- isGasAsset: false,
131
- isSynthetic: false,
132
- symbol: 'ASDF-1234',
133
- ticker: 'ASDF',
134
- }),
135
- );
136
- });
165
+ expect(fakeAvaxAsset).toEqual(
166
+ expect.objectContaining({
167
+ address: "1234",
168
+ chain: Chain.Avalanche,
169
+ decimal: 18,
170
+ isGasAsset: false,
171
+ isSynthetic: false,
172
+ symbol: "ASDF-1234",
173
+ ticker: "ASDF",
174
+ }),
175
+ );
176
+ });
177
+ });
178
+
179
+ describe("fromStringWithBase", () => {
180
+ test("creates AssetValue from string with base", async () => {
181
+ const fakeAvaxAssetString = "AVAX.ASDF-1234";
182
+ const fakeAvaxAsset = await AssetValue.fromStringWithBase(fakeAvaxAssetString, 1, 8);
183
+
184
+ expect(fakeAvaxAsset).toEqual(
185
+ expect.objectContaining({
186
+ address: "1234",
187
+ chain: Chain.Avalanche,
188
+ decimal: 18,
189
+ isGasAsset: false,
190
+ isSynthetic: false,
191
+ symbol: "ASDF-1234",
192
+ ticker: "ASDF",
193
+ }),
194
+ );
195
+ expect(fakeAvaxAsset.getValue("string")).toBe("100000000");
196
+ expect(fakeAvaxAsset.getBaseValue("string")).toBe("100000000000000000000000000");
137
197
  });
138
198
  });
139
199
 
140
- describe('fromIdentifierSync', () => {
141
- test('(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists', async () => {
200
+ describe("fromUrl", () => {
201
+ test("creates AssetValue from url like format", async () => {
202
+ const synthETHString = "THOR.ETH.ETH";
203
+ const ethString = "ETH.ETH";
204
+ const thorString = "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
205
+ const synthThorString = "THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
206
+
207
+ const synthETH = await AssetValue.fromUrl(synthETHString);
208
+ const eth = await AssetValue.fromUrl(ethString);
209
+ const thor = await AssetValue.fromUrl(thorString);
210
+ const synthThor = await AssetValue.fromUrl(synthThorString);
211
+
212
+ expect(synthETH.toString()).toBe("ETH/ETH");
213
+ expect(eth.toString()).toBe("ETH.ETH");
214
+ expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
215
+ expect(synthThor.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
216
+ });
217
+ });
218
+
219
+ describe("fromIdentifierSync", () => {
220
+ test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
142
221
  await AssetValue.loadStaticAssets();
143
222
  const thor = AssetValue.fromIdentifierSync(
144
- 'ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9',
223
+ "ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
145
224
  );
146
225
 
147
226
  expect(thor).toBeDefined();
148
227
  expect(thor).toEqual(
149
228
  expect.objectContaining({
150
- address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
229
+ address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
151
230
  chain: Chain.Arbitrum,
152
231
  decimal: 6,
153
232
  isGasAsset: false,
154
233
  isSynthetic: false,
155
- symbol: 'USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
156
- ticker: 'USDT',
234
+ symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
235
+ ticker: "USDT",
157
236
  }),
158
237
  );
159
238
  });
160
239
  });
161
240
 
162
- describe('fromStringSync', () => {
163
- test('creates AssetValue from string via `@swapkit/tokens` lists', async () => {
241
+ describe("fromStringSync", () => {
242
+ test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
164
243
  await AssetValue.loadStaticAssets();
165
- const thor = AssetValue.fromStringSync('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
244
+ const thor = AssetValue.fromStringSync("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
166
245
 
167
246
  expect(thor).toBeDefined();
168
247
  expect(thor).toEqual(
169
248
  expect.objectContaining({
170
- address: '0xa5f2211b9b8170f694421f2046281775e8468044',
249
+ address: "0xa5f2211b9b8170f694421f2046281775e8468044",
171
250
  chain: Chain.Ethereum,
172
251
  decimal: 18,
173
252
  isGasAsset: false,
174
253
  isSynthetic: false,
175
- symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
176
- ticker: 'THOR',
254
+ symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
255
+ ticker: "THOR",
256
+ }),
257
+ );
258
+
259
+ const usdc = AssetValue.fromStringSync("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48");
260
+ expect(usdc).toBeDefined();
261
+ expect(usdc).toEqual(
262
+ expect.objectContaining({
263
+ address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
264
+ chain: Chain.Ethereum,
265
+ decimal: 6,
266
+ isGasAsset: false,
267
+ isSynthetic: false,
268
+ symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
269
+ ticker: "USDC",
177
270
  }),
178
271
  );
179
272
  });
180
273
 
181
- test('returns undefined if string is not in `@swapkit/tokens` lists', async () => {
274
+ test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
182
275
  await AssetValue.loadStaticAssets();
183
- const fakeAvaxUSDCAssetString = 'AVAX.USDC-1234';
276
+ const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
184
277
  const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
185
278
 
186
- expect(fakeAvaxUSDCAsset).toBeUndefined();
279
+ expect(fakeAvaxUSDCAsset).toBeDefined();
280
+ expect(fakeAvaxUSDCAsset).toEqual(
281
+ expect.objectContaining({
282
+ address: "1234",
283
+ chain: Chain.Avalanche,
284
+ decimal: 18,
285
+ isGasAsset: false,
286
+ isSynthetic: false,
287
+ symbol: "USDC-1234",
288
+ ticker: "USDC",
289
+ }),
290
+ );
291
+ });
292
+
293
+ test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
294
+ await AssetValue.loadStaticAssets();
295
+ const avaxBTCb = "AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50";
296
+ const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
297
+
298
+ expect(AvaxBTCb).toBeDefined();
299
+ expect(AvaxBTCb).toEqual(
300
+ expect.objectContaining({
301
+ address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
302
+ chain: Chain.Avalanche,
303
+ decimal: 8,
304
+ isGasAsset: false,
305
+ isSynthetic: false,
306
+ symbol: "BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50",
307
+ ticker: "BTC.b",
308
+ }),
309
+ );
310
+ });
311
+ });
312
+
313
+ describe("fromStringWithBaseSync", () => {
314
+ test("creates AssetValue from string with base decimals via `@swapkit/tokens` lists", async () => {
315
+ await AssetValue.loadStaticAssets();
316
+ const btc = AssetValue.fromStringWithBaseSync("BTC.BTC", 5200000000000, 8);
317
+
318
+ expect(btc).toBeDefined();
319
+ expect(btc).toEqual(
320
+ expect.objectContaining({
321
+ chain: Chain.Bitcoin,
322
+ decimal: 8,
323
+ isGasAsset: true,
324
+ isSynthetic: false,
325
+ symbol: "BTC",
326
+ ticker: "BTC",
327
+ }),
328
+ );
329
+
330
+ expect(btc.getValue("string")).toBe("52000");
331
+ expect(btc.getBaseValue("string")).toBe("5200000000000");
332
+ });
333
+
334
+ test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
335
+ await AssetValue.loadStaticAssets();
336
+ const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
337
+ const fakeAvaxUSDCAsset = AssetValue.fromStringWithBaseSync(fakeAvaxUSDCAssetString, 1, 8);
338
+
339
+ expect(fakeAvaxUSDCAsset).toBeDefined();
340
+ expect(fakeAvaxUSDCAsset).toEqual(
341
+ expect.objectContaining({
342
+ address: "1234",
343
+ chain: Chain.Avalanche,
344
+ decimal: 18,
345
+ isGasAsset: false,
346
+ isSynthetic: false,
347
+ symbol: "USDC-1234",
348
+ ticker: "USDC",
349
+ }),
350
+ );
351
+
352
+ expect(fakeAvaxUSDCAsset.getValue("string")).toBe("0.00000001");
353
+ expect(fakeAvaxUSDCAsset.getBaseValue("string")).toBe("10000000000");
354
+ });
355
+
356
+ test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
357
+ await AssetValue.loadStaticAssets();
358
+ const avaxUSDC = "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e";
359
+ const AvaxUSDC = AssetValue.fromStringWithBaseSync(avaxUSDC, 100000000, 8);
360
+
361
+ expect(AvaxUSDC).toBeDefined();
362
+ expect(AvaxUSDC).toEqual(
363
+ expect.objectContaining({
364
+ address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
365
+ chain: Chain.Avalanche,
366
+ decimal: 6,
367
+ isGasAsset: false,
368
+ isSynthetic: false,
369
+ symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
370
+ ticker: "USDC",
371
+ }),
372
+ );
373
+
374
+ expect(AvaxUSDC.getValue("string")).toBe("1");
375
+ expect(AvaxUSDC.getBaseValue("string")).toBe("1000000");
187
376
  });
188
377
  });
189
378
 
190
- describe('fromChainOrSignature', () => {
191
- test('creates AssetValue from common asset string or chain', () => {
379
+ describe("fromChainOrSignature", () => {
380
+ test("creates AssetValue from common asset string or chain", () => {
192
381
  const customBaseAsset = [Chain.Cosmos, Chain.BinanceSmartChain, Chain.THORChain, Chain.Maya];
193
- Object.values(Chain)
194
- .filter((c) => !customBaseAsset.includes(c))
195
- .forEach((chain) => {
196
- const asset = AssetValue.fromChainOrSignature(chain);
197
- expect(asset).toEqual(
198
- expect.objectContaining({
199
- address: undefined,
200
- chain,
201
- decimal: BaseDecimal[chain],
202
- isGasAsset: ![Chain.Arbitrum, Chain.Optimism].includes(chain),
203
- isSynthetic: false,
204
- symbol: chain,
205
- ticker: chain,
206
- type: 'Native',
207
- }),
208
- );
209
- });
382
+ const filteredChains = Object.values(Chain).filter((c) => !customBaseAsset.includes(c));
383
+
384
+ for (const chain of filteredChains) {
385
+ const asset = AssetValue.fromChainOrSignature(chain);
386
+ expect(asset).toEqual(
387
+ expect.objectContaining({
388
+ address: undefined,
389
+ chain,
390
+ decimal: BaseDecimal[chain],
391
+ isGasAsset: ![Chain.Arbitrum, Chain.Optimism].includes(chain),
392
+ isSynthetic: false,
393
+ symbol: chain,
394
+ ticker: chain,
395
+ type: "Native",
396
+ }),
397
+ );
398
+ }
210
399
 
211
400
  const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
212
401
  expect(cosmosAsset).toEqual(
@@ -216,9 +405,9 @@ describe('AssetValue', () => {
216
405
  decimal: BaseDecimal.GAIA,
217
406
  isGasAsset: true,
218
407
  isSynthetic: false,
219
- symbol: 'ATOM',
220
- ticker: 'ATOM',
221
- type: 'Native',
408
+ symbol: "ATOM",
409
+ ticker: "ATOM",
410
+ type: "Native",
222
411
  }),
223
412
  );
224
413
 
@@ -230,9 +419,9 @@ describe('AssetValue', () => {
230
419
  decimal: BaseDecimal.BSC,
231
420
  isGasAsset: true,
232
421
  isSynthetic: false,
233
- symbol: 'BNB',
234
- ticker: 'BNB',
235
- type: 'Native',
422
+ symbol: "BNB",
423
+ ticker: "BNB",
424
+ type: "Native",
236
425
  }),
237
426
  );
238
427
 
@@ -244,9 +433,9 @@ describe('AssetValue', () => {
244
433
  decimal: BaseDecimal.THOR,
245
434
  isGasAsset: true,
246
435
  isSynthetic: false,
247
- symbol: 'RUNE',
248
- ticker: 'RUNE',
249
- type: 'Native',
436
+ symbol: "RUNE",
437
+ ticker: "RUNE",
438
+ type: "Native",
250
439
  }),
251
440
  );
252
441
 
@@ -258,45 +447,64 @@ describe('AssetValue', () => {
258
447
  decimal: BaseDecimal.MAYA,
259
448
  isGasAsset: true,
260
449
  isSynthetic: false,
261
- symbol: 'CACAO',
262
- ticker: 'CACAO',
263
- type: 'Native',
450
+ symbol: "CACAO",
451
+ ticker: "CACAO",
452
+ type: "Native",
264
453
  }),
265
454
  );
266
455
 
267
- const thor = AssetValue.fromChainOrSignature('ETH.THOR');
456
+ const thor = AssetValue.fromChainOrSignature("ETH.THOR");
268
457
  expect(thor).toEqual(
269
458
  expect.objectContaining({
270
- address: '0xa5f2211b9b8170f694421f2046281775e8468044',
459
+ address: "0xa5f2211b9b8170f694421f2046281775e8468044",
271
460
  chain: Chain.Ethereum,
272
461
  decimal: 18,
273
462
  isGasAsset: false,
274
463
  isSynthetic: false,
275
- symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
276
- ticker: 'THOR',
464
+ symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
465
+ ticker: "THOR",
277
466
  }),
278
467
  );
279
468
 
280
- const vthor = AssetValue.fromChainOrSignature('ETH.vTHOR');
469
+ const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
281
470
  expect(vthor).toEqual(
282
471
  expect.objectContaining({
283
- address: '0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
472
+ address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
284
473
  chain: Chain.Ethereum,
285
474
  decimal: 18,
286
475
  isGasAsset: false,
287
476
  isSynthetic: false,
288
- symbol: 'vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
289
- ticker: 'vTHOR',
477
+ symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
478
+ ticker: "vTHOR",
290
479
  }),
291
480
  );
292
481
  });
293
482
  });
294
483
 
295
- describe('loadStaticAssets', () => {
296
- test('loads static assets from `@swapkit/tokens` lists', async () => {
484
+ describe("loadStaticAssets", () => {
485
+ test("loads static assets from `@swapkit/tokens` lists", async () => {
297
486
  // Dummy test - think of sth more meaningful
298
487
  const { ok } = await AssetValue.loadStaticAssets();
299
488
  expect(ok).toBe(true);
300
489
  });
301
490
  });
302
491
  });
492
+
493
+ describe("getMinAmountByChain", () => {
494
+ test("returns min amount for chain", () => {
495
+ expect(getMinAmountByChain(Chain.THORChain).getValue("string")).toBe("0");
496
+ expect(getMinAmountByChain(Chain.Maya).getValue("string")).toBe("0");
497
+ expect(getMinAmountByChain(Chain.Cosmos).getValue("string")).toBe("0.000001");
498
+
499
+ expect(getMinAmountByChain(Chain.Bitcoin).getValue("string")).toBe("0.00010001");
500
+ expect(getMinAmountByChain(Chain.Litecoin).getValue("string")).toBe("0.00010001");
501
+ expect(getMinAmountByChain(Chain.BitcoinCash).getValue("string")).toBe("0.00010001");
502
+ expect(getMinAmountByChain(Chain.Dogecoin).getValue("string")).toBe("1.00000001");
503
+
504
+ expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue("string")).toBe("0.00000001");
505
+ expect(getMinAmountByChain(Chain.Ethereum).getValue("string")).toBe("0.00000001");
506
+ expect(getMinAmountByChain(Chain.Avalanche).getValue("string")).toBe("0.00000001");
507
+ expect(getMinAmountByChain(Chain.Arbitrum).getValue("string")).toBe("0.00000001");
508
+ expect(getMinAmountByChain(Chain.Optimism).getValue("string")).toBe("0.00000001");
509
+ });
510
+ });
@@ -0,0 +1,30 @@
1
+ import { describe, expect, test } from "vitest";
2
+
3
+ import { formatBigIntToSafeValue } from "../bigIntArithmetics.ts";
4
+
5
+ describe("BigIntArithmatics", () => {
6
+ describe("formatBigIntToSafeValue", () => {
7
+ test("parse bigint with decimals to string", () => {
8
+ const safeValue1 = formatBigIntToSafeValue({
9
+ value: BigInt(0),
10
+ decimal: 6,
11
+ bigIntDecimal: 6,
12
+ });
13
+ expect(safeValue1).toBe("0");
14
+
15
+ const safeValue2 = formatBigIntToSafeValue({
16
+ value: BigInt(15),
17
+ decimal: 0,
18
+ bigIntDecimal: 0,
19
+ });
20
+ expect(safeValue2).toBe("15");
21
+
22
+ const safeValue3 = formatBigIntToSafeValue({
23
+ value: BigInt(123456789),
24
+ decimal: 4,
25
+ bigIntDecimal: 4,
26
+ });
27
+ expect(safeValue3).toBe("12345.6789");
28
+ });
29
+ });
30
+ });