@swapkit/helpers 1.0.0-rc.71 → 1.0.0-rc.73
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 +32 -19
- package/dist/index.es.js +376 -361
- 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 +187 -173
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +41 -41
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +18 -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,197 +109,211 @@ 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 fakeAvaxAssetString =
|
|
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:
|
|
186
|
+
address: "1234",
|
|
187
187
|
chain: Chain.Avalanche,
|
|
188
188
|
decimal: 18,
|
|
189
189
|
isGasAsset: false,
|
|
190
190
|
isSynthetic: false,
|
|
191
|
-
symbol:
|
|
192
|
-
ticker:
|
|
191
|
+
symbol: "ASDF-1234",
|
|
192
|
+
ticker: "ASDF",
|
|
193
193
|
}),
|
|
194
194
|
);
|
|
195
|
-
expect(fakeAvaxAsset.getValue(
|
|
196
|
-
expect(fakeAvaxAsset.getBaseValue(
|
|
195
|
+
expect(fakeAvaxAsset.getValue("string")).toBe("100000000");
|
|
196
|
+
expect(fakeAvaxAsset.getBaseValue("string")).toBe("100000000000000000000000000");
|
|
197
197
|
});
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
describe(
|
|
201
|
-
test(
|
|
202
|
-
const synthETHString =
|
|
203
|
-
const ethString =
|
|
204
|
-
const thorString =
|
|
205
|
-
const synthThorString =
|
|
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(
|
|
213
|
-
expect(eth.toString()).toBe(
|
|
214
|
-
expect(thor.toString()).toBe(
|
|
215
|
-
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");
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
-
describe(
|
|
220
|
-
test(
|
|
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
|
-
|
|
223
|
+
"ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
224
224
|
);
|
|
225
225
|
|
|
226
226
|
expect(thor).toBeDefined();
|
|
227
227
|
expect(thor).toEqual(
|
|
228
228
|
expect.objectContaining({
|
|
229
|
-
address:
|
|
229
|
+
address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
230
230
|
chain: Chain.Arbitrum,
|
|
231
231
|
decimal: 6,
|
|
232
232
|
isGasAsset: false,
|
|
233
233
|
isSynthetic: false,
|
|
234
|
-
symbol:
|
|
235
|
-
ticker:
|
|
234
|
+
symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
235
|
+
ticker: "USDT",
|
|
236
236
|
}),
|
|
237
237
|
);
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
describe(
|
|
242
|
-
test(
|
|
241
|
+
describe("fromStringSync", () => {
|
|
242
|
+
test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
243
243
|
await AssetValue.loadStaticAssets();
|
|
244
|
-
const thor = AssetValue.fromStringSync(
|
|
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:
|
|
249
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
250
250
|
chain: Chain.Ethereum,
|
|
251
251
|
decimal: 18,
|
|
252
252
|
isGasAsset: false,
|
|
253
253
|
isSynthetic: false,
|
|
254
|
-
symbol:
|
|
255
|
-
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",
|
|
256
270
|
}),
|
|
257
271
|
);
|
|
258
272
|
});
|
|
259
273
|
|
|
260
|
-
test(
|
|
274
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
261
275
|
await AssetValue.loadStaticAssets();
|
|
262
|
-
const fakeAvaxUSDCAssetString =
|
|
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:
|
|
282
|
+
address: "1234",
|
|
269
283
|
chain: Chain.Avalanche,
|
|
270
284
|
decimal: 18,
|
|
271
285
|
isGasAsset: false,
|
|
272
286
|
isSynthetic: false,
|
|
273
|
-
symbol:
|
|
274
|
-
ticker:
|
|
287
|
+
symbol: "USDC-1234",
|
|
288
|
+
ticker: "USDC",
|
|
275
289
|
}),
|
|
276
290
|
);
|
|
277
291
|
});
|
|
278
292
|
|
|
279
|
-
test(
|
|
293
|
+
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
280
294
|
await AssetValue.loadStaticAssets();
|
|
281
|
-
const avaxBTCb =
|
|
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:
|
|
301
|
+
address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
|
|
288
302
|
chain: Chain.Avalanche,
|
|
289
303
|
decimal: 8,
|
|
290
304
|
isGasAsset: false,
|
|
291
305
|
isSynthetic: false,
|
|
292
|
-
symbol:
|
|
293
|
-
ticker:
|
|
306
|
+
symbol: "BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50",
|
|
307
|
+
ticker: "BTC.b",
|
|
294
308
|
}),
|
|
295
309
|
);
|
|
296
310
|
});
|
|
297
311
|
});
|
|
298
312
|
|
|
299
|
-
describe(
|
|
300
|
-
test(
|
|
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(
|
|
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:
|
|
312
|
-
ticker:
|
|
325
|
+
symbol: "BTC",
|
|
326
|
+
ticker: "BTC",
|
|
313
327
|
}),
|
|
314
328
|
);
|
|
315
329
|
|
|
316
|
-
expect(btc.getValue(
|
|
317
|
-
expect(btc.getBaseValue(
|
|
330
|
+
expect(btc.getValue("string")).toBe("52000");
|
|
331
|
+
expect(btc.getBaseValue("string")).toBe("5200000000000");
|
|
318
332
|
});
|
|
319
333
|
|
|
320
|
-
test(
|
|
334
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
321
335
|
await AssetValue.loadStaticAssets();
|
|
322
|
-
const fakeAvaxUSDCAssetString =
|
|
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:
|
|
342
|
+
address: "1234",
|
|
329
343
|
chain: Chain.Avalanche,
|
|
330
344
|
decimal: 18,
|
|
331
345
|
isGasAsset: false,
|
|
332
346
|
isSynthetic: false,
|
|
333
|
-
symbol:
|
|
334
|
-
ticker:
|
|
347
|
+
symbol: "USDC-1234",
|
|
348
|
+
ticker: "USDC",
|
|
335
349
|
}),
|
|
336
350
|
);
|
|
337
351
|
|
|
338
|
-
expect(fakeAvaxUSDCAsset.getValue(
|
|
339
|
-
expect(fakeAvaxUSDCAsset.getBaseValue(
|
|
352
|
+
expect(fakeAvaxUSDCAsset.getValue("string")).toBe("0.00000001");
|
|
353
|
+
expect(fakeAvaxUSDCAsset.getBaseValue("string")).toBe("10000000000");
|
|
340
354
|
});
|
|
341
355
|
|
|
342
|
-
test(
|
|
356
|
+
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
343
357
|
await AssetValue.loadStaticAssets();
|
|
344
|
-
const avaxUSDC =
|
|
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:
|
|
364
|
+
address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
351
365
|
chain: Chain.Avalanche,
|
|
352
366
|
decimal: 6,
|
|
353
367
|
isGasAsset: false,
|
|
354
368
|
isSynthetic: false,
|
|
355
|
-
symbol:
|
|
356
|
-
ticker:
|
|
369
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
370
|
+
ticker: "USDC",
|
|
357
371
|
}),
|
|
358
372
|
);
|
|
359
373
|
|
|
360
|
-
expect(AvaxUSDC.getValue(
|
|
361
|
-
expect(AvaxUSDC.getBaseValue(
|
|
374
|
+
expect(AvaxUSDC.getValue("string")).toBe("1");
|
|
375
|
+
expect(AvaxUSDC.getBaseValue("string")).toBe("1000000");
|
|
362
376
|
});
|
|
363
377
|
});
|
|
364
378
|
|
|
365
|
-
describe(
|
|
366
|
-
test(
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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:
|
|
395
|
-
ticker:
|
|
396
|
-
type:
|
|
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:
|
|
409
|
-
ticker:
|
|
410
|
-
type:
|
|
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:
|
|
423
|
-
ticker:
|
|
424
|
-
type:
|
|
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:
|
|
437
|
-
ticker:
|
|
438
|
-
type:
|
|
450
|
+
symbol: "CACAO",
|
|
451
|
+
ticker: "CACAO",
|
|
452
|
+
type: "Native",
|
|
439
453
|
}),
|
|
440
454
|
);
|
|
441
455
|
|
|
442
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
456
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
443
457
|
expect(thor).toEqual(
|
|
444
458
|
expect.objectContaining({
|
|
445
|
-
address:
|
|
459
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
446
460
|
chain: Chain.Ethereum,
|
|
447
461
|
decimal: 18,
|
|
448
462
|
isGasAsset: false,
|
|
449
463
|
isSynthetic: false,
|
|
450
|
-
symbol:
|
|
451
|
-
ticker:
|
|
464
|
+
symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
465
|
+
ticker: "THOR",
|
|
452
466
|
}),
|
|
453
467
|
);
|
|
454
468
|
|
|
455
|
-
const vthor = AssetValue.fromChainOrSignature(
|
|
469
|
+
const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
|
|
456
470
|
expect(vthor).toEqual(
|
|
457
471
|
expect.objectContaining({
|
|
458
|
-
address:
|
|
472
|
+
address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
459
473
|
chain: Chain.Ethereum,
|
|
460
474
|
decimal: 18,
|
|
461
475
|
isGasAsset: false,
|
|
462
476
|
isSynthetic: false,
|
|
463
|
-
symbol:
|
|
464
|
-
ticker:
|
|
477
|
+
symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
478
|
+
ticker: "vTHOR",
|
|
465
479
|
}),
|
|
466
480
|
);
|
|
467
481
|
});
|
|
468
482
|
});
|
|
469
483
|
|
|
470
|
-
describe(
|
|
471
|
-
test(
|
|
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(
|
|
480
|
-
test(
|
|
481
|
-
expect(getMinAmountByChain(Chain.THORChain).getValue(
|
|
482
|
-
expect(getMinAmountByChain(Chain.Maya).getValue(
|
|
483
|
-
expect(getMinAmountByChain(Chain.Cosmos).getValue(
|
|
484
|
-
|
|
485
|
-
expect(getMinAmountByChain(Chain.Bitcoin).getValue(
|
|
486
|
-
expect(getMinAmountByChain(Chain.Litecoin).getValue(
|
|
487
|
-
expect(getMinAmountByChain(Chain.BitcoinCash).getValue(
|
|
488
|
-
expect(getMinAmountByChain(Chain.Dogecoin).getValue(
|
|
489
|
-
|
|
490
|
-
expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue(
|
|
491
|
-
expect(getMinAmountByChain(Chain.Ethereum).getValue(
|
|
492
|
-
expect(getMinAmountByChain(Chain.Avalanche).getValue(
|
|
493
|
-
expect(getMinAmountByChain(Chain.Arbitrum).getValue(
|
|
494
|
-
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");
|
|
495
509
|
});
|
|
496
510
|
});
|