@gfxlabs/oku-chains 1.12.4 → 1.12.6

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.
@@ -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,77 @@ 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
+ * 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.
307
+ */
308
+ export declare function isNonEvmChain(c: IChainInfo | string): 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.6",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index-mjs.js",