@gfxlabs/oku-chains 1.12.3 → 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/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,13 +7025,147 @@ 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
  }
6914
7032
  return chain;
6915
7033
  }
6916
7034
 
7035
+ /**
7036
+ * Error thrown when a network cannot be found by any lookup method.
7037
+ */
7038
+ class NetworkNotFoundError extends Error {
7039
+ constructor(input) {
7040
+ super(`chain not found: ${String(input)}`);
7041
+ this.name = "NetworkNotFoundError";
7042
+ }
7043
+ }
7044
+ /**
7045
+ * Build a lookup index from a list of chains for fast repeated lookups.
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.
7052
+ */
7053
+ function buildNetworkIndex(chains) {
7054
+ const byId = new Map();
7055
+ const byName = new Map();
7056
+ const byCAIP2 = new Map();
7057
+ for (const chain of chains) {
7058
+ if (chain.id !== NON_EVM_CHAIN_ID) {
7059
+ byId.set(chain.id, chain);
7060
+ }
7061
+ byName.set(chain.internalName, chain);
7062
+ byCAIP2.set(`${chain.caip2Namespace}:${caip2Reference(chain)}`, chain);
7063
+ }
7064
+ return { byId, byName, byCAIP2 };
7065
+ }
7066
+ /**
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.
7069
+ */
7070
+ function networkById$1(id, idx) {
7071
+ const chain = idx.byId.get(id);
7072
+ if (!chain) {
7073
+ throw new NetworkNotFoundError(id);
7074
+ }
7075
+ return chain;
7076
+ }
7077
+ /**
7078
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7079
+ * "bitcoin").
7080
+ */
7081
+ function networkByName$1(name, idx) {
7082
+ const chain = idx.byName.get(name);
7083
+ if (!chain) {
7084
+ throw new NetworkNotFoundError(name);
7085
+ }
7086
+ return chain;
7087
+ }
7088
+ /**
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.
7092
+ */
7093
+ function networkByCAIP2$1(caip2, idx) {
7094
+ // Validate the format
7095
+ parseCAIP2(caip2);
7096
+ const chain = idx.byCAIP2.get(caip2);
7097
+ if (!chain) {
7098
+ throw new NetworkNotFoundError(caip2);
7099
+ }
7100
+ return chain;
7101
+ }
7102
+ /**
7103
+ * Look up a chain from a string. Tries, in order:
7104
+ * 1. CAIP-2 identifier (if the string contains ":")
7105
+ * 2. Internal name
7106
+ * 3. Numeric chain ID (parsed from string)
7107
+ *
7108
+ * Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
7109
+ * never via the numeric-id fallback.
7110
+ *
7111
+ * Mirrors the Go `NetworkByString` function.
7112
+ */
7113
+ function networkByString$1(s, idx) {
7114
+ if (s === "") {
7115
+ throw new NetworkNotFoundError("empty string");
7116
+ }
7117
+ // Try CAIP-2
7118
+ if (s.includes(":")) {
7119
+ return networkByCAIP2$1(s, idx);
7120
+ }
7121
+ // Try internal name
7122
+ const byName = idx.byName.get(s);
7123
+ if (byName) {
7124
+ return byName;
7125
+ }
7126
+ // Try numeric chain ID
7127
+ const parsed = Number(s);
7128
+ if (!Number.isNaN(parsed) && Number.isFinite(parsed)) {
7129
+ const byId = idx.byId.get(Math.trunc(parsed));
7130
+ if (byId) {
7131
+ return byId;
7132
+ }
7133
+ }
7134
+ throw new NetworkNotFoundError(s);
7135
+ }
7136
+ /**
7137
+ * Resolve a chain from an arbitrary input. Accepts:
7138
+ * - `number`: treated as a numeric chain ID (EVM-only)
7139
+ * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
7140
+ * internal name, then as a numeric chain ID string
7141
+ * - `IChainInfo`: returned directly (pass-through)
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
+ *
7146
+ * Mirrors the Go `NetworkByAny` function.
7147
+ *
7148
+ * @throws {NetworkNotFoundError} if no matching chain is found
7149
+ */
7150
+ function networkByAny$1(v, idx) {
7151
+ if (v == null) {
7152
+ throw new NetworkNotFoundError("null");
7153
+ }
7154
+ // Pass-through if already a chain config object
7155
+ if (typeof v === "object" && "id" in v && "internalName" in v) {
7156
+ return v;
7157
+ }
7158
+ // Numeric chain ID
7159
+ if (typeof v === "number") {
7160
+ return networkById$1(Math.trunc(v), idx);
7161
+ }
7162
+ // String: CAIP-2, name, or numeric string
7163
+ if (typeof v === "string") {
7164
+ return networkByString$1(v, idx);
7165
+ }
7166
+ throw new NetworkNotFoundError(v);
7167
+ }
7168
+
6917
7169
  const MAINNET_CHAINS = [
6918
7170
  arbitrum,
6919
7171
  base,
@@ -6964,15 +7216,114 @@ const MAINNET_CHAINS = [
6964
7216
  gensyn,
6965
7217
  pharos,
6966
7218
  ];
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);
7242
+ /**
7243
+ * Resolve a chain from an arbitrary input. Accepts:
7244
+ * - `number`: treated as chain ID
7245
+ * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
7246
+ * internal name, then as a numeric chain ID string
7247
+ * - `IChainInfo`: returned directly (pass-through)
7248
+ *
7249
+ * Mirrors the Go `NetworkByAny` function.
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
+ *
7255
+ * @example
7256
+ * ```ts
7257
+ * import { networkByAny } from "@gfxlabs/oku-chains";
7258
+ *
7259
+ * networkByAny(1) // by chain ID (EVM)
7260
+ * networkByAny("mainnet") // by internal name
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)
7265
+ * ```
7266
+ *
7267
+ * @throws {NetworkNotFoundError} if no matching chain is found
7268
+ */
7269
+ function networkByAny(v) {
7270
+ return networkByAny$1(v, _idx);
7271
+ }
7272
+ /**
7273
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
7274
+ * and are not resolvable here.
7275
+ *
7276
+ * @throws {NetworkNotFoundError} if no matching chain is found
7277
+ */
7278
+ function networkById(id) {
7279
+ return networkById$1(id, _idx);
7280
+ }
7281
+ /**
7282
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
7283
+ * "bitcoin").
7284
+ *
7285
+ * @throws {NetworkNotFoundError} if no matching chain is found
7286
+ */
7287
+ function networkByName(name) {
7288
+ return networkByName$1(name, _idx);
7289
+ }
7290
+ /**
7291
+ * Look up a chain from a string. Tries, in order:
7292
+ * 1. CAIP-2 identifier (if the string contains ":")
7293
+ * 2. Internal name
7294
+ * 3. Numeric chain ID (parsed from string)
7295
+ *
7296
+ * @throws {NetworkNotFoundError} if no matching chain is found
7297
+ */
7298
+ function networkByString(s) {
7299
+ return networkByString$1(s, _idx);
7300
+ }
7301
+ /**
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.
7305
+ *
7306
+ * @throws {NetworkNotFoundError} if no matching chain is found
7307
+ */
7308
+ function networkByCAIP2(caip2) {
7309
+ return networkByCAIP2$1(caip2, _idx);
7310
+ }
6967
7311
 
7312
+ exports.ALL_NETWORKS = ALL_NETWORKS;
6968
7313
  exports.MAINNET_CHAINS = MAINNET_CHAINS;
7314
+ exports.NON_EVM_CHAINS = NON_EVM_CHAINS;
7315
+ exports.NON_EVM_CHAIN_ID = NON_EVM_CHAIN_ID;
7316
+ exports.NetworkNotFoundError = NetworkNotFoundError;
6969
7317
  exports.arbitrum = arbitrum;
6970
7318
  exports.avalanche = avalanche;
6971
7319
  exports.base = base;
7320
+ exports.bitcoin = bitcoin;
6972
7321
  exports.blast = blast;
6973
7322
  exports.bob = bob;
6974
7323
  exports.boba = boba;
6975
7324
  exports.bsc = bsc;
7325
+ exports.buildNetworkIndex = buildNetworkIndex;
7326
+ exports.caip2Reference = caip2Reference;
6976
7327
  exports.celo = celo;
6977
7328
  exports.corn = corn;
6978
7329
  exports.etherlink = etherlink;
@@ -6984,17 +7335,25 @@ exports.gnosis = gnosis;
6984
7335
  exports.goat = goat;
6985
7336
  exports.hemi = hemi;
6986
7337
  exports.hyperevm = hyperevm;
7338
+ exports.isEvmChain = isEvmChain;
7339
+ exports.isNonEvmChain = isNonEvmChain;
6987
7340
  exports.lens = lens;
6988
7341
  exports.lightlink = lightlink;
6989
7342
  exports.linea = linea;
6990
7343
  exports.lisk = lisk;
6991
7344
  exports.mainnet = mainnet;
7345
+ exports.makeConfig = makeConfig;
6992
7346
  exports.manta = manta;
6993
7347
  exports.mantle = mantle;
6994
7348
  exports.matchain = matchain;
6995
7349
  exports.metal = metal;
6996
7350
  exports.monad = monad;
6997
7351
  exports.moonbeam = moonbeam;
7352
+ exports.networkByAny = networkByAny;
7353
+ exports.networkByCAIP2 = networkByCAIP2;
7354
+ exports.networkById = networkById;
7355
+ exports.networkByName = networkByName;
7356
+ exports.networkByString = networkByString;
6998
7357
  exports.nibiru = nibiru;
6999
7358
  exports.optimism = optimism;
7000
7359
  exports.parseCAIP2 = parseCAIP2;
@@ -1,6 +1,10 @@
1
1
  export * from "./definitions/index";
2
+ export * from "./non-evm/index";
2
3
  export * from "./spec/index";
3
4
  export * from "./util/caip2";
5
+ export { makeConfig } from "./util/index";
6
+ export { buildNetworkIndex, type NetworkIndex, NetworkNotFoundError, } from "./util/lookup";
7
+ import type { IChainInfo } from "./spec";
4
8
  export declare const MAINNET_CHAINS: readonly [Readonly<{
5
9
  name: "Arbitrum";
6
10
  launchTime: 1688997600;
@@ -10760,3 +10764,75 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
10760
10764
  } & {
10761
10765
  caip2Namespace: string;
10762
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[];
10780
+ /**
10781
+ * Resolve a chain from an arbitrary input. Accepts:
10782
+ * - `number`: treated as chain ID
10783
+ * - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
10784
+ * internal name, then as a numeric chain ID string
10785
+ * - `IChainInfo`: returned directly (pass-through)
10786
+ *
10787
+ * Mirrors the Go `NetworkByAny` function.
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
+ *
10793
+ * @example
10794
+ * ```ts
10795
+ * import { networkByAny } from "@gfxlabs/oku-chains";
10796
+ *
10797
+ * networkByAny(1) // by chain ID (EVM)
10798
+ * networkByAny("mainnet") // by internal name
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)
10803
+ * ```
10804
+ *
10805
+ * @throws {NetworkNotFoundError} if no matching chain is found
10806
+ */
10807
+ export declare function networkByAny(v: string | number | IChainInfo): IChainInfo;
10808
+ /**
10809
+ * Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
10810
+ * and are not resolvable here.
10811
+ *
10812
+ * @throws {NetworkNotFoundError} if no matching chain is found
10813
+ */
10814
+ export declare function networkById(id: number): IChainInfo;
10815
+ /**
10816
+ * Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
10817
+ * "bitcoin").
10818
+ *
10819
+ * @throws {NetworkNotFoundError} if no matching chain is found
10820
+ */
10821
+ export declare function networkByName(name: string): IChainInfo;
10822
+ /**
10823
+ * Look up a chain from a string. Tries, in order:
10824
+ * 1. CAIP-2 identifier (if the string contains ":")
10825
+ * 2. Internal name
10826
+ * 3. Numeric chain ID (parsed from string)
10827
+ *
10828
+ * @throws {NetworkNotFoundError} if no matching chain is found
10829
+ */
10830
+ export declare function networkByString(s: string): IChainInfo;
10831
+ /**
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.
10835
+ *
10836
+ * @throws {NetworkNotFoundError} if no matching chain is found
10837
+ */
10838
+ export declare function networkByCAIP2(caip2: string): IChainInfo;
@@ -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;