@swapkit/helpers 1.0.0-rc.70 → 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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -19
- package/dist/index.es.js +400 -363
- package/dist/index.es.js.map +1 -1
- package/package.json +12 -16
- package/src/helpers/__tests__/asset.test.ts +64 -62
- package/src/helpers/__tests__/memo.test.ts +42 -40
- package/src/helpers/__tests__/others.test.ts +31 -31
- package/src/helpers/asset.ts +53 -52
- package/src/helpers/liquidity.ts +9 -9
- package/src/helpers/memo.ts +17 -18
- package/src/helpers/others.ts +3 -3
- package/src/helpers/validators.ts +5 -5
- package/src/index.ts +9 -9
- package/src/modules/__tests__/assetValue.test.ts +245 -144
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +78 -40
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +17 -2
- package/src/modules/swapKitNumber.ts +1 -1
- package/src/types.ts +13 -13
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { BaseDecimal, Chain } from
|
|
2
|
-
import { describe, expect, test } from
|
|
1
|
+
import { BaseDecimal, Chain } from "@swapkit/types";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { AssetValue, getMinAmountByChain } from
|
|
4
|
+
import { AssetValue, getMinAmountByChain } from "../assetValue.ts";
|
|
5
5
|
|
|
6
|
-
describe(
|
|
7
|
-
describe(
|
|
8
|
-
test(
|
|
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:
|
|
13
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
14
14
|
});
|
|
15
15
|
expect(fakeAvaxUSDCAsset.toString()).toBe(
|
|
16
|
-
|
|
16
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
const ethSynth = new AssetValue({
|
|
20
20
|
chain: Chain.THORChain,
|
|
21
|
-
symbol:
|
|
21
|
+
symbol: "ETH/ETH",
|
|
22
22
|
decimal: 8,
|
|
23
23
|
value: 1234567890,
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
expect(ethSynth.toString()).toBe(
|
|
27
|
-
expect(ethSynth.mul(21.37).getValue(
|
|
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:
|
|
31
|
+
symbol: "ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
32
32
|
decimal: 8,
|
|
33
33
|
value: 1234567890,
|
|
34
34
|
});
|
|
35
|
-
expect(ethThorSynth.toString()).toBe(
|
|
35
|
+
expect(ethThorSynth.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
36
36
|
|
|
37
37
|
const atomDerived = new AssetValue({
|
|
38
|
-
identifier:
|
|
38
|
+
identifier: "THOR.ATOM",
|
|
39
39
|
decimal: 6,
|
|
40
40
|
value: 123456789,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
expect(atomDerived.toString()).toBe(
|
|
43
|
+
expect(atomDerived.toString()).toBe("THOR.ATOM");
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
describe(
|
|
48
|
-
test(
|
|
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:
|
|
53
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
54
54
|
});
|
|
55
55
|
expect(fakeAvaxUSDCAsset.toUrl()).toBe(
|
|
56
|
-
|
|
56
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
60
|
-
expect(thor.toUrl()).toBe(
|
|
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:
|
|
64
|
+
symbol: "ETH/ETH",
|
|
65
65
|
decimal: 8,
|
|
66
66
|
value: 1234567890,
|
|
67
67
|
});
|
|
68
|
-
expect(ethSynth.toUrl()).toBe(
|
|
68
|
+
expect(ethSynth.toUrl()).toBe("THOR.ETH.ETH");
|
|
69
69
|
|
|
70
70
|
const ethThorSynth = new AssetValue({
|
|
71
71
|
chain: Chain.THORChain,
|
|
72
|
-
symbol:
|
|
72
|
+
symbol: "ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
73
73
|
decimal: 8,
|
|
74
74
|
value: 1234567890,
|
|
75
75
|
});
|
|
76
|
-
expect(ethThorSynth.toUrl()).toBe(
|
|
76
|
+
expect(ethThorSynth.toUrl()).toBe("THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
describe(
|
|
81
|
-
test(
|
|
82
|
-
const firstThor = AssetValue.fromChainOrSignature(
|
|
83
|
-
const secondThor = AssetValue.fromChainOrSignature(
|
|
84
|
-
const vThor = AssetValue.fromChainOrSignature(
|
|
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:
|
|
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:
|
|
93
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
94
94
|
decimal: 6,
|
|
95
95
|
value: 1234,
|
|
96
96
|
});
|
|
@@ -109,192 +109,293 @@ describe('AssetValue', () => {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
describe(
|
|
113
|
-
test(
|
|
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(
|
|
118
|
+
expect(avaxUSDCAsset.getValue("string")).toBe("1234.5678");
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
describe(
|
|
123
|
-
test(
|
|
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:
|
|
128
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
129
129
|
});
|
|
130
|
-
expect(avaxUSDCAsset.toString()).toBe(
|
|
130
|
+
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
|
|
131
131
|
|
|
132
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
133
|
-
expect(thor.toString()).toBe(
|
|
132
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
133
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
134
134
|
|
|
135
|
-
const ethSynth = await AssetValue.fromIdentifier(
|
|
136
|
-
expect(ethSynth.toString()).toBe(
|
|
135
|
+
const ethSynth = await AssetValue.fromIdentifier("ETH/ETH");
|
|
136
|
+
expect(ethSynth.toString()).toBe("ETH/ETH");
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
describe(
|
|
141
|
-
test(
|
|
140
|
+
describe("fromIdentifier", () => {
|
|
141
|
+
test.skip("creates AssetValue from string", async () => {
|
|
142
142
|
const avaxUSDCAsset = await AssetValue.fromIdentifier(
|
|
143
|
-
|
|
143
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
144
144
|
);
|
|
145
145
|
|
|
146
146
|
expect(avaxUSDCAsset).toEqual(
|
|
147
147
|
expect.objectContaining({
|
|
148
|
-
address:
|
|
148
|
+
address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
149
149
|
chain: Chain.Avalanche,
|
|
150
150
|
decimal: 6,
|
|
151
151
|
isGasAsset: false,
|
|
152
152
|
isSynthetic: false,
|
|
153
|
-
symbol:
|
|
154
|
-
ticker:
|
|
153
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
154
|
+
ticker: "USDC",
|
|
155
155
|
}),
|
|
156
156
|
);
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
describe(
|
|
161
|
-
test(
|
|
162
|
-
const fakeAvaxAssetString =
|
|
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:
|
|
167
|
+
address: "1234",
|
|
168
168
|
chain: Chain.Avalanche,
|
|
169
169
|
decimal: 18,
|
|
170
170
|
isGasAsset: false,
|
|
171
171
|
isSynthetic: false,
|
|
172
|
-
symbol:
|
|
173
|
-
ticker:
|
|
172
|
+
symbol: "ASDF-1234",
|
|
173
|
+
ticker: "ASDF",
|
|
174
174
|
}),
|
|
175
175
|
);
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
-
describe(
|
|
180
|
-
test(
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
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");
|
|
197
|
+
});
|
|
198
|
+
});
|
|
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";
|
|
185
206
|
|
|
186
207
|
const synthETH = await AssetValue.fromUrl(synthETHString);
|
|
187
208
|
const eth = await AssetValue.fromUrl(ethString);
|
|
188
209
|
const thor = await AssetValue.fromUrl(thorString);
|
|
189
210
|
const synthThor = await AssetValue.fromUrl(synthThorString);
|
|
190
211
|
|
|
191
|
-
expect(synthETH.toString()).toBe(
|
|
192
|
-
expect(eth.toString()).toBe(
|
|
193
|
-
expect(thor.toString()).toBe(
|
|
194
|
-
expect(synthThor.toString()).toBe(
|
|
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");
|
|
195
216
|
});
|
|
196
217
|
});
|
|
197
218
|
|
|
198
|
-
describe(
|
|
199
|
-
test(
|
|
219
|
+
describe("fromIdentifierSync", () => {
|
|
220
|
+
test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
200
221
|
await AssetValue.loadStaticAssets();
|
|
201
222
|
const thor = AssetValue.fromIdentifierSync(
|
|
202
|
-
|
|
223
|
+
"ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
203
224
|
);
|
|
204
225
|
|
|
205
226
|
expect(thor).toBeDefined();
|
|
206
227
|
expect(thor).toEqual(
|
|
207
228
|
expect.objectContaining({
|
|
208
|
-
address:
|
|
229
|
+
address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
209
230
|
chain: Chain.Arbitrum,
|
|
210
231
|
decimal: 6,
|
|
211
232
|
isGasAsset: false,
|
|
212
233
|
isSynthetic: false,
|
|
213
|
-
symbol:
|
|
214
|
-
ticker:
|
|
234
|
+
symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
235
|
+
ticker: "USDT",
|
|
215
236
|
}),
|
|
216
237
|
);
|
|
217
238
|
});
|
|
218
239
|
});
|
|
219
240
|
|
|
220
|
-
describe(
|
|
221
|
-
test(
|
|
241
|
+
describe("fromStringSync", () => {
|
|
242
|
+
test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
222
243
|
await AssetValue.loadStaticAssets();
|
|
223
|
-
const thor = AssetValue.fromStringSync(
|
|
244
|
+
const thor = AssetValue.fromStringSync("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
224
245
|
|
|
225
246
|
expect(thor).toBeDefined();
|
|
226
247
|
expect(thor).toEqual(
|
|
227
248
|
expect.objectContaining({
|
|
228
|
-
address:
|
|
249
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
229
250
|
chain: Chain.Ethereum,
|
|
230
251
|
decimal: 18,
|
|
231
252
|
isGasAsset: false,
|
|
232
253
|
isSynthetic: false,
|
|
233
|
-
symbol:
|
|
234
|
-
ticker:
|
|
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",
|
|
235
270
|
}),
|
|
236
271
|
);
|
|
237
272
|
});
|
|
238
273
|
|
|
239
|
-
test(
|
|
274
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
240
275
|
await AssetValue.loadStaticAssets();
|
|
241
|
-
const fakeAvaxUSDCAssetString =
|
|
276
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
242
277
|
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
243
278
|
|
|
244
279
|
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
245
280
|
expect(fakeAvaxUSDCAsset).toEqual(
|
|
246
281
|
expect.objectContaining({
|
|
247
|
-
address:
|
|
282
|
+
address: "1234",
|
|
248
283
|
chain: Chain.Avalanche,
|
|
249
284
|
decimal: 18,
|
|
250
285
|
isGasAsset: false,
|
|
251
286
|
isSynthetic: false,
|
|
252
|
-
symbol:
|
|
253
|
-
ticker:
|
|
287
|
+
symbol: "USDC-1234",
|
|
288
|
+
ticker: "USDC",
|
|
254
289
|
}),
|
|
255
290
|
);
|
|
256
291
|
});
|
|
257
292
|
|
|
258
|
-
test(
|
|
293
|
+
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
259
294
|
await AssetValue.loadStaticAssets();
|
|
260
|
-
const avaxBTCb =
|
|
295
|
+
const avaxBTCb = "AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50";
|
|
261
296
|
const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
|
|
262
297
|
|
|
263
298
|
expect(AvaxBTCb).toBeDefined();
|
|
264
299
|
expect(AvaxBTCb).toEqual(
|
|
265
300
|
expect.objectContaining({
|
|
266
|
-
address:
|
|
301
|
+
address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
|
|
267
302
|
chain: Chain.Avalanche,
|
|
268
303
|
decimal: 8,
|
|
269
304
|
isGasAsset: false,
|
|
270
305
|
isSynthetic: false,
|
|
271
|
-
symbol:
|
|
272
|
-
ticker:
|
|
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",
|
|
273
371
|
}),
|
|
274
372
|
);
|
|
373
|
+
|
|
374
|
+
expect(AvaxUSDC.getValue("string")).toBe("1");
|
|
375
|
+
expect(AvaxUSDC.getBaseValue("string")).toBe("1000000");
|
|
275
376
|
});
|
|
276
377
|
});
|
|
277
378
|
|
|
278
|
-
describe(
|
|
279
|
-
test(
|
|
379
|
+
describe("fromChainOrSignature", () => {
|
|
380
|
+
test("creates AssetValue from common asset string or chain", () => {
|
|
280
381
|
const customBaseAsset = [Chain.Cosmos, Chain.BinanceSmartChain, Chain.THORChain, Chain.Maya];
|
|
281
|
-
Object.values(Chain)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
+
}
|
|
298
399
|
|
|
299
400
|
const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
|
|
300
401
|
expect(cosmosAsset).toEqual(
|
|
@@ -304,9 +405,9 @@ describe('AssetValue', () => {
|
|
|
304
405
|
decimal: BaseDecimal.GAIA,
|
|
305
406
|
isGasAsset: true,
|
|
306
407
|
isSynthetic: false,
|
|
307
|
-
symbol:
|
|
308
|
-
ticker:
|
|
309
|
-
type:
|
|
408
|
+
symbol: "ATOM",
|
|
409
|
+
ticker: "ATOM",
|
|
410
|
+
type: "Native",
|
|
310
411
|
}),
|
|
311
412
|
);
|
|
312
413
|
|
|
@@ -318,9 +419,9 @@ describe('AssetValue', () => {
|
|
|
318
419
|
decimal: BaseDecimal.BSC,
|
|
319
420
|
isGasAsset: true,
|
|
320
421
|
isSynthetic: false,
|
|
321
|
-
symbol:
|
|
322
|
-
ticker:
|
|
323
|
-
type:
|
|
422
|
+
symbol: "BNB",
|
|
423
|
+
ticker: "BNB",
|
|
424
|
+
type: "Native",
|
|
324
425
|
}),
|
|
325
426
|
);
|
|
326
427
|
|
|
@@ -332,9 +433,9 @@ describe('AssetValue', () => {
|
|
|
332
433
|
decimal: BaseDecimal.THOR,
|
|
333
434
|
isGasAsset: true,
|
|
334
435
|
isSynthetic: false,
|
|
335
|
-
symbol:
|
|
336
|
-
ticker:
|
|
337
|
-
type:
|
|
436
|
+
symbol: "RUNE",
|
|
437
|
+
ticker: "RUNE",
|
|
438
|
+
type: "Native",
|
|
338
439
|
}),
|
|
339
440
|
);
|
|
340
441
|
|
|
@@ -346,42 +447,42 @@ describe('AssetValue', () => {
|
|
|
346
447
|
decimal: BaseDecimal.MAYA,
|
|
347
448
|
isGasAsset: true,
|
|
348
449
|
isSynthetic: false,
|
|
349
|
-
symbol:
|
|
350
|
-
ticker:
|
|
351
|
-
type:
|
|
450
|
+
symbol: "CACAO",
|
|
451
|
+
ticker: "CACAO",
|
|
452
|
+
type: "Native",
|
|
352
453
|
}),
|
|
353
454
|
);
|
|
354
455
|
|
|
355
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
456
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
356
457
|
expect(thor).toEqual(
|
|
357
458
|
expect.objectContaining({
|
|
358
|
-
address:
|
|
459
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
359
460
|
chain: Chain.Ethereum,
|
|
360
461
|
decimal: 18,
|
|
361
462
|
isGasAsset: false,
|
|
362
463
|
isSynthetic: false,
|
|
363
|
-
symbol:
|
|
364
|
-
ticker:
|
|
464
|
+
symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
465
|
+
ticker: "THOR",
|
|
365
466
|
}),
|
|
366
467
|
);
|
|
367
468
|
|
|
368
|
-
const vthor = AssetValue.fromChainOrSignature(
|
|
469
|
+
const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
|
|
369
470
|
expect(vthor).toEqual(
|
|
370
471
|
expect.objectContaining({
|
|
371
|
-
address:
|
|
472
|
+
address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
372
473
|
chain: Chain.Ethereum,
|
|
373
474
|
decimal: 18,
|
|
374
475
|
isGasAsset: false,
|
|
375
476
|
isSynthetic: false,
|
|
376
|
-
symbol:
|
|
377
|
-
ticker:
|
|
477
|
+
symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
478
|
+
ticker: "vTHOR",
|
|
378
479
|
}),
|
|
379
480
|
);
|
|
380
481
|
});
|
|
381
482
|
});
|
|
382
483
|
|
|
383
|
-
describe(
|
|
384
|
-
test(
|
|
484
|
+
describe("loadStaticAssets", () => {
|
|
485
|
+
test("loads static assets from `@swapkit/tokens` lists", async () => {
|
|
385
486
|
// Dummy test - think of sth more meaningful
|
|
386
487
|
const { ok } = await AssetValue.loadStaticAssets();
|
|
387
488
|
expect(ok).toBe(true);
|
|
@@ -389,21 +490,21 @@ describe('AssetValue', () => {
|
|
|
389
490
|
});
|
|
390
491
|
});
|
|
391
492
|
|
|
392
|
-
describe(
|
|
393
|
-
test(
|
|
394
|
-
expect(getMinAmountByChain(Chain.THORChain).getValue(
|
|
395
|
-
expect(getMinAmountByChain(Chain.Maya).getValue(
|
|
396
|
-
expect(getMinAmountByChain(Chain.Cosmos).getValue(
|
|
397
|
-
|
|
398
|
-
expect(getMinAmountByChain(Chain.Bitcoin).getValue(
|
|
399
|
-
expect(getMinAmountByChain(Chain.Litecoin).getValue(
|
|
400
|
-
expect(getMinAmountByChain(Chain.BitcoinCash).getValue(
|
|
401
|
-
expect(getMinAmountByChain(Chain.Dogecoin).getValue(
|
|
402
|
-
|
|
403
|
-
expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue(
|
|
404
|
-
expect(getMinAmountByChain(Chain.Ethereum).getValue(
|
|
405
|
-
expect(getMinAmountByChain(Chain.Avalanche).getValue(
|
|
406
|
-
expect(getMinAmountByChain(Chain.Arbitrum).getValue(
|
|
407
|
-
expect(getMinAmountByChain(Chain.Optimism).getValue(
|
|
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");
|
|
408
509
|
});
|
|
409
510
|
});
|