@gfxlabs/oku-chains 1.12.4 → 1.12.5

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
@@ -6845,6 +6845,111 @@
6845
6845
  },
6846
6846
  });
6847
6847
 
6848
+ /**
6849
+ * Placeholder numeric `id` used by non-EVM chains.
6850
+ *
6851
+ * viem's `Chain` (which {@link IChainInfo} extends) requires a numeric `id`,
6852
+ * but non-EVM chains (e.g. Bitcoin) have no EVM chain id. They use `0` as a
6853
+ * sentinel and rely on `caip2Namespace` + `caip2Reference` for identity and
6854
+ * resolution instead. `0` is never a valid EVM chain id, so it cannot collide.
6855
+ */
6856
+ const NON_EVM_CHAIN_ID = 0;
6857
+ /**
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.
6862
+ */
6863
+ function isNonEvmChain(c) {
6864
+ return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6865
+ }
6866
+ /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6867
+ function isEvmChain(c) {
6868
+ return !isNonEvmChain(c);
6869
+ }
6870
+
6871
+ /**
6872
+ * Bitcoin mainnet.
6873
+ *
6874
+ * A non-EVM chain expressed within the EVM-shaped {@link IChainInfo} so it
6875
+ * flows through the existing resolvers and consumers unchanged. Because viem's
6876
+ * `Chain` requires a numeric `id`, Bitcoin uses the {@link NON_EVM_CHAIN_ID}
6877
+ * (`0`) placeholder and is identified/resolved via CAIP-2 instead:
6878
+ * `bip122:000000000019d6689c085ae165831e93`, where the reference is the first
6879
+ * 32 hex chars of the genesis block hash per the CAIP-2 `bip122` namespace.
6880
+ *
6881
+ * EVM-only fields (uniswap, morpho, contracts, etc.) are present but empty.
6882
+ *
6883
+ * Refs:
6884
+ * - https://github.com/ChainAgnostic/namespaces/blob/main/bip122/caip2.md
6885
+ */
6886
+ const chain = viem.defineChain({
6887
+ id: NON_EVM_CHAIN_ID,
6888
+ name: "Bitcoin",
6889
+ nativeCurrency: {
6890
+ name: "Bitcoin",
6891
+ symbol: "BTC",
6892
+ decimals: 8,
6893
+ },
6894
+ rpcUrls: {
6895
+ default: {
6896
+ http: ["https://bitcoin-rpc.publicnode.com"],
6897
+ },
6898
+ },
6899
+ blockExplorers: {
6900
+ default: {
6901
+ name: "mempool.space",
6902
+ url: "https://mempool.space",
6903
+ apiUrl: "https://mempool.space/api",
6904
+ },
6905
+ },
6906
+ });
6907
+ const bitcoin = makeConfig({
6908
+ ...chain,
6909
+ caip2Namespace: "bip122",
6910
+ caip2Reference: "000000000019d6689c085ae165831e93",
6911
+ internalName: "bitcoin",
6912
+ transactionType: "bitcoin",
6913
+ sortIndex: 1000,
6914
+ launchTime: 1231006505,
6915
+ blockTimeSeconds: 600,
6916
+ deprecated: false,
6917
+ logoUrl: "https://cms.oku.trade/cdn/public/chains/bitcoin-logo.webp",
6918
+ nativeLogoUrl: "https://cms.oku.trade/cdn/public/natives/btc.png",
6919
+ blockAid: "bitcoin",
6920
+ estimatedSwapGas: 0,
6921
+ estimatedBridgeGas: 0,
6922
+ estimatedWrapGas: 0,
6923
+ initCodeHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
6924
+ defaultPool: "0x0000000000000000000000000000000000000000",
6925
+ defaultToken0: "0x0000000000000000000000000000000000000000",
6926
+ defaultToken1: "0x0000000000000000000000000000000000000000",
6927
+ tokenList: [],
6928
+ stables: [],
6929
+ watchlist: [],
6930
+ v4Watchlist: [],
6931
+ externalId: {
6932
+ coingecko: "bitcoin",
6933
+ },
6934
+ markets: {},
6935
+ bridges: {},
6936
+ oracles: {
6937
+ coingecko: {
6938
+ slug: "bitcoin",
6939
+ native: "bitcoin",
6940
+ },
6941
+ },
6942
+ uniswap: {},
6943
+ morpho: {},
6944
+ token: {},
6945
+ oku: {},
6946
+ contracts: {
6947
+ nftManager: {
6948
+ address: "0x0000000000000000000000000000000000000000",
6949
+ },
6950
+ },
6951
+ });
6952
+
6848
6953
  /**
6849
6954
  * Parse a CAIP-2 chain ID string into its namespace and reference components.
6850
6955
  *
@@ -6878,20 +6983,33 @@
6878
6983
  function formatCAIP2(id) {
6879
6984
  return `${id.namespace}:${id.reference}`;
6880
6985
  }
6986
+ /**
6987
+ * The CAIP-2 reference component for a chain.
6988
+ *
6989
+ * If the chain sets an explicit `caip2Reference` (e.g. a non-EVM chain like
6990
+ * Bitcoin, whose reference is a genesis hash prefix), it is used verbatim.
6991
+ * Otherwise the reference is derived from the numeric `id` (the historical
6992
+ * behavior for EVM chains, e.g. "1" for Ethereum mainnet).
6993
+ */
6994
+ function caip2Reference(chain) {
6995
+ return chain.caip2Reference ?? String(chain.id);
6996
+ }
6881
6997
  /**
6882
6998
  * Convert a chain config to its CAIP-2 identifier string.
6883
6999
  *
6884
7000
  * @example
6885
7001
  * ```ts
6886
- * import { mainnet } from "@gfxlabs/oku-chains";
7002
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6887
7003
  * toCAIP2(mainnet)
6888
7004
  * // => "eip155:1"
7005
+ * toCAIP2(bitcoin)
7006
+ * // => "bip122:000000000019d6689c085ae165831e93"
6889
7007
  * ```
6890
7008
  */
6891
7009
  function toCAIP2(chain) {
6892
7010
  return formatCAIP2({
6893
7011
  namespace: chain.caip2Namespace,
6894
- reference: String(chain.id),
7012
+ reference: caip2Reference(chain),
6895
7013
  });
6896
7014
  }
6897
7015
  /**
@@ -6908,7 +7026,7 @@
6908
7026
  */
6909
7027
  function fromCAIP2(caip2, chains) {
6910
7028
  const { namespace, reference } = parseCAIP2(caip2);
6911
- const chain = chains.find((c) => c.caip2Namespace === namespace && String(c.id) === reference);
7029
+ const chain = chains.find((c) => c.caip2Namespace === namespace && caip2Reference(c) === reference);
6912
7030
  if (!chain) {
6913
7031
  throw new Error(`No chain found for CAIP-2 identifier: "${caip2}"`);
6914
7032
  }
@@ -6927,20 +7045,28 @@
6927
7045
  /**
6928
7046
  * Build a lookup index from a list of chains for fast repeated lookups.
6929
7047
  * Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
7048
+ *
7049
+ * Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
7050
+ * intentionally NOT registered in `byId` (they are not resolvable by numeric
7051
+ * id, and would otherwise all collide on `0`). They remain resolvable by
7052
+ * internal name and by their explicit CAIP-2 identifier.
6930
7053
  */
6931
7054
  function buildNetworkIndex(chains) {
6932
7055
  const byId = new Map();
6933
7056
  const byName = new Map();
6934
7057
  const byCAIP2 = new Map();
6935
7058
  for (const chain of chains) {
6936
- byId.set(chain.id, chain);
7059
+ if (chain.id !== NON_EVM_CHAIN_ID) {
7060
+ byId.set(chain.id, chain);
7061
+ }
6937
7062
  byName.set(chain.internalName, chain);
6938
- byCAIP2.set(`${chain.caip2Namespace}:${chain.id}`, chain);
7063
+ byCAIP2.set(`${chain.caip2Namespace}:${caip2Reference(chain)}`, chain);
6939
7064
  }
6940
7065
  return { byId, byName, byCAIP2 };
6941
7066
  }
6942
7067
  /**
6943
- * Look up a chain by its numeric chain ID.
7068
+ * Look up a chain by its numeric chain ID. Non-EVM chains use the
7069
+ * {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
6944
7070
  */
6945
7071
  function networkById$1(id, idx) {
6946
7072
  const chain = idx.byId.get(id);
@@ -6950,7 +7076,8 @@
6950
7076
  return chain;
6951
7077
  }
6952
7078
  /**
6953
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7079
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7080
+ * "bitcoin").
6954
7081
  */
6955
7082
  function networkByName$1(name, idx) {
6956
7083
  const chain = idx.byName.get(name);
@@ -6960,7 +7087,9 @@
6960
7087
  return chain;
6961
7088
  }
6962
7089
  /**
6963
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7090
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7091
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7092
+ * non-EVM chains.
6964
7093
  */
6965
7094
  function networkByCAIP2$1(caip2, idx) {
6966
7095
  // Validate the format
@@ -6977,6 +7106,9 @@
6977
7106
  * 2. Internal name
6978
7107
  * 3. Numeric chain ID (parsed from string)
6979
7108
  *
7109
+ * Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
7110
+ * never via the numeric-id fallback.
7111
+ *
6980
7112
  * Mirrors the Go `NetworkByString` function.
6981
7113
  */
6982
7114
  function networkByString$1(s, idx) {
@@ -7004,11 +7136,14 @@
7004
7136
  }
7005
7137
  /**
7006
7138
  * Resolve a chain from an arbitrary input. Accepts:
7007
- * - `number`: treated as chain ID
7139
+ * - `number`: treated as a numeric chain ID (EVM-only)
7008
7140
  * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
7009
7141
  * internal name, then as a numeric chain ID string
7010
7142
  * - `IChainInfo`: returned directly (pass-through)
7011
7143
  *
7144
+ * Non-EVM chains have a placeholder numeric id, so they can only be resolved
7145
+ * via their CAIP-2 identifier or internal name (or passed through directly).
7146
+ *
7012
7147
  * Mirrors the Go `NetworkByAny` function.
7013
7148
  *
7014
7149
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7082,8 +7217,29 @@
7082
7217
  gensyn,
7083
7218
  pharos,
7084
7219
  ];
7085
- /** Pre-built lookup index over MAINNET_CHAINS (like Go's module-level maps). */
7086
- const _idx = buildNetworkIndex(MAINNET_CHAINS);
7220
+ /**
7221
+ * Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
7222
+ * EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
7223
+ * resolvable only via CAIP-2 (or internal name). Kept as a separate array so
7224
+ * the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
7225
+ * unaffected.
7226
+ */
7227
+ const NON_EVM_CHAINS = [
7228
+ bitcoin,
7229
+ ];
7230
+ /**
7231
+ * All networks, EVM and non-EVM. Use this when you need to enumerate every
7232
+ * supported chain regardless of type.
7233
+ */
7234
+ const ALL_NETWORKS = [
7235
+ ...MAINNET_CHAINS,
7236
+ ...NON_EVM_CHAINS,
7237
+ ];
7238
+ /**
7239
+ * Pre-built lookup index over all networks (EVM + non-EVM), like Go's
7240
+ * module-level maps. Resolution functions below bind to this index.
7241
+ */
7242
+ const _idx = buildNetworkIndex(ALL_NETWORKS);
7087
7243
  /**
7088
7244
  * Resolve a chain from an arbitrary input. Accepts:
7089
7245
  * - `number`: treated as chain ID
@@ -7093,14 +7249,20 @@
7093
7249
  *
7094
7250
  * Mirrors the Go `NetworkByAny` function.
7095
7251
  *
7252
+ * Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
7253
+ * resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
7254
+ * if you need to distinguish them.
7255
+ *
7096
7256
  * @example
7097
7257
  * ```ts
7098
7258
  * import { networkByAny } from "@gfxlabs/oku-chains";
7099
7259
  *
7100
- * networkByAny(1) // by chain ID
7260
+ * networkByAny(1) // by chain ID (EVM)
7101
7261
  * networkByAny("mainnet") // by internal name
7102
- * networkByAny("eip155:1") // by CAIP-2
7103
- * networkByAny("42161") // by chain ID string
7262
+ * networkByAny("eip155:1") // by CAIP-2 (EVM)
7263
+ * networkByAny("42161") // by chain ID string (EVM)
7264
+ * networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
7265
+ * networkByAny("bitcoin") // by internal name (non-EVM)
7104
7266
  * ```
7105
7267
  *
7106
7268
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7109,7 +7271,8 @@
7109
7271
  return networkByAny$1(v, _idx);
7110
7272
  }
7111
7273
  /**
7112
- * Look up a chain by its numeric chain ID.
7274
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
7275
+ * and are not resolvable here.
7113
7276
  *
7114
7277
  * @throws {NetworkNotFoundError} if no matching chain is found
7115
7278
  */
@@ -7117,7 +7280,8 @@
7117
7280
  return networkById$1(id, _idx);
7118
7281
  }
7119
7282
  /**
7120
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7283
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7284
+ * "bitcoin").
7121
7285
  *
7122
7286
  * @throws {NetworkNotFoundError} if no matching chain is found
7123
7287
  */
@@ -7136,7 +7300,9 @@
7136
7300
  return networkByString$1(s, _idx);
7137
7301
  }
7138
7302
  /**
7139
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7303
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7304
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7305
+ * non-EVM chains.
7140
7306
  *
7141
7307
  * @throws {NetworkNotFoundError} if no matching chain is found
7142
7308
  */
@@ -7144,16 +7310,21 @@
7144
7310
  return networkByCAIP2$1(caip2, _idx);
7145
7311
  }
7146
7312
 
7313
+ exports.ALL_NETWORKS = ALL_NETWORKS;
7147
7314
  exports.MAINNET_CHAINS = MAINNET_CHAINS;
7315
+ exports.NON_EVM_CHAINS = NON_EVM_CHAINS;
7316
+ exports.NON_EVM_CHAIN_ID = NON_EVM_CHAIN_ID;
7148
7317
  exports.NetworkNotFoundError = NetworkNotFoundError;
7149
7318
  exports.arbitrum = arbitrum;
7150
7319
  exports.avalanche = avalanche;
7151
7320
  exports.base = base;
7321
+ exports.bitcoin = bitcoin;
7152
7322
  exports.blast = blast;
7153
7323
  exports.bob = bob;
7154
7324
  exports.boba = boba;
7155
7325
  exports.bsc = bsc;
7156
7326
  exports.buildNetworkIndex = buildNetworkIndex;
7327
+ exports.caip2Reference = caip2Reference;
7157
7328
  exports.celo = celo;
7158
7329
  exports.corn = corn;
7159
7330
  exports.etherlink = etherlink;
@@ -7165,11 +7336,14 @@
7165
7336
  exports.goat = goat;
7166
7337
  exports.hemi = hemi;
7167
7338
  exports.hyperevm = hyperevm;
7339
+ exports.isEvmChain = isEvmChain;
7340
+ exports.isNonEvmChain = isNonEvmChain;
7168
7341
  exports.lens = lens;
7169
7342
  exports.lightlink = lightlink;
7170
7343
  exports.linea = linea;
7171
7344
  exports.lisk = lisk;
7172
7345
  exports.mainnet = mainnet;
7346
+ exports.makeConfig = makeConfig;
7173
7347
  exports.manta = manta;
7174
7348
  exports.mantle = mantle;
7175
7349
  exports.matchain = matchain;
package/dist/index-mjs.js CHANGED
@@ -6842,6 +6842,111 @@ const zkSync = makeConfig({
6842
6842
  },
6843
6843
  });
6844
6844
 
6845
+ /**
6846
+ * Placeholder numeric `id` used by non-EVM chains.
6847
+ *
6848
+ * viem's `Chain` (which {@link IChainInfo} extends) requires a numeric `id`,
6849
+ * but non-EVM chains (e.g. Bitcoin) have no EVM chain id. They use `0` as a
6850
+ * sentinel and rely on `caip2Namespace` + `caip2Reference` for identity and
6851
+ * resolution instead. `0` is never a valid EVM chain id, so it cannot collide.
6852
+ */
6853
+ const NON_EVM_CHAIN_ID = 0;
6854
+ /**
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.
6859
+ */
6860
+ function isNonEvmChain(c) {
6861
+ return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6862
+ }
6863
+ /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6864
+ function isEvmChain(c) {
6865
+ return !isNonEvmChain(c);
6866
+ }
6867
+
6868
+ /**
6869
+ * Bitcoin mainnet.
6870
+ *
6871
+ * A non-EVM chain expressed within the EVM-shaped {@link IChainInfo} so it
6872
+ * flows through the existing resolvers and consumers unchanged. Because viem's
6873
+ * `Chain` requires a numeric `id`, Bitcoin uses the {@link NON_EVM_CHAIN_ID}
6874
+ * (`0`) placeholder and is identified/resolved via CAIP-2 instead:
6875
+ * `bip122:000000000019d6689c085ae165831e93`, where the reference is the first
6876
+ * 32 hex chars of the genesis block hash per the CAIP-2 `bip122` namespace.
6877
+ *
6878
+ * EVM-only fields (uniswap, morpho, contracts, etc.) are present but empty.
6879
+ *
6880
+ * Refs:
6881
+ * - https://github.com/ChainAgnostic/namespaces/blob/main/bip122/caip2.md
6882
+ */
6883
+ const chain = defineChain({
6884
+ id: NON_EVM_CHAIN_ID,
6885
+ name: "Bitcoin",
6886
+ nativeCurrency: {
6887
+ name: "Bitcoin",
6888
+ symbol: "BTC",
6889
+ decimals: 8,
6890
+ },
6891
+ rpcUrls: {
6892
+ default: {
6893
+ http: ["https://bitcoin-rpc.publicnode.com"],
6894
+ },
6895
+ },
6896
+ blockExplorers: {
6897
+ default: {
6898
+ name: "mempool.space",
6899
+ url: "https://mempool.space",
6900
+ apiUrl: "https://mempool.space/api",
6901
+ },
6902
+ },
6903
+ });
6904
+ const bitcoin = makeConfig({
6905
+ ...chain,
6906
+ caip2Namespace: "bip122",
6907
+ caip2Reference: "000000000019d6689c085ae165831e93",
6908
+ internalName: "bitcoin",
6909
+ transactionType: "bitcoin",
6910
+ sortIndex: 1000,
6911
+ launchTime: 1231006505,
6912
+ blockTimeSeconds: 600,
6913
+ deprecated: false,
6914
+ logoUrl: "https://cms.oku.trade/cdn/public/chains/bitcoin-logo.webp",
6915
+ nativeLogoUrl: "https://cms.oku.trade/cdn/public/natives/btc.png",
6916
+ blockAid: "bitcoin",
6917
+ estimatedSwapGas: 0,
6918
+ estimatedBridgeGas: 0,
6919
+ estimatedWrapGas: 0,
6920
+ initCodeHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
6921
+ defaultPool: "0x0000000000000000000000000000000000000000",
6922
+ defaultToken0: "0x0000000000000000000000000000000000000000",
6923
+ defaultToken1: "0x0000000000000000000000000000000000000000",
6924
+ tokenList: [],
6925
+ stables: [],
6926
+ watchlist: [],
6927
+ v4Watchlist: [],
6928
+ externalId: {
6929
+ coingecko: "bitcoin",
6930
+ },
6931
+ markets: {},
6932
+ bridges: {},
6933
+ oracles: {
6934
+ coingecko: {
6935
+ slug: "bitcoin",
6936
+ native: "bitcoin",
6937
+ },
6938
+ },
6939
+ uniswap: {},
6940
+ morpho: {},
6941
+ token: {},
6942
+ oku: {},
6943
+ contracts: {
6944
+ nftManager: {
6945
+ address: "0x0000000000000000000000000000000000000000",
6946
+ },
6947
+ },
6948
+ });
6949
+
6845
6950
  /**
6846
6951
  * Parse a CAIP-2 chain ID string into its namespace and reference components.
6847
6952
  *
@@ -6875,20 +6980,33 @@ function parseCAIP2(caip2) {
6875
6980
  function formatCAIP2(id) {
6876
6981
  return `${id.namespace}:${id.reference}`;
6877
6982
  }
6983
+ /**
6984
+ * The CAIP-2 reference component for a chain.
6985
+ *
6986
+ * If the chain sets an explicit `caip2Reference` (e.g. a non-EVM chain like
6987
+ * Bitcoin, whose reference is a genesis hash prefix), it is used verbatim.
6988
+ * Otherwise the reference is derived from the numeric `id` (the historical
6989
+ * behavior for EVM chains, e.g. "1" for Ethereum mainnet).
6990
+ */
6991
+ function caip2Reference(chain) {
6992
+ return chain.caip2Reference ?? String(chain.id);
6993
+ }
6878
6994
  /**
6879
6995
  * Convert a chain config to its CAIP-2 identifier string.
6880
6996
  *
6881
6997
  * @example
6882
6998
  * ```ts
6883
- * import { mainnet } from "@gfxlabs/oku-chains";
6999
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6884
7000
  * toCAIP2(mainnet)
6885
7001
  * // => "eip155:1"
7002
+ * toCAIP2(bitcoin)
7003
+ * // => "bip122:000000000019d6689c085ae165831e93"
6886
7004
  * ```
6887
7005
  */
6888
7006
  function toCAIP2(chain) {
6889
7007
  return formatCAIP2({
6890
7008
  namespace: chain.caip2Namespace,
6891
- reference: String(chain.id),
7009
+ reference: caip2Reference(chain),
6892
7010
  });
6893
7011
  }
6894
7012
  /**
@@ -6905,7 +7023,7 @@ function toCAIP2(chain) {
6905
7023
  */
6906
7024
  function fromCAIP2(caip2, chains) {
6907
7025
  const { namespace, reference } = parseCAIP2(caip2);
6908
- const chain = chains.find((c) => c.caip2Namespace === namespace && String(c.id) === reference);
7026
+ const chain = chains.find((c) => c.caip2Namespace === namespace && caip2Reference(c) === reference);
6909
7027
  if (!chain) {
6910
7028
  throw new Error(`No chain found for CAIP-2 identifier: "${caip2}"`);
6911
7029
  }
@@ -6924,20 +7042,28 @@ class NetworkNotFoundError extends Error {
6924
7042
  /**
6925
7043
  * Build a lookup index from a list of chains for fast repeated lookups.
6926
7044
  * Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
7045
+ *
7046
+ * Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
7047
+ * intentionally NOT registered in `byId` (they are not resolvable by numeric
7048
+ * id, and would otherwise all collide on `0`). They remain resolvable by
7049
+ * internal name and by their explicit CAIP-2 identifier.
6927
7050
  */
6928
7051
  function buildNetworkIndex(chains) {
6929
7052
  const byId = new Map();
6930
7053
  const byName = new Map();
6931
7054
  const byCAIP2 = new Map();
6932
7055
  for (const chain of chains) {
6933
- byId.set(chain.id, chain);
7056
+ if (chain.id !== NON_EVM_CHAIN_ID) {
7057
+ byId.set(chain.id, chain);
7058
+ }
6934
7059
  byName.set(chain.internalName, chain);
6935
- byCAIP2.set(`${chain.caip2Namespace}:${chain.id}`, chain);
7060
+ byCAIP2.set(`${chain.caip2Namespace}:${caip2Reference(chain)}`, chain);
6936
7061
  }
6937
7062
  return { byId, byName, byCAIP2 };
6938
7063
  }
6939
7064
  /**
6940
- * Look up a chain by its numeric chain ID.
7065
+ * Look up a chain by its numeric chain ID. Non-EVM chains use the
7066
+ * {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
6941
7067
  */
6942
7068
  function networkById$1(id, idx) {
6943
7069
  const chain = idx.byId.get(id);
@@ -6947,7 +7073,8 @@ function networkById$1(id, idx) {
6947
7073
  return chain;
6948
7074
  }
6949
7075
  /**
6950
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7076
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7077
+ * "bitcoin").
6951
7078
  */
6952
7079
  function networkByName$1(name, idx) {
6953
7080
  const chain = idx.byName.get(name);
@@ -6957,7 +7084,9 @@ function networkByName$1(name, idx) {
6957
7084
  return chain;
6958
7085
  }
6959
7086
  /**
6960
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7087
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7088
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7089
+ * non-EVM chains.
6961
7090
  */
6962
7091
  function networkByCAIP2$1(caip2, idx) {
6963
7092
  // Validate the format
@@ -6974,6 +7103,9 @@ function networkByCAIP2$1(caip2, idx) {
6974
7103
  * 2. Internal name
6975
7104
  * 3. Numeric chain ID (parsed from string)
6976
7105
  *
7106
+ * Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
7107
+ * never via the numeric-id fallback.
7108
+ *
6977
7109
  * Mirrors the Go `NetworkByString` function.
6978
7110
  */
6979
7111
  function networkByString$1(s, idx) {
@@ -7001,11 +7133,14 @@ function networkByString$1(s, idx) {
7001
7133
  }
7002
7134
  /**
7003
7135
  * Resolve a chain from an arbitrary input. Accepts:
7004
- * - `number`: treated as chain ID
7136
+ * - `number`: treated as a numeric chain ID (EVM-only)
7005
7137
  * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
7006
7138
  * internal name, then as a numeric chain ID string
7007
7139
  * - `IChainInfo`: returned directly (pass-through)
7008
7140
  *
7141
+ * Non-EVM chains have a placeholder numeric id, so they can only be resolved
7142
+ * via their CAIP-2 identifier or internal name (or passed through directly).
7143
+ *
7009
7144
  * Mirrors the Go `NetworkByAny` function.
7010
7145
  *
7011
7146
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7079,8 +7214,29 @@ const MAINNET_CHAINS = [
7079
7214
  gensyn,
7080
7215
  pharos,
7081
7216
  ];
7082
- /** Pre-built lookup index over MAINNET_CHAINS (like Go's module-level maps). */
7083
- const _idx = buildNetworkIndex(MAINNET_CHAINS);
7217
+ /**
7218
+ * Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
7219
+ * EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
7220
+ * resolvable only via CAIP-2 (or internal name). Kept as a separate array so
7221
+ * the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
7222
+ * unaffected.
7223
+ */
7224
+ const NON_EVM_CHAINS = [
7225
+ bitcoin,
7226
+ ];
7227
+ /**
7228
+ * All networks, EVM and non-EVM. Use this when you need to enumerate every
7229
+ * supported chain regardless of type.
7230
+ */
7231
+ const ALL_NETWORKS = [
7232
+ ...MAINNET_CHAINS,
7233
+ ...NON_EVM_CHAINS,
7234
+ ];
7235
+ /**
7236
+ * Pre-built lookup index over all networks (EVM + non-EVM), like Go's
7237
+ * module-level maps. Resolution functions below bind to this index.
7238
+ */
7239
+ const _idx = buildNetworkIndex(ALL_NETWORKS);
7084
7240
  /**
7085
7241
  * Resolve a chain from an arbitrary input. Accepts:
7086
7242
  * - `number`: treated as chain ID
@@ -7090,14 +7246,20 @@ const _idx = buildNetworkIndex(MAINNET_CHAINS);
7090
7246
  *
7091
7247
  * Mirrors the Go `NetworkByAny` function.
7092
7248
  *
7249
+ * Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
7250
+ * resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
7251
+ * if you need to distinguish them.
7252
+ *
7093
7253
  * @example
7094
7254
  * ```ts
7095
7255
  * import { networkByAny } from "@gfxlabs/oku-chains";
7096
7256
  *
7097
- * networkByAny(1) // by chain ID
7257
+ * networkByAny(1) // by chain ID (EVM)
7098
7258
  * networkByAny("mainnet") // by internal name
7099
- * networkByAny("eip155:1") // by CAIP-2
7100
- * networkByAny("42161") // by chain ID string
7259
+ * networkByAny("eip155:1") // by CAIP-2 (EVM)
7260
+ * networkByAny("42161") // by chain ID string (EVM)
7261
+ * networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
7262
+ * networkByAny("bitcoin") // by internal name (non-EVM)
7101
7263
  * ```
7102
7264
  *
7103
7265
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7106,7 +7268,8 @@ function networkByAny(v) {
7106
7268
  return networkByAny$1(v, _idx);
7107
7269
  }
7108
7270
  /**
7109
- * Look up a chain by its numeric chain ID.
7271
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
7272
+ * and are not resolvable here.
7110
7273
  *
7111
7274
  * @throws {NetworkNotFoundError} if no matching chain is found
7112
7275
  */
@@ -7114,7 +7277,8 @@ function networkById(id) {
7114
7277
  return networkById$1(id, _idx);
7115
7278
  }
7116
7279
  /**
7117
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7280
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7281
+ * "bitcoin").
7118
7282
  *
7119
7283
  * @throws {NetworkNotFoundError} if no matching chain is found
7120
7284
  */
@@ -7133,7 +7297,9 @@ function networkByString(s) {
7133
7297
  return networkByString$1(s, _idx);
7134
7298
  }
7135
7299
  /**
7136
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7300
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7301
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7302
+ * non-EVM chains.
7137
7303
  *
7138
7304
  * @throws {NetworkNotFoundError} if no matching chain is found
7139
7305
  */
@@ -7141,4 +7307,4 @@ function networkByCAIP2(caip2) {
7141
7307
  return networkByCAIP2$1(caip2, _idx);
7142
7308
  }
7143
7309
 
7144
- export { MAINNET_CHAINS, NetworkNotFoundError, arbitrum, avalanche, base, blast, bob, boba, bsc, buildNetworkIndex, celo, corn, etherlink, filecoin, formatCAIP2, fromCAIP2, gensyn, gnosis, goat, hemi, hyperevm, lens, lightlink, linea, lisk, mainnet, 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 };
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 };
package/dist/index.js CHANGED
@@ -6844,6 +6844,111 @@ const zkSync = makeConfig({
6844
6844
  },
6845
6845
  });
6846
6846
 
6847
+ /**
6848
+ * Placeholder numeric `id` used by non-EVM chains.
6849
+ *
6850
+ * viem's `Chain` (which {@link IChainInfo} extends) requires a numeric `id`,
6851
+ * but non-EVM chains (e.g. Bitcoin) have no EVM chain id. They use `0` as a
6852
+ * sentinel and rely on `caip2Namespace` + `caip2Reference` for identity and
6853
+ * resolution instead. `0` is never a valid EVM chain id, so it cannot collide.
6854
+ */
6855
+ const NON_EVM_CHAIN_ID = 0;
6856
+ /**
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.
6861
+ */
6862
+ function isNonEvmChain(c) {
6863
+ return c.id === NON_EVM_CHAIN_ID && c.caip2Namespace !== "eip155";
6864
+ }
6865
+ /** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
6866
+ function isEvmChain(c) {
6867
+ return !isNonEvmChain(c);
6868
+ }
6869
+
6870
+ /**
6871
+ * Bitcoin mainnet.
6872
+ *
6873
+ * A non-EVM chain expressed within the EVM-shaped {@link IChainInfo} so it
6874
+ * flows through the existing resolvers and consumers unchanged. Because viem's
6875
+ * `Chain` requires a numeric `id`, Bitcoin uses the {@link NON_EVM_CHAIN_ID}
6876
+ * (`0`) placeholder and is identified/resolved via CAIP-2 instead:
6877
+ * `bip122:000000000019d6689c085ae165831e93`, where the reference is the first
6878
+ * 32 hex chars of the genesis block hash per the CAIP-2 `bip122` namespace.
6879
+ *
6880
+ * EVM-only fields (uniswap, morpho, contracts, etc.) are present but empty.
6881
+ *
6882
+ * Refs:
6883
+ * - https://github.com/ChainAgnostic/namespaces/blob/main/bip122/caip2.md
6884
+ */
6885
+ const chain = viem.defineChain({
6886
+ id: NON_EVM_CHAIN_ID,
6887
+ name: "Bitcoin",
6888
+ nativeCurrency: {
6889
+ name: "Bitcoin",
6890
+ symbol: "BTC",
6891
+ decimals: 8,
6892
+ },
6893
+ rpcUrls: {
6894
+ default: {
6895
+ http: ["https://bitcoin-rpc.publicnode.com"],
6896
+ },
6897
+ },
6898
+ blockExplorers: {
6899
+ default: {
6900
+ name: "mempool.space",
6901
+ url: "https://mempool.space",
6902
+ apiUrl: "https://mempool.space/api",
6903
+ },
6904
+ },
6905
+ });
6906
+ const bitcoin = makeConfig({
6907
+ ...chain,
6908
+ caip2Namespace: "bip122",
6909
+ caip2Reference: "000000000019d6689c085ae165831e93",
6910
+ internalName: "bitcoin",
6911
+ transactionType: "bitcoin",
6912
+ sortIndex: 1000,
6913
+ launchTime: 1231006505,
6914
+ blockTimeSeconds: 600,
6915
+ deprecated: false,
6916
+ logoUrl: "https://cms.oku.trade/cdn/public/chains/bitcoin-logo.webp",
6917
+ nativeLogoUrl: "https://cms.oku.trade/cdn/public/natives/btc.png",
6918
+ blockAid: "bitcoin",
6919
+ estimatedSwapGas: 0,
6920
+ estimatedBridgeGas: 0,
6921
+ estimatedWrapGas: 0,
6922
+ initCodeHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
6923
+ defaultPool: "0x0000000000000000000000000000000000000000",
6924
+ defaultToken0: "0x0000000000000000000000000000000000000000",
6925
+ defaultToken1: "0x0000000000000000000000000000000000000000",
6926
+ tokenList: [],
6927
+ stables: [],
6928
+ watchlist: [],
6929
+ v4Watchlist: [],
6930
+ externalId: {
6931
+ coingecko: "bitcoin",
6932
+ },
6933
+ markets: {},
6934
+ bridges: {},
6935
+ oracles: {
6936
+ coingecko: {
6937
+ slug: "bitcoin",
6938
+ native: "bitcoin",
6939
+ },
6940
+ },
6941
+ uniswap: {},
6942
+ morpho: {},
6943
+ token: {},
6944
+ oku: {},
6945
+ contracts: {
6946
+ nftManager: {
6947
+ address: "0x0000000000000000000000000000000000000000",
6948
+ },
6949
+ },
6950
+ });
6951
+
6847
6952
  /**
6848
6953
  * Parse a CAIP-2 chain ID string into its namespace and reference components.
6849
6954
  *
@@ -6877,20 +6982,33 @@ function parseCAIP2(caip2) {
6877
6982
  function formatCAIP2(id) {
6878
6983
  return `${id.namespace}:${id.reference}`;
6879
6984
  }
6985
+ /**
6986
+ * The CAIP-2 reference component for a chain.
6987
+ *
6988
+ * If the chain sets an explicit `caip2Reference` (e.g. a non-EVM chain like
6989
+ * Bitcoin, whose reference is a genesis hash prefix), it is used verbatim.
6990
+ * Otherwise the reference is derived from the numeric `id` (the historical
6991
+ * behavior for EVM chains, e.g. "1" for Ethereum mainnet).
6992
+ */
6993
+ function caip2Reference(chain) {
6994
+ return chain.caip2Reference ?? String(chain.id);
6995
+ }
6880
6996
  /**
6881
6997
  * Convert a chain config to its CAIP-2 identifier string.
6882
6998
  *
6883
6999
  * @example
6884
7000
  * ```ts
6885
- * import { mainnet } from "@gfxlabs/oku-chains";
7001
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
6886
7002
  * toCAIP2(mainnet)
6887
7003
  * // => "eip155:1"
7004
+ * toCAIP2(bitcoin)
7005
+ * // => "bip122:000000000019d6689c085ae165831e93"
6888
7006
  * ```
6889
7007
  */
6890
7008
  function toCAIP2(chain) {
6891
7009
  return formatCAIP2({
6892
7010
  namespace: chain.caip2Namespace,
6893
- reference: String(chain.id),
7011
+ reference: caip2Reference(chain),
6894
7012
  });
6895
7013
  }
6896
7014
  /**
@@ -6907,7 +7025,7 @@ function toCAIP2(chain) {
6907
7025
  */
6908
7026
  function fromCAIP2(caip2, chains) {
6909
7027
  const { namespace, reference } = parseCAIP2(caip2);
6910
- const chain = chains.find((c) => c.caip2Namespace === namespace && String(c.id) === reference);
7028
+ const chain = chains.find((c) => c.caip2Namespace === namespace && caip2Reference(c) === reference);
6911
7029
  if (!chain) {
6912
7030
  throw new Error(`No chain found for CAIP-2 identifier: "${caip2}"`);
6913
7031
  }
@@ -6926,20 +7044,28 @@ class NetworkNotFoundError extends Error {
6926
7044
  /**
6927
7045
  * Build a lookup index from a list of chains for fast repeated lookups.
6928
7046
  * Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
7047
+ *
7048
+ * Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
7049
+ * intentionally NOT registered in `byId` (they are not resolvable by numeric
7050
+ * id, and would otherwise all collide on `0`). They remain resolvable by
7051
+ * internal name and by their explicit CAIP-2 identifier.
6929
7052
  */
6930
7053
  function buildNetworkIndex(chains) {
6931
7054
  const byId = new Map();
6932
7055
  const byName = new Map();
6933
7056
  const byCAIP2 = new Map();
6934
7057
  for (const chain of chains) {
6935
- byId.set(chain.id, chain);
7058
+ if (chain.id !== NON_EVM_CHAIN_ID) {
7059
+ byId.set(chain.id, chain);
7060
+ }
6936
7061
  byName.set(chain.internalName, chain);
6937
- byCAIP2.set(`${chain.caip2Namespace}:${chain.id}`, chain);
7062
+ byCAIP2.set(`${chain.caip2Namespace}:${caip2Reference(chain)}`, chain);
6938
7063
  }
6939
7064
  return { byId, byName, byCAIP2 };
6940
7065
  }
6941
7066
  /**
6942
- * Look up a chain by its numeric chain ID.
7067
+ * Look up a chain by its numeric chain ID. Non-EVM chains use the
7068
+ * {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
6943
7069
  */
6944
7070
  function networkById$1(id, idx) {
6945
7071
  const chain = idx.byId.get(id);
@@ -6949,7 +7075,8 @@ function networkById$1(id, idx) {
6949
7075
  return chain;
6950
7076
  }
6951
7077
  /**
6952
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7078
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7079
+ * "bitcoin").
6953
7080
  */
6954
7081
  function networkByName$1(name, idx) {
6955
7082
  const chain = idx.byName.get(name);
@@ -6959,7 +7086,9 @@ function networkByName$1(name, idx) {
6959
7086
  return chain;
6960
7087
  }
6961
7088
  /**
6962
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7089
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7090
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7091
+ * non-EVM chains.
6963
7092
  */
6964
7093
  function networkByCAIP2$1(caip2, idx) {
6965
7094
  // Validate the format
@@ -6976,6 +7105,9 @@ function networkByCAIP2$1(caip2, idx) {
6976
7105
  * 2. Internal name
6977
7106
  * 3. Numeric chain ID (parsed from string)
6978
7107
  *
7108
+ * Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
7109
+ * never via the numeric-id fallback.
7110
+ *
6979
7111
  * Mirrors the Go `NetworkByString` function.
6980
7112
  */
6981
7113
  function networkByString$1(s, idx) {
@@ -7003,11 +7135,14 @@ function networkByString$1(s, idx) {
7003
7135
  }
7004
7136
  /**
7005
7137
  * Resolve a chain from an arbitrary input. Accepts:
7006
- * - `number`: treated as chain ID
7138
+ * - `number`: treated as a numeric chain ID (EVM-only)
7007
7139
  * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
7008
7140
  * internal name, then as a numeric chain ID string
7009
7141
  * - `IChainInfo`: returned directly (pass-through)
7010
7142
  *
7143
+ * Non-EVM chains have a placeholder numeric id, so they can only be resolved
7144
+ * via their CAIP-2 identifier or internal name (or passed through directly).
7145
+ *
7011
7146
  * Mirrors the Go `NetworkByAny` function.
7012
7147
  *
7013
7148
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7081,8 +7216,29 @@ const MAINNET_CHAINS = [
7081
7216
  gensyn,
7082
7217
  pharos,
7083
7218
  ];
7084
- /** Pre-built lookup index over MAINNET_CHAINS (like Go's module-level maps). */
7085
- const _idx = buildNetworkIndex(MAINNET_CHAINS);
7219
+ /**
7220
+ * Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
7221
+ * EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
7222
+ * resolvable only via CAIP-2 (or internal name). Kept as a separate array so
7223
+ * the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
7224
+ * unaffected.
7225
+ */
7226
+ const NON_EVM_CHAINS = [
7227
+ bitcoin,
7228
+ ];
7229
+ /**
7230
+ * All networks, EVM and non-EVM. Use this when you need to enumerate every
7231
+ * supported chain regardless of type.
7232
+ */
7233
+ const ALL_NETWORKS = [
7234
+ ...MAINNET_CHAINS,
7235
+ ...NON_EVM_CHAINS,
7236
+ ];
7237
+ /**
7238
+ * Pre-built lookup index over all networks (EVM + non-EVM), like Go's
7239
+ * module-level maps. Resolution functions below bind to this index.
7240
+ */
7241
+ const _idx = buildNetworkIndex(ALL_NETWORKS);
7086
7242
  /**
7087
7243
  * Resolve a chain from an arbitrary input. Accepts:
7088
7244
  * - `number`: treated as chain ID
@@ -7092,14 +7248,20 @@ const _idx = buildNetworkIndex(MAINNET_CHAINS);
7092
7248
  *
7093
7249
  * Mirrors the Go `NetworkByAny` function.
7094
7250
  *
7251
+ * Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
7252
+ * resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
7253
+ * if you need to distinguish them.
7254
+ *
7095
7255
  * @example
7096
7256
  * ```ts
7097
7257
  * import { networkByAny } from "@gfxlabs/oku-chains";
7098
7258
  *
7099
- * networkByAny(1) // by chain ID
7259
+ * networkByAny(1) // by chain ID (EVM)
7100
7260
  * networkByAny("mainnet") // by internal name
7101
- * networkByAny("eip155:1") // by CAIP-2
7102
- * networkByAny("42161") // by chain ID string
7261
+ * networkByAny("eip155:1") // by CAIP-2 (EVM)
7262
+ * networkByAny("42161") // by chain ID string (EVM)
7263
+ * networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
7264
+ * networkByAny("bitcoin") // by internal name (non-EVM)
7103
7265
  * ```
7104
7266
  *
7105
7267
  * @throws {NetworkNotFoundError} if no matching chain is found
@@ -7108,7 +7270,8 @@ function networkByAny(v) {
7108
7270
  return networkByAny$1(v, _idx);
7109
7271
  }
7110
7272
  /**
7111
- * Look up a chain by its numeric chain ID.
7273
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
7274
+ * and are not resolvable here.
7112
7275
  *
7113
7276
  * @throws {NetworkNotFoundError} if no matching chain is found
7114
7277
  */
@@ -7116,7 +7279,8 @@ function networkById(id) {
7116
7279
  return networkById$1(id, _idx);
7117
7280
  }
7118
7281
  /**
7119
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
7282
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7283
+ * "bitcoin").
7120
7284
  *
7121
7285
  * @throws {NetworkNotFoundError} if no matching chain is found
7122
7286
  */
@@ -7135,7 +7299,9 @@ function networkByString(s) {
7135
7299
  return networkByString$1(s, _idx);
7136
7300
  }
7137
7301
  /**
7138
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
7302
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
7303
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
7304
+ * non-EVM chains.
7139
7305
  *
7140
7306
  * @throws {NetworkNotFoundError} if no matching chain is found
7141
7307
  */
@@ -7143,16 +7309,21 @@ function networkByCAIP2(caip2) {
7143
7309
  return networkByCAIP2$1(caip2, _idx);
7144
7310
  }
7145
7311
 
7312
+ exports.ALL_NETWORKS = ALL_NETWORKS;
7146
7313
  exports.MAINNET_CHAINS = MAINNET_CHAINS;
7314
+ exports.NON_EVM_CHAINS = NON_EVM_CHAINS;
7315
+ exports.NON_EVM_CHAIN_ID = NON_EVM_CHAIN_ID;
7147
7316
  exports.NetworkNotFoundError = NetworkNotFoundError;
7148
7317
  exports.arbitrum = arbitrum;
7149
7318
  exports.avalanche = avalanche;
7150
7319
  exports.base = base;
7320
+ exports.bitcoin = bitcoin;
7151
7321
  exports.blast = blast;
7152
7322
  exports.bob = bob;
7153
7323
  exports.boba = boba;
7154
7324
  exports.bsc = bsc;
7155
7325
  exports.buildNetworkIndex = buildNetworkIndex;
7326
+ exports.caip2Reference = caip2Reference;
7156
7327
  exports.celo = celo;
7157
7328
  exports.corn = corn;
7158
7329
  exports.etherlink = etherlink;
@@ -7164,11 +7335,14 @@ exports.gnosis = gnosis;
7164
7335
  exports.goat = goat;
7165
7336
  exports.hemi = hemi;
7166
7337
  exports.hyperevm = hyperevm;
7338
+ exports.isEvmChain = isEvmChain;
7339
+ exports.isNonEvmChain = isNonEvmChain;
7167
7340
  exports.lens = lens;
7168
7341
  exports.lightlink = lightlink;
7169
7342
  exports.linea = linea;
7170
7343
  exports.lisk = lisk;
7171
7344
  exports.mainnet = mainnet;
7345
+ exports.makeConfig = makeConfig;
7172
7346
  exports.manta = manta;
7173
7347
  exports.mantle = mantle;
7174
7348
  exports.matchain = matchain;
@@ -1,7 +1,9 @@
1
1
  export * from "./definitions/index";
2
+ export * from "./non-evm/index";
2
3
  export * from "./spec/index";
3
4
  export * from "./util/caip2";
4
- export { NetworkNotFoundError, type NetworkIndex, buildNetworkIndex, } from "./util/lookup";
5
+ export { makeConfig } from "./util/index";
6
+ export { buildNetworkIndex, type NetworkIndex, NetworkNotFoundError, } from "./util/lookup";
5
7
  import type { IChainInfo } from "./spec";
6
8
  export declare const MAINNET_CHAINS: readonly [Readonly<{
7
9
  name: "Arbitrum";
@@ -10762,6 +10764,19 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
10762
10764
  } & {
10763
10765
  caip2Namespace: string;
10764
10766
  }>];
10767
+ /**
10768
+ * Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
10769
+ * EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
10770
+ * resolvable only via CAIP-2 (or internal name). Kept as a separate array so
10771
+ * the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
10772
+ * unaffected.
10773
+ */
10774
+ export declare const NON_EVM_CHAINS: readonly IChainInfo[];
10775
+ /**
10776
+ * All networks, EVM and non-EVM. Use this when you need to enumerate every
10777
+ * supported chain regardless of type.
10778
+ */
10779
+ export declare const ALL_NETWORKS: readonly IChainInfo[];
10765
10780
  /**
10766
10781
  * Resolve a chain from an arbitrary input. Accepts:
10767
10782
  * - `number`: treated as chain ID
@@ -10771,27 +10786,35 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
10771
10786
  *
10772
10787
  * Mirrors the Go `NetworkByAny` function.
10773
10788
  *
10789
+ * Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
10790
+ * resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
10791
+ * if you need to distinguish them.
10792
+ *
10774
10793
  * @example
10775
10794
  * ```ts
10776
10795
  * import { networkByAny } from "@gfxlabs/oku-chains";
10777
10796
  *
10778
- * networkByAny(1) // by chain ID
10797
+ * networkByAny(1) // by chain ID (EVM)
10779
10798
  * networkByAny("mainnet") // by internal name
10780
- * networkByAny("eip155:1") // by CAIP-2
10781
- * networkByAny("42161") // by chain ID string
10799
+ * networkByAny("eip155:1") // by CAIP-2 (EVM)
10800
+ * networkByAny("42161") // by chain ID string (EVM)
10801
+ * networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
10802
+ * networkByAny("bitcoin") // by internal name (non-EVM)
10782
10803
  * ```
10783
10804
  *
10784
10805
  * @throws {NetworkNotFoundError} if no matching chain is found
10785
10806
  */
10786
10807
  export declare function networkByAny(v: string | number | IChainInfo): IChainInfo;
10787
10808
  /**
10788
- * Look up a chain by its numeric chain ID.
10809
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
10810
+ * and are not resolvable here.
10789
10811
  *
10790
10812
  * @throws {NetworkNotFoundError} if no matching chain is found
10791
10813
  */
10792
10814
  export declare function networkById(id: number): IChainInfo;
10793
10815
  /**
10794
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
10816
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
10817
+ * "bitcoin").
10795
10818
  *
10796
10819
  * @throws {NetworkNotFoundError} if no matching chain is found
10797
10820
  */
@@ -10806,7 +10829,9 @@ export declare function networkByName(name: string): IChainInfo;
10806
10829
  */
10807
10830
  export declare function networkByString(s: string): IChainInfo;
10808
10831
  /**
10809
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
10832
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
10833
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
10834
+ * non-EVM chains.
10810
10835
  *
10811
10836
  * @throws {NetworkNotFoundError} if no matching chain is found
10812
10837
  */
@@ -0,0 +1,83 @@
1
+ export declare const bitcoin: Readonly<{
2
+ caip2Namespace: "bip122";
3
+ caip2Reference: "000000000019d6689c085ae165831e93";
4
+ internalName: "bitcoin";
5
+ transactionType: "bitcoin";
6
+ sortIndex: 1000;
7
+ launchTime: 1231006505;
8
+ blockTimeSeconds: 600;
9
+ deprecated: false;
10
+ logoUrl: "https://cms.oku.trade/cdn/public/chains/bitcoin-logo.webp";
11
+ nativeLogoUrl: "https://cms.oku.trade/cdn/public/natives/btc.png";
12
+ blockAid: "bitcoin";
13
+ estimatedSwapGas: 0;
14
+ estimatedBridgeGas: 0;
15
+ estimatedWrapGas: 0;
16
+ initCodeHash: "0x0000000000000000000000000000000000000000000000000000000000000000";
17
+ defaultPool: "0x0000000000000000000000000000000000000000";
18
+ defaultToken0: "0x0000000000000000000000000000000000000000";
19
+ defaultToken1: "0x0000000000000000000000000000000000000000";
20
+ tokenList: never[];
21
+ stables: never[];
22
+ watchlist: never[];
23
+ v4Watchlist: never[];
24
+ externalId: {
25
+ coingecko: string;
26
+ };
27
+ markets: {};
28
+ bridges: {};
29
+ oracles: {
30
+ coingecko: {
31
+ slug: string;
32
+ native: string;
33
+ };
34
+ };
35
+ uniswap: {};
36
+ morpho: {};
37
+ token: {};
38
+ oku: {};
39
+ contracts: {
40
+ nftManager: {
41
+ address: "0x0000000000000000000000000000000000000000";
42
+ };
43
+ };
44
+ blockExplorers: {
45
+ readonly default: {
46
+ readonly name: "mempool.space";
47
+ readonly url: "https://mempool.space";
48
+ readonly apiUrl: "https://mempool.space/api";
49
+ };
50
+ };
51
+ blockTime?: number | undefined | undefined;
52
+ ensTlds?: readonly string[] | undefined;
53
+ id: 0;
54
+ name: "Bitcoin";
55
+ nativeCurrency: {
56
+ readonly name: "Bitcoin";
57
+ readonly symbol: "BTC";
58
+ readonly decimals: 8;
59
+ };
60
+ experimental_preconfirmationTime?: number | undefined | undefined;
61
+ rpcUrls: {
62
+ readonly default: {
63
+ readonly http: readonly ["https://bitcoin-rpc.publicnode.com"];
64
+ };
65
+ };
66
+ sourceId?: number | undefined | undefined;
67
+ testnet?: boolean | undefined | undefined;
68
+ custom?: Record<string, unknown> | undefined;
69
+ extendSchema?: Record<string, unknown> | undefined;
70
+ fees?: import("viem").ChainFees<undefined> | undefined;
71
+ formatters?: undefined;
72
+ prepareTransactionRequest?: ((args: import("viem").PrepareTransactionRequestParameters, options: {
73
+ phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
74
+ }) => Promise<import("viem").PrepareTransactionRequestParameters>) | [fn: ((args: import("viem").PrepareTransactionRequestParameters, options: {
75
+ phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
76
+ }) => Promise<import("viem").PrepareTransactionRequestParameters>) | undefined, options: {
77
+ runAt: readonly ("beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters")[];
78
+ }] | undefined;
79
+ serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable> | undefined;
80
+ verifyHash?: ((client: import("viem").Client, parameters: import("viem").VerifyHashActionParameters) => Promise<import("viem").VerifyHashActionReturnType>) | undefined;
81
+ } & {
82
+ caip2Namespace: string;
83
+ }>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Non-EVM chain definitions.
3
+ *
4
+ * This folder holds chains that are not EVM-based and therefore do not extend
5
+ * viem's `Chain` (they have no numeric chain id). Each file exports an
6
+ * {@link INonEvmChainInfo} built via {@link makeNonEvmConfig}. These chains are
7
+ * resolvable only via CAIP-2 (and internal name), never via a numeric id.
8
+ *
9
+ * This barrel is maintained by hand (barrelsby only regenerates
10
+ * `src/definitions/`). Re-export new chains here when you add them.
11
+ */
12
+ export * from "./bitcoin";
@@ -164,6 +164,19 @@ export interface Oracles {
164
164
  }
165
165
  export interface IChainInfo<formatters extends ChainFormatters | undefined = ChainFormatters | undefined> extends Chain<formatters> {
166
166
  caip2Namespace: string;
167
+ /**
168
+ * Explicit CAIP-2 reference component.
169
+ *
170
+ * When set, it is used verbatim as the reference half of the chain's CAIP-2
171
+ * identifier (e.g. Bitcoin's genesis hash prefix
172
+ * "000000000019d6689c085ae165831e93"). When omitted, the reference is
173
+ * derived from the numeric `id` (the historical behavior, e.g. "1" for
174
+ * Ethereum mainnet).
175
+ *
176
+ * Non-EVM chains (which use `id: 0` as a placeholder since viem requires a
177
+ * numeric id) MUST set this so their CAIP-2 identifier resolves correctly.
178
+ */
179
+ caip2Reference?: string;
167
180
  logoUrl: string;
168
181
  launchTime: number;
169
182
  nativeLogoUrl: string;
@@ -219,3 +232,21 @@ export interface IChainInfo<formatters extends ChainFormatters | undefined = Cha
219
232
  metrom?: ChainContract;
220
233
  };
221
234
  }
235
+ /**
236
+ * Placeholder numeric `id` used by non-EVM chains.
237
+ *
238
+ * viem's `Chain` (which {@link IChainInfo} extends) requires a numeric `id`,
239
+ * but non-EVM chains (e.g. Bitcoin) have no EVM chain id. They use `0` as a
240
+ * sentinel and rely on `caip2Namespace` + `caip2Reference` for identity and
241
+ * resolution instead. `0` is never a valid EVM chain id, so it cannot collide.
242
+ */
243
+ export declare const NON_EVM_CHAIN_ID = 0;
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.
249
+ */
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;
@@ -26,14 +26,25 @@ export declare function parseCAIP2(caip2: string): CAIP2Identifier;
26
26
  * ```
27
27
  */
28
28
  export declare function formatCAIP2(id: CAIP2Identifier): string;
29
+ /**
30
+ * The CAIP-2 reference component for a chain.
31
+ *
32
+ * If the chain sets an explicit `caip2Reference` (e.g. a non-EVM chain like
33
+ * Bitcoin, whose reference is a genesis hash prefix), it is used verbatim.
34
+ * Otherwise the reference is derived from the numeric `id` (the historical
35
+ * behavior for EVM chains, e.g. "1" for Ethereum mainnet).
36
+ */
37
+ export declare function caip2Reference(chain: IChainInfo): string;
29
38
  /**
30
39
  * Convert a chain config to its CAIP-2 identifier string.
31
40
  *
32
41
  * @example
33
42
  * ```ts
34
- * import { mainnet } from "@gfxlabs/oku-chains";
43
+ * import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
35
44
  * toCAIP2(mainnet)
36
45
  * // => "eip155:1"
46
+ * toCAIP2(bitcoin)
47
+ * // => "bip122:000000000019d6689c085ae165831e93"
37
48
  * ```
38
49
  */
39
50
  export declare function toCAIP2(chain: IChainInfo): string;
@@ -16,18 +16,27 @@ export interface NetworkIndex {
16
16
  /**
17
17
  * Build a lookup index from a list of chains for fast repeated lookups.
18
18
  * Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
19
+ *
20
+ * Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
21
+ * intentionally NOT registered in `byId` (they are not resolvable by numeric
22
+ * id, and would otherwise all collide on `0`). They remain resolvable by
23
+ * internal name and by their explicit CAIP-2 identifier.
19
24
  */
20
25
  export declare function buildNetworkIndex(chains: readonly IChainInfo[]): NetworkIndex;
21
26
  /**
22
- * Look up a chain by its numeric chain ID.
27
+ * Look up a chain by its numeric chain ID. Non-EVM chains use the
28
+ * {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
23
29
  */
24
30
  export declare function networkById(id: number, idx: NetworkIndex): IChainInfo;
25
31
  /**
26
- * Look up a chain by its internal name (e.g. "arbitrum", "mainnet").
32
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
33
+ * "bitcoin").
27
34
  */
28
35
  export declare function networkByName(name: string, idx: NetworkIndex): IChainInfo;
29
36
  /**
30
- * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1").
37
+ * Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
38
+ * "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
39
+ * non-EVM chains.
31
40
  */
32
41
  export declare function networkByCAIP2(caip2: string, idx: NetworkIndex): IChainInfo;
33
42
  /**
@@ -36,16 +45,22 @@ export declare function networkByCAIP2(caip2: string, idx: NetworkIndex): IChain
36
45
  * 2. Internal name
37
46
  * 3. Numeric chain ID (parsed from string)
38
47
  *
48
+ * Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
49
+ * never via the numeric-id fallback.
50
+ *
39
51
  * Mirrors the Go `NetworkByString` function.
40
52
  */
41
53
  export declare function networkByString(s: string, idx: NetworkIndex): IChainInfo;
42
54
  /**
43
55
  * Resolve a chain from an arbitrary input. Accepts:
44
- * - `number`: treated as chain ID
56
+ * - `number`: treated as a numeric chain ID (EVM-only)
45
57
  * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
46
58
  * internal name, then as a numeric chain ID string
47
59
  * - `IChainInfo`: returned directly (pass-through)
48
60
  *
61
+ * Non-EVM chains have a placeholder numeric id, so they can only be resolved
62
+ * via their CAIP-2 identifier or internal name (or passed through directly).
63
+ *
49
64
  * Mirrors the Go `NetworkByAny` function.
50
65
  *
51
66
  * @throws {NetworkNotFoundError} if no matching chain is found
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfxlabs/oku-chains",
3
- "version": "1.12.4",
3
+ "version": "1.12.5",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index-mjs.js",