@swapkit/helpers 1.0.0-rc.71 → 1.0.0-rc.72

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