@swapkit/helpers 0.0.0-nightly-20240208140027
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.
- package/LICENSE +201 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +490 -0
- package/dist/index.es.js +1241 -0
- package/dist/index.es.js.map +1 -0
- package/package.json +53 -0
- package/src/helpers/__tests__/asset.test.ts +157 -0
- package/src/helpers/__tests__/memo.test.ts +79 -0
- package/src/helpers/__tests__/others.test.ts +59 -0
- package/src/helpers/asset.ts +227 -0
- package/src/helpers/liquidity.ts +180 -0
- package/src/helpers/memo.ts +93 -0
- package/src/helpers/others.ts +20 -0
- package/src/helpers/validators.ts +18 -0
- package/src/index.ts +17 -0
- package/src/modules/__tests__/assetValue.test.ts +409 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +533 -0
- package/src/modules/assetValue.ts +266 -0
- package/src/modules/bigIntArithmetics.ts +419 -0
- package/src/modules/swapKitError.ts +79 -0
- package/src/modules/swapKitNumber.ts +16 -0
- package/src/types.ts +30 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { BaseDecimal, Chain } from '@swapkit/types';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { AssetValue, getMinAmountByChain } from '../assetValue.ts';
|
|
5
|
+
|
|
6
|
+
describe('AssetValue', () => {
|
|
7
|
+
describe('assetValue', () => {
|
|
8
|
+
test('returns asset ticker with value', () => {
|
|
9
|
+
const fakeAvaxUSDCAsset = new AssetValue({
|
|
10
|
+
decimal: 6,
|
|
11
|
+
value: 1234567890,
|
|
12
|
+
chain: Chain.Avalanche,
|
|
13
|
+
symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
14
|
+
});
|
|
15
|
+
expect(fakeAvaxUSDCAsset.toString()).toBe(
|
|
16
|
+
'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const ethSynth = new AssetValue({
|
|
20
|
+
chain: Chain.THORChain,
|
|
21
|
+
symbol: 'ETH/ETH',
|
|
22
|
+
decimal: 8,
|
|
23
|
+
value: 1234567890,
|
|
24
|
+
});
|
|
25
|
+
|
|
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');
|
|
36
|
+
|
|
37
|
+
const atomDerived = new AssetValue({
|
|
38
|
+
identifier: 'THOR.ATOM',
|
|
39
|
+
decimal: 6,
|
|
40
|
+
value: 123456789,
|
|
41
|
+
});
|
|
42
|
+
|
|
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');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
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');
|
|
85
|
+
const firstUsdc = new AssetValue({
|
|
86
|
+
chain: Chain.Avalanche,
|
|
87
|
+
symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
88
|
+
decimal: 6,
|
|
89
|
+
value: 1234567890,
|
|
90
|
+
});
|
|
91
|
+
const secondUsdc = new AssetValue({
|
|
92
|
+
chain: Chain.Avalanche,
|
|
93
|
+
symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
94
|
+
decimal: 6,
|
|
95
|
+
value: 1234,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(firstThor.eq(firstThor)).toBe(true);
|
|
99
|
+
expect(firstThor.eq(secondThor)).toBe(true);
|
|
100
|
+
expect(firstThor.eq(vThor)).toBe(false);
|
|
101
|
+
expect(firstThor.eq(firstUsdc)).toBe(false);
|
|
102
|
+
expect(firstThor.eq(secondUsdc)).toBe(false);
|
|
103
|
+
|
|
104
|
+
expect(firstUsdc.eq(firstThor)).toBe(false);
|
|
105
|
+
expect(firstUsdc.eq(secondThor)).toBe(false);
|
|
106
|
+
expect(firstUsdc.eq(vThor)).toBe(false);
|
|
107
|
+
expect(firstUsdc.eq(firstUsdc)).toBe(true);
|
|
108
|
+
expect(firstUsdc.eq(secondUsdc)).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
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({
|
|
125
|
+
decimal: 6,
|
|
126
|
+
value: 1234567890,
|
|
127
|
+
chain: Chain.Avalanche,
|
|
128
|
+
symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
129
|
+
});
|
|
130
|
+
expect(avaxUSDCAsset.toString()).toBe('AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e');
|
|
131
|
+
|
|
132
|
+
const thor = AssetValue.fromChainOrSignature('ETH.THOR');
|
|
133
|
+
expect(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
|
|
134
|
+
|
|
135
|
+
const ethSynth = await AssetValue.fromIdentifier('ETH/ETH');
|
|
136
|
+
expect(ethSynth.toString()).toBe('ETH/ETH');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('fromIdentifier', () => {
|
|
141
|
+
test('creates AssetValue from string', async () => {
|
|
142
|
+
const avaxUSDCAsset = await AssetValue.fromIdentifier(
|
|
143
|
+
'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(avaxUSDCAsset).toEqual(
|
|
147
|
+
expect.objectContaining({
|
|
148
|
+
address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
149
|
+
chain: Chain.Avalanche,
|
|
150
|
+
decimal: 6,
|
|
151
|
+
isGasAsset: false,
|
|
152
|
+
isSynthetic: false,
|
|
153
|
+
symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
154
|
+
ticker: 'USDC',
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('fromString', () => {
|
|
161
|
+
test('creates AssetValue from string', async () => {
|
|
162
|
+
const fakeAvaxAssetString = 'AVAX.ASDF-1234';
|
|
163
|
+
const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
|
|
164
|
+
|
|
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('fromUrl', () => {
|
|
180
|
+
test('creates AssetValue from url like format', async () => {
|
|
181
|
+
const synthETHString = 'THOR.ETH.ETH';
|
|
182
|
+
const ethString = 'ETH.ETH';
|
|
183
|
+
const thorString = 'ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044';
|
|
184
|
+
const synthThorString = 'THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044';
|
|
185
|
+
|
|
186
|
+
const synthETH = await AssetValue.fromUrl(synthETHString);
|
|
187
|
+
const eth = await AssetValue.fromUrl(ethString);
|
|
188
|
+
const thor = await AssetValue.fromUrl(thorString);
|
|
189
|
+
const synthThor = await AssetValue.fromUrl(synthThorString);
|
|
190
|
+
|
|
191
|
+
expect(synthETH.toString()).toBe('ETH/ETH');
|
|
192
|
+
expect(eth.toString()).toBe('ETH.ETH');
|
|
193
|
+
expect(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
|
|
194
|
+
expect(synthThor.toString()).toBe('ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('fromIdentifierSync', () => {
|
|
199
|
+
test('(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists', async () => {
|
|
200
|
+
await AssetValue.loadStaticAssets();
|
|
201
|
+
const thor = AssetValue.fromIdentifierSync(
|
|
202
|
+
'ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9',
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
expect(thor).toBeDefined();
|
|
206
|
+
expect(thor).toEqual(
|
|
207
|
+
expect.objectContaining({
|
|
208
|
+
address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
209
|
+
chain: Chain.Arbitrum,
|
|
210
|
+
decimal: 6,
|
|
211
|
+
isGasAsset: false,
|
|
212
|
+
isSynthetic: false,
|
|
213
|
+
symbol: 'USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
214
|
+
ticker: 'USDT',
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('fromStringSync', () => {
|
|
221
|
+
test('creates AssetValue from string via `@swapkit/tokens` lists', async () => {
|
|
222
|
+
await AssetValue.loadStaticAssets();
|
|
223
|
+
const thor = AssetValue.fromStringSync('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
|
|
224
|
+
|
|
225
|
+
expect(thor).toBeDefined();
|
|
226
|
+
expect(thor).toEqual(
|
|
227
|
+
expect.objectContaining({
|
|
228
|
+
address: '0xa5f2211b9b8170f694421f2046281775e8468044',
|
|
229
|
+
chain: Chain.Ethereum,
|
|
230
|
+
decimal: 18,
|
|
231
|
+
isGasAsset: false,
|
|
232
|
+
isSynthetic: false,
|
|
233
|
+
symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
|
|
234
|
+
ticker: 'THOR',
|
|
235
|
+
}),
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('returns safe decimals if string is not in `@swapkit/tokens` lists', async () => {
|
|
240
|
+
await AssetValue.loadStaticAssets();
|
|
241
|
+
const fakeAvaxUSDCAssetString = 'AVAX.USDC-1234';
|
|
242
|
+
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
243
|
+
|
|
244
|
+
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
245
|
+
expect(fakeAvaxUSDCAsset).toEqual(
|
|
246
|
+
expect.objectContaining({
|
|
247
|
+
address: '1234',
|
|
248
|
+
chain: Chain.Avalanche,
|
|
249
|
+
decimal: 18,
|
|
250
|
+
isGasAsset: false,
|
|
251
|
+
isSynthetic: false,
|
|
252
|
+
symbol: 'USDC-1234',
|
|
253
|
+
ticker: 'USDC',
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('returns proper avax string with address from `@swapkit/tokens` lists', async () => {
|
|
259
|
+
await AssetValue.loadStaticAssets();
|
|
260
|
+
const avaxBTCb = 'AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50';
|
|
261
|
+
const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
|
|
262
|
+
|
|
263
|
+
expect(AvaxBTCb).toBeDefined();
|
|
264
|
+
expect(AvaxBTCb).toEqual(
|
|
265
|
+
expect.objectContaining({
|
|
266
|
+
address: '0x152b9d0fdc40c096757f570a51e494bd4b943e50',
|
|
267
|
+
chain: Chain.Avalanche,
|
|
268
|
+
decimal: 8,
|
|
269
|
+
isGasAsset: false,
|
|
270
|
+
isSynthetic: false,
|
|
271
|
+
symbol: 'BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50',
|
|
272
|
+
ticker: 'BTC.b',
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('fromChainOrSignature', () => {
|
|
279
|
+
test('creates AssetValue from common asset string or chain', () => {
|
|
280
|
+
const customBaseAsset = [Chain.Cosmos, Chain.BinanceSmartChain, Chain.THORChain, Chain.Maya];
|
|
281
|
+
Object.values(Chain)
|
|
282
|
+
.filter((c) => !customBaseAsset.includes(c))
|
|
283
|
+
.forEach((chain) => {
|
|
284
|
+
const asset = AssetValue.fromChainOrSignature(chain);
|
|
285
|
+
expect(asset).toEqual(
|
|
286
|
+
expect.objectContaining({
|
|
287
|
+
address: undefined,
|
|
288
|
+
chain,
|
|
289
|
+
decimal: BaseDecimal[chain],
|
|
290
|
+
isGasAsset: ![Chain.Arbitrum, Chain.Optimism].includes(chain),
|
|
291
|
+
isSynthetic: false,
|
|
292
|
+
symbol: chain,
|
|
293
|
+
ticker: chain,
|
|
294
|
+
type: 'Native',
|
|
295
|
+
}),
|
|
296
|
+
);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
|
|
300
|
+
expect(cosmosAsset).toEqual(
|
|
301
|
+
expect.objectContaining({
|
|
302
|
+
address: undefined,
|
|
303
|
+
chain: Chain.Cosmos,
|
|
304
|
+
decimal: BaseDecimal.GAIA,
|
|
305
|
+
isGasAsset: true,
|
|
306
|
+
isSynthetic: false,
|
|
307
|
+
symbol: 'ATOM',
|
|
308
|
+
ticker: 'ATOM',
|
|
309
|
+
type: 'Native',
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const bscAsset = AssetValue.fromChainOrSignature(Chain.BinanceSmartChain);
|
|
314
|
+
expect(bscAsset).toEqual(
|
|
315
|
+
expect.objectContaining({
|
|
316
|
+
address: undefined,
|
|
317
|
+
chain: Chain.BinanceSmartChain,
|
|
318
|
+
decimal: BaseDecimal.BSC,
|
|
319
|
+
isGasAsset: true,
|
|
320
|
+
isSynthetic: false,
|
|
321
|
+
symbol: 'BNB',
|
|
322
|
+
ticker: 'BNB',
|
|
323
|
+
type: 'Native',
|
|
324
|
+
}),
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const thorAsset = AssetValue.fromChainOrSignature(Chain.THORChain);
|
|
328
|
+
expect(thorAsset).toEqual(
|
|
329
|
+
expect.objectContaining({
|
|
330
|
+
address: undefined,
|
|
331
|
+
chain: Chain.THORChain,
|
|
332
|
+
decimal: BaseDecimal.THOR,
|
|
333
|
+
isGasAsset: true,
|
|
334
|
+
isSynthetic: false,
|
|
335
|
+
symbol: 'RUNE',
|
|
336
|
+
ticker: 'RUNE',
|
|
337
|
+
type: 'Native',
|
|
338
|
+
}),
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
const cacaoAsset = AssetValue.fromChainOrSignature(Chain.Maya);
|
|
342
|
+
expect(cacaoAsset).toEqual(
|
|
343
|
+
expect.objectContaining({
|
|
344
|
+
address: undefined,
|
|
345
|
+
chain: Chain.Maya,
|
|
346
|
+
decimal: BaseDecimal.MAYA,
|
|
347
|
+
isGasAsset: true,
|
|
348
|
+
isSynthetic: false,
|
|
349
|
+
symbol: 'CACAO',
|
|
350
|
+
ticker: 'CACAO',
|
|
351
|
+
type: 'Native',
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const thor = AssetValue.fromChainOrSignature('ETH.THOR');
|
|
356
|
+
expect(thor).toEqual(
|
|
357
|
+
expect.objectContaining({
|
|
358
|
+
address: '0xa5f2211b9b8170f694421f2046281775e8468044',
|
|
359
|
+
chain: Chain.Ethereum,
|
|
360
|
+
decimal: 18,
|
|
361
|
+
isGasAsset: false,
|
|
362
|
+
isSynthetic: false,
|
|
363
|
+
symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
|
|
364
|
+
ticker: 'THOR',
|
|
365
|
+
}),
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
const vthor = AssetValue.fromChainOrSignature('ETH.vTHOR');
|
|
369
|
+
expect(vthor).toEqual(
|
|
370
|
+
expect.objectContaining({
|
|
371
|
+
address: '0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
|
|
372
|
+
chain: Chain.Ethereum,
|
|
373
|
+
decimal: 18,
|
|
374
|
+
isGasAsset: false,
|
|
375
|
+
isSynthetic: false,
|
|
376
|
+
symbol: 'vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
|
|
377
|
+
ticker: 'vTHOR',
|
|
378
|
+
}),
|
|
379
|
+
);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
describe('loadStaticAssets', () => {
|
|
384
|
+
test('loads static assets from `@swapkit/tokens` lists', async () => {
|
|
385
|
+
// Dummy test - think of sth more meaningful
|
|
386
|
+
const { ok } = await AssetValue.loadStaticAssets();
|
|
387
|
+
expect(ok).toBe(true);
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
describe('getMinAmountByChain', () => {
|
|
393
|
+
test('returns min amount for chain', () => {
|
|
394
|
+
expect(getMinAmountByChain(Chain.THORChain).getValue('string')).toBe('0');
|
|
395
|
+
expect(getMinAmountByChain(Chain.Maya).getValue('string')).toBe('0');
|
|
396
|
+
expect(getMinAmountByChain(Chain.Cosmos).getValue('string')).toBe('0.000001');
|
|
397
|
+
|
|
398
|
+
expect(getMinAmountByChain(Chain.Bitcoin).getValue('string')).toBe('0.00010001');
|
|
399
|
+
expect(getMinAmountByChain(Chain.Litecoin).getValue('string')).toBe('0.00010001');
|
|
400
|
+
expect(getMinAmountByChain(Chain.BitcoinCash).getValue('string')).toBe('0.00010001');
|
|
401
|
+
expect(getMinAmountByChain(Chain.Dogecoin).getValue('string')).toBe('1.00000001');
|
|
402
|
+
|
|
403
|
+
expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue('string')).toBe('0.00000001');
|
|
404
|
+
expect(getMinAmountByChain(Chain.Ethereum).getValue('string')).toBe('0.00000001');
|
|
405
|
+
expect(getMinAmountByChain(Chain.Avalanche).getValue('string')).toBe('0.00000001');
|
|
406
|
+
expect(getMinAmountByChain(Chain.Arbitrum).getValue('string')).toBe('0.00000001');
|
|
407
|
+
expect(getMinAmountByChain(Chain.Optimism).getValue('string')).toBe('0.00000001');
|
|
408
|
+
});
|
|
409
|
+
});
|
|
@@ -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
|
+
});
|