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