@chainflip/utils 2.1.7 → 2.2.0-alpha.1
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/async.cjs +1 -0
- package/dist/async.mjs +1 -0
- package/dist/chainflip.cjs +85 -6
- package/dist/chainflip.d.cts +41 -6
- package/dist/chainflip.d.mts +41 -6
- package/dist/chainflip.mjs +86 -7
- package/dist/tickMath.cjs +1 -1
- package/dist/tron.cjs +15 -0
- package/dist/tron.d.cts +4 -0
- package/dist/tron.d.mts +4 -0
- package/dist/tron.mjs +14 -0
- package/package.json +3 -3
package/dist/async.cjs
CHANGED
package/dist/async.mjs
CHANGED
package/dist/chainflip.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_assertion = require('./assertion.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/chainflip.ts
|
|
4
5
|
const chainflipAssets = [
|
|
@@ -14,6 +15,8 @@ const chainflipAssets = [
|
|
|
14
15
|
"Sol",
|
|
15
16
|
"SolUsdc",
|
|
16
17
|
"SolUsdt",
|
|
18
|
+
"Trx",
|
|
19
|
+
"TrxUsdt",
|
|
17
20
|
"HubDot",
|
|
18
21
|
"HubUsdt",
|
|
19
22
|
"HubUsdc"
|
|
@@ -29,7 +32,11 @@ const priceAssets = [
|
|
|
29
32
|
"Fine"
|
|
30
33
|
];
|
|
31
34
|
const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
|
|
32
|
-
const chainflipEvmChains = [
|
|
35
|
+
const chainflipEvmChains = [
|
|
36
|
+
"Ethereum",
|
|
37
|
+
"Arbitrum",
|
|
38
|
+
"Tron"
|
|
39
|
+
];
|
|
33
40
|
const chainflipChains = [
|
|
34
41
|
...chainflipEvmChains,
|
|
35
42
|
"Bitcoin",
|
|
@@ -48,7 +55,8 @@ const addressTypes = [
|
|
|
48
55
|
"Btc",
|
|
49
56
|
"Arb",
|
|
50
57
|
"Sol",
|
|
51
|
-
"Hub"
|
|
58
|
+
"Hub",
|
|
59
|
+
"Tron"
|
|
52
60
|
];
|
|
53
61
|
const legacyAddressTypes = ["Dot"];
|
|
54
62
|
function readAssetValue(map, asset) {
|
|
@@ -129,6 +137,16 @@ const assetConstants = {
|
|
|
129
137
|
chain: "Assethub",
|
|
130
138
|
symbol: "USDT",
|
|
131
139
|
decimals: 6
|
|
140
|
+
},
|
|
141
|
+
Trx: {
|
|
142
|
+
chain: "Tron",
|
|
143
|
+
symbol: "TRX",
|
|
144
|
+
decimals: 6
|
|
145
|
+
},
|
|
146
|
+
TrxUsdt: {
|
|
147
|
+
chain: "Tron",
|
|
148
|
+
symbol: "USDT",
|
|
149
|
+
decimals: 6
|
|
132
150
|
}
|
|
133
151
|
};
|
|
134
152
|
const anyAssetConstants = {
|
|
@@ -147,7 +165,8 @@ const assetSymbols = [
|
|
|
147
165
|
"SOL",
|
|
148
166
|
"USDC",
|
|
149
167
|
"USDT",
|
|
150
|
-
"WBTC"
|
|
168
|
+
"WBTC",
|
|
169
|
+
"TRX"
|
|
151
170
|
];
|
|
152
171
|
const chainConstants = {
|
|
153
172
|
Ethereum: {
|
|
@@ -220,6 +239,13 @@ const chainConstants = {
|
|
|
220
239
|
gasAsset: "HubDot",
|
|
221
240
|
addressType: "Hub",
|
|
222
241
|
blockTimeSeconds: 3
|
|
242
|
+
},
|
|
243
|
+
Tron: {
|
|
244
|
+
chainflipAssets: ["Trx", "TrxUsdt"],
|
|
245
|
+
assets: ["TRX", "USDT"],
|
|
246
|
+
gasAsset: "Trx",
|
|
247
|
+
addressType: "Tron",
|
|
248
|
+
blockTimeSeconds: 3
|
|
223
249
|
}
|
|
224
250
|
};
|
|
225
251
|
const anyChainConstants = {
|
|
@@ -292,6 +318,14 @@ const internalAssetToRpcAsset = {
|
|
|
292
318
|
HubUsdc: {
|
|
293
319
|
chain: "Assethub",
|
|
294
320
|
asset: "USDC"
|
|
321
|
+
},
|
|
322
|
+
Trx: {
|
|
323
|
+
chain: "Tron",
|
|
324
|
+
asset: "TRX"
|
|
325
|
+
},
|
|
326
|
+
TrxUsdt: {
|
|
327
|
+
chain: "Tron",
|
|
328
|
+
asset: "USDT"
|
|
295
329
|
}
|
|
296
330
|
};
|
|
297
331
|
const anyInternalAssetToRpcAsset = {
|
|
@@ -306,7 +340,8 @@ const chainContractId = {
|
|
|
306
340
|
Bitcoin: 3,
|
|
307
341
|
Arbitrum: 4,
|
|
308
342
|
Solana: 5,
|
|
309
|
-
Assethub: 6
|
|
343
|
+
Assethub: 6,
|
|
344
|
+
Tron: 7
|
|
310
345
|
};
|
|
311
346
|
const assetContractId = {
|
|
312
347
|
Eth: 1,
|
|
@@ -323,7 +358,9 @@ const assetContractId = {
|
|
|
323
358
|
HubUsdc: 13,
|
|
324
359
|
Wbtc: 14,
|
|
325
360
|
ArbUsdt: 15,
|
|
326
|
-
SolUsdt: 16
|
|
361
|
+
SolUsdt: 16,
|
|
362
|
+
Trx: 17,
|
|
363
|
+
TrxUsdt: 18
|
|
327
364
|
};
|
|
328
365
|
function getInternalAsset(asset, assert = true) {
|
|
329
366
|
const internalAsset = {
|
|
@@ -349,6 +386,10 @@ function getInternalAsset(asset, assert = true) {
|
|
|
349
386
|
USDC: "HubUsdc",
|
|
350
387
|
USDT: "HubUsdt",
|
|
351
388
|
DOT: "HubDot"
|
|
389
|
+
},
|
|
390
|
+
Tron: {
|
|
391
|
+
TRX: "Trx",
|
|
392
|
+
USDT: "TrxUsdt"
|
|
352
393
|
}
|
|
353
394
|
}[asset.chain]?.[asset.asset];
|
|
354
395
|
if (internalAsset) return internalAsset;
|
|
@@ -391,7 +432,9 @@ const chainflipAssetToPriceAssetMap = {
|
|
|
391
432
|
HubUsdt: "Usdt",
|
|
392
433
|
Flip: null,
|
|
393
434
|
HubDot: null,
|
|
394
|
-
Wbtc: "Btc"
|
|
435
|
+
Wbtc: "Btc",
|
|
436
|
+
Trx: null,
|
|
437
|
+
TrxUsdt: "Usdt"
|
|
395
438
|
};
|
|
396
439
|
function isChainflipAsset(asset) {
|
|
397
440
|
return chainflipAssets.includes(asset);
|
|
@@ -411,6 +454,41 @@ function isLegacyChainflipChain(chain) {
|
|
|
411
454
|
function isAnyChainflipChain(chain) {
|
|
412
455
|
return isChainflipChain(chain) || isLegacyChainflipChain(chain);
|
|
413
456
|
}
|
|
457
|
+
const parseSemver = (version) => {
|
|
458
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
459
|
+
require_assertion.assert(!Number.isNaN(major) && !Number.isNaN(minor) && !Number.isNaN(patch), `Invalid semver version: ${version}`);
|
|
460
|
+
return {
|
|
461
|
+
major,
|
|
462
|
+
minor,
|
|
463
|
+
patch
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
const parseBlockSpecId = (blockVersion) => {
|
|
467
|
+
const stringVersion = /@(\d+)$/.exec(blockVersion)?.[1];
|
|
468
|
+
require_assertion.assert(stringVersion, `Could not parse spec version from blockVersion: ${blockVersion}`);
|
|
469
|
+
const digitCount = Math.ceil(stringVersion.length / 3);
|
|
470
|
+
const paddedVersion = stringVersion.padStart(digitCount * 3, "0");
|
|
471
|
+
return {
|
|
472
|
+
major: Number.parseInt(paddedVersion.slice(0, digitCount), 10),
|
|
473
|
+
minor: Number.parseInt(paddedVersion.slice(digitCount, digitCount * 2), 10),
|
|
474
|
+
patch: Number.parseInt(paddedVersion.slice(digitCount * 2, digitCount * 3), 10)
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* returns -1 if a < b
|
|
479
|
+
* returns 0 if a == b
|
|
480
|
+
* returns 1 if a > b
|
|
481
|
+
*/
|
|
482
|
+
const compareSemvers = (a, b) => {
|
|
483
|
+
if (a.major < b.major) return -1;
|
|
484
|
+
if (a.major > b.major) return 1;
|
|
485
|
+
if (a.minor < b.minor) return -1;
|
|
486
|
+
if (a.minor > b.minor) return 1;
|
|
487
|
+
if (a.patch < b.patch) return -1;
|
|
488
|
+
if (a.patch > b.patch) return 1;
|
|
489
|
+
return 0;
|
|
490
|
+
};
|
|
491
|
+
const isBlockSpecLessThanVersion = (desiredVersion, blockVersion) => compareSemvers(parseBlockSpecId(blockVersion), parseSemver(desiredVersion)) === -1;
|
|
414
492
|
|
|
415
493
|
//#endregion
|
|
416
494
|
exports.addressTypes = addressTypes;
|
|
@@ -434,6 +512,7 @@ exports.getInternalAssets = getInternalAssets;
|
|
|
434
512
|
exports.internalAssetToRpcAsset = internalAssetToRpcAsset;
|
|
435
513
|
exports.isAnyChainflipAsset = isAnyChainflipAsset;
|
|
436
514
|
exports.isAnyChainflipChain = isAnyChainflipChain;
|
|
515
|
+
exports.isBlockSpecLessThanVersion = isBlockSpecLessThanVersion;
|
|
437
516
|
exports.isChainflipAsset = isChainflipAsset;
|
|
438
517
|
exports.isChainflipChain = isChainflipChain;
|
|
439
518
|
exports.isLegacyChainflipAsset = isLegacyChainflipAsset;
|
package/dist/chainflip.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/chainflip.d.ts
|
|
2
|
-
declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "HubDot", "HubUsdt", "HubUsdc"];
|
|
2
|
+
declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
|
|
3
3
|
declare const legacyChainflipAssets: readonly ["Dot"];
|
|
4
4
|
type ChainflipAsset = (typeof chainflipAssets)[number];
|
|
5
5
|
type LegacyChainflipAsset = (typeof legacyChainflipAssets)[number];
|
|
@@ -9,16 +9,16 @@ type PriceAsset = (typeof priceAssets)[number];
|
|
|
9
9
|
type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
|
|
10
10
|
type AnyBaseChainflipAsset = Exclude<AnyChainflipAsset, 'Usdc'>;
|
|
11
11
|
declare const baseChainflipAssets: BaseChainflipAsset[];
|
|
12
|
-
declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
|
|
12
|
+
declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum", "Tron"];
|
|
13
13
|
type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
|
|
14
|
-
declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Solana", "Assethub"];
|
|
14
|
+
declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
|
|
15
15
|
type ChainflipChain = (typeof chainflipChains)[number];
|
|
16
16
|
declare const legacyChainflipChains: readonly ["Polkadot"];
|
|
17
17
|
type LegacyChainflipChain = (typeof legacyChainflipChains)[number];
|
|
18
18
|
type AnyChainflipChain = ChainflipChain | LegacyChainflipChain;
|
|
19
19
|
declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
|
|
20
20
|
type ChainflipNetwork = (typeof chainflipNetworks)[number];
|
|
21
|
-
declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
|
|
21
|
+
declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub", "Tron"];
|
|
22
22
|
type AddressType = (typeof addressTypes)[number];
|
|
23
23
|
declare const legacyAddressTypes: readonly ["Dot"];
|
|
24
24
|
type LegacyAddressType = (typeof legacyAddressTypes)[number];
|
|
@@ -140,6 +140,16 @@ declare const assetConstants: {
|
|
|
140
140
|
readonly symbol: "USDT";
|
|
141
141
|
readonly decimals: 6;
|
|
142
142
|
};
|
|
143
|
+
readonly Trx: {
|
|
144
|
+
readonly chain: "Tron";
|
|
145
|
+
readonly symbol: "TRX";
|
|
146
|
+
readonly decimals: 6;
|
|
147
|
+
};
|
|
148
|
+
readonly TrxUsdt: {
|
|
149
|
+
readonly chain: "Tron";
|
|
150
|
+
readonly symbol: "USDT";
|
|
151
|
+
readonly decimals: 6;
|
|
152
|
+
};
|
|
143
153
|
};
|
|
144
154
|
declare const anyAssetConstants: {
|
|
145
155
|
readonly Dot: {
|
|
@@ -222,8 +232,18 @@ declare const anyAssetConstants: {
|
|
|
222
232
|
readonly symbol: "USDT";
|
|
223
233
|
readonly decimals: 6;
|
|
224
234
|
};
|
|
235
|
+
readonly Trx: {
|
|
236
|
+
readonly chain: "Tron";
|
|
237
|
+
readonly symbol: "TRX";
|
|
238
|
+
readonly decimals: 6;
|
|
239
|
+
};
|
|
240
|
+
readonly TrxUsdt: {
|
|
241
|
+
readonly chain: "Tron";
|
|
242
|
+
readonly symbol: "USDT";
|
|
243
|
+
readonly decimals: 6;
|
|
244
|
+
};
|
|
225
245
|
};
|
|
226
|
-
declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
|
|
246
|
+
declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
|
|
227
247
|
type AssetSymbol = (typeof assetSymbols)[number];
|
|
228
248
|
declare const chainConstants: {
|
|
229
249
|
readonly Ethereum: {
|
|
@@ -261,6 +281,13 @@ declare const chainConstants: {
|
|
|
261
281
|
readonly addressType: "Hub";
|
|
262
282
|
readonly blockTimeSeconds: 3;
|
|
263
283
|
};
|
|
284
|
+
readonly Tron: {
|
|
285
|
+
readonly chainflipAssets: ["Trx", "TrxUsdt"];
|
|
286
|
+
readonly assets: ["TRX", "USDT"];
|
|
287
|
+
readonly gasAsset: "Trx";
|
|
288
|
+
readonly addressType: "Tron";
|
|
289
|
+
readonly blockTimeSeconds: 3;
|
|
290
|
+
};
|
|
264
291
|
};
|
|
265
292
|
declare const anyChainConstants: {
|
|
266
293
|
readonly Polkadot: {
|
|
@@ -305,6 +332,13 @@ declare const anyChainConstants: {
|
|
|
305
332
|
readonly addressType: "Hub";
|
|
306
333
|
readonly blockTimeSeconds: 3;
|
|
307
334
|
};
|
|
335
|
+
readonly Tron: {
|
|
336
|
+
readonly chainflipAssets: ["Trx", "TrxUsdt"];
|
|
337
|
+
readonly assets: ["TRX", "USDT"];
|
|
338
|
+
readonly gasAsset: "Trx";
|
|
339
|
+
readonly addressType: "Tron";
|
|
340
|
+
readonly blockTimeSeconds: 3;
|
|
341
|
+
};
|
|
308
342
|
};
|
|
309
343
|
declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
|
|
310
344
|
declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
|
|
@@ -353,5 +387,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
|
|
|
353
387
|
declare function isChainflipChain(chain: string): chain is ChainflipChain;
|
|
354
388
|
declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
|
|
355
389
|
declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
|
|
390
|
+
declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
|
|
356
391
|
//#endregion
|
|
357
|
-
export { AddressType, AnyAddressType, AnyAssetAndChain, AnyAssetOfChain, AnyBaseAssetAndChain, AnyBaseChainAssetMap, AnyBaseChainflipAsset, AnyChainAssetMap, AnyChainMap, AnyChainflipAsset, AnyChainflipChain, AnyInternalAssetMap, AnyUncheckedAssetAndChain, AssetAndChain, AssetOfChain, AssetSymbol, BaseAssetAndChain, BaseChainAssetMap, BaseChainflipAsset, ChainAssetMap, ChainMap, ChainflipAsset, ChainflipChain, ChainflipEvmChain, ChainflipNetwork, InternalAssetMap, LegacyAddressType, LegacyChainflipAsset, LegacyChainflipChain, PriceAsset, UncheckedAssetAndChain, addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
|
392
|
+
export { AddressType, AnyAddressType, AnyAssetAndChain, AnyAssetOfChain, AnyBaseAssetAndChain, AnyBaseChainAssetMap, AnyBaseChainflipAsset, AnyChainAssetMap, AnyChainMap, AnyChainflipAsset, AnyChainflipChain, AnyInternalAssetMap, AnyUncheckedAssetAndChain, AssetAndChain, AssetOfChain, AssetSymbol, BaseAssetAndChain, BaseChainAssetMap, BaseChainflipAsset, ChainAssetMap, ChainMap, ChainflipAsset, ChainflipChain, ChainflipEvmChain, ChainflipNetwork, InternalAssetMap, LegacyAddressType, LegacyChainflipAsset, LegacyChainflipChain, PriceAsset, UncheckedAssetAndChain, addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isBlockSpecLessThanVersion, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
package/dist/chainflip.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/chainflip.d.ts
|
|
2
|
-
declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "HubDot", "HubUsdt", "HubUsdc"];
|
|
2
|
+
declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
|
|
3
3
|
declare const legacyChainflipAssets: readonly ["Dot"];
|
|
4
4
|
type ChainflipAsset = (typeof chainflipAssets)[number];
|
|
5
5
|
type LegacyChainflipAsset = (typeof legacyChainflipAssets)[number];
|
|
@@ -9,16 +9,16 @@ type PriceAsset = (typeof priceAssets)[number];
|
|
|
9
9
|
type BaseChainflipAsset = Exclude<ChainflipAsset, 'Usdc'>;
|
|
10
10
|
type AnyBaseChainflipAsset = Exclude<AnyChainflipAsset, 'Usdc'>;
|
|
11
11
|
declare const baseChainflipAssets: BaseChainflipAsset[];
|
|
12
|
-
declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
|
|
12
|
+
declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum", "Tron"];
|
|
13
13
|
type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
|
|
14
|
-
declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Bitcoin", "Solana", "Assethub"];
|
|
14
|
+
declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
|
|
15
15
|
type ChainflipChain = (typeof chainflipChains)[number];
|
|
16
16
|
declare const legacyChainflipChains: readonly ["Polkadot"];
|
|
17
17
|
type LegacyChainflipChain = (typeof legacyChainflipChains)[number];
|
|
18
18
|
type AnyChainflipChain = ChainflipChain | LegacyChainflipChain;
|
|
19
19
|
declare const chainflipNetworks: readonly ["backspin", "sisyphos", "perseverance", "mainnet"];
|
|
20
20
|
type ChainflipNetwork = (typeof chainflipNetworks)[number];
|
|
21
|
-
declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
|
|
21
|
+
declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub", "Tron"];
|
|
22
22
|
type AddressType = (typeof addressTypes)[number];
|
|
23
23
|
declare const legacyAddressTypes: readonly ["Dot"];
|
|
24
24
|
type LegacyAddressType = (typeof legacyAddressTypes)[number];
|
|
@@ -140,6 +140,16 @@ declare const assetConstants: {
|
|
|
140
140
|
readonly symbol: "USDT";
|
|
141
141
|
readonly decimals: 6;
|
|
142
142
|
};
|
|
143
|
+
readonly Trx: {
|
|
144
|
+
readonly chain: "Tron";
|
|
145
|
+
readonly symbol: "TRX";
|
|
146
|
+
readonly decimals: 6;
|
|
147
|
+
};
|
|
148
|
+
readonly TrxUsdt: {
|
|
149
|
+
readonly chain: "Tron";
|
|
150
|
+
readonly symbol: "USDT";
|
|
151
|
+
readonly decimals: 6;
|
|
152
|
+
};
|
|
143
153
|
};
|
|
144
154
|
declare const anyAssetConstants: {
|
|
145
155
|
readonly Dot: {
|
|
@@ -222,8 +232,18 @@ declare const anyAssetConstants: {
|
|
|
222
232
|
readonly symbol: "USDT";
|
|
223
233
|
readonly decimals: 6;
|
|
224
234
|
};
|
|
235
|
+
readonly Trx: {
|
|
236
|
+
readonly chain: "Tron";
|
|
237
|
+
readonly symbol: "TRX";
|
|
238
|
+
readonly decimals: 6;
|
|
239
|
+
};
|
|
240
|
+
readonly TrxUsdt: {
|
|
241
|
+
readonly chain: "Tron";
|
|
242
|
+
readonly symbol: "USDT";
|
|
243
|
+
readonly decimals: 6;
|
|
244
|
+
};
|
|
225
245
|
};
|
|
226
|
-
declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
|
|
246
|
+
declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
|
|
227
247
|
type AssetSymbol = (typeof assetSymbols)[number];
|
|
228
248
|
declare const chainConstants: {
|
|
229
249
|
readonly Ethereum: {
|
|
@@ -261,6 +281,13 @@ declare const chainConstants: {
|
|
|
261
281
|
readonly addressType: "Hub";
|
|
262
282
|
readonly blockTimeSeconds: 3;
|
|
263
283
|
};
|
|
284
|
+
readonly Tron: {
|
|
285
|
+
readonly chainflipAssets: ["Trx", "TrxUsdt"];
|
|
286
|
+
readonly assets: ["TRX", "USDT"];
|
|
287
|
+
readonly gasAsset: "Trx";
|
|
288
|
+
readonly addressType: "Tron";
|
|
289
|
+
readonly blockTimeSeconds: 3;
|
|
290
|
+
};
|
|
264
291
|
};
|
|
265
292
|
declare const anyChainConstants: {
|
|
266
293
|
readonly Polkadot: {
|
|
@@ -305,6 +332,13 @@ declare const anyChainConstants: {
|
|
|
305
332
|
readonly addressType: "Hub";
|
|
306
333
|
readonly blockTimeSeconds: 3;
|
|
307
334
|
};
|
|
335
|
+
readonly Tron: {
|
|
336
|
+
readonly chainflipAssets: ["Trx", "TrxUsdt"];
|
|
337
|
+
readonly assets: ["TRX", "USDT"];
|
|
338
|
+
readonly gasAsset: "Trx";
|
|
339
|
+
readonly addressType: "Tron";
|
|
340
|
+
readonly blockTimeSeconds: 3;
|
|
341
|
+
};
|
|
308
342
|
};
|
|
309
343
|
declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
|
|
310
344
|
declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
|
|
@@ -353,5 +387,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
|
|
|
353
387
|
declare function isChainflipChain(chain: string): chain is ChainflipChain;
|
|
354
388
|
declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
|
|
355
389
|
declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
|
|
390
|
+
declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
|
|
356
391
|
//#endregion
|
|
357
|
-
export { AddressType, AnyAddressType, AnyAssetAndChain, AnyAssetOfChain, AnyBaseAssetAndChain, AnyBaseChainAssetMap, AnyBaseChainflipAsset, AnyChainAssetMap, AnyChainMap, AnyChainflipAsset, AnyChainflipChain, AnyInternalAssetMap, AnyUncheckedAssetAndChain, AssetAndChain, AssetOfChain, AssetSymbol, BaseAssetAndChain, BaseChainAssetMap, BaseChainflipAsset, ChainAssetMap, ChainMap, ChainflipAsset, ChainflipChain, ChainflipEvmChain, ChainflipNetwork, InternalAssetMap, LegacyAddressType, LegacyChainflipAsset, LegacyChainflipChain, PriceAsset, UncheckedAssetAndChain, addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
|
392
|
+
export { AddressType, AnyAddressType, AnyAssetAndChain, AnyAssetOfChain, AnyBaseAssetAndChain, AnyBaseChainAssetMap, AnyBaseChainflipAsset, AnyChainAssetMap, AnyChainMap, AnyChainflipAsset, AnyChainflipChain, AnyInternalAssetMap, AnyUncheckedAssetAndChain, AssetAndChain, AssetOfChain, AssetSymbol, BaseAssetAndChain, BaseChainAssetMap, BaseChainflipAsset, ChainAssetMap, ChainMap, ChainflipAsset, ChainflipChain, ChainflipEvmChain, ChainflipNetwork, InternalAssetMap, LegacyAddressType, LegacyChainflipAsset, LegacyChainflipChain, PriceAsset, UncheckedAssetAndChain, addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isBlockSpecLessThanVersion, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
package/dist/chainflip.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assert } from "./assertion.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/chainflip.ts
|
|
2
4
|
const chainflipAssets = [
|
|
3
5
|
"Usdc",
|
|
@@ -12,6 +14,8 @@ const chainflipAssets = [
|
|
|
12
14
|
"Sol",
|
|
13
15
|
"SolUsdc",
|
|
14
16
|
"SolUsdt",
|
|
17
|
+
"Trx",
|
|
18
|
+
"TrxUsdt",
|
|
15
19
|
"HubDot",
|
|
16
20
|
"HubUsdt",
|
|
17
21
|
"HubUsdc"
|
|
@@ -27,7 +31,11 @@ const priceAssets = [
|
|
|
27
31
|
"Fine"
|
|
28
32
|
];
|
|
29
33
|
const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
|
|
30
|
-
const chainflipEvmChains = [
|
|
34
|
+
const chainflipEvmChains = [
|
|
35
|
+
"Ethereum",
|
|
36
|
+
"Arbitrum",
|
|
37
|
+
"Tron"
|
|
38
|
+
];
|
|
31
39
|
const chainflipChains = [
|
|
32
40
|
...chainflipEvmChains,
|
|
33
41
|
"Bitcoin",
|
|
@@ -46,7 +54,8 @@ const addressTypes = [
|
|
|
46
54
|
"Btc",
|
|
47
55
|
"Arb",
|
|
48
56
|
"Sol",
|
|
49
|
-
"Hub"
|
|
57
|
+
"Hub",
|
|
58
|
+
"Tron"
|
|
50
59
|
];
|
|
51
60
|
const legacyAddressTypes = ["Dot"];
|
|
52
61
|
function readAssetValue(map, asset) {
|
|
@@ -127,6 +136,16 @@ const assetConstants = {
|
|
|
127
136
|
chain: "Assethub",
|
|
128
137
|
symbol: "USDT",
|
|
129
138
|
decimals: 6
|
|
139
|
+
},
|
|
140
|
+
Trx: {
|
|
141
|
+
chain: "Tron",
|
|
142
|
+
symbol: "TRX",
|
|
143
|
+
decimals: 6
|
|
144
|
+
},
|
|
145
|
+
TrxUsdt: {
|
|
146
|
+
chain: "Tron",
|
|
147
|
+
symbol: "USDT",
|
|
148
|
+
decimals: 6
|
|
130
149
|
}
|
|
131
150
|
};
|
|
132
151
|
const anyAssetConstants = {
|
|
@@ -145,7 +164,8 @@ const assetSymbols = [
|
|
|
145
164
|
"SOL",
|
|
146
165
|
"USDC",
|
|
147
166
|
"USDT",
|
|
148
|
-
"WBTC"
|
|
167
|
+
"WBTC",
|
|
168
|
+
"TRX"
|
|
149
169
|
];
|
|
150
170
|
const chainConstants = {
|
|
151
171
|
Ethereum: {
|
|
@@ -218,6 +238,13 @@ const chainConstants = {
|
|
|
218
238
|
gasAsset: "HubDot",
|
|
219
239
|
addressType: "Hub",
|
|
220
240
|
blockTimeSeconds: 3
|
|
241
|
+
},
|
|
242
|
+
Tron: {
|
|
243
|
+
chainflipAssets: ["Trx", "TrxUsdt"],
|
|
244
|
+
assets: ["TRX", "USDT"],
|
|
245
|
+
gasAsset: "Trx",
|
|
246
|
+
addressType: "Tron",
|
|
247
|
+
blockTimeSeconds: 3
|
|
221
248
|
}
|
|
222
249
|
};
|
|
223
250
|
const anyChainConstants = {
|
|
@@ -290,6 +317,14 @@ const internalAssetToRpcAsset = {
|
|
|
290
317
|
HubUsdc: {
|
|
291
318
|
chain: "Assethub",
|
|
292
319
|
asset: "USDC"
|
|
320
|
+
},
|
|
321
|
+
Trx: {
|
|
322
|
+
chain: "Tron",
|
|
323
|
+
asset: "TRX"
|
|
324
|
+
},
|
|
325
|
+
TrxUsdt: {
|
|
326
|
+
chain: "Tron",
|
|
327
|
+
asset: "USDT"
|
|
293
328
|
}
|
|
294
329
|
};
|
|
295
330
|
const anyInternalAssetToRpcAsset = {
|
|
@@ -304,7 +339,8 @@ const chainContractId = {
|
|
|
304
339
|
Bitcoin: 3,
|
|
305
340
|
Arbitrum: 4,
|
|
306
341
|
Solana: 5,
|
|
307
|
-
Assethub: 6
|
|
342
|
+
Assethub: 6,
|
|
343
|
+
Tron: 7
|
|
308
344
|
};
|
|
309
345
|
const assetContractId = {
|
|
310
346
|
Eth: 1,
|
|
@@ -321,7 +357,9 @@ const assetContractId = {
|
|
|
321
357
|
HubUsdc: 13,
|
|
322
358
|
Wbtc: 14,
|
|
323
359
|
ArbUsdt: 15,
|
|
324
|
-
SolUsdt: 16
|
|
360
|
+
SolUsdt: 16,
|
|
361
|
+
Trx: 17,
|
|
362
|
+
TrxUsdt: 18
|
|
325
363
|
};
|
|
326
364
|
function getInternalAsset(asset, assert = true) {
|
|
327
365
|
const internalAsset = {
|
|
@@ -347,6 +385,10 @@ function getInternalAsset(asset, assert = true) {
|
|
|
347
385
|
USDC: "HubUsdc",
|
|
348
386
|
USDT: "HubUsdt",
|
|
349
387
|
DOT: "HubDot"
|
|
388
|
+
},
|
|
389
|
+
Tron: {
|
|
390
|
+
TRX: "Trx",
|
|
391
|
+
USDT: "TrxUsdt"
|
|
350
392
|
}
|
|
351
393
|
}[asset.chain]?.[asset.asset];
|
|
352
394
|
if (internalAsset) return internalAsset;
|
|
@@ -389,7 +431,9 @@ const chainflipAssetToPriceAssetMap = {
|
|
|
389
431
|
HubUsdt: "Usdt",
|
|
390
432
|
Flip: null,
|
|
391
433
|
HubDot: null,
|
|
392
|
-
Wbtc: "Btc"
|
|
434
|
+
Wbtc: "Btc",
|
|
435
|
+
Trx: null,
|
|
436
|
+
TrxUsdt: "Usdt"
|
|
393
437
|
};
|
|
394
438
|
function isChainflipAsset(asset) {
|
|
395
439
|
return chainflipAssets.includes(asset);
|
|
@@ -409,6 +453,41 @@ function isLegacyChainflipChain(chain) {
|
|
|
409
453
|
function isAnyChainflipChain(chain) {
|
|
410
454
|
return isChainflipChain(chain) || isLegacyChainflipChain(chain);
|
|
411
455
|
}
|
|
456
|
+
const parseSemver = (version) => {
|
|
457
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
458
|
+
assert(!Number.isNaN(major) && !Number.isNaN(minor) && !Number.isNaN(patch), `Invalid semver version: ${version}`);
|
|
459
|
+
return {
|
|
460
|
+
major,
|
|
461
|
+
minor,
|
|
462
|
+
patch
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
const parseBlockSpecId = (blockVersion) => {
|
|
466
|
+
const stringVersion = /@(\d+)$/.exec(blockVersion)?.[1];
|
|
467
|
+
assert(stringVersion, `Could not parse spec version from blockVersion: ${blockVersion}`);
|
|
468
|
+
const digitCount = Math.ceil(stringVersion.length / 3);
|
|
469
|
+
const paddedVersion = stringVersion.padStart(digitCount * 3, "0");
|
|
470
|
+
return {
|
|
471
|
+
major: Number.parseInt(paddedVersion.slice(0, digitCount), 10),
|
|
472
|
+
minor: Number.parseInt(paddedVersion.slice(digitCount, digitCount * 2), 10),
|
|
473
|
+
patch: Number.parseInt(paddedVersion.slice(digitCount * 2, digitCount * 3), 10)
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* returns -1 if a < b
|
|
478
|
+
* returns 0 if a == b
|
|
479
|
+
* returns 1 if a > b
|
|
480
|
+
*/
|
|
481
|
+
const compareSemvers = (a, b) => {
|
|
482
|
+
if (a.major < b.major) return -1;
|
|
483
|
+
if (a.major > b.major) return 1;
|
|
484
|
+
if (a.minor < b.minor) return -1;
|
|
485
|
+
if (a.minor > b.minor) return 1;
|
|
486
|
+
if (a.patch < b.patch) return -1;
|
|
487
|
+
if (a.patch > b.patch) return 1;
|
|
488
|
+
return 0;
|
|
489
|
+
};
|
|
490
|
+
const isBlockSpecLessThanVersion = (desiredVersion, blockVersion) => compareSemvers(parseBlockSpecId(blockVersion), parseSemver(desiredVersion)) === -1;
|
|
412
491
|
|
|
413
492
|
//#endregion
|
|
414
|
-
export { addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
|
493
|
+
export { addressTypes, anyAssetConstants, anyChainConstants, anyInternalAssetToRpcAsset, assetConstants, assetContractId, assetSymbols, baseChainflipAssets, chainConstants, chainContractId, chainflipAssetToPriceAssetMap, chainflipAssets, chainflipChains, chainflipEvmChains, chainflipNetworks, getAnyInternalAsset, getInternalAsset, getInternalAssets, internalAssetToRpcAsset, isAnyChainflipAsset, isAnyChainflipChain, isBlockSpecLessThanVersion, isChainflipAsset, isChainflipChain, isLegacyChainflipAsset, isLegacyChainflipChain, isValidAssetAndChain, legacyAddressTypes, legacyChainflipAssets, legacyChainflipChains, priceAssets, readAssetValue };
|
package/dist/tickMath.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_chainflip = require('./chainflip.cjs');
|
|
4
4
|
let bignumber_js = require("bignumber.js");
|
|
5
|
-
bignumber_js = require_runtime.__toESM(bignumber_js);
|
|
5
|
+
bignumber_js = require_runtime.__toESM(bignumber_js, 1);
|
|
6
6
|
|
|
7
7
|
//#region src/tickMath.ts
|
|
8
8
|
const MIN_TICK = -887272;
|
package/dist/tron.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_base58 = require('./base58.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/tron.ts
|
|
5
|
+
const isValidTronAddress = (address) => {
|
|
6
|
+
try {
|
|
7
|
+
if (!address.startsWith("T")) return false;
|
|
8
|
+
return require_base58.decode(address).length === 25;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.isValidTronAddress = isValidTronAddress;
|
package/dist/tron.d.cts
ADDED
package/dist/tron.d.mts
ADDED
package/dist/tron.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { decode } from "./base58.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/tron.ts
|
|
4
|
+
const isValidTronAddress = (address) => {
|
|
5
|
+
try {
|
|
6
|
+
if (!address.startsWith("T")) return false;
|
|
7
|
+
return decode(address).length === 25;
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { isValidTronAddress };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainflip/utils",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@date-fns/utc": "^2.1.1",
|
|
26
|
-
"@noble/hashes": "^2.0
|
|
27
|
-
"bignumber.js": "^
|
|
26
|
+
"@noble/hashes": "^2.2.0",
|
|
27
|
+
"bignumber.js": "^11.1.1",
|
|
28
28
|
"date-fns": "4.1.0"
|
|
29
29
|
},
|
|
30
30
|
"repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
|