@swapkit/helpers 1.0.0-rc.1 → 1.0.0-rc.100
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.js +2452 -0
- package/dist/index.js.map +30 -0
- package/package.json +26 -36
- package/src/helpers/__tests__/asset.test.ts +149 -105
- package/src/helpers/__tests__/memo.test.ts +52 -40
- package/src/helpers/__tests__/others.test.ts +42 -37
- package/src/helpers/__tests__/validators.test.ts +24 -0
- package/src/helpers/asset.ts +139 -91
- package/src/helpers/derivationPath.ts +53 -0
- package/src/helpers/liquidity.ts +50 -43
- package/src/helpers/memo.ts +31 -28
- package/src/helpers/others.ts +35 -57
- package/src/helpers/validators.ts +15 -6
- package/src/helpers/web3wallets.ts +177 -0
- package/src/index.ts +14 -8
- package/src/modules/__tests__/assetValue.test.ts +420 -117
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +351 -149
- package/src/modules/assetValue.ts +243 -171
- package/src/modules/bigIntArithmetics.ts +313 -153
- package/src/modules/requestClient.ts +39 -0
- package/src/modules/swapKitError.ts +33 -5
- package/src/modules/swapKitNumber.ts +6 -3
- package/src/types/abis/erc20.ts +99 -0
- package/src/types/abis/mayaEvmVaults.ts +331 -0
- package/src/types/abis/tcEthVault.ts +496 -0
- package/src/types/chains.ts +220 -0
- package/src/types/commonTypes.ts +119 -0
- package/src/types/derivationPath.ts +56 -0
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/index.ts +10 -0
- package/src/types/network.ts +43 -0
- package/src/types/sdk.ts +44 -0
- package/src/types/tokens.ts +30 -0
- package/src/types/wallet.ts +47 -0
- package/LICENSE +0 -201
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -333
- package/dist/index.es.js +0 -661
- package/src/helpers/number.ts +0 -40
|
@@ -1,57 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { BaseDecimal, Chain } from "../../types/chains.ts";
|
|
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
|
-
expect(fakeAvaxUSDCAsset.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
expect(thor.assetValue).toBe('0 THOR');
|
|
15
|
+
expect(fakeAvaxUSDCAsset.toString()).toBe(
|
|
16
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
17
|
+
);
|
|
19
18
|
|
|
20
19
|
const ethSynth = new AssetValue({
|
|
21
20
|
chain: Chain.THORChain,
|
|
22
|
-
symbol:
|
|
21
|
+
symbol: "ETH/ETH",
|
|
23
22
|
decimal: 8,
|
|
24
23
|
value: 1234567890,
|
|
25
24
|
});
|
|
26
25
|
|
|
27
|
-
expect(ethSynth.
|
|
28
|
-
expect(ethSynth.
|
|
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");
|
|
29
36
|
|
|
30
37
|
const atomDerived = new AssetValue({
|
|
31
|
-
identifier:
|
|
38
|
+
identifier: "THOR.ATOM",
|
|
32
39
|
decimal: 6,
|
|
33
40
|
value: 123456789,
|
|
34
41
|
});
|
|
35
42
|
|
|
36
|
-
expect(atomDerived.
|
|
37
|
-
|
|
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");
|
|
38
77
|
});
|
|
39
78
|
});
|
|
40
79
|
|
|
41
|
-
describe(
|
|
42
|
-
test(
|
|
43
|
-
const firstThor = AssetValue.fromChainOrSignature(
|
|
44
|
-
const secondThor = AssetValue.fromChainOrSignature(
|
|
45
|
-
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");
|
|
46
85
|
const firstUsdc = new AssetValue({
|
|
47
86
|
chain: Chain.Avalanche,
|
|
48
|
-
symbol:
|
|
87
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
49
88
|
decimal: 6,
|
|
50
89
|
value: 1234567890,
|
|
51
90
|
});
|
|
52
91
|
const secondUsdc = new AssetValue({
|
|
53
92
|
chain: Chain.Avalanche,
|
|
54
|
-
symbol:
|
|
93
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
55
94
|
decimal: 6,
|
|
56
95
|
value: 1234,
|
|
57
96
|
});
|
|
@@ -70,136 +109,353 @@ describe('AssetValue', () => {
|
|
|
70
109
|
});
|
|
71
110
|
});
|
|
72
111
|
|
|
73
|
-
describe(
|
|
74
|
-
test(
|
|
75
|
-
const
|
|
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({
|
|
76
125
|
decimal: 6,
|
|
77
126
|
value: 1234567890,
|
|
78
127
|
chain: Chain.Avalanche,
|
|
79
|
-
symbol:
|
|
128
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
80
129
|
});
|
|
81
|
-
expect(
|
|
82
|
-
'AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
|
|
83
|
-
);
|
|
130
|
+
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
|
|
84
131
|
|
|
85
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
86
|
-
expect(thor.toString()).toBe(
|
|
132
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
133
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
87
134
|
|
|
88
|
-
const ethSynth = await AssetValue.fromIdentifier(
|
|
89
|
-
expect(ethSynth.toString()).toBe(
|
|
135
|
+
const ethSynth = await AssetValue.fromIdentifier("ETH/ETH");
|
|
136
|
+
expect(ethSynth.toString()).toBe("ETH/ETH");
|
|
90
137
|
});
|
|
91
138
|
});
|
|
92
139
|
|
|
93
|
-
describe(
|
|
94
|
-
test(
|
|
95
|
-
const
|
|
96
|
-
|
|
140
|
+
describe("fromIdentifier", () => {
|
|
141
|
+
test("creates AssetValue from string", async () => {
|
|
142
|
+
const avaxUSDCAsset = await AssetValue.fromIdentifier(
|
|
143
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
144
|
+
);
|
|
97
145
|
|
|
98
|
-
expect(
|
|
146
|
+
expect(avaxUSDCAsset).toEqual(
|
|
99
147
|
expect.objectContaining({
|
|
100
|
-
address:
|
|
148
|
+
address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
101
149
|
chain: Chain.Avalanche,
|
|
102
150
|
decimal: 6,
|
|
103
151
|
isGasAsset: false,
|
|
104
152
|
isSynthetic: false,
|
|
105
|
-
symbol:
|
|
106
|
-
ticker:
|
|
153
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
154
|
+
ticker: "USDC",
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
test("creates AssetValue from string with multiple dashes", async () => {
|
|
159
|
+
const ethPendleLptAsset = await AssetValue.fromIdentifier("ETH.PENDLE-LPT-0x1234");
|
|
160
|
+
|
|
161
|
+
expect(ethPendleLptAsset).toEqual(
|
|
162
|
+
expect.objectContaining({
|
|
163
|
+
address: "0x1234",
|
|
164
|
+
chain: Chain.Ethereum,
|
|
165
|
+
decimal: 18,
|
|
166
|
+
isGasAsset: false,
|
|
167
|
+
isSynthetic: false,
|
|
168
|
+
symbol: "PENDLE-LPT-0x1234",
|
|
169
|
+
ticker: "PENDLE-LPT",
|
|
107
170
|
}),
|
|
108
171
|
);
|
|
109
172
|
});
|
|
110
173
|
});
|
|
111
174
|
|
|
112
|
-
describe(
|
|
113
|
-
test(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
|
|
175
|
+
describe("fromString", () => {
|
|
176
|
+
test("creates AssetValue from string", async () => {
|
|
177
|
+
const fakeAvaxAssetString = "AVAX.ASDF-1234";
|
|
178
|
+
const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
|
|
117
179
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
180
|
+
expect(fakeAvaxAsset).toEqual(
|
|
181
|
+
expect.objectContaining({
|
|
182
|
+
address: "1234",
|
|
183
|
+
chain: Chain.Avalanche,
|
|
184
|
+
decimal: 18,
|
|
185
|
+
isGasAsset: false,
|
|
186
|
+
isSynthetic: false,
|
|
187
|
+
symbol: "ASDF-1234",
|
|
188
|
+
ticker: "ASDF",
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
test("creates AssetValue from string with multiple dashes", async () => {
|
|
193
|
+
const fakeAvaxAssetString = "AVAX.ASDF-LP-1234";
|
|
194
|
+
const fakeAvaxAsset = await AssetValue.fromString(fakeAvaxAssetString);
|
|
195
|
+
|
|
196
|
+
expect(fakeAvaxAsset).toEqual(
|
|
197
|
+
expect.objectContaining({
|
|
198
|
+
address: "1234",
|
|
199
|
+
chain: Chain.Avalanche,
|
|
200
|
+
decimal: 18,
|
|
201
|
+
isGasAsset: false,
|
|
202
|
+
isSynthetic: false,
|
|
203
|
+
symbol: "ASDF-LP-1234",
|
|
204
|
+
ticker: "ASDF-LP",
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe("fromStringWithBase", () => {
|
|
211
|
+
test("creates AssetValue from string with base", async () => {
|
|
212
|
+
const fakeAvaxAssetString = "AVAX.ASDF-1234";
|
|
213
|
+
const fakeAvaxAsset = await AssetValue.fromStringWithBase(fakeAvaxAssetString, 1, 8);
|
|
214
|
+
|
|
215
|
+
expect(fakeAvaxAsset).toEqual(
|
|
216
|
+
expect.objectContaining({
|
|
217
|
+
address: "1234",
|
|
218
|
+
chain: Chain.Avalanche,
|
|
219
|
+
decimal: 18,
|
|
220
|
+
isGasAsset: false,
|
|
221
|
+
isSynthetic: false,
|
|
222
|
+
symbol: "ASDF-1234",
|
|
223
|
+
ticker: "ASDF",
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
expect(fakeAvaxAsset.getValue("string")).toBe("100000000");
|
|
227
|
+
expect(fakeAvaxAsset.getBaseValue("string")).toBe("100000000000000000000000000");
|
|
130
228
|
});
|
|
131
229
|
});
|
|
132
230
|
|
|
133
|
-
describe(
|
|
134
|
-
test(
|
|
231
|
+
describe("fromUrl", () => {
|
|
232
|
+
test("creates AssetValue from url like format", async () => {
|
|
233
|
+
const synthETHString = "THOR.ETH.ETH";
|
|
234
|
+
const ethString = "ETH.ETH";
|
|
235
|
+
const thorString = "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
|
|
236
|
+
const synthThorString = "THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
|
|
237
|
+
const synthDashesString = "THOR.ETH.PENDLE-LPT-0x1234";
|
|
238
|
+
|
|
239
|
+
const synthETH = await AssetValue.fromUrl(synthETHString);
|
|
240
|
+
const eth = await AssetValue.fromUrl(ethString);
|
|
241
|
+
const thor = await AssetValue.fromUrl(thorString);
|
|
242
|
+
const synthThor = await AssetValue.fromUrl(synthThorString);
|
|
243
|
+
const synthDashes = await AssetValue.fromUrl(synthDashesString);
|
|
244
|
+
|
|
245
|
+
expect(synthETH.toString()).toBe("ETH/ETH");
|
|
246
|
+
expect(eth.toString()).toBe("ETH.ETH");
|
|
247
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
248
|
+
expect(synthThor.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
249
|
+
expect(synthDashes.toString()).toBe("ETH/PENDLE-LPT-0x1234");
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("fromIdentifierSync", () => {
|
|
254
|
+
test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
135
255
|
await AssetValue.loadStaticAssets();
|
|
136
256
|
const thor = AssetValue.fromIdentifierSync(
|
|
137
|
-
|
|
257
|
+
"ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
138
258
|
);
|
|
139
259
|
|
|
140
260
|
expect(thor).toBeDefined();
|
|
141
261
|
expect(thor).toEqual(
|
|
142
262
|
expect.objectContaining({
|
|
143
|
-
address:
|
|
263
|
+
address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
144
264
|
chain: Chain.Arbitrum,
|
|
145
265
|
decimal: 6,
|
|
146
266
|
isGasAsset: false,
|
|
147
267
|
isSynthetic: false,
|
|
148
|
-
symbol:
|
|
149
|
-
ticker:
|
|
268
|
+
symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
269
|
+
ticker: "USDT",
|
|
150
270
|
}),
|
|
151
271
|
);
|
|
152
272
|
});
|
|
153
273
|
});
|
|
154
274
|
|
|
155
|
-
describe(
|
|
156
|
-
test(
|
|
275
|
+
describe("fromStringSync", () => {
|
|
276
|
+
test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
157
277
|
await AssetValue.loadStaticAssets();
|
|
158
|
-
const thor = AssetValue.fromStringSync(
|
|
278
|
+
const thor = AssetValue.fromStringSync("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
159
279
|
|
|
160
280
|
expect(thor).toBeDefined();
|
|
161
281
|
expect(thor).toEqual(
|
|
162
282
|
expect.objectContaining({
|
|
163
|
-
address:
|
|
283
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
284
|
+
chain: Chain.Ethereum,
|
|
285
|
+
decimal: 18,
|
|
286
|
+
isGasAsset: false,
|
|
287
|
+
isSynthetic: false,
|
|
288
|
+
symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
289
|
+
ticker: "THOR",
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
const usdc = AssetValue.fromStringSync("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48");
|
|
294
|
+
expect(usdc).toBeDefined();
|
|
295
|
+
expect(usdc).toEqual(
|
|
296
|
+
expect.objectContaining({
|
|
297
|
+
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
164
298
|
chain: Chain.Ethereum,
|
|
299
|
+
decimal: 6,
|
|
300
|
+
isGasAsset: false,
|
|
301
|
+
isSynthetic: false,
|
|
302
|
+
symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
303
|
+
ticker: "USDC",
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
309
|
+
await AssetValue.loadStaticAssets();
|
|
310
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
311
|
+
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
312
|
+
|
|
313
|
+
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
314
|
+
expect(fakeAvaxUSDCAsset).toEqual(
|
|
315
|
+
expect.objectContaining({
|
|
316
|
+
address: "1234",
|
|
317
|
+
chain: Chain.Avalanche,
|
|
165
318
|
decimal: 18,
|
|
166
319
|
isGasAsset: false,
|
|
167
320
|
isSynthetic: false,
|
|
168
|
-
symbol:
|
|
169
|
-
ticker:
|
|
321
|
+
symbol: "USDC-1234",
|
|
322
|
+
ticker: "USDC",
|
|
170
323
|
}),
|
|
171
324
|
);
|
|
172
325
|
});
|
|
173
326
|
|
|
174
|
-
test(
|
|
327
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists with multiple dashes", async () => {
|
|
175
328
|
await AssetValue.loadStaticAssets();
|
|
176
|
-
const fakeAvaxUSDCAssetString =
|
|
329
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-LPT-1234";
|
|
177
330
|
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
178
331
|
|
|
179
|
-
expect(fakeAvaxUSDCAsset).
|
|
332
|
+
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
333
|
+
expect(fakeAvaxUSDCAsset).toEqual(
|
|
334
|
+
expect.objectContaining({
|
|
335
|
+
address: "1234",
|
|
336
|
+
chain: Chain.Avalanche,
|
|
337
|
+
decimal: 18,
|
|
338
|
+
isGasAsset: false,
|
|
339
|
+
isSynthetic: false,
|
|
340
|
+
symbol: "USDC-LPT-1234",
|
|
341
|
+
ticker: "USDC-LPT",
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
347
|
+
await AssetValue.loadStaticAssets();
|
|
348
|
+
const avaxBTCb = "AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50";
|
|
349
|
+
const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
|
|
350
|
+
|
|
351
|
+
expect(AvaxBTCb).toBeDefined();
|
|
352
|
+
expect(AvaxBTCb).toEqual(
|
|
353
|
+
expect.objectContaining({
|
|
354
|
+
address: "0x152b9d0fdc40c096757f570a51e494bd4b943e50",
|
|
355
|
+
chain: Chain.Avalanche,
|
|
356
|
+
decimal: 8,
|
|
357
|
+
isGasAsset: false,
|
|
358
|
+
isSynthetic: false,
|
|
359
|
+
symbol: "BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50",
|
|
360
|
+
ticker: "BTC.b",
|
|
361
|
+
}),
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe("fromStringWithBaseSync", () => {
|
|
367
|
+
test("creates AssetValue from string with base decimals via `@swapkit/tokens` lists", async () => {
|
|
368
|
+
await AssetValue.loadStaticAssets();
|
|
369
|
+
const btc = AssetValue.fromStringWithBaseSync("BTC.BTC", 5200000000000, 8);
|
|
370
|
+
|
|
371
|
+
expect(btc).toBeDefined();
|
|
372
|
+
expect(btc).toEqual(
|
|
373
|
+
expect.objectContaining({
|
|
374
|
+
chain: Chain.Bitcoin,
|
|
375
|
+
decimal: 8,
|
|
376
|
+
isGasAsset: true,
|
|
377
|
+
isSynthetic: false,
|
|
378
|
+
symbol: "BTC",
|
|
379
|
+
ticker: "BTC",
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
expect(btc.getValue("string")).toBe("52000");
|
|
384
|
+
expect(btc.getBaseValue("string")).toBe("5200000000000");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
388
|
+
await AssetValue.loadStaticAssets();
|
|
389
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
390
|
+
const fakeAvaxUSDCAsset = AssetValue.fromStringWithBaseSync(fakeAvaxUSDCAssetString, 1, 8);
|
|
391
|
+
|
|
392
|
+
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
393
|
+
expect(fakeAvaxUSDCAsset).toEqual(
|
|
394
|
+
expect.objectContaining({
|
|
395
|
+
address: "1234",
|
|
396
|
+
chain: Chain.Avalanche,
|
|
397
|
+
decimal: 18,
|
|
398
|
+
isGasAsset: false,
|
|
399
|
+
isSynthetic: false,
|
|
400
|
+
symbol: "USDC-1234",
|
|
401
|
+
ticker: "USDC",
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
expect(fakeAvaxUSDCAsset.getValue("string")).toBe("0.00000001");
|
|
406
|
+
expect(fakeAvaxUSDCAsset.getBaseValue("string")).toBe("10000000000");
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
410
|
+
await AssetValue.loadStaticAssets();
|
|
411
|
+
const avaxUSDC = "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e";
|
|
412
|
+
const AvaxUSDC = AssetValue.fromStringWithBaseSync(avaxUSDC, 100000000, 8);
|
|
413
|
+
|
|
414
|
+
expect(AvaxUSDC).toBeDefined();
|
|
415
|
+
expect(AvaxUSDC).toEqual(
|
|
416
|
+
expect.objectContaining({
|
|
417
|
+
address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
418
|
+
chain: Chain.Avalanche,
|
|
419
|
+
decimal: 6,
|
|
420
|
+
isGasAsset: false,
|
|
421
|
+
isSynthetic: false,
|
|
422
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
423
|
+
ticker: "USDC",
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
expect(AvaxUSDC.getValue("string")).toBe("1");
|
|
428
|
+
expect(AvaxUSDC.getBaseValue("string")).toBe("1000000");
|
|
180
429
|
});
|
|
181
430
|
});
|
|
182
431
|
|
|
183
|
-
describe(
|
|
184
|
-
test(
|
|
185
|
-
const customBaseAsset = [
|
|
186
|
-
|
|
187
|
-
.
|
|
188
|
-
.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
432
|
+
describe("fromChainOrSignature", () => {
|
|
433
|
+
test("creates AssetValue from common asset string or chain", () => {
|
|
434
|
+
const customBaseAsset = [
|
|
435
|
+
Chain.Cosmos,
|
|
436
|
+
Chain.BinanceSmartChain,
|
|
437
|
+
Chain.THORChain,
|
|
438
|
+
Chain.Maya,
|
|
439
|
+
Chain.Arbitrum,
|
|
440
|
+
Chain.Optimism,
|
|
441
|
+
];
|
|
442
|
+
const filteredChains = Object.values(Chain).filter((c) => !customBaseAsset.includes(c));
|
|
443
|
+
|
|
444
|
+
for (const chain of filteredChains) {
|
|
445
|
+
const asset = AssetValue.fromChainOrSignature(chain);
|
|
446
|
+
expect(asset).toEqual(
|
|
447
|
+
expect.objectContaining({
|
|
448
|
+
address: undefined,
|
|
449
|
+
chain,
|
|
450
|
+
decimal: BaseDecimal[chain],
|
|
451
|
+
isGasAsset: true,
|
|
452
|
+
isSynthetic: false,
|
|
453
|
+
symbol: chain,
|
|
454
|
+
ticker: chain,
|
|
455
|
+
type: "Native",
|
|
456
|
+
}),
|
|
457
|
+
);
|
|
458
|
+
}
|
|
203
459
|
|
|
204
460
|
const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
|
|
205
461
|
expect(cosmosAsset).toEqual(
|
|
@@ -209,9 +465,9 @@ describe('AssetValue', () => {
|
|
|
209
465
|
decimal: BaseDecimal.GAIA,
|
|
210
466
|
isGasAsset: true,
|
|
211
467
|
isSynthetic: false,
|
|
212
|
-
symbol:
|
|
213
|
-
ticker:
|
|
214
|
-
type:
|
|
468
|
+
symbol: "ATOM",
|
|
469
|
+
ticker: "ATOM",
|
|
470
|
+
type: "Native",
|
|
215
471
|
}),
|
|
216
472
|
);
|
|
217
473
|
|
|
@@ -223,9 +479,9 @@ describe('AssetValue', () => {
|
|
|
223
479
|
decimal: BaseDecimal.BSC,
|
|
224
480
|
isGasAsset: true,
|
|
225
481
|
isSynthetic: false,
|
|
226
|
-
symbol:
|
|
227
|
-
ticker:
|
|
228
|
-
type:
|
|
482
|
+
symbol: "BNB",
|
|
483
|
+
ticker: "BNB",
|
|
484
|
+
type: "Native",
|
|
229
485
|
}),
|
|
230
486
|
);
|
|
231
487
|
|
|
@@ -237,9 +493,9 @@ describe('AssetValue', () => {
|
|
|
237
493
|
decimal: BaseDecimal.THOR,
|
|
238
494
|
isGasAsset: true,
|
|
239
495
|
isSynthetic: false,
|
|
240
|
-
symbol:
|
|
241
|
-
ticker:
|
|
242
|
-
type:
|
|
496
|
+
symbol: "RUNE",
|
|
497
|
+
ticker: "RUNE",
|
|
498
|
+
type: "Native",
|
|
243
499
|
}),
|
|
244
500
|
);
|
|
245
501
|
|
|
@@ -251,45 +507,92 @@ describe('AssetValue', () => {
|
|
|
251
507
|
decimal: BaseDecimal.MAYA,
|
|
252
508
|
isGasAsset: true,
|
|
253
509
|
isSynthetic: false,
|
|
254
|
-
symbol:
|
|
255
|
-
ticker:
|
|
256
|
-
type:
|
|
510
|
+
symbol: "CACAO",
|
|
511
|
+
ticker: "CACAO",
|
|
512
|
+
type: "Native",
|
|
257
513
|
}),
|
|
258
514
|
);
|
|
259
515
|
|
|
260
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
516
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
261
517
|
expect(thor).toEqual(
|
|
262
518
|
expect.objectContaining({
|
|
263
|
-
address:
|
|
519
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
264
520
|
chain: Chain.Ethereum,
|
|
265
521
|
decimal: 18,
|
|
266
522
|
isGasAsset: false,
|
|
267
523
|
isSynthetic: false,
|
|
268
|
-
symbol:
|
|
269
|
-
ticker:
|
|
524
|
+
symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
525
|
+
ticker: "THOR",
|
|
270
526
|
}),
|
|
271
527
|
);
|
|
272
528
|
|
|
273
|
-
const vthor = AssetValue.fromChainOrSignature(
|
|
529
|
+
const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
|
|
274
530
|
expect(vthor).toEqual(
|
|
275
531
|
expect.objectContaining({
|
|
276
|
-
address:
|
|
532
|
+
address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
277
533
|
chain: Chain.Ethereum,
|
|
278
534
|
decimal: 18,
|
|
279
535
|
isGasAsset: false,
|
|
280
536
|
isSynthetic: false,
|
|
281
|
-
symbol:
|
|
282
|
-
ticker:
|
|
537
|
+
symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
538
|
+
ticker: "vTHOR",
|
|
539
|
+
}),
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
const arbAsset = AssetValue.fromChainOrSignature(Chain.Arbitrum);
|
|
543
|
+
expect(arbAsset).toEqual(
|
|
544
|
+
expect.objectContaining({
|
|
545
|
+
address: undefined,
|
|
546
|
+
chain: Chain.Arbitrum,
|
|
547
|
+
decimal: BaseDecimal.ARB,
|
|
548
|
+
isGasAsset: true,
|
|
549
|
+
isSynthetic: false,
|
|
550
|
+
symbol: "ETH",
|
|
551
|
+
ticker: "ETH",
|
|
552
|
+
type: "Native",
|
|
553
|
+
}),
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
const opAsset = AssetValue.fromChainOrSignature(Chain.Optimism);
|
|
557
|
+
expect(opAsset).toEqual(
|
|
558
|
+
expect.objectContaining({
|
|
559
|
+
address: undefined,
|
|
560
|
+
chain: Chain.Optimism,
|
|
561
|
+
decimal: BaseDecimal.OP,
|
|
562
|
+
isGasAsset: true,
|
|
563
|
+
isSynthetic: false,
|
|
564
|
+
symbol: "ETH",
|
|
565
|
+
ticker: "ETH",
|
|
566
|
+
type: "Native",
|
|
283
567
|
}),
|
|
284
568
|
);
|
|
285
569
|
});
|
|
286
570
|
});
|
|
287
571
|
|
|
288
|
-
describe(
|
|
289
|
-
test(
|
|
572
|
+
describe("loadStaticAssets", () => {
|
|
573
|
+
test("loads static assets from `@swapkit/tokens` lists", async () => {
|
|
290
574
|
// Dummy test - think of sth more meaningful
|
|
291
575
|
const { ok } = await AssetValue.loadStaticAssets();
|
|
292
576
|
expect(ok).toBe(true);
|
|
293
577
|
});
|
|
294
578
|
});
|
|
295
579
|
});
|
|
580
|
+
|
|
581
|
+
describe("getMinAmountByChain", () => {
|
|
582
|
+
test("returns min amount for chain", () => {
|
|
583
|
+
expect(getMinAmountByChain(Chain.THORChain).getValue("string")).toBe("0");
|
|
584
|
+
expect(getMinAmountByChain(Chain.Maya).getValue("string")).toBe("0");
|
|
585
|
+
expect(getMinAmountByChain(Chain.Cosmos).getValue("string")).toBe("0.000001");
|
|
586
|
+
|
|
587
|
+
expect(getMinAmountByChain(Chain.Bitcoin).getValue("string")).toBe("0.00010001");
|
|
588
|
+
expect(getMinAmountByChain(Chain.Litecoin).getValue("string")).toBe("0.00010001");
|
|
589
|
+
expect(getMinAmountByChain(Chain.BitcoinCash).getValue("string")).toBe("0.00010001");
|
|
590
|
+
expect(getMinAmountByChain(Chain.Dogecoin).getValue("string")).toBe("1.00000001");
|
|
591
|
+
|
|
592
|
+
expect(getMinAmountByChain(Chain.BinanceSmartChain).getValue("string")).toBe("0.00000001");
|
|
593
|
+
expect(getMinAmountByChain(Chain.Ethereum).getValue("string")).toBe("0.00000001");
|
|
594
|
+
expect(getMinAmountByChain(Chain.Avalanche).getValue("string")).toBe("0.00000001");
|
|
595
|
+
expect(getMinAmountByChain(Chain.Arbitrum).getValue("string")).toBe("0.00000001");
|
|
596
|
+
expect(getMinAmountByChain(Chain.Optimism).getValue("string")).toBe("0.00000001");
|
|
597
|
+
});
|
|
598
|
+
});
|