@swapkit/helpers 1.0.0-rc.10 → 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 +24 -37
- 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 +130 -94
- 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 +30 -13
- package/src/helpers/validators.ts +15 -6
- package/src/helpers/web3wallets.ts +177 -0
- package/src/index.ts +14 -9
- package/src/modules/__tests__/assetValue.test.ts +414 -117
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
- package/src/modules/assetValue.ts +218 -152
- package/src/modules/bigIntArithmetics.ts +214 -165
- package/src/modules/requestClient.ts +39 -0
- package/src/modules/swapKitError.ts +33 -5
- package/src/modules/swapKitNumber.ts +8 -1
- 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 -355
- package/dist/index.es.js +0 -1064
- package/src/helpers/request.ts +0 -16
|
@@ -1,64 +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.assetValue).toBe('1234567890 USDC');
|
|
16
15
|
expect(fakeAvaxUSDCAsset.toString()).toBe(
|
|
17
|
-
|
|
16
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
18
17
|
);
|
|
19
|
-
expect(fakeAvaxUSDCAsset.toString(true)).toBe('AVAX.USDC');
|
|
20
|
-
|
|
21
|
-
const thor = AssetValue.fromChainOrSignature('ETH.THOR');
|
|
22
|
-
expect(thor.assetValue).toBe('0 THOR');
|
|
23
18
|
|
|
24
19
|
const ethSynth = new AssetValue({
|
|
25
20
|
chain: Chain.THORChain,
|
|
26
|
-
symbol:
|
|
21
|
+
symbol: "ETH/ETH",
|
|
27
22
|
decimal: 8,
|
|
28
23
|
value: 1234567890,
|
|
29
24
|
});
|
|
30
25
|
|
|
31
|
-
expect(ethSynth.
|
|
32
|
-
expect(ethSynth.
|
|
33
|
-
|
|
34
|
-
|
|
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");
|
|
35
36
|
|
|
36
37
|
const atomDerived = new AssetValue({
|
|
37
|
-
identifier:
|
|
38
|
+
identifier: "THOR.ATOM",
|
|
38
39
|
decimal: 6,
|
|
39
40
|
value: 123456789,
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
expect(atomDerived.
|
|
43
|
-
|
|
44
|
-
|
|
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");
|
|
45
77
|
});
|
|
46
78
|
});
|
|
47
79
|
|
|
48
|
-
describe(
|
|
49
|
-
test(
|
|
50
|
-
const firstThor = AssetValue.fromChainOrSignature(
|
|
51
|
-
const secondThor = AssetValue.fromChainOrSignature(
|
|
52
|
-
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");
|
|
53
85
|
const firstUsdc = new AssetValue({
|
|
54
86
|
chain: Chain.Avalanche,
|
|
55
|
-
symbol:
|
|
87
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
56
88
|
decimal: 6,
|
|
57
89
|
value: 1234567890,
|
|
58
90
|
});
|
|
59
91
|
const secondUsdc = new AssetValue({
|
|
60
92
|
chain: Chain.Avalanche,
|
|
61
|
-
symbol:
|
|
93
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
62
94
|
decimal: 6,
|
|
63
95
|
value: 1234,
|
|
64
96
|
});
|
|
@@ -77,135 +109,353 @@ describe('AssetValue', () => {
|
|
|
77
109
|
});
|
|
78
110
|
});
|
|
79
111
|
|
|
80
|
-
describe(
|
|
81
|
-
test(
|
|
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 () => {
|
|
82
124
|
const avaxUSDCAsset = new AssetValue({
|
|
83
125
|
decimal: 6,
|
|
84
126
|
value: 1234567890,
|
|
85
127
|
chain: Chain.Avalanche,
|
|
86
|
-
symbol:
|
|
128
|
+
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
87
129
|
});
|
|
88
|
-
expect(avaxUSDCAsset.toString()).toBe(
|
|
130
|
+
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
|
|
89
131
|
|
|
90
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
91
|
-
expect(thor.toString()).toBe(
|
|
132
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
133
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
92
134
|
|
|
93
|
-
const ethSynth = await AssetValue.fromIdentifier(
|
|
94
|
-
expect(ethSynth.toString()).toBe(
|
|
135
|
+
const ethSynth = await AssetValue.fromIdentifier("ETH/ETH");
|
|
136
|
+
expect(ethSynth.toString()).toBe("ETH/ETH");
|
|
95
137
|
});
|
|
96
138
|
});
|
|
97
139
|
|
|
98
|
-
describe(
|
|
99
|
-
test(
|
|
140
|
+
describe("fromIdentifier", () => {
|
|
141
|
+
test("creates AssetValue from string", async () => {
|
|
100
142
|
const avaxUSDCAsset = await AssetValue.fromIdentifier(
|
|
101
|
-
|
|
143
|
+
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
102
144
|
);
|
|
103
145
|
|
|
104
146
|
expect(avaxUSDCAsset).toEqual(
|
|
105
147
|
expect.objectContaining({
|
|
106
|
-
address:
|
|
148
|
+
address: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
107
149
|
chain: Chain.Avalanche,
|
|
108
150
|
decimal: 6,
|
|
109
151
|
isGasAsset: false,
|
|
110
152
|
isSynthetic: false,
|
|
111
|
-
symbol:
|
|
112
|
-
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",
|
|
113
170
|
}),
|
|
114
171
|
);
|
|
115
172
|
});
|
|
116
173
|
});
|
|
117
174
|
|
|
118
|
-
describe(
|
|
119
|
-
test(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
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);
|
|
123
179
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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");
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
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");
|
|
136
250
|
});
|
|
137
251
|
});
|
|
138
252
|
|
|
139
|
-
describe(
|
|
140
|
-
test(
|
|
253
|
+
describe("fromIdentifierSync", () => {
|
|
254
|
+
test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
141
255
|
await AssetValue.loadStaticAssets();
|
|
142
256
|
const thor = AssetValue.fromIdentifierSync(
|
|
143
|
-
|
|
257
|
+
"ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
144
258
|
);
|
|
145
259
|
|
|
146
260
|
expect(thor).toBeDefined();
|
|
147
261
|
expect(thor).toEqual(
|
|
148
262
|
expect.objectContaining({
|
|
149
|
-
address:
|
|
263
|
+
address: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
150
264
|
chain: Chain.Arbitrum,
|
|
151
265
|
decimal: 6,
|
|
152
266
|
isGasAsset: false,
|
|
153
267
|
isSynthetic: false,
|
|
154
|
-
symbol:
|
|
155
|
-
ticker:
|
|
268
|
+
symbol: "USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
|
|
269
|
+
ticker: "USDT",
|
|
156
270
|
}),
|
|
157
271
|
);
|
|
158
272
|
});
|
|
159
273
|
});
|
|
160
274
|
|
|
161
|
-
describe(
|
|
162
|
-
test(
|
|
275
|
+
describe("fromStringSync", () => {
|
|
276
|
+
test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
163
277
|
await AssetValue.loadStaticAssets();
|
|
164
|
-
const thor = AssetValue.fromStringSync(
|
|
278
|
+
const thor = AssetValue.fromStringSync("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
165
279
|
|
|
166
280
|
expect(thor).toBeDefined();
|
|
167
281
|
expect(thor).toEqual(
|
|
168
282
|
expect.objectContaining({
|
|
169
|
-
address:
|
|
283
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
170
284
|
chain: Chain.Ethereum,
|
|
171
285
|
decimal: 18,
|
|
172
286
|
isGasAsset: false,
|
|
173
287
|
isSynthetic: false,
|
|
174
|
-
symbol:
|
|
175
|
-
ticker:
|
|
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",
|
|
298
|
+
chain: Chain.Ethereum,
|
|
299
|
+
decimal: 6,
|
|
300
|
+
isGasAsset: false,
|
|
301
|
+
isSynthetic: false,
|
|
302
|
+
symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
303
|
+
ticker: "USDC",
|
|
176
304
|
}),
|
|
177
305
|
);
|
|
178
306
|
});
|
|
179
307
|
|
|
180
|
-
test(
|
|
308
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
181
309
|
await AssetValue.loadStaticAssets();
|
|
182
|
-
const fakeAvaxUSDCAssetString =
|
|
310
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
183
311
|
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
184
312
|
|
|
185
|
-
expect(fakeAvaxUSDCAsset).
|
|
313
|
+
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
314
|
+
expect(fakeAvaxUSDCAsset).toEqual(
|
|
315
|
+
expect.objectContaining({
|
|
316
|
+
address: "1234",
|
|
317
|
+
chain: Chain.Avalanche,
|
|
318
|
+
decimal: 18,
|
|
319
|
+
isGasAsset: false,
|
|
320
|
+
isSynthetic: false,
|
|
321
|
+
symbol: "USDC-1234",
|
|
322
|
+
ticker: "USDC",
|
|
323
|
+
}),
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("returns safe decimals if string is not in `@swapkit/tokens` lists with multiple dashes", async () => {
|
|
328
|
+
await AssetValue.loadStaticAssets();
|
|
329
|
+
const fakeAvaxUSDCAssetString = "AVAX.USDC-LPT-1234";
|
|
330
|
+
const fakeAvaxUSDCAsset = AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
|
|
331
|
+
|
|
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
|
+
);
|
|
186
363
|
});
|
|
187
364
|
});
|
|
188
365
|
|
|
189
|
-
describe(
|
|
190
|
-
test(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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");
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
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
|
+
}
|
|
209
459
|
|
|
210
460
|
const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
|
|
211
461
|
expect(cosmosAsset).toEqual(
|
|
@@ -215,9 +465,9 @@ describe('AssetValue', () => {
|
|
|
215
465
|
decimal: BaseDecimal.GAIA,
|
|
216
466
|
isGasAsset: true,
|
|
217
467
|
isSynthetic: false,
|
|
218
|
-
symbol:
|
|
219
|
-
ticker:
|
|
220
|
-
type:
|
|
468
|
+
symbol: "ATOM",
|
|
469
|
+
ticker: "ATOM",
|
|
470
|
+
type: "Native",
|
|
221
471
|
}),
|
|
222
472
|
);
|
|
223
473
|
|
|
@@ -229,9 +479,9 @@ describe('AssetValue', () => {
|
|
|
229
479
|
decimal: BaseDecimal.BSC,
|
|
230
480
|
isGasAsset: true,
|
|
231
481
|
isSynthetic: false,
|
|
232
|
-
symbol:
|
|
233
|
-
ticker:
|
|
234
|
-
type:
|
|
482
|
+
symbol: "BNB",
|
|
483
|
+
ticker: "BNB",
|
|
484
|
+
type: "Native",
|
|
235
485
|
}),
|
|
236
486
|
);
|
|
237
487
|
|
|
@@ -243,9 +493,9 @@ describe('AssetValue', () => {
|
|
|
243
493
|
decimal: BaseDecimal.THOR,
|
|
244
494
|
isGasAsset: true,
|
|
245
495
|
isSynthetic: false,
|
|
246
|
-
symbol:
|
|
247
|
-
ticker:
|
|
248
|
-
type:
|
|
496
|
+
symbol: "RUNE",
|
|
497
|
+
ticker: "RUNE",
|
|
498
|
+
type: "Native",
|
|
249
499
|
}),
|
|
250
500
|
);
|
|
251
501
|
|
|
@@ -257,45 +507,92 @@ describe('AssetValue', () => {
|
|
|
257
507
|
decimal: BaseDecimal.MAYA,
|
|
258
508
|
isGasAsset: true,
|
|
259
509
|
isSynthetic: false,
|
|
260
|
-
symbol:
|
|
261
|
-
ticker:
|
|
262
|
-
type:
|
|
510
|
+
symbol: "CACAO",
|
|
511
|
+
ticker: "CACAO",
|
|
512
|
+
type: "Native",
|
|
263
513
|
}),
|
|
264
514
|
);
|
|
265
515
|
|
|
266
|
-
const thor = AssetValue.fromChainOrSignature(
|
|
516
|
+
const thor = AssetValue.fromChainOrSignature("ETH.THOR");
|
|
267
517
|
expect(thor).toEqual(
|
|
268
518
|
expect.objectContaining({
|
|
269
|
-
address:
|
|
519
|
+
address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
270
520
|
chain: Chain.Ethereum,
|
|
271
521
|
decimal: 18,
|
|
272
522
|
isGasAsset: false,
|
|
273
523
|
isSynthetic: false,
|
|
274
|
-
symbol:
|
|
275
|
-
ticker:
|
|
524
|
+
symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
525
|
+
ticker: "THOR",
|
|
276
526
|
}),
|
|
277
527
|
);
|
|
278
528
|
|
|
279
|
-
const vthor = AssetValue.fromChainOrSignature(
|
|
529
|
+
const vthor = AssetValue.fromChainOrSignature("ETH.vTHOR");
|
|
280
530
|
expect(vthor).toEqual(
|
|
281
531
|
expect.objectContaining({
|
|
282
|
-
address:
|
|
532
|
+
address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
283
533
|
chain: Chain.Ethereum,
|
|
284
534
|
decimal: 18,
|
|
285
535
|
isGasAsset: false,
|
|
286
536
|
isSynthetic: false,
|
|
287
|
-
symbol:
|
|
288
|
-
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",
|
|
289
567
|
}),
|
|
290
568
|
);
|
|
291
569
|
});
|
|
292
570
|
});
|
|
293
571
|
|
|
294
|
-
describe(
|
|
295
|
-
test(
|
|
572
|
+
describe("loadStaticAssets", () => {
|
|
573
|
+
test("loads static assets from `@swapkit/tokens` lists", async () => {
|
|
296
574
|
// Dummy test - think of sth more meaningful
|
|
297
575
|
const { ok } = await AssetValue.loadStaticAssets();
|
|
298
576
|
expect(ok).toBe(true);
|
|
299
577
|
});
|
|
300
578
|
});
|
|
301
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
|
+
});
|