@chainflip/utils 2.1.7 → 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 = [
@@ -411,6 +412,41 @@ function isLegacyChainflipChain(chain) {
411
412
  function isAnyChainflipChain(chain) {
412
413
  return isChainflipChain(chain) || isLegacyChainflipChain(chain);
413
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;
414
450
 
415
451
  //#endregion
416
452
  exports.addressTypes = addressTypes;
@@ -434,6 +470,7 @@ exports.getInternalAssets = getInternalAssets;
434
470
  exports.internalAssetToRpcAsset = internalAssetToRpcAsset;
435
471
  exports.isAnyChainflipAsset = isAnyChainflipAsset;
436
472
  exports.isAnyChainflipChain = isAnyChainflipChain;
473
+ exports.isBlockSpecLessThanVersion = isBlockSpecLessThanVersion;
437
474
  exports.isChainflipAsset = isChainflipAsset;
438
475
  exports.isChainflipChain = isChainflipChain;
439
476
  exports.isLegacyChainflipAsset = isLegacyChainflipAsset;
@@ -353,5 +353,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
353
353
  declare function isChainflipChain(chain: string): chain is ChainflipChain;
354
354
  declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
355
355
  declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
356
+ declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
356
357
  //#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 };
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 };
@@ -353,5 +353,6 @@ declare function isAnyChainflipAsset(asset: string): asset is AnyChainflipAsset;
353
353
  declare function isChainflipChain(chain: string): chain is ChainflipChain;
354
354
  declare function isLegacyChainflipChain(chain: string): chain is LegacyChainflipChain;
355
355
  declare function isAnyChainflipChain(chain: string): chain is AnyChainflipChain;
356
+ declare const isBlockSpecLessThanVersion: (desiredVersion: `${string}.${string}.${string}`, blockVersion: string) => boolean;
356
357
  //#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 };
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",
@@ -409,6 +411,41 @@ function isLegacyChainflipChain(chain) {
409
411
  function isAnyChainflipChain(chain) {
410
412
  return isChainflipChain(chain) || isLegacyChainflipChain(chain);
411
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;
412
449
 
413
450
  //#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 };
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/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "2.1.7",
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
  },