@swapkit/helpers 1.0.0-rc.118 → 1.0.0-rc.119
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 +2 -2
- package/dist/index.js.map +10 -10
- package/package.json +3 -3
- package/src/helpers/__tests__/asset.test.ts +0 -7
- package/src/helpers/asset.ts +28 -27
- package/src/modules/__tests__/assetValue.test.ts +116 -117
- package/src/modules/assetValue.ts +119 -94
- package/src/types/chains.ts +2 -18
- package/src/types/derivationPath.ts +0 -2
- package/src/types/network.ts +0 -2
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
6
|
-
"ky": "1.
|
|
5
|
+
"@swapkit/tokens": "1.0.0-rc.61",
|
|
6
|
+
"ky": "1.4.0",
|
|
7
7
|
"zod": "3.23.8"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
},
|
|
30
30
|
"type": "module",
|
|
31
31
|
"types": "./src/index.ts",
|
|
32
|
-
"version": "1.0.0-rc.
|
|
32
|
+
"version": "1.0.0-rc.119"
|
|
33
33
|
}
|
|
@@ -36,13 +36,6 @@ describe("getAssetType", () => {
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
describe("for Binance chain", () => {
|
|
40
|
-
test('should return "BEP2" for non-BNB tickers', () => {
|
|
41
|
-
const result = getAssetType({ chain: Chain.Binance, symbol: "NOT_BNB" });
|
|
42
|
-
expect(result).toBe("BEP2");
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
39
|
describe("for Binance Smart Chain", () => {
|
|
47
40
|
test('should return "BEP20" for non-BNB tickers', () => {
|
|
48
41
|
const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: "NOT_BNB" });
|
package/src/helpers/asset.ts
CHANGED
|
@@ -6,12 +6,14 @@ import type { TokenNames } from "../types/tokens.ts";
|
|
|
6
6
|
|
|
7
7
|
const getDecimalMethodHex = "0x313ce567";
|
|
8
8
|
|
|
9
|
-
export type CommonAssetString =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export type CommonAssetString = (typeof CommonAssetStrings)[number] | Chain;
|
|
10
|
+
|
|
11
|
+
export const CommonAssetStrings = [
|
|
12
|
+
`${Chain.Maya}.MAYA`,
|
|
13
|
+
`${Chain.Ethereum}.THOR`,
|
|
14
|
+
`${Chain.Ethereum}.vTHOR`,
|
|
15
|
+
`${Chain.Kujira}.USK`,
|
|
16
|
+
] as const;
|
|
15
17
|
|
|
16
18
|
const getContractDecimals = async ({ chain, to }: { chain: EVMChain; to: string }) => {
|
|
17
19
|
try {
|
|
@@ -112,18 +114,18 @@ export const getGasAsset = ({ chain }: { chain: Chain }) => {
|
|
|
112
114
|
switch (chain) {
|
|
113
115
|
case Chain.Arbitrum:
|
|
114
116
|
case Chain.Optimism:
|
|
115
|
-
return AssetValue.
|
|
117
|
+
return AssetValue.from({ asset: `${chain}.ETH` });
|
|
116
118
|
case Chain.Maya:
|
|
117
|
-
return AssetValue.
|
|
119
|
+
return AssetValue.from({ asset: `${chain}.CACAO` });
|
|
118
120
|
case Chain.Cosmos:
|
|
119
|
-
return AssetValue.
|
|
121
|
+
return AssetValue.from({ asset: `${chain}.ATOM` });
|
|
120
122
|
case Chain.BinanceSmartChain:
|
|
121
|
-
return AssetValue.
|
|
123
|
+
return AssetValue.from({ asset: `${chain}.BNB` });
|
|
122
124
|
case Chain.THORChain:
|
|
123
|
-
return AssetValue.
|
|
125
|
+
return AssetValue.from({ asset: `${chain}.RUNE` });
|
|
124
126
|
|
|
125
127
|
default:
|
|
126
|
-
return AssetValue.
|
|
128
|
+
return AssetValue.from({ asset: `${chain}.${chain}` });
|
|
127
129
|
}
|
|
128
130
|
};
|
|
129
131
|
|
|
@@ -150,28 +152,29 @@ export const getCommonAssetInfo = (
|
|
|
150
152
|
assetString: CommonAssetString,
|
|
151
153
|
): { identifier: string; decimal: number } => {
|
|
152
154
|
switch (assetString) {
|
|
155
|
+
case Chain.Arbitrum:
|
|
156
|
+
case Chain.Optimism:
|
|
157
|
+
return { identifier: `${assetString}.ETH`, decimal: BaseDecimal[assetString] };
|
|
158
|
+
|
|
153
159
|
case `${Chain.Ethereum}.THOR`:
|
|
154
160
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
155
161
|
case `${Chain.Ethereum}.vTHOR`:
|
|
156
162
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
157
|
-
case Chain.Arbitrum:
|
|
158
|
-
return { identifier: `${Chain.Arbitrum}.ETH`, decimal: BaseDecimal[assetString] };
|
|
159
|
-
case Chain.Optimism:
|
|
160
|
-
return { identifier: `${Chain.Optimism}.ETH`, decimal: BaseDecimal[assetString] };
|
|
161
163
|
case Chain.Cosmos:
|
|
162
|
-
return { identifier:
|
|
164
|
+
return { identifier: `${assetString}.ATOM`, decimal: BaseDecimal[assetString] };
|
|
163
165
|
case Chain.THORChain:
|
|
164
|
-
return { identifier:
|
|
166
|
+
return { identifier: `${assetString}.RUNE`, decimal: BaseDecimal[assetString] };
|
|
165
167
|
case Chain.BinanceSmartChain:
|
|
166
|
-
return { identifier:
|
|
168
|
+
return { identifier: `${assetString}.BNB`, decimal: BaseDecimal[assetString] };
|
|
167
169
|
case Chain.Maya:
|
|
168
|
-
return { identifier:
|
|
170
|
+
return { identifier: `${assetString}.CACAO`, decimal: BaseDecimal[assetString] };
|
|
171
|
+
case Chain.Radix:
|
|
172
|
+
return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal[assetString] };
|
|
173
|
+
|
|
169
174
|
case `${Chain.Maya}.MAYA`:
|
|
170
|
-
return { identifier:
|
|
175
|
+
return { identifier: assetString, decimal: 4 };
|
|
171
176
|
case `${Chain.Kujira}.USK`:
|
|
172
|
-
return { identifier:
|
|
173
|
-
case Chain.Radix:
|
|
174
|
-
return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal.XRD };
|
|
177
|
+
return { identifier: assetString, decimal: 6 };
|
|
175
178
|
|
|
176
179
|
default:
|
|
177
180
|
return { identifier: `${assetString}.${assetString}`, decimal: BaseDecimal[assetString] };
|
|
@@ -187,10 +190,8 @@ export const getAssetType = ({ chain, symbol }: { chain: Chain; symbol: string }
|
|
|
187
190
|
return symbol === "ATOM" ? "Native" : Chain.Cosmos;
|
|
188
191
|
case Chain.Kujira:
|
|
189
192
|
return symbol === Chain.Kujira ? "Native" : Chain.Kujira;
|
|
190
|
-
case Chain.Binance:
|
|
191
|
-
return symbol === Chain.Binance ? "Native" : "BEP2";
|
|
192
193
|
case Chain.BinanceSmartChain:
|
|
193
|
-
return symbol ===
|
|
194
|
+
return symbol === "BNB" ? "Native" : "BEP20";
|
|
194
195
|
case Chain.Ethereum:
|
|
195
196
|
return symbol === Chain.Ethereum ? "Native" : "ERC20";
|
|
196
197
|
case Chain.Avalanche:
|
|
@@ -67,7 +67,7 @@ describe("AssetValue", () => {
|
|
|
67
67
|
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
68
68
|
);
|
|
69
69
|
|
|
70
|
-
const thor = AssetValue.
|
|
70
|
+
const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
71
71
|
expect(thor.toUrl()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
72
72
|
|
|
73
73
|
const ethSynth = new AssetValue({
|
|
@@ -90,9 +90,9 @@ describe("AssetValue", () => {
|
|
|
90
90
|
|
|
91
91
|
describe("eq", () => {
|
|
92
92
|
test("checks if assets are same chain and symbol", () => {
|
|
93
|
-
const firstThor = AssetValue.
|
|
94
|
-
const secondThor = AssetValue.
|
|
95
|
-
const vThor = AssetValue.
|
|
93
|
+
const firstThor = AssetValue.from({ asset: "ETH.THOR" });
|
|
94
|
+
const secondThor = AssetValue.from({ asset: "ETH.THOR" });
|
|
95
|
+
const vThor = AssetValue.from({ asset: "ETH.vTHOR" });
|
|
96
96
|
const firstUsdc = new AssetValue({
|
|
97
97
|
chain: Chain.Avalanche,
|
|
98
98
|
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
@@ -120,10 +120,10 @@ describe("AssetValue", () => {
|
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
test("check if assets have same value, even if not same asset", () => {
|
|
123
|
-
const firstThor = AssetValue.
|
|
124
|
-
const secondThor = AssetValue.
|
|
125
|
-
const thirdThor = AssetValue.
|
|
126
|
-
const vThor = AssetValue.
|
|
123
|
+
const firstThor = AssetValue.from({ asset: "ETH.THOR", value: "20" });
|
|
124
|
+
const secondThor = AssetValue.from({ asset: "ETH.THOR", value: "35" });
|
|
125
|
+
const thirdThor = AssetValue.from({ asset: "ETH.THOR", value: "35" });
|
|
126
|
+
const vThor = AssetValue.from({ asset: "ETH.vTHOR", value: "20" });
|
|
127
127
|
|
|
128
128
|
expect(firstThor.eqValue(firstThor)).toBe(true);
|
|
129
129
|
expect(firstThor.eqValue(secondThor)).toBe(false);
|
|
@@ -132,10 +132,10 @@ describe("AssetValue", () => {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
test("check if assets have identical asset and value", () => {
|
|
135
|
-
const firstThor = AssetValue.
|
|
136
|
-
const secondThor = AssetValue.
|
|
137
|
-
const thirdThor = AssetValue.
|
|
138
|
-
const vThor = AssetValue.
|
|
135
|
+
const firstThor = AssetValue.from({ asset: "ETH.THOR", value: "20" });
|
|
136
|
+
const secondThor = AssetValue.from({ asset: "ETH.THOR", value: "35" });
|
|
137
|
+
const thirdThor = AssetValue.from({ asset: "ETH.THOR", value: "35" });
|
|
138
|
+
const vThor = AssetValue.from({ asset: "ETH.vTHOR", value: "20" });
|
|
139
139
|
|
|
140
140
|
expect(firstThor.eq(firstThor)).toBe(true);
|
|
141
141
|
expect(firstThor.eq(secondThor)).toBe(false);
|
|
@@ -146,10 +146,11 @@ describe("AssetValue", () => {
|
|
|
146
146
|
|
|
147
147
|
describe("from bigint", () => {
|
|
148
148
|
test("returns asset value with correct decimal", async () => {
|
|
149
|
-
const avaxUSDCAsset = await AssetValue.
|
|
150
|
-
`${Chain.Avalanche}.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e`,
|
|
151
|
-
1234567800n,
|
|
152
|
-
|
|
149
|
+
const avaxUSDCAsset = await AssetValue.from({
|
|
150
|
+
asset: `${Chain.Avalanche}.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e`,
|
|
151
|
+
value: 1234567800n,
|
|
152
|
+
asyncTokenLookup: true,
|
|
153
|
+
});
|
|
153
154
|
expect(avaxUSDCAsset.getValue("string")).toBe("1234.5678");
|
|
154
155
|
});
|
|
155
156
|
});
|
|
@@ -164,19 +165,20 @@ describe("AssetValue", () => {
|
|
|
164
165
|
});
|
|
165
166
|
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e");
|
|
166
167
|
|
|
167
|
-
const thor = AssetValue.
|
|
168
|
+
const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
168
169
|
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
169
170
|
|
|
170
|
-
const ethSynth = await AssetValue.
|
|
171
|
+
const ethSynth = await AssetValue.from({ asset: "ETH/ETH", asyncTokenLookup: true });
|
|
171
172
|
expect(ethSynth.toString()).toBe("ETH/ETH");
|
|
172
173
|
});
|
|
173
174
|
});
|
|
174
175
|
|
|
175
176
|
describe("fromIdentifier", () => {
|
|
176
177
|
test("creates AssetValue from string", async () => {
|
|
177
|
-
const avaxUSDCAsset = await AssetValue.
|
|
178
|
-
"AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
179
|
-
|
|
178
|
+
const avaxUSDCAsset = await AssetValue.from({
|
|
179
|
+
asset: "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
180
|
+
asyncTokenLookup: true,
|
|
181
|
+
});
|
|
180
182
|
|
|
181
183
|
expect(avaxUSDCAsset).toEqual(
|
|
182
184
|
expect.objectContaining({
|
|
@@ -192,7 +194,10 @@ describe("AssetValue", () => {
|
|
|
192
194
|
});
|
|
193
195
|
|
|
194
196
|
test("creates AssetValue from string with multiple dashes", async () => {
|
|
195
|
-
const ethPendleLptAsset = await AssetValue.
|
|
197
|
+
const ethPendleLptAsset = await AssetValue.from({
|
|
198
|
+
asset: "ETH.PENDLE-LPT-0x1234",
|
|
199
|
+
asyncTokenLookup: true,
|
|
200
|
+
});
|
|
196
201
|
|
|
197
202
|
expect(ethPendleLptAsset).toEqual(
|
|
198
203
|
expect.objectContaining({
|
|
@@ -211,7 +216,10 @@ describe("AssetValue", () => {
|
|
|
211
216
|
describe("fromString", () => {
|
|
212
217
|
test("creates AssetValue from string", async () => {
|
|
213
218
|
const fakeAvaxAssetString = "AVAX.ASDF-1234";
|
|
214
|
-
const fakeAvaxAsset = await AssetValue.
|
|
219
|
+
const fakeAvaxAsset = await AssetValue.from({
|
|
220
|
+
asset: fakeAvaxAssetString,
|
|
221
|
+
asyncTokenLookup: true,
|
|
222
|
+
});
|
|
215
223
|
|
|
216
224
|
expect(fakeAvaxAsset).toEqual(
|
|
217
225
|
expect.objectContaining({
|
|
@@ -228,7 +236,10 @@ describe("AssetValue", () => {
|
|
|
228
236
|
|
|
229
237
|
test("creates AssetValue from string with multiple dashes", async () => {
|
|
230
238
|
const fakeAvaxAssetString = "AVAX.ASDF-LP-1234";
|
|
231
|
-
const fakeAvaxAsset = await AssetValue.
|
|
239
|
+
const fakeAvaxAsset = await AssetValue.from({
|
|
240
|
+
asset: fakeAvaxAssetString,
|
|
241
|
+
asyncTokenLookup: true,
|
|
242
|
+
});
|
|
232
243
|
|
|
233
244
|
expect(fakeAvaxAsset).toEqual(
|
|
234
245
|
expect.objectContaining({
|
|
@@ -244,9 +255,10 @@ describe("AssetValue", () => {
|
|
|
244
255
|
});
|
|
245
256
|
|
|
246
257
|
test("creates AssetValue with _ symbol", async () => {
|
|
247
|
-
const radixXWBTC = await AssetValue.
|
|
248
|
-
"XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
249
|
-
|
|
258
|
+
const radixXWBTC = await AssetValue.from({
|
|
259
|
+
asset: "XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
260
|
+
asyncTokenLookup: true,
|
|
261
|
+
});
|
|
250
262
|
|
|
251
263
|
expect(radixXWBTC).toEqual(
|
|
252
264
|
expect.objectContaining({
|
|
@@ -265,7 +277,12 @@ describe("AssetValue", () => {
|
|
|
265
277
|
describe("fromStringWithBase", () => {
|
|
266
278
|
test("creates AssetValue from string with base", async () => {
|
|
267
279
|
const fakeAvaxAssetString = "AVAX.ASDF-1234";
|
|
268
|
-
const fakeAvaxAsset = await AssetValue.
|
|
280
|
+
const fakeAvaxAsset = await AssetValue.from({
|
|
281
|
+
asset: fakeAvaxAssetString,
|
|
282
|
+
value: 1,
|
|
283
|
+
fromBaseDecimal: 8,
|
|
284
|
+
asyncTokenLookup: true,
|
|
285
|
+
});
|
|
269
286
|
|
|
270
287
|
expect(fakeAvaxAsset).toEqual(
|
|
271
288
|
expect.objectContaining({
|
|
@@ -278,24 +295,24 @@ describe("AssetValue", () => {
|
|
|
278
295
|
ticker: "ASDF",
|
|
279
296
|
}),
|
|
280
297
|
);
|
|
281
|
-
expect(fakeAvaxAsset.getValue("string")).toBe("
|
|
282
|
-
expect(fakeAvaxAsset.getBaseValue("string")).toBe("
|
|
298
|
+
expect(fakeAvaxAsset.getValue("string")).toBe("0.00000001");
|
|
299
|
+
expect(fakeAvaxAsset.getBaseValue("string")).toBe("10000000000");
|
|
283
300
|
});
|
|
284
301
|
});
|
|
285
302
|
|
|
286
303
|
describe("fromUrl", () => {
|
|
287
|
-
test("creates AssetValue from url like format",
|
|
304
|
+
test("creates AssetValue from url like format", () => {
|
|
288
305
|
const synthETHString = "THOR.ETH.ETH";
|
|
289
306
|
const ethString = "ETH.ETH";
|
|
290
307
|
const thorString = "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
|
|
291
308
|
const synthThorString = "THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044";
|
|
292
309
|
const synthDashesString = "THOR.ETH.PENDLE-LPT-0x1234";
|
|
293
310
|
|
|
294
|
-
const synthETH =
|
|
295
|
-
const eth =
|
|
296
|
-
const thor =
|
|
297
|
-
const synthThor =
|
|
298
|
-
const synthDashes =
|
|
311
|
+
const synthETH = AssetValue.fromUrl(synthETHString);
|
|
312
|
+
const eth = AssetValue.fromUrl(ethString);
|
|
313
|
+
const thor = AssetValue.fromUrl(thorString);
|
|
314
|
+
const synthThor = AssetValue.fromUrl(synthThorString);
|
|
315
|
+
const synthDashes = AssetValue.fromUrl(synthDashesString);
|
|
299
316
|
|
|
300
317
|
expect(synthETH.toString()).toBe("ETH/ETH");
|
|
301
318
|
expect(eth.toString()).toBe("ETH.ETH");
|
|
@@ -308,9 +325,9 @@ describe("AssetValue", () => {
|
|
|
308
325
|
describe("fromIdentifierSync", () => {
|
|
309
326
|
test("(same as fromIdentifier) - creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
310
327
|
await AssetValue.loadStaticAssets();
|
|
311
|
-
const thor = AssetValue.
|
|
312
|
-
"ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
313
|
-
);
|
|
328
|
+
const thor = AssetValue.from({
|
|
329
|
+
asset: "ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9",
|
|
330
|
+
});
|
|
314
331
|
|
|
315
332
|
expect(thor).toBeDefined();
|
|
316
333
|
expect(thor).toEqual(
|
|
@@ -330,7 +347,9 @@ describe("AssetValue", () => {
|
|
|
330
347
|
describe("fromStringSync", () => {
|
|
331
348
|
test("creates AssetValue from string via `@swapkit/tokens` lists", async () => {
|
|
332
349
|
await AssetValue.loadStaticAssets();
|
|
333
|
-
const thor = AssetValue.
|
|
350
|
+
const thor = AssetValue.from({
|
|
351
|
+
asset: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
352
|
+
});
|
|
334
353
|
|
|
335
354
|
expect(thor).toBeDefined();
|
|
336
355
|
expect(thor).toEqual(
|
|
@@ -345,7 +364,9 @@ describe("AssetValue", () => {
|
|
|
345
364
|
}),
|
|
346
365
|
);
|
|
347
366
|
|
|
348
|
-
const usdc = AssetValue.
|
|
367
|
+
const usdc = AssetValue.from({
|
|
368
|
+
asset: "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
369
|
+
});
|
|
349
370
|
expect(usdc).toBeDefined();
|
|
350
371
|
expect(usdc).toEqual(
|
|
351
372
|
expect.objectContaining({
|
|
@@ -363,7 +384,7 @@ describe("AssetValue", () => {
|
|
|
363
384
|
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
364
385
|
await AssetValue.loadStaticAssets();
|
|
365
386
|
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
366
|
-
const fakeAvaxUSDCAsset = AssetValue.
|
|
387
|
+
const fakeAvaxUSDCAsset = AssetValue.from({ asset: fakeAvaxUSDCAssetString });
|
|
367
388
|
|
|
368
389
|
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
369
390
|
expect(fakeAvaxUSDCAsset).toEqual(
|
|
@@ -382,10 +403,10 @@ describe("AssetValue", () => {
|
|
|
382
403
|
test("returns safe decimals if string is not in `@swapkit/tokens` lists with multiple dashes", async () => {
|
|
383
404
|
await AssetValue.loadStaticAssets();
|
|
384
405
|
const fakeAvaxUSDCAssetString = "AVAX.USDC-LPT-1234";
|
|
385
|
-
const
|
|
406
|
+
const fakeAvaxUSDCAsset2 = AssetValue.from({ asset: fakeAvaxUSDCAssetString });
|
|
386
407
|
|
|
387
|
-
expect(
|
|
388
|
-
expect(
|
|
408
|
+
expect(fakeAvaxUSDCAsset2).toBeDefined();
|
|
409
|
+
expect(fakeAvaxUSDCAsset2).toEqual(
|
|
389
410
|
expect.objectContaining({
|
|
390
411
|
address: "1234",
|
|
391
412
|
chain: Chain.Avalanche,
|
|
@@ -401,7 +422,7 @@ describe("AssetValue", () => {
|
|
|
401
422
|
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
402
423
|
await AssetValue.loadStaticAssets();
|
|
403
424
|
const avaxBTCb = "AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50";
|
|
404
|
-
const AvaxBTCb = AssetValue.
|
|
425
|
+
const AvaxBTCb = AssetValue.from({ asset: avaxBTCb });
|
|
405
426
|
|
|
406
427
|
expect(AvaxBTCb).toBeDefined();
|
|
407
428
|
expect(AvaxBTCb).toEqual(
|
|
@@ -421,7 +442,11 @@ describe("AssetValue", () => {
|
|
|
421
442
|
describe("fromStringWithBaseSync", () => {
|
|
422
443
|
test("creates AssetValue from string with base decimals via `@swapkit/tokens` lists", async () => {
|
|
423
444
|
await AssetValue.loadStaticAssets();
|
|
424
|
-
const btc = AssetValue.
|
|
445
|
+
const btc = AssetValue.from({
|
|
446
|
+
asset: "BTC.BTC",
|
|
447
|
+
value: 5200000000000,
|
|
448
|
+
fromBaseDecimal: 8,
|
|
449
|
+
});
|
|
425
450
|
|
|
426
451
|
expect(btc).toBeDefined();
|
|
427
452
|
expect(btc).toEqual(
|
|
@@ -442,7 +467,11 @@ describe("AssetValue", () => {
|
|
|
442
467
|
test("returns safe decimals if string is not in `@swapkit/tokens` lists", async () => {
|
|
443
468
|
await AssetValue.loadStaticAssets();
|
|
444
469
|
const fakeAvaxUSDCAssetString = "AVAX.USDC-1234";
|
|
445
|
-
const fakeAvaxUSDCAsset = AssetValue.
|
|
470
|
+
const fakeAvaxUSDCAsset = AssetValue.from({
|
|
471
|
+
asset: fakeAvaxUSDCAssetString,
|
|
472
|
+
value: 1,
|
|
473
|
+
fromBaseDecimal: 8,
|
|
474
|
+
});
|
|
446
475
|
|
|
447
476
|
expect(fakeAvaxUSDCAsset).toBeDefined();
|
|
448
477
|
expect(fakeAvaxUSDCAsset).toEqual(
|
|
@@ -464,7 +493,11 @@ describe("AssetValue", () => {
|
|
|
464
493
|
test("returns proper avax string with address from `@swapkit/tokens` lists", async () => {
|
|
465
494
|
await AssetValue.loadStaticAssets();
|
|
466
495
|
const avaxUSDC = "AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e";
|
|
467
|
-
const AvaxUSDC = AssetValue.
|
|
496
|
+
const AvaxUSDC = AssetValue.from({
|
|
497
|
+
asset: avaxUSDC,
|
|
498
|
+
value: 100000000,
|
|
499
|
+
fromBaseDecimal: 8,
|
|
500
|
+
});
|
|
468
501
|
|
|
469
502
|
expect(AvaxUSDC).toBeDefined();
|
|
470
503
|
expect(AvaxUSDC).toEqual(
|
|
@@ -486,34 +519,7 @@ describe("AssetValue", () => {
|
|
|
486
519
|
|
|
487
520
|
describe("fromChainOrSignature", () => {
|
|
488
521
|
test("creates AssetValue from common asset string or chain", () => {
|
|
489
|
-
const
|
|
490
|
-
Chain.Cosmos,
|
|
491
|
-
Chain.BinanceSmartChain,
|
|
492
|
-
Chain.THORChain,
|
|
493
|
-
Chain.Maya,
|
|
494
|
-
Chain.Arbitrum,
|
|
495
|
-
Chain.Optimism,
|
|
496
|
-
Chain.Radix,
|
|
497
|
-
];
|
|
498
|
-
const filteredChains = Object.values(Chain).filter((c) => !customBaseAsset.includes(c));
|
|
499
|
-
|
|
500
|
-
for (const chain of filteredChains) {
|
|
501
|
-
const asset = AssetValue.fromChainOrSignature(chain);
|
|
502
|
-
expect(asset).toEqual(
|
|
503
|
-
expect.objectContaining({
|
|
504
|
-
address: undefined,
|
|
505
|
-
chain,
|
|
506
|
-
decimal: BaseDecimal[chain],
|
|
507
|
-
isGasAsset: true,
|
|
508
|
-
isSynthetic: false,
|
|
509
|
-
symbol: chain,
|
|
510
|
-
ticker: chain,
|
|
511
|
-
type: "Native",
|
|
512
|
-
}),
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
const cosmosAsset = AssetValue.fromChainOrSignature(Chain.Cosmos);
|
|
522
|
+
const cosmosAsset = AssetValue.from({ chain: Chain.Cosmos });
|
|
517
523
|
expect(cosmosAsset).toEqual(
|
|
518
524
|
expect.objectContaining({
|
|
519
525
|
address: undefined,
|
|
@@ -527,7 +533,7 @@ describe("AssetValue", () => {
|
|
|
527
533
|
}),
|
|
528
534
|
);
|
|
529
535
|
|
|
530
|
-
const bscAsset = AssetValue.
|
|
536
|
+
const bscAsset = AssetValue.from({ chain: Chain.BinanceSmartChain });
|
|
531
537
|
expect(bscAsset).toEqual(
|
|
532
538
|
expect.objectContaining({
|
|
533
539
|
address: undefined,
|
|
@@ -541,7 +547,7 @@ describe("AssetValue", () => {
|
|
|
541
547
|
}),
|
|
542
548
|
);
|
|
543
549
|
|
|
544
|
-
const thorAsset = AssetValue.
|
|
550
|
+
const thorAsset = AssetValue.from({ chain: Chain.THORChain });
|
|
545
551
|
expect(thorAsset).toEqual(
|
|
546
552
|
expect.objectContaining({
|
|
547
553
|
address: undefined,
|
|
@@ -555,7 +561,7 @@ describe("AssetValue", () => {
|
|
|
555
561
|
}),
|
|
556
562
|
);
|
|
557
563
|
|
|
558
|
-
const cacaoAsset = AssetValue.
|
|
564
|
+
const cacaoAsset = AssetValue.from({ chain: Chain.Maya });
|
|
559
565
|
expect(cacaoAsset).toEqual(
|
|
560
566
|
expect.objectContaining({
|
|
561
567
|
address: undefined,
|
|
@@ -569,33 +575,34 @@ describe("AssetValue", () => {
|
|
|
569
575
|
}),
|
|
570
576
|
);
|
|
571
577
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
)
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
)
|
|
597
|
-
|
|
598
|
-
|
|
578
|
+
// TODO enable when BE fixes case sensitivity
|
|
579
|
+
// const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
580
|
+
// expect(thor).toEqual(
|
|
581
|
+
// expect.objectContaining({
|
|
582
|
+
// address: "0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
583
|
+
// chain: Chain.Ethereum,
|
|
584
|
+
// decimal: 18,
|
|
585
|
+
// isGasAsset: false,
|
|
586
|
+
// isSynthetic: false,
|
|
587
|
+
// symbol: "THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
|
|
588
|
+
// ticker: "THOR",
|
|
589
|
+
// }),
|
|
590
|
+
// );
|
|
591
|
+
|
|
592
|
+
// const vthor = AssetValue.from({ asset: "ETH.vTHOR" });
|
|
593
|
+
// expect(vthor).toEqual(
|
|
594
|
+
// expect.objectContaining({
|
|
595
|
+
// address: "0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
596
|
+
// chain: Chain.Ethereum,
|
|
597
|
+
// decimal: 18,
|
|
598
|
+
// isGasAsset: false,
|
|
599
|
+
// isSynthetic: false,
|
|
600
|
+
// symbol: "vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
601
|
+
// ticker: "vTHOR",
|
|
602
|
+
// }),
|
|
603
|
+
// );
|
|
604
|
+
|
|
605
|
+
const arbAsset = AssetValue.from({ chain: Chain.Arbitrum });
|
|
599
606
|
expect(arbAsset).toEqual(
|
|
600
607
|
expect.objectContaining({
|
|
601
608
|
address: undefined,
|
|
@@ -609,7 +616,7 @@ describe("AssetValue", () => {
|
|
|
609
616
|
}),
|
|
610
617
|
);
|
|
611
618
|
|
|
612
|
-
const opAsset = AssetValue.
|
|
619
|
+
const opAsset = AssetValue.from({ chain: Chain.Optimism });
|
|
613
620
|
expect(opAsset).toEqual(
|
|
614
621
|
expect.objectContaining({
|
|
615
622
|
address: undefined,
|
|
@@ -623,7 +630,7 @@ describe("AssetValue", () => {
|
|
|
623
630
|
}),
|
|
624
631
|
);
|
|
625
632
|
|
|
626
|
-
const xrdAsset = AssetValue.
|
|
633
|
+
const xrdAsset = AssetValue.from({ chain: Chain.Radix });
|
|
627
634
|
expect(xrdAsset).toEqual(
|
|
628
635
|
expect.objectContaining({
|
|
629
636
|
address: undefined,
|
|
@@ -638,14 +645,6 @@ describe("AssetValue", () => {
|
|
|
638
645
|
);
|
|
639
646
|
});
|
|
640
647
|
});
|
|
641
|
-
|
|
642
|
-
describe("loadStaticAssets", () => {
|
|
643
|
-
test("loads static assets from `@swapkit/tokens` lists", async () => {
|
|
644
|
-
// Dummy test - think of sth more meaningful
|
|
645
|
-
const { ok } = await AssetValue.loadStaticAssets();
|
|
646
|
-
expect(ok).toBe(true);
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
648
|
});
|
|
650
649
|
|
|
651
650
|
describe("getMinAmountByChain", () => {
|