@chainflip/utils 2.1.7-tron-dev.2 → 2.1.8

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.
@@ -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,8 +15,6 @@ const chainflipAssets = [
14
15
  "Sol",
15
16
  "SolUsdc",
16
17
  "SolUsdt",
17
- "Trx",
18
- "TrxUsdt",
19
18
  "HubDot",
20
19
  "HubUsdt",
21
20
  "HubUsdc"
@@ -31,11 +30,7 @@ const priceAssets = [
31
30
  "Fine"
32
31
  ];
33
32
  const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
34
- const chainflipEvmChains = [
35
- "Ethereum",
36
- "Arbitrum",
37
- "Tron"
38
- ];
33
+ const chainflipEvmChains = ["Ethereum", "Arbitrum"];
39
34
  const chainflipChains = [
40
35
  ...chainflipEvmChains,
41
36
  "Bitcoin",
@@ -54,8 +49,7 @@ const addressTypes = [
54
49
  "Btc",
55
50
  "Arb",
56
51
  "Sol",
57
- "Hub",
58
- "Tron"
52
+ "Hub"
59
53
  ];
60
54
  const legacyAddressTypes = ["Dot"];
61
55
  function readAssetValue(map, asset) {
@@ -136,16 +130,6 @@ const assetConstants = {
136
130
  chain: "Assethub",
137
131
  symbol: "USDT",
138
132
  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
149
133
  }
150
134
  };
151
135
  const anyAssetConstants = {
@@ -164,8 +148,7 @@ const assetSymbols = [
164
148
  "SOL",
165
149
  "USDC",
166
150
  "USDT",
167
- "WBTC",
168
- "TRX"
151
+ "WBTC"
169
152
  ];
170
153
  const chainConstants = {
171
154
  Ethereum: {
@@ -238,13 +221,6 @@ const chainConstants = {
238
221
  gasAsset: "HubDot",
239
222
  addressType: "Hub",
240
223
  blockTimeSeconds: 3
241
- },
242
- Tron: {
243
- chainflipAssets: ["Trx", "TrxUsdt"],
244
- assets: ["TRX", "USDT"],
245
- gasAsset: "Trx",
246
- addressType: "Tron",
247
- blockTimeSeconds: 3
248
224
  }
249
225
  };
250
226
  const anyChainConstants = {
@@ -317,14 +293,6 @@ const internalAssetToRpcAsset = {
317
293
  HubUsdc: {
318
294
  chain: "Assethub",
319
295
  asset: "USDC"
320
- },
321
- Trx: {
322
- chain: "Tron",
323
- asset: "TRX"
324
- },
325
- TrxUsdt: {
326
- chain: "Tron",
327
- asset: "USDT"
328
296
  }
329
297
  };
330
298
  const anyInternalAssetToRpcAsset = {
@@ -339,8 +307,7 @@ const chainContractId = {
339
307
  Bitcoin: 3,
340
308
  Arbitrum: 4,
341
309
  Solana: 5,
342
- Assethub: 6,
343
- Tron: 7
310
+ Assethub: 6
344
311
  };
345
312
  const assetContractId = {
346
313
  Eth: 1,
@@ -357,9 +324,7 @@ const assetContractId = {
357
324
  HubUsdc: 13,
358
325
  Wbtc: 14,
359
326
  ArbUsdt: 15,
360
- SolUsdt: 16,
361
- Trx: 17,
362
- TrxUsdt: 18
327
+ SolUsdt: 16
363
328
  };
364
329
  function getInternalAsset(asset, assert = true) {
365
330
  const internalAsset = {
@@ -385,10 +350,6 @@ function getInternalAsset(asset, assert = true) {
385
350
  USDC: "HubUsdc",
386
351
  USDT: "HubUsdt",
387
352
  DOT: "HubDot"
388
- },
389
- Tron: {
390
- TRX: "Trx",
391
- USDT: "TrxUsdt"
392
353
  }
393
354
  }[asset.chain]?.[asset.asset];
394
355
  if (internalAsset) return internalAsset;
@@ -431,9 +392,7 @@ const chainflipAssetToPriceAssetMap = {
431
392
  HubUsdt: "Usdt",
432
393
  Flip: null,
433
394
  HubDot: null,
434
- Wbtc: "Btc",
435
- Trx: null,
436
- TrxUsdt: "Usdt"
395
+ Wbtc: "Btc"
437
396
  };
438
397
  function isChainflipAsset(asset) {
439
398
  return chainflipAssets.includes(asset);
@@ -453,6 +412,41 @@ function isLegacyChainflipChain(chain) {
453
412
  function isAnyChainflipChain(chain) {
454
413
  return isChainflipChain(chain) || isLegacyChainflipChain(chain);
455
414
  }
415
+ const parseSemver = (version) => {
416
+ const [major, minor, patch] = version.split(".").map(Number);
417
+ require_assertion.assert(!Number.isNaN(major) && !Number.isNaN(minor) && !Number.isNaN(patch), `Invalid semver version: ${version}`);
418
+ return {
419
+ major,
420
+ minor,
421
+ patch
422
+ };
423
+ };
424
+ const parseBlockSpecId = (blockVersion) => {
425
+ const stringVersion = /@(\d+)$/.exec(blockVersion)?.[1];
426
+ require_assertion.assert(stringVersion, `Could not parse spec version from blockVersion: ${blockVersion}`);
427
+ const digitCount = Math.ceil(stringVersion.length / 3);
428
+ const paddedVersion = stringVersion.padStart(digitCount * 3, "0");
429
+ return {
430
+ major: Number.parseInt(paddedVersion.slice(0, digitCount), 10),
431
+ minor: Number.parseInt(paddedVersion.slice(digitCount, digitCount * 2), 10),
432
+ patch: Number.parseInt(paddedVersion.slice(digitCount * 2, digitCount * 3), 10)
433
+ };
434
+ };
435
+ /**
436
+ * returns -1 if a < b
437
+ * returns 0 if a == b
438
+ * returns 1 if a > b
439
+ */
440
+ const compareSemvers = (a, b) => {
441
+ if (a.major < b.major) return -1;
442
+ if (a.major > b.major) return 1;
443
+ if (a.minor < b.minor) return -1;
444
+ if (a.minor > b.minor) return 1;
445
+ if (a.patch < b.patch) return -1;
446
+ if (a.patch > b.patch) return 1;
447
+ return 0;
448
+ };
449
+ const isBlockSpecLessThanVersion = (desiredVersion, blockVersion) => compareSemvers(parseBlockSpecId(blockVersion), parseSemver(desiredVersion)) === -1;
456
450
 
457
451
  //#endregion
458
452
  exports.addressTypes = addressTypes;
@@ -476,6 +470,7 @@ exports.getInternalAssets = getInternalAssets;
476
470
  exports.internalAssetToRpcAsset = internalAssetToRpcAsset;
477
471
  exports.isAnyChainflipAsset = isAnyChainflipAsset;
478
472
  exports.isAnyChainflipChain = isAnyChainflipChain;
473
+ exports.isBlockSpecLessThanVersion = isBlockSpecLessThanVersion;
479
474
  exports.isChainflipAsset = isChainflipAsset;
480
475
  exports.isChainflipChain = isChainflipChain;
481
476
  exports.isLegacyChainflipAsset = isLegacyChainflipAsset;
@@ -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", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
2
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "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", "Tron"];
12
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
13
13
  type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
14
- declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
14
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "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", "Tron"];
21
+ declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
22
22
  type AddressType = (typeof addressTypes)[number];
23
23
  declare const legacyAddressTypes: readonly ["Dot"];
24
24
  type LegacyAddressType = (typeof legacyAddressTypes)[number];
@@ -140,16 +140,6 @@ 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
- };
153
143
  };
154
144
  declare const anyAssetConstants: {
155
145
  readonly Dot: {
@@ -232,18 +222,8 @@ declare const anyAssetConstants: {
232
222
  readonly symbol: "USDT";
233
223
  readonly decimals: 6;
234
224
  };
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
- };
245
225
  };
246
- declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
226
+ declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
247
227
  type AssetSymbol = (typeof assetSymbols)[number];
248
228
  declare const chainConstants: {
249
229
  readonly Ethereum: {
@@ -281,13 +261,6 @@ declare const chainConstants: {
281
261
  readonly addressType: "Hub";
282
262
  readonly blockTimeSeconds: 3;
283
263
  };
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
- };
291
264
  };
292
265
  declare const anyChainConstants: {
293
266
  readonly Polkadot: {
@@ -332,13 +305,6 @@ declare const anyChainConstants: {
332
305
  readonly addressType: "Hub";
333
306
  readonly blockTimeSeconds: 3;
334
307
  };
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
- };
342
308
  };
343
309
  declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
344
310
  declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
@@ -387,5 +353,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
387
353
  declare function isChainflipChain(chain: string): chain is ChainflipChain;
388
354
  declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
389
355
  declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
356
+ declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
390
357
  //#endregion
391
- 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 };
358
+ 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 };
@@ -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", "Trx", "TrxUsdt", "HubDot", "HubUsdt", "HubUsdc"];
2
+ declare const chainflipAssets: readonly ["Usdc", "Usdt", "Wbtc", "Flip", "Eth", "Btc", "ArbUsdc", "ArbUsdt", "ArbEth", "Sol", "SolUsdc", "SolUsdt", "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", "Tron"];
12
+ declare const chainflipEvmChains: readonly ["Ethereum", "Arbitrum"];
13
13
  type ChainflipEvmChain = (typeof chainflipEvmChains)[number];
14
- declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "Tron", "Bitcoin", "Solana", "Assethub"];
14
+ declare const chainflipChains: readonly ["Ethereum", "Arbitrum", "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", "Tron"];
21
+ declare const addressTypes: readonly ["Eth", "Btc", "Arb", "Sol", "Hub"];
22
22
  type AddressType = (typeof addressTypes)[number];
23
23
  declare const legacyAddressTypes: readonly ["Dot"];
24
24
  type LegacyAddressType = (typeof legacyAddressTypes)[number];
@@ -140,16 +140,6 @@ 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
- };
153
143
  };
154
144
  declare const anyAssetConstants: {
155
145
  readonly Dot: {
@@ -232,18 +222,8 @@ declare const anyAssetConstants: {
232
222
  readonly symbol: "USDT";
233
223
  readonly decimals: 6;
234
224
  };
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
- };
245
225
  };
246
- declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC", "TRX"];
226
+ declare const assetSymbols: readonly ["BTC", "DOT", "ETH", "FLIP", "SOL", "USDC", "USDT", "WBTC"];
247
227
  type AssetSymbol = (typeof assetSymbols)[number];
248
228
  declare const chainConstants: {
249
229
  readonly Ethereum: {
@@ -281,13 +261,6 @@ declare const chainConstants: {
281
261
  readonly addressType: "Hub";
282
262
  readonly blockTimeSeconds: 3;
283
263
  };
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
- };
291
264
  };
292
265
  declare const anyChainConstants: {
293
266
  readonly Polkadot: {
@@ -332,13 +305,6 @@ declare const anyChainConstants: {
332
305
  readonly addressType: "Hub";
333
306
  readonly blockTimeSeconds: 3;
334
307
  };
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
- };
342
308
  };
343
309
  declare const internalAssetToRpcAsset: InternalAssetMap<AssetAndChain>;
344
310
  declare const anyInternalAssetToRpcAsset: AnyInternalAssetMap<AnyAssetAndChain>;
@@ -387,5 +353,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
387
353
  declare function isChainflipChain(chain: string): chain is ChainflipChain;
388
354
  declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
389
355
  declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
356
+ declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
390
357
  //#endregion
391
- 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 };
358
+ 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 };
@@ -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,8 +14,6 @@ const chainflipAssets = [
12
14
  "Sol",
13
15
  "SolUsdc",
14
16
  "SolUsdt",
15
- "Trx",
16
- "TrxUsdt",
17
17
  "HubDot",
18
18
  "HubUsdt",
19
19
  "HubUsdc"
@@ -29,11 +29,7 @@ const priceAssets = [
29
29
  "Fine"
30
30
  ];
31
31
  const baseChainflipAssets = chainflipAssets.filter((asset) => asset !== "Usdc");
32
- const chainflipEvmChains = [
33
- "Ethereum",
34
- "Arbitrum",
35
- "Tron"
36
- ];
32
+ const chainflipEvmChains = ["Ethereum", "Arbitrum"];
37
33
  const chainflipChains = [
38
34
  ...chainflipEvmChains,
39
35
  "Bitcoin",
@@ -52,8 +48,7 @@ const addressTypes = [
52
48
  "Btc",
53
49
  "Arb",
54
50
  "Sol",
55
- "Hub",
56
- "Tron"
51
+ "Hub"
57
52
  ];
58
53
  const legacyAddressTypes = ["Dot"];
59
54
  function readAssetValue(map, asset) {
@@ -134,16 +129,6 @@ const assetConstants = {
134
129
  chain: "Assethub",
135
130
  symbol: "USDT",
136
131
  decimals: 6
137
- },
138
- Trx: {
139
- chain: "Tron",
140
- symbol: "TRX",
141
- decimals: 6
142
- },
143
- TrxUsdt: {
144
- chain: "Tron",
145
- symbol: "USDT",
146
- decimals: 6
147
132
  }
148
133
  };
149
134
  const anyAssetConstants = {
@@ -162,8 +147,7 @@ const assetSymbols = [
162
147
  "SOL",
163
148
  "USDC",
164
149
  "USDT",
165
- "WBTC",
166
- "TRX"
150
+ "WBTC"
167
151
  ];
168
152
  const chainConstants = {
169
153
  Ethereum: {
@@ -236,13 +220,6 @@ const chainConstants = {
236
220
  gasAsset: "HubDot",
237
221
  addressType: "Hub",
238
222
  blockTimeSeconds: 3
239
- },
240
- Tron: {
241
- chainflipAssets: ["Trx", "TrxUsdt"],
242
- assets: ["TRX", "USDT"],
243
- gasAsset: "Trx",
244
- addressType: "Tron",
245
- blockTimeSeconds: 3
246
223
  }
247
224
  };
248
225
  const anyChainConstants = {
@@ -315,14 +292,6 @@ const internalAssetToRpcAsset = {
315
292
  HubUsdc: {
316
293
  chain: "Assethub",
317
294
  asset: "USDC"
318
- },
319
- Trx: {
320
- chain: "Tron",
321
- asset: "TRX"
322
- },
323
- TrxUsdt: {
324
- chain: "Tron",
325
- asset: "USDT"
326
295
  }
327
296
  };
328
297
  const anyInternalAssetToRpcAsset = {
@@ -337,8 +306,7 @@ const chainContractId = {
337
306
  Bitcoin: 3,
338
307
  Arbitrum: 4,
339
308
  Solana: 5,
340
- Assethub: 6,
341
- Tron: 7
309
+ Assethub: 6
342
310
  };
343
311
  const assetContractId = {
344
312
  Eth: 1,
@@ -355,9 +323,7 @@ const assetContractId = {
355
323
  HubUsdc: 13,
356
324
  Wbtc: 14,
357
325
  ArbUsdt: 15,
358
- SolUsdt: 16,
359
- Trx: 17,
360
- TrxUsdt: 18
326
+ SolUsdt: 16
361
327
  };
362
328
  function getInternalAsset(asset, assert = true) {
363
329
  const internalAsset = {
@@ -383,10 +349,6 @@ function getInternalAsset(asset, assert = true) {
383
349
  USDC: "HubUsdc",
384
350
  USDT: "HubUsdt",
385
351
  DOT: "HubDot"
386
- },
387
- Tron: {
388
- TRX: "Trx",
389
- USDT: "TrxUsdt"
390
352
  }
391
353
  }[asset.chain]?.[asset.asset];
392
354
  if (internalAsset) return internalAsset;
@@ -429,9 +391,7 @@ const chainflipAssetToPriceAssetMap = {
429
391
  HubUsdt: "Usdt",
430
392
  Flip: null,
431
393
  HubDot: null,
432
- Wbtc: "Btc",
433
- Trx: null,
434
- TrxUsdt: "Usdt"
394
+ Wbtc: "Btc"
435
395
  };
436
396
  function isChainflipAsset(asset) {
437
397
  return chainflipAssets.includes(asset);
@@ -451,6 +411,41 @@ function isLegacyChainflipChain(chain) {
451
411
  function isAnyChainflipChain(chain) {
452
412
  return isChainflipChain(chain) || isLegacyChainflipChain(chain);
453
413
  }
414
+ const parseSemver = (version) => {
415
+ const [major, minor, patch] = version.split(".").map(Number);
416
+ assert(!Number.isNaN(major) && !Number.isNaN(minor) && !Number.isNaN(patch), `Invalid semver version: ${version}`);
417
+ return {
418
+ major,
419
+ minor,
420
+ patch
421
+ };
422
+ };
423
+ const parseBlockSpecId = (blockVersion) => {
424
+ const stringVersion = /@(\d+)$/.exec(blockVersion)?.[1];
425
+ assert(stringVersion, `Could not parse spec version from blockVersion: ${blockVersion}`);
426
+ const digitCount = Math.ceil(stringVersion.length / 3);
427
+ const paddedVersion = stringVersion.padStart(digitCount * 3, "0");
428
+ return {
429
+ major: Number.parseInt(paddedVersion.slice(0, digitCount), 10),
430
+ minor: Number.parseInt(paddedVersion.slice(digitCount, digitCount * 2), 10),
431
+ patch: Number.parseInt(paddedVersion.slice(digitCount * 2, digitCount * 3), 10)
432
+ };
433
+ };
434
+ /**
435
+ * returns -1 if a < b
436
+ * returns 0 if a == b
437
+ * returns 1 if a > b
438
+ */
439
+ const compareSemvers = (a, b) => {
440
+ if (a.major < b.major) return -1;
441
+ if (a.major > b.major) return 1;
442
+ if (a.minor < b.minor) return -1;
443
+ if (a.minor > b.minor) return 1;
444
+ if (a.patch < b.patch) return -1;
445
+ if (a.patch > b.patch) return 1;
446
+ return 0;
447
+ };
448
+ const isBlockSpecLessThanVersion = (desiredVersion, blockVersion) => compareSemvers(parseBlockSpecId(blockVersion), parseSemver(desiredVersion)) === -1;
454
449
 
455
450
  //#endregion
456
- 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 };
451
+ 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "2.1.7-tron-dev.2",
3
+ "version": "2.1.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@date-fns/utc": "^2.1.1",
26
- "@noble/hashes": "^2.0.1",
26
+ "@noble/hashes": "^2.2.0",
27
27
  "bignumber.js": "^10.0.2",
28
28
  "date-fns": "4.1.0"
29
29
  },