@gfxlabs/oku-chains 1.12.5 → 1.12.7

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/browser.js CHANGED
@@ -1261,6 +1261,7 @@
1261
1261
  sortIndex: 10,
1262
1262
  logoUrl: "https://cms.oku.trade/cdn/public/chains/celo-logo.svg",
1263
1263
  deprecated: false,
1264
+ liteChain: true,
1264
1265
  estimatedSwapGas: 300000,
1265
1266
  estimatedBridgeGas: 200000,
1266
1267
  estimatedWrapGas: 60000,
@@ -6855,17 +6856,102 @@
6855
6856
  */
6856
6857
  const NON_EVM_CHAIN_ID = 0;
6857
6858
  /**
6858
- * True if the chain is non-EVM (i.e. uses the {@link NON_EVM_CHAIN_ID}
6859
- * placeholder id and a non-`eip155` CAIP-2 namespace). Non-EVM chains live in
6860
- * the same {@link IChainInfo} shape as EVM chains, so EVM-only fields
6861
- * (contracts, uniswap metadata, etc.) will be present but empty.
6859
+ * High-level chain family, derived from the chain's CAIP-2 namespace.
6860
+ *
6861
+ * The underlying string value of each member is the CAIP-2 namespace it maps
6862
+ * to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
6863
+ * resolve a chain's type directly from its `caip2Namespace` without relying on
6864
+ * sentinel values like {@link NON_EVM_CHAIN_ID}.
6865
+ *
6866
+ * @see https://chainagnostic.org/CAIPs/caip-2
6862
6867
  */
6863
- function isNonEvmChain(c) {
6864
- return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6868
+ exports.ChainType = void 0;
6869
+ (function (ChainType) {
6870
+ /** EVM chains (CAIP-2 namespace `eip155`). */
6871
+ ChainType["EVM"] = "eip155";
6872
+ /** Bitcoin (CAIP-2 namespace `bip122`). */
6873
+ ChainType["Bitcoin"] = "bip122";
6874
+ /** Solana (CAIP-2 namespace `solana`). */
6875
+ ChainType["Solana"] = "solana";
6876
+ /** Unknown / unrecognized CAIP-2 namespace. */
6877
+ ChainType["Unknown"] = "";
6878
+ })(exports.ChainType || (exports.ChainType = {}));
6879
+ /** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
6880
+ const CHAIN_TYPE_BY_NAMESPACE = {
6881
+ [exports.ChainType.EVM]: exports.ChainType.EVM,
6882
+ [exports.ChainType.Bitcoin]: exports.ChainType.Bitcoin,
6883
+ [exports.ChainType.Solana]: exports.ChainType.Solana,
6884
+ };
6885
+ /**
6886
+ * Resolve a CAIP-2 namespace from a chain-like value:
6887
+ * - an {@link IChainInfo} object: its `caip2Namespace`
6888
+ * - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
6889
+ * - a bare namespace string (e.g. `"eip155"`): used verbatim
6890
+ *
6891
+ * Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
6892
+ * namespace and resolves to {@link ChainType.Unknown} here. Use the
6893
+ * index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
6894
+ * those (they look the chain up first).
6895
+ */
6896
+ function namespaceOf(c) {
6897
+ if (typeof c === "string") {
6898
+ const sep = c.indexOf(":");
6899
+ return sep === -1 ? c : c.slice(0, sep);
6900
+ }
6901
+ return c.caip2Namespace;
6865
6902
  }
6866
- /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6867
- function isEvmChain(c) {
6868
- return !isNonEvmChain(c);
6903
+ /**
6904
+ * The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
6905
+ *
6906
+ * Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
6907
+ * like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
6908
+ * canonical way to determine a chain's family. Prefer it over inspecting the
6909
+ * numeric `id` (which is a placeholder for non-EVM chains).
6910
+ *
6911
+ * @example
6912
+ * ```ts
6913
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6914
+ * chainType(mainnet) // => ChainType.EVM
6915
+ * chainType(bitcoin) // => ChainType.Bitcoin
6916
+ * chainType("eip155:1") // => ChainType.EVM
6917
+ * chainType("bip122") // => ChainType.Bitcoin
6918
+ * ```
6919
+ */
6920
+ function chainType$1(c) {
6921
+ return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? exports.ChainType.Unknown;
6922
+ }
6923
+ /**
6924
+ * True if the chain belongs to the given {@link ChainType} family.
6925
+ *
6926
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
6927
+ * checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
6928
+ *
6929
+ * @example
6930
+ * ```ts
6931
+ * import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
6932
+ * isNetworkType(ChainType.Bitcoin, bitcoin) // => true
6933
+ * isNetworkType(ChainType.EVM, bitcoin) // => false
6934
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
6935
+ * ```
6936
+ */
6937
+ function isNetworkType$1(type, c) {
6938
+ return chainType$1(c) === type;
6939
+ }
6940
+ /**
6941
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
6942
+ * {@link IChainInfo} object or a CAIP-2 string.
6943
+ */
6944
+ function isEvmChain$1(c) {
6945
+ return isNetworkType$1(exports.ChainType.EVM, c);
6946
+ }
6947
+ /**
6948
+ * True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
6949
+ * Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
6950
+ * EVM-only fields (contracts, uniswap metadata, etc.) will be present but
6951
+ * empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
6952
+ */
6953
+ function isNonEvmChain$1(c) {
6954
+ return !isEvmChain$1(c);
6869
6955
  }
6870
6956
 
6871
6957
  /**
@@ -7309,6 +7395,93 @@
7309
7395
  function networkByCAIP2(caip2) {
7310
7396
  return networkByCAIP2$1(caip2, _idx);
7311
7397
  }
7398
+ /**
7399
+ * Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
7400
+ * `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
7401
+ */
7402
+ function namespaceOfChainLike(c) {
7403
+ if (typeof c === "object") {
7404
+ return c.caip2Namespace;
7405
+ }
7406
+ if (typeof c === "string") {
7407
+ // Full CAIP-2 identifier (namespace:reference) — classify by namespace.
7408
+ const sep = c.indexOf(":");
7409
+ if (sep !== -1) {
7410
+ return c.slice(0, sep);
7411
+ }
7412
+ // Bare CAIP-2 namespace (e.g. "eip155", "bip122").
7413
+ if (Object.values(exports.ChainType).includes(c) && c !== "") {
7414
+ return c;
7415
+ }
7416
+ // Otherwise treat as an internal name or numeric id string: resolve it.
7417
+ try {
7418
+ return networkByString$1(c, _idx).caip2Namespace;
7419
+ }
7420
+ catch {
7421
+ return "";
7422
+ }
7423
+ }
7424
+ // Numeric chain id.
7425
+ try {
7426
+ return networkById$1(Math.trunc(c), _idx).caip2Namespace;
7427
+ }
7428
+ catch {
7429
+ return "";
7430
+ }
7431
+ }
7432
+ /**
7433
+ * The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
7434
+ * CAIP-2 identifier or namespace string, an internal name, or a numeric chain
7435
+ * id. Internal names and numeric ids are resolved via the network index.
7436
+ *
7437
+ * @example
7438
+ * ```ts
7439
+ * import { chainType, ChainType } from "@gfxlabs/oku-chains";
7440
+ * chainType(1) // => ChainType.EVM
7441
+ * chainType("mainnet") // => ChainType.EVM
7442
+ * chainType("eip155:1") // => ChainType.EVM
7443
+ * chainType("bitcoin") // => ChainType.Bitcoin
7444
+ * chainType("bip122") // => ChainType.Bitcoin
7445
+ * ```
7446
+ */
7447
+ function chainType(c) {
7448
+ return chainType$1(namespaceOfChainLike(c));
7449
+ }
7450
+ /**
7451
+ * True if the chain belongs to the given {@link ChainType} family. Accepts an
7452
+ * {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
7453
+ * internal name, or a numeric chain id.
7454
+ *
7455
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
7456
+ * checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
7457
+ *
7458
+ * @example
7459
+ * ```ts
7460
+ * import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
7461
+ * isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
7462
+ * isNetworkType(ChainType.EVM, 1) // => true
7463
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
7464
+ * ```
7465
+ */
7466
+ function isNetworkType(type, c) {
7467
+ return isNetworkType$1(type, namespaceOfChainLike(c));
7468
+ }
7469
+ /**
7470
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
7471
+ * {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
7472
+ * chain id.
7473
+ */
7474
+ function isEvmChain(c) {
7475
+ return isEvmChain$1(namespaceOfChainLike(c));
7476
+ }
7477
+ /**
7478
+ * True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
7479
+ * an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
7480
+ * numeric chain id.
7481
+ */
7482
+ function isNonEvmChain(c) {
7483
+ return isNonEvmChain$1(namespaceOfChainLike(c));
7484
+ }
7312
7485
 
7313
7486
  exports.ALL_NETWORKS = ALL_NETWORKS;
7314
7487
  exports.MAINNET_CHAINS = MAINNET_CHAINS;
@@ -7326,6 +7499,7 @@
7326
7499
  exports.buildNetworkIndex = buildNetworkIndex;
7327
7500
  exports.caip2Reference = caip2Reference;
7328
7501
  exports.celo = celo;
7502
+ exports.chainType = chainType;
7329
7503
  exports.corn = corn;
7330
7504
  exports.etherlink = etherlink;
7331
7505
  exports.filecoin = filecoin;
@@ -7337,6 +7511,7 @@
7337
7511
  exports.hemi = hemi;
7338
7512
  exports.hyperevm = hyperevm;
7339
7513
  exports.isEvmChain = isEvmChain;
7514
+ exports.isNetworkType = isNetworkType;
7340
7515
  exports.isNonEvmChain = isNonEvmChain;
7341
7516
  exports.lens = lens;
7342
7517
  exports.lightlink = lightlink;
package/dist/index-mjs.js CHANGED
@@ -1258,6 +1258,7 @@ const celo = makeConfig({
1258
1258
  sortIndex: 10,
1259
1259
  logoUrl: "https://cms.oku.trade/cdn/public/chains/celo-logo.svg",
1260
1260
  deprecated: false,
1261
+ liteChain: true,
1261
1262
  estimatedSwapGas: 300000,
1262
1263
  estimatedBridgeGas: 200000,
1263
1264
  estimatedWrapGas: 60000,
@@ -6852,17 +6853,102 @@ const zkSync = makeConfig({
6852
6853
  */
6853
6854
  const NON_EVM_CHAIN_ID = 0;
6854
6855
  /**
6855
- * True if the chain is non-EVM (i.e. uses the {@link NON_EVM_CHAIN_ID}
6856
- * placeholder id and a non-`eip155` CAIP-2 namespace). Non-EVM chains live in
6857
- * the same {@link IChainInfo} shape as EVM chains, so EVM-only fields
6858
- * (contracts, uniswap metadata, etc.) will be present but empty.
6856
+ * High-level chain family, derived from the chain's CAIP-2 namespace.
6857
+ *
6858
+ * The underlying string value of each member is the CAIP-2 namespace it maps
6859
+ * to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
6860
+ * resolve a chain's type directly from its `caip2Namespace` without relying on
6861
+ * sentinel values like {@link NON_EVM_CHAIN_ID}.
6862
+ *
6863
+ * @see https://chainagnostic.org/CAIPs/caip-2
6859
6864
  */
6860
- function isNonEvmChain(c) {
6861
- return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6865
+ var ChainType;
6866
+ (function (ChainType) {
6867
+ /** EVM chains (CAIP-2 namespace `eip155`). */
6868
+ ChainType["EVM"] = "eip155";
6869
+ /** Bitcoin (CAIP-2 namespace `bip122`). */
6870
+ ChainType["Bitcoin"] = "bip122";
6871
+ /** Solana (CAIP-2 namespace `solana`). */
6872
+ ChainType["Solana"] = "solana";
6873
+ /** Unknown / unrecognized CAIP-2 namespace. */
6874
+ ChainType["Unknown"] = "";
6875
+ })(ChainType || (ChainType = {}));
6876
+ /** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
6877
+ const CHAIN_TYPE_BY_NAMESPACE = {
6878
+ [ChainType.EVM]: ChainType.EVM,
6879
+ [ChainType.Bitcoin]: ChainType.Bitcoin,
6880
+ [ChainType.Solana]: ChainType.Solana,
6881
+ };
6882
+ /**
6883
+ * Resolve a CAIP-2 namespace from a chain-like value:
6884
+ * - an {@link IChainInfo} object: its `caip2Namespace`
6885
+ * - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
6886
+ * - a bare namespace string (e.g. `"eip155"`): used verbatim
6887
+ *
6888
+ * Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
6889
+ * namespace and resolves to {@link ChainType.Unknown} here. Use the
6890
+ * index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
6891
+ * those (they look the chain up first).
6892
+ */
6893
+ function namespaceOf(c) {
6894
+ if (typeof c === "string") {
6895
+ const sep = c.indexOf(":");
6896
+ return sep === -1 ? c : c.slice(0, sep);
6897
+ }
6898
+ return c.caip2Namespace;
6862
6899
  }
6863
- /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6864
- function isEvmChain(c) {
6865
- return !isNonEvmChain(c);
6900
+ /**
6901
+ * The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
6902
+ *
6903
+ * Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
6904
+ * like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
6905
+ * canonical way to determine a chain's family. Prefer it over inspecting the
6906
+ * numeric `id` (which is a placeholder for non-EVM chains).
6907
+ *
6908
+ * @example
6909
+ * ```ts
6910
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6911
+ * chainType(mainnet) // => ChainType.EVM
6912
+ * chainType(bitcoin) // => ChainType.Bitcoin
6913
+ * chainType("eip155:1") // => ChainType.EVM
6914
+ * chainType("bip122") // => ChainType.Bitcoin
6915
+ * ```
6916
+ */
6917
+ function chainType$1(c) {
6918
+ return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? ChainType.Unknown;
6919
+ }
6920
+ /**
6921
+ * True if the chain belongs to the given {@link ChainType} family.
6922
+ *
6923
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
6924
+ * checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
6925
+ *
6926
+ * @example
6927
+ * ```ts
6928
+ * import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
6929
+ * isNetworkType(ChainType.Bitcoin, bitcoin) // => true
6930
+ * isNetworkType(ChainType.EVM, bitcoin) // => false
6931
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
6932
+ * ```
6933
+ */
6934
+ function isNetworkType$1(type, c) {
6935
+ return chainType$1(c) === type;
6936
+ }
6937
+ /**
6938
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
6939
+ * {@link IChainInfo} object or a CAIP-2 string.
6940
+ */
6941
+ function isEvmChain$1(c) {
6942
+ return isNetworkType$1(ChainType.EVM, c);
6943
+ }
6944
+ /**
6945
+ * True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
6946
+ * Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
6947
+ * EVM-only fields (contracts, uniswap metadata, etc.) will be present but
6948
+ * empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
6949
+ */
6950
+ function isNonEvmChain$1(c) {
6951
+ return !isEvmChain$1(c);
6866
6952
  }
6867
6953
 
6868
6954
  /**
@@ -7306,5 +7392,92 @@ function networkByString(s) {
7306
7392
  function networkByCAIP2(caip2) {
7307
7393
  return networkByCAIP2$1(caip2, _idx);
7308
7394
  }
7395
+ /**
7396
+ * Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
7397
+ * `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
7398
+ */
7399
+ function namespaceOfChainLike(c) {
7400
+ if (typeof c === "object") {
7401
+ return c.caip2Namespace;
7402
+ }
7403
+ if (typeof c === "string") {
7404
+ // Full CAIP-2 identifier (namespace:reference) — classify by namespace.
7405
+ const sep = c.indexOf(":");
7406
+ if (sep !== -1) {
7407
+ return c.slice(0, sep);
7408
+ }
7409
+ // Bare CAIP-2 namespace (e.g. "eip155", "bip122").
7410
+ if (Object.values(ChainType).includes(c) && c !== "") {
7411
+ return c;
7412
+ }
7413
+ // Otherwise treat as an internal name or numeric id string: resolve it.
7414
+ try {
7415
+ return networkByString$1(c, _idx).caip2Namespace;
7416
+ }
7417
+ catch {
7418
+ return "";
7419
+ }
7420
+ }
7421
+ // Numeric chain id.
7422
+ try {
7423
+ return networkById$1(Math.trunc(c), _idx).caip2Namespace;
7424
+ }
7425
+ catch {
7426
+ return "";
7427
+ }
7428
+ }
7429
+ /**
7430
+ * The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
7431
+ * CAIP-2 identifier or namespace string, an internal name, or a numeric chain
7432
+ * id. Internal names and numeric ids are resolved via the network index.
7433
+ *
7434
+ * @example
7435
+ * ```ts
7436
+ * import { chainType, ChainType } from "@gfxlabs/oku-chains";
7437
+ * chainType(1) // => ChainType.EVM
7438
+ * chainType("mainnet") // => ChainType.EVM
7439
+ * chainType("eip155:1") // => ChainType.EVM
7440
+ * chainType("bitcoin") // => ChainType.Bitcoin
7441
+ * chainType("bip122") // => ChainType.Bitcoin
7442
+ * ```
7443
+ */
7444
+ function chainType(c) {
7445
+ return chainType$1(namespaceOfChainLike(c));
7446
+ }
7447
+ /**
7448
+ * True if the chain belongs to the given {@link ChainType} family. Accepts an
7449
+ * {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
7450
+ * internal name, or a numeric chain id.
7451
+ *
7452
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
7453
+ * checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
7454
+ *
7455
+ * @example
7456
+ * ```ts
7457
+ * import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
7458
+ * isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
7459
+ * isNetworkType(ChainType.EVM, 1) // => true
7460
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
7461
+ * ```
7462
+ */
7463
+ function isNetworkType(type, c) {
7464
+ return isNetworkType$1(type, namespaceOfChainLike(c));
7465
+ }
7466
+ /**
7467
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
7468
+ * {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
7469
+ * chain id.
7470
+ */
7471
+ function isEvmChain(c) {
7472
+ return isEvmChain$1(namespaceOfChainLike(c));
7473
+ }
7474
+ /**
7475
+ * True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
7476
+ * an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
7477
+ * numeric chain id.
7478
+ */
7479
+ function isNonEvmChain(c) {
7480
+ return isNonEvmChain$1(namespaceOfChainLike(c));
7481
+ }
7309
7482
 
7310
- export { ALL_NETWORKS, MAINNET_CHAINS, NON_EVM_CHAINS, NON_EVM_CHAIN_ID, NetworkNotFoundError, arbitrum, avalanche, base, bitcoin, blast, bob, boba, bsc, buildNetworkIndex, caip2Reference, celo, corn, etherlink, filecoin, formatCAIP2, fromCAIP2, gensyn, gnosis, goat, hemi, hyperevm, isEvmChain, isNonEvmChain, lens, lightlink, linea, lisk, mainnet, makeConfig, manta, mantle, matchain, metal, monad, moonbeam, networkByAny, networkByCAIP2, networkById, networkByName, networkByString, nibiru, optimism, parseCAIP2, pharos, plasma, polygon, polygonZkEvm, redbelly, ronin, rootstock, saga, scroll, sei, sonic, taiko, telos, toCAIP2, tronShasta, unichain, worldchain, xdc, zerog, zkSync };
7483
+ export { ALL_NETWORKS, ChainType, MAINNET_CHAINS, NON_EVM_CHAINS, NON_EVM_CHAIN_ID, NetworkNotFoundError, arbitrum, avalanche, base, bitcoin, blast, bob, boba, bsc, buildNetworkIndex, caip2Reference, celo, chainType, corn, etherlink, filecoin, formatCAIP2, fromCAIP2, gensyn, gnosis, goat, hemi, hyperevm, isEvmChain, isNetworkType, isNonEvmChain, lens, lightlink, linea, lisk, mainnet, makeConfig, manta, mantle, matchain, metal, monad, moonbeam, networkByAny, networkByCAIP2, networkById, networkByName, networkByString, nibiru, optimism, parseCAIP2, pharos, plasma, polygon, polygonZkEvm, redbelly, ronin, rootstock, saga, scroll, sei, sonic, taiko, telos, toCAIP2, tronShasta, unichain, worldchain, xdc, zerog, zkSync };
package/dist/index.js CHANGED
@@ -1260,6 +1260,7 @@ const celo = makeConfig({
1260
1260
  sortIndex: 10,
1261
1261
  logoUrl: "https://cms.oku.trade/cdn/public/chains/celo-logo.svg",
1262
1262
  deprecated: false,
1263
+ liteChain: true,
1263
1264
  estimatedSwapGas: 300000,
1264
1265
  estimatedBridgeGas: 200000,
1265
1266
  estimatedWrapGas: 60000,
@@ -6854,17 +6855,102 @@ const zkSync = makeConfig({
6854
6855
  */
6855
6856
  const NON_EVM_CHAIN_ID = 0;
6856
6857
  /**
6857
- * True if the chain is non-EVM (i.e. uses the {@link NON_EVM_CHAIN_ID}
6858
- * placeholder id and a non-`eip155` CAIP-2 namespace). Non-EVM chains live in
6859
- * the same {@link IChainInfo} shape as EVM chains, so EVM-only fields
6860
- * (contracts, uniswap metadata, etc.) will be present but empty.
6858
+ * High-level chain family, derived from the chain's CAIP-2 namespace.
6859
+ *
6860
+ * The underlying string value of each member is the CAIP-2 namespace it maps
6861
+ * to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
6862
+ * resolve a chain's type directly from its `caip2Namespace` without relying on
6863
+ * sentinel values like {@link NON_EVM_CHAIN_ID}.
6864
+ *
6865
+ * @see https://chainagnostic.org/CAIPs/caip-2
6861
6866
  */
6862
- function isNonEvmChain(c) {
6863
- return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6867
+ exports.ChainType = void 0;
6868
+ (function (ChainType) {
6869
+ /** EVM chains (CAIP-2 namespace `eip155`). */
6870
+ ChainType["EVM"] = "eip155";
6871
+ /** Bitcoin (CAIP-2 namespace `bip122`). */
6872
+ ChainType["Bitcoin"] = "bip122";
6873
+ /** Solana (CAIP-2 namespace `solana`). */
6874
+ ChainType["Solana"] = "solana";
6875
+ /** Unknown / unrecognized CAIP-2 namespace. */
6876
+ ChainType["Unknown"] = "";
6877
+ })(exports.ChainType || (exports.ChainType = {}));
6878
+ /** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
6879
+ const CHAIN_TYPE_BY_NAMESPACE = {
6880
+ [exports.ChainType.EVM]: exports.ChainType.EVM,
6881
+ [exports.ChainType.Bitcoin]: exports.ChainType.Bitcoin,
6882
+ [exports.ChainType.Solana]: exports.ChainType.Solana,
6883
+ };
6884
+ /**
6885
+ * Resolve a CAIP-2 namespace from a chain-like value:
6886
+ * - an {@link IChainInfo} object: its `caip2Namespace`
6887
+ * - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
6888
+ * - a bare namespace string (e.g. `"eip155"`): used verbatim
6889
+ *
6890
+ * Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
6891
+ * namespace and resolves to {@link ChainType.Unknown} here. Use the
6892
+ * index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
6893
+ * those (they look the chain up first).
6894
+ */
6895
+ function namespaceOf(c) {
6896
+ if (typeof c === "string") {
6897
+ const sep = c.indexOf(":");
6898
+ return sep === -1 ? c : c.slice(0, sep);
6899
+ }
6900
+ return c.caip2Namespace;
6864
6901
  }
6865
- /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6866
- function isEvmChain(c) {
6867
- return !isNonEvmChain(c);
6902
+ /**
6903
+ * The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
6904
+ *
6905
+ * Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
6906
+ * like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
6907
+ * canonical way to determine a chain's family. Prefer it over inspecting the
6908
+ * numeric `id` (which is a placeholder for non-EVM chains).
6909
+ *
6910
+ * @example
6911
+ * ```ts
6912
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6913
+ * chainType(mainnet) // => ChainType.EVM
6914
+ * chainType(bitcoin) // => ChainType.Bitcoin
6915
+ * chainType("eip155:1") // => ChainType.EVM
6916
+ * chainType("bip122") // => ChainType.Bitcoin
6917
+ * ```
6918
+ */
6919
+ function chainType$1(c) {
6920
+ return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? exports.ChainType.Unknown;
6921
+ }
6922
+ /**
6923
+ * True if the chain belongs to the given {@link ChainType} family.
6924
+ *
6925
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
6926
+ * checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
6927
+ *
6928
+ * @example
6929
+ * ```ts
6930
+ * import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
6931
+ * isNetworkType(ChainType.Bitcoin, bitcoin) // => true
6932
+ * isNetworkType(ChainType.EVM, bitcoin) // => false
6933
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
6934
+ * ```
6935
+ */
6936
+ function isNetworkType$1(type, c) {
6937
+ return chainType$1(c) === type;
6938
+ }
6939
+ /**
6940
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
6941
+ * {@link IChainInfo} object or a CAIP-2 string.
6942
+ */
6943
+ function isEvmChain$1(c) {
6944
+ return isNetworkType$1(exports.ChainType.EVM, c);
6945
+ }
6946
+ /**
6947
+ * True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
6948
+ * Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
6949
+ * EVM-only fields (contracts, uniswap metadata, etc.) will be present but
6950
+ * empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
6951
+ */
6952
+ function isNonEvmChain$1(c) {
6953
+ return !isEvmChain$1(c);
6868
6954
  }
6869
6955
 
6870
6956
  /**
@@ -7308,6 +7394,93 @@ function networkByString(s) {
7308
7394
  function networkByCAIP2(caip2) {
7309
7395
  return networkByCAIP2$1(caip2, _idx);
7310
7396
  }
7397
+ /**
7398
+ * Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
7399
+ * `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
7400
+ */
7401
+ function namespaceOfChainLike(c) {
7402
+ if (typeof c === "object") {
7403
+ return c.caip2Namespace;
7404
+ }
7405
+ if (typeof c === "string") {
7406
+ // Full CAIP-2 identifier (namespace:reference) — classify by namespace.
7407
+ const sep = c.indexOf(":");
7408
+ if (sep !== -1) {
7409
+ return c.slice(0, sep);
7410
+ }
7411
+ // Bare CAIP-2 namespace (e.g. "eip155", "bip122").
7412
+ if (Object.values(exports.ChainType).includes(c) && c !== "") {
7413
+ return c;
7414
+ }
7415
+ // Otherwise treat as an internal name or numeric id string: resolve it.
7416
+ try {
7417
+ return networkByString$1(c, _idx).caip2Namespace;
7418
+ }
7419
+ catch {
7420
+ return "";
7421
+ }
7422
+ }
7423
+ // Numeric chain id.
7424
+ try {
7425
+ return networkById$1(Math.trunc(c), _idx).caip2Namespace;
7426
+ }
7427
+ catch {
7428
+ return "";
7429
+ }
7430
+ }
7431
+ /**
7432
+ * The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
7433
+ * CAIP-2 identifier or namespace string, an internal name, or a numeric chain
7434
+ * id. Internal names and numeric ids are resolved via the network index.
7435
+ *
7436
+ * @example
7437
+ * ```ts
7438
+ * import { chainType, ChainType } from "@gfxlabs/oku-chains";
7439
+ * chainType(1) // => ChainType.EVM
7440
+ * chainType("mainnet") // => ChainType.EVM
7441
+ * chainType("eip155:1") // => ChainType.EVM
7442
+ * chainType("bitcoin") // => ChainType.Bitcoin
7443
+ * chainType("bip122") // => ChainType.Bitcoin
7444
+ * ```
7445
+ */
7446
+ function chainType(c) {
7447
+ return chainType$1(namespaceOfChainLike(c));
7448
+ }
7449
+ /**
7450
+ * True if the chain belongs to the given {@link ChainType} family. Accepts an
7451
+ * {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
7452
+ * internal name, or a numeric chain id.
7453
+ *
7454
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
7455
+ * checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
7456
+ *
7457
+ * @example
7458
+ * ```ts
7459
+ * import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
7460
+ * isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
7461
+ * isNetworkType(ChainType.EVM, 1) // => true
7462
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
7463
+ * ```
7464
+ */
7465
+ function isNetworkType(type, c) {
7466
+ return isNetworkType$1(type, namespaceOfChainLike(c));
7467
+ }
7468
+ /**
7469
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
7470
+ * {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
7471
+ * chain id.
7472
+ */
7473
+ function isEvmChain(c) {
7474
+ return isEvmChain$1(namespaceOfChainLike(c));
7475
+ }
7476
+ /**
7477
+ * True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
7478
+ * an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
7479
+ * numeric chain id.
7480
+ */
7481
+ function isNonEvmChain(c) {
7482
+ return isNonEvmChain$1(namespaceOfChainLike(c));
7483
+ }
7311
7484
 
7312
7485
  exports.ALL_NETWORKS = ALL_NETWORKS;
7313
7486
  exports.MAINNET_CHAINS = MAINNET_CHAINS;
@@ -7325,6 +7498,7 @@ exports.bsc = bsc;
7325
7498
  exports.buildNetworkIndex = buildNetworkIndex;
7326
7499
  exports.caip2Reference = caip2Reference;
7327
7500
  exports.celo = celo;
7501
+ exports.chainType = chainType;
7328
7502
  exports.corn = corn;
7329
7503
  exports.etherlink = etherlink;
7330
7504
  exports.filecoin = filecoin;
@@ -7336,6 +7510,7 @@ exports.goat = goat;
7336
7510
  exports.hemi = hemi;
7337
7511
  exports.hyperevm = hyperevm;
7338
7512
  exports.isEvmChain = isEvmChain;
7513
+ exports.isNetworkType = isNetworkType;
7339
7514
  exports.isNonEvmChain = isNonEvmChain;
7340
7515
  exports.lens = lens;
7341
7516
  exports.lightlink = lightlink;
@@ -5,6 +5,7 @@ export declare const celo: Readonly<{
5
5
  sortIndex: 10;
6
6
  logoUrl: "https://cms.oku.trade/cdn/public/chains/celo-logo.svg";
7
7
  deprecated: false;
8
+ liteChain: true;
8
9
  estimatedSwapGas: 300000;
9
10
  estimatedBridgeGas: 200000;
10
11
  estimatedWrapGas: 60000;
@@ -5,6 +5,7 @@ export * from "./util/caip2";
5
5
  export { makeConfig } from "./util/index";
6
6
  export { buildNetworkIndex, type NetworkIndex, NetworkNotFoundError, } from "./util/lookup";
7
7
  import type { IChainInfo } from "./spec";
8
+ import { ChainType } from "./spec";
8
9
  export declare const MAINNET_CHAINS: readonly [Readonly<{
9
10
  name: "Arbitrum";
10
11
  launchTime: 1688997600;
@@ -6255,6 +6256,7 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
6255
6256
  sortIndex: 10;
6256
6257
  logoUrl: "https://cms.oku.trade/cdn/public/chains/celo-logo.svg";
6257
6258
  deprecated: false;
6259
+ liteChain: true;
6258
6260
  estimatedSwapGas: 300000;
6259
6261
  estimatedBridgeGas: 200000;
6260
6262
  estimatedWrapGas: 60000;
@@ -10836,3 +10838,59 @@ export declare function networkByString(s: string): IChainInfo;
10836
10838
  * @throws {NetworkNotFoundError} if no matching chain is found
10837
10839
  */
10838
10840
  export declare function networkByCAIP2(caip2: string): IChainInfo;
10841
+ /**
10842
+ * Accepted input for the chain-family helpers ({@link chainType},
10843
+ * {@link isNetworkType}, etc.).
10844
+ *
10845
+ * - `IChainInfo`: classified by its `caip2Namespace`.
10846
+ * - CAIP-2 string (contains `:`, e.g. `"eip155:1"`) or bare namespace
10847
+ * (e.g. `"bip122"`): classified directly by the namespace, no lookup needed.
10848
+ * - internal name (e.g. `"bitcoin"`) or numeric id / id string: resolved to a
10849
+ * chain via the network index first, then classified.
10850
+ */
10851
+ export type ChainLike = IChainInfo | string | number;
10852
+ /**
10853
+ * The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
10854
+ * CAIP-2 identifier or namespace string, an internal name, or a numeric chain
10855
+ * id. Internal names and numeric ids are resolved via the network index.
10856
+ *
10857
+ * @example
10858
+ * ```ts
10859
+ * import { chainType, ChainType } from "@gfxlabs/oku-chains";
10860
+ * chainType(1) // => ChainType.EVM
10861
+ * chainType("mainnet") // => ChainType.EVM
10862
+ * chainType("eip155:1") // => ChainType.EVM
10863
+ * chainType("bitcoin") // => ChainType.Bitcoin
10864
+ * chainType("bip122") // => ChainType.Bitcoin
10865
+ * ```
10866
+ */
10867
+ export declare function chainType(c: ChainLike): ChainType;
10868
+ /**
10869
+ * True if the chain belongs to the given {@link ChainType} family. Accepts an
10870
+ * {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
10871
+ * internal name, or a numeric chain id.
10872
+ *
10873
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
10874
+ * checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
10875
+ *
10876
+ * @example
10877
+ * ```ts
10878
+ * import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
10879
+ * isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
10880
+ * isNetworkType(ChainType.EVM, 1) // => true
10881
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
10882
+ * ```
10883
+ */
10884
+ export declare function isNetworkType(type: ChainType, c: ChainLike): boolean;
10885
+ /**
10886
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
10887
+ * {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
10888
+ * chain id.
10889
+ */
10890
+ export declare function isEvmChain(c: ChainLike): boolean;
10891
+ /**
10892
+ * True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
10893
+ * an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
10894
+ * numeric chain id.
10895
+ */
10896
+ export declare function isNonEvmChain(c: ChainLike): boolean;
@@ -242,11 +242,67 @@ export interface IChainInfo<formatters extends ChainFormatters | undefined = Cha
242
242
  */
243
243
  export declare const NON_EVM_CHAIN_ID = 0;
244
244
  /**
245
- * True if the chain is non-EVM (i.e. uses the {@link NON_EVM_CHAIN_ID}
246
- * placeholder id and a non-`eip155` CAIP-2 namespace). Non-EVM chains live in
247
- * the same {@link IChainInfo} shape as EVM chains, so EVM-only fields
248
- * (contracts, uniswap metadata, etc.) will be present but empty.
245
+ * High-level chain family, derived from the chain's CAIP-2 namespace.
246
+ *
247
+ * The underlying string value of each member is the CAIP-2 namespace it maps
248
+ * to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
249
+ * resolve a chain's type directly from its `caip2Namespace` without relying on
250
+ * sentinel values like {@link NON_EVM_CHAIN_ID}.
251
+ *
252
+ * @see https://chainagnostic.org/CAIPs/caip-2
253
+ */
254
+ export declare enum ChainType {
255
+ /** EVM chains (CAIP-2 namespace `eip155`). */
256
+ EVM = "eip155",
257
+ /** Bitcoin (CAIP-2 namespace `bip122`). */
258
+ Bitcoin = "bip122",
259
+ /** Solana (CAIP-2 namespace `solana`). */
260
+ Solana = "solana",
261
+ /** Unknown / unrecognized CAIP-2 namespace. */
262
+ Unknown = ""
263
+ }
264
+ /**
265
+ * The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
266
+ *
267
+ * Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
268
+ * like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
269
+ * canonical way to determine a chain's family. Prefer it over inspecting the
270
+ * numeric `id` (which is a placeholder for non-EVM chains).
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
275
+ * chainType(mainnet) // => ChainType.EVM
276
+ * chainType(bitcoin) // => ChainType.Bitcoin
277
+ * chainType("eip155:1") // => ChainType.EVM
278
+ * chainType("bip122") // => ChainType.Bitcoin
279
+ * ```
280
+ */
281
+ export declare function chainType(c: IChainInfo | string): ChainType;
282
+ /**
283
+ * True if the chain belongs to the given {@link ChainType} family.
284
+ *
285
+ * Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
286
+ * checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
291
+ * isNetworkType(ChainType.Bitcoin, bitcoin) // => true
292
+ * isNetworkType(ChainType.EVM, bitcoin) // => false
293
+ * isNetworkType(ChainType.EVM, "eip155:1") // => true
294
+ * ```
295
+ */
296
+ export declare function isNetworkType(type: ChainType, c: IChainInfo | string): boolean;
297
+ /**
298
+ * True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
299
+ * {@link IChainInfo} object or a CAIP-2 string.
300
+ */
301
+ export declare function isEvmChain(c: IChainInfo | string): boolean;
302
+ /**
303
+ * True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
304
+ * Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
305
+ * EVM-only fields (contracts, uniswap metadata, etc.) will be present but
306
+ * empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
249
307
  */
250
- export declare function isNonEvmChain(c: IChainInfo): boolean;
251
- /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
252
- export declare function isEvmChain(c: IChainInfo): boolean;
308
+ export declare function isNonEvmChain(c: IChainInfo | string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfxlabs/oku-chains",
3
- "version": "1.12.5",
3
+ "version": "1.12.7",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index-mjs.js",