@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.
- package/dist/browser.js +365 -17
- package/dist/index-mjs.js +356 -18
- package/dist/index.js +365 -17
- package/dist/types/index.d.ts +89 -7
- package/dist/types/non-evm/bitcoin.d.ts +83 -0
- package/dist/types/non-evm/index.d.ts +12 -0
- package/dist/types/spec/index.d.ts +87 -0
- package/dist/types/util/caip2.d.ts +12 -1
- package/dist/types/util/lookup.d.ts +19 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6844,6 +6844,196 @@ 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
|
+
* High-level chain family, derived from the chain's CAIP-2 namespace.
|
|
6858
|
+
*
|
|
6859
|
+
* The underlying string value of each member is the CAIP-2 namespace it maps
|
|
6860
|
+
* to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
|
|
6861
|
+
* resolve a chain's type directly from its `caip2Namespace` without relying on
|
|
6862
|
+
* sentinel values like {@link NON_EVM_CHAIN_ID}.
|
|
6863
|
+
*
|
|
6864
|
+
* @see https://chainagnostic.org/CAIPs/caip-2
|
|
6865
|
+
*/
|
|
6866
|
+
exports.ChainType = void 0;
|
|
6867
|
+
(function (ChainType) {
|
|
6868
|
+
/** EVM chains (CAIP-2 namespace `eip155`). */
|
|
6869
|
+
ChainType["EVM"] = "eip155";
|
|
6870
|
+
/** Bitcoin (CAIP-2 namespace `bip122`). */
|
|
6871
|
+
ChainType["Bitcoin"] = "bip122";
|
|
6872
|
+
/** Solana (CAIP-2 namespace `solana`). */
|
|
6873
|
+
ChainType["Solana"] = "solana";
|
|
6874
|
+
/** Unknown / unrecognized CAIP-2 namespace. */
|
|
6875
|
+
ChainType["Unknown"] = "";
|
|
6876
|
+
})(exports.ChainType || (exports.ChainType = {}));
|
|
6877
|
+
/** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
|
|
6878
|
+
const CHAIN_TYPE_BY_NAMESPACE = {
|
|
6879
|
+
[exports.ChainType.EVM]: exports.ChainType.EVM,
|
|
6880
|
+
[exports.ChainType.Bitcoin]: exports.ChainType.Bitcoin,
|
|
6881
|
+
[exports.ChainType.Solana]: exports.ChainType.Solana,
|
|
6882
|
+
};
|
|
6883
|
+
/**
|
|
6884
|
+
* Resolve a CAIP-2 namespace from a chain-like value:
|
|
6885
|
+
* - an {@link IChainInfo} object: its `caip2Namespace`
|
|
6886
|
+
* - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
|
|
6887
|
+
* - a bare namespace string (e.g. `"eip155"`): used verbatim
|
|
6888
|
+
*
|
|
6889
|
+
* Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
|
|
6890
|
+
* namespace and resolves to {@link ChainType.Unknown} here. Use the
|
|
6891
|
+
* index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
|
|
6892
|
+
* those (they look the chain up first).
|
|
6893
|
+
*/
|
|
6894
|
+
function namespaceOf(c) {
|
|
6895
|
+
if (typeof c === "string") {
|
|
6896
|
+
const sep = c.indexOf(":");
|
|
6897
|
+
return sep === -1 ? c : c.slice(0, sep);
|
|
6898
|
+
}
|
|
6899
|
+
return c.caip2Namespace;
|
|
6900
|
+
}
|
|
6901
|
+
/**
|
|
6902
|
+
* The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
|
|
6903
|
+
*
|
|
6904
|
+
* Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
|
|
6905
|
+
* like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
|
|
6906
|
+
* canonical way to determine a chain's family. Prefer it over inspecting the
|
|
6907
|
+
* numeric `id` (which is a placeholder for non-EVM chains).
|
|
6908
|
+
*
|
|
6909
|
+
* @example
|
|
6910
|
+
* ```ts
|
|
6911
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
6912
|
+
* chainType(mainnet) // => ChainType.EVM
|
|
6913
|
+
* chainType(bitcoin) // => ChainType.Bitcoin
|
|
6914
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
6915
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
6916
|
+
* ```
|
|
6917
|
+
*/
|
|
6918
|
+
function chainType$1(c) {
|
|
6919
|
+
return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? exports.ChainType.Unknown;
|
|
6920
|
+
}
|
|
6921
|
+
/**
|
|
6922
|
+
* True if the chain belongs to the given {@link ChainType} family.
|
|
6923
|
+
*
|
|
6924
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
6925
|
+
* checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
|
|
6926
|
+
*
|
|
6927
|
+
* @example
|
|
6928
|
+
* ```ts
|
|
6929
|
+
* import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
|
|
6930
|
+
* isNetworkType(ChainType.Bitcoin, bitcoin) // => true
|
|
6931
|
+
* isNetworkType(ChainType.EVM, bitcoin) // => false
|
|
6932
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
6933
|
+
* ```
|
|
6934
|
+
*/
|
|
6935
|
+
function isNetworkType$1(type, c) {
|
|
6936
|
+
return chainType$1(c) === type;
|
|
6937
|
+
}
|
|
6938
|
+
/**
|
|
6939
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
6940
|
+
* {@link IChainInfo} object or a CAIP-2 string.
|
|
6941
|
+
*/
|
|
6942
|
+
function isEvmChain$1(c) {
|
|
6943
|
+
return isNetworkType$1(exports.ChainType.EVM, c);
|
|
6944
|
+
}
|
|
6945
|
+
/**
|
|
6946
|
+
* True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
|
|
6947
|
+
* Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
|
|
6948
|
+
* EVM-only fields (contracts, uniswap metadata, etc.) will be present but
|
|
6949
|
+
* empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
|
|
6950
|
+
*/
|
|
6951
|
+
function isNonEvmChain$1(c) {
|
|
6952
|
+
return !isEvmChain$1(c);
|
|
6953
|
+
}
|
|
6954
|
+
|
|
6955
|
+
/**
|
|
6956
|
+
* Bitcoin mainnet.
|
|
6957
|
+
*
|
|
6958
|
+
* A non-EVM chain expressed within the EVM-shaped {@link IChainInfo} so it
|
|
6959
|
+
* flows through the existing resolvers and consumers unchanged. Because viem's
|
|
6960
|
+
* `Chain` requires a numeric `id`, Bitcoin uses the {@link NON_EVM_CHAIN_ID}
|
|
6961
|
+
* (`0`) placeholder and is identified/resolved via CAIP-2 instead:
|
|
6962
|
+
* `bip122:000000000019d6689c085ae165831e93`, where the reference is the first
|
|
6963
|
+
* 32 hex chars of the genesis block hash per the CAIP-2 `bip122` namespace.
|
|
6964
|
+
*
|
|
6965
|
+
* EVM-only fields (uniswap, morpho, contracts, etc.) are present but empty.
|
|
6966
|
+
*
|
|
6967
|
+
* Refs:
|
|
6968
|
+
* - https://github.com/ChainAgnostic/namespaces/blob/main/bip122/caip2.md
|
|
6969
|
+
*/
|
|
6970
|
+
const chain = viem.defineChain({
|
|
6971
|
+
id: NON_EVM_CHAIN_ID,
|
|
6972
|
+
name: "Bitcoin",
|
|
6973
|
+
nativeCurrency: {
|
|
6974
|
+
name: "Bitcoin",
|
|
6975
|
+
symbol: "BTC",
|
|
6976
|
+
decimals: 8,
|
|
6977
|
+
},
|
|
6978
|
+
rpcUrls: {
|
|
6979
|
+
default: {
|
|
6980
|
+
http: ["https://bitcoin-rpc.publicnode.com"],
|
|
6981
|
+
},
|
|
6982
|
+
},
|
|
6983
|
+
blockExplorers: {
|
|
6984
|
+
default: {
|
|
6985
|
+
name: "mempool.space",
|
|
6986
|
+
url: "https://mempool.space",
|
|
6987
|
+
apiUrl: "https://mempool.space/api",
|
|
6988
|
+
},
|
|
6989
|
+
},
|
|
6990
|
+
});
|
|
6991
|
+
const bitcoin = makeConfig({
|
|
6992
|
+
...chain,
|
|
6993
|
+
caip2Namespace: "bip122",
|
|
6994
|
+
caip2Reference: "000000000019d6689c085ae165831e93",
|
|
6995
|
+
internalName: "bitcoin",
|
|
6996
|
+
transactionType: "bitcoin",
|
|
6997
|
+
sortIndex: 1000,
|
|
6998
|
+
launchTime: 1231006505,
|
|
6999
|
+
blockTimeSeconds: 600,
|
|
7000
|
+
deprecated: false,
|
|
7001
|
+
logoUrl: "https://cms.oku.trade/cdn/public/chains/bitcoin-logo.webp",
|
|
7002
|
+
nativeLogoUrl: "https://cms.oku.trade/cdn/public/natives/btc.png",
|
|
7003
|
+
blockAid: "bitcoin",
|
|
7004
|
+
estimatedSwapGas: 0,
|
|
7005
|
+
estimatedBridgeGas: 0,
|
|
7006
|
+
estimatedWrapGas: 0,
|
|
7007
|
+
initCodeHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
7008
|
+
defaultPool: "0x0000000000000000000000000000000000000000",
|
|
7009
|
+
defaultToken0: "0x0000000000000000000000000000000000000000",
|
|
7010
|
+
defaultToken1: "0x0000000000000000000000000000000000000000",
|
|
7011
|
+
tokenList: [],
|
|
7012
|
+
stables: [],
|
|
7013
|
+
watchlist: [],
|
|
7014
|
+
v4Watchlist: [],
|
|
7015
|
+
externalId: {
|
|
7016
|
+
coingecko: "bitcoin",
|
|
7017
|
+
},
|
|
7018
|
+
markets: {},
|
|
7019
|
+
bridges: {},
|
|
7020
|
+
oracles: {
|
|
7021
|
+
coingecko: {
|
|
7022
|
+
slug: "bitcoin",
|
|
7023
|
+
native: "bitcoin",
|
|
7024
|
+
},
|
|
7025
|
+
},
|
|
7026
|
+
uniswap: {},
|
|
7027
|
+
morpho: {},
|
|
7028
|
+
token: {},
|
|
7029
|
+
oku: {},
|
|
7030
|
+
contracts: {
|
|
7031
|
+
nftManager: {
|
|
7032
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
7033
|
+
},
|
|
7034
|
+
},
|
|
7035
|
+
});
|
|
7036
|
+
|
|
6847
7037
|
/**
|
|
6848
7038
|
* Parse a CAIP-2 chain ID string into its namespace and reference components.
|
|
6849
7039
|
*
|
|
@@ -6877,20 +7067,33 @@ function parseCAIP2(caip2) {
|
|
|
6877
7067
|
function formatCAIP2(id) {
|
|
6878
7068
|
return `${id.namespace}:${id.reference}`;
|
|
6879
7069
|
}
|
|
7070
|
+
/**
|
|
7071
|
+
* The CAIP-2 reference component for a chain.
|
|
7072
|
+
*
|
|
7073
|
+
* If the chain sets an explicit `caip2Reference` (e.g. a non-EVM chain like
|
|
7074
|
+
* Bitcoin, whose reference is a genesis hash prefix), it is used verbatim.
|
|
7075
|
+
* Otherwise the reference is derived from the numeric `id` (the historical
|
|
7076
|
+
* behavior for EVM chains, e.g. "1" for Ethereum mainnet).
|
|
7077
|
+
*/
|
|
7078
|
+
function caip2Reference(chain) {
|
|
7079
|
+
return chain.caip2Reference ?? String(chain.id);
|
|
7080
|
+
}
|
|
6880
7081
|
/**
|
|
6881
7082
|
* Convert a chain config to its CAIP-2 identifier string.
|
|
6882
7083
|
*
|
|
6883
7084
|
* @example
|
|
6884
7085
|
* ```ts
|
|
6885
|
-
* import { mainnet } from "@gfxlabs/oku-chains";
|
|
7086
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
6886
7087
|
* toCAIP2(mainnet)
|
|
6887
7088
|
* // => "eip155:1"
|
|
7089
|
+
* toCAIP2(bitcoin)
|
|
7090
|
+
* // => "bip122:000000000019d6689c085ae165831e93"
|
|
6888
7091
|
* ```
|
|
6889
7092
|
*/
|
|
6890
7093
|
function toCAIP2(chain) {
|
|
6891
7094
|
return formatCAIP2({
|
|
6892
7095
|
namespace: chain.caip2Namespace,
|
|
6893
|
-
reference:
|
|
7096
|
+
reference: caip2Reference(chain),
|
|
6894
7097
|
});
|
|
6895
7098
|
}
|
|
6896
7099
|
/**
|
|
@@ -6907,7 +7110,7 @@ function toCAIP2(chain) {
|
|
|
6907
7110
|
*/
|
|
6908
7111
|
function fromCAIP2(caip2, chains) {
|
|
6909
7112
|
const { namespace, reference } = parseCAIP2(caip2);
|
|
6910
|
-
const chain = chains.find((c) => c.caip2Namespace === namespace &&
|
|
7113
|
+
const chain = chains.find((c) => c.caip2Namespace === namespace && caip2Reference(c) === reference);
|
|
6911
7114
|
if (!chain) {
|
|
6912
7115
|
throw new Error(`No chain found for CAIP-2 identifier: "${caip2}"`);
|
|
6913
7116
|
}
|
|
@@ -6926,20 +7129,28 @@ class NetworkNotFoundError extends Error {
|
|
|
6926
7129
|
/**
|
|
6927
7130
|
* Build a lookup index from a list of chains for fast repeated lookups.
|
|
6928
7131
|
* Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
|
|
7132
|
+
*
|
|
7133
|
+
* Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
|
|
7134
|
+
* intentionally NOT registered in `byId` (they are not resolvable by numeric
|
|
7135
|
+
* id, and would otherwise all collide on `0`). They remain resolvable by
|
|
7136
|
+
* internal name and by their explicit CAIP-2 identifier.
|
|
6929
7137
|
*/
|
|
6930
7138
|
function buildNetworkIndex(chains) {
|
|
6931
7139
|
const byId = new Map();
|
|
6932
7140
|
const byName = new Map();
|
|
6933
7141
|
const byCAIP2 = new Map();
|
|
6934
7142
|
for (const chain of chains) {
|
|
6935
|
-
|
|
7143
|
+
if (chain.id !== NON_EVM_CHAIN_ID) {
|
|
7144
|
+
byId.set(chain.id, chain);
|
|
7145
|
+
}
|
|
6936
7146
|
byName.set(chain.internalName, chain);
|
|
6937
|
-
byCAIP2.set(`${chain.caip2Namespace}:${chain
|
|
7147
|
+
byCAIP2.set(`${chain.caip2Namespace}:${caip2Reference(chain)}`, chain);
|
|
6938
7148
|
}
|
|
6939
7149
|
return { byId, byName, byCAIP2 };
|
|
6940
7150
|
}
|
|
6941
7151
|
/**
|
|
6942
|
-
* Look up a chain by its numeric chain ID.
|
|
7152
|
+
* Look up a chain by its numeric chain ID. Non-EVM chains use the
|
|
7153
|
+
* {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
|
|
6943
7154
|
*/
|
|
6944
7155
|
function networkById$1(id, idx) {
|
|
6945
7156
|
const chain = idx.byId.get(id);
|
|
@@ -6949,7 +7160,8 @@ function networkById$1(id, idx) {
|
|
|
6949
7160
|
return chain;
|
|
6950
7161
|
}
|
|
6951
7162
|
/**
|
|
6952
|
-
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet"
|
|
7163
|
+
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
|
|
7164
|
+
* "bitcoin").
|
|
6953
7165
|
*/
|
|
6954
7166
|
function networkByName$1(name, idx) {
|
|
6955
7167
|
const chain = idx.byName.get(name);
|
|
@@ -6959,7 +7171,9 @@ function networkByName$1(name, idx) {
|
|
|
6959
7171
|
return chain;
|
|
6960
7172
|
}
|
|
6961
7173
|
/**
|
|
6962
|
-
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1"
|
|
7174
|
+
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
|
|
7175
|
+
* "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
|
|
7176
|
+
* non-EVM chains.
|
|
6963
7177
|
*/
|
|
6964
7178
|
function networkByCAIP2$1(caip2, idx) {
|
|
6965
7179
|
// Validate the format
|
|
@@ -6976,6 +7190,9 @@ function networkByCAIP2$1(caip2, idx) {
|
|
|
6976
7190
|
* 2. Internal name
|
|
6977
7191
|
* 3. Numeric chain ID (parsed from string)
|
|
6978
7192
|
*
|
|
7193
|
+
* Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
|
|
7194
|
+
* never via the numeric-id fallback.
|
|
7195
|
+
*
|
|
6979
7196
|
* Mirrors the Go `NetworkByString` function.
|
|
6980
7197
|
*/
|
|
6981
7198
|
function networkByString$1(s, idx) {
|
|
@@ -7003,11 +7220,14 @@ function networkByString$1(s, idx) {
|
|
|
7003
7220
|
}
|
|
7004
7221
|
/**
|
|
7005
7222
|
* Resolve a chain from an arbitrary input. Accepts:
|
|
7006
|
-
* - `number`: treated as chain ID
|
|
7223
|
+
* - `number`: treated as a numeric chain ID (EVM-only)
|
|
7007
7224
|
* - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
|
|
7008
7225
|
* internal name, then as a numeric chain ID string
|
|
7009
7226
|
* - `IChainInfo`: returned directly (pass-through)
|
|
7010
7227
|
*
|
|
7228
|
+
* Non-EVM chains have a placeholder numeric id, so they can only be resolved
|
|
7229
|
+
* via their CAIP-2 identifier or internal name (or passed through directly).
|
|
7230
|
+
*
|
|
7011
7231
|
* Mirrors the Go `NetworkByAny` function.
|
|
7012
7232
|
*
|
|
7013
7233
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
@@ -7081,8 +7301,29 @@ const MAINNET_CHAINS = [
|
|
|
7081
7301
|
gensyn,
|
|
7082
7302
|
pharos,
|
|
7083
7303
|
];
|
|
7084
|
-
/**
|
|
7085
|
-
|
|
7304
|
+
/**
|
|
7305
|
+
* Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
|
|
7306
|
+
* EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
|
|
7307
|
+
* resolvable only via CAIP-2 (or internal name). Kept as a separate array so
|
|
7308
|
+
* the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
|
|
7309
|
+
* unaffected.
|
|
7310
|
+
*/
|
|
7311
|
+
const NON_EVM_CHAINS = [
|
|
7312
|
+
bitcoin,
|
|
7313
|
+
];
|
|
7314
|
+
/**
|
|
7315
|
+
* All networks, EVM and non-EVM. Use this when you need to enumerate every
|
|
7316
|
+
* supported chain regardless of type.
|
|
7317
|
+
*/
|
|
7318
|
+
const ALL_NETWORKS = [
|
|
7319
|
+
...MAINNET_CHAINS,
|
|
7320
|
+
...NON_EVM_CHAINS,
|
|
7321
|
+
];
|
|
7322
|
+
/**
|
|
7323
|
+
* Pre-built lookup index over all networks (EVM + non-EVM), like Go's
|
|
7324
|
+
* module-level maps. Resolution functions below bind to this index.
|
|
7325
|
+
*/
|
|
7326
|
+
const _idx = buildNetworkIndex(ALL_NETWORKS);
|
|
7086
7327
|
/**
|
|
7087
7328
|
* Resolve a chain from an arbitrary input. Accepts:
|
|
7088
7329
|
* - `number`: treated as chain ID
|
|
@@ -7092,14 +7333,20 @@ const _idx = buildNetworkIndex(MAINNET_CHAINS);
|
|
|
7092
7333
|
*
|
|
7093
7334
|
* Mirrors the Go `NetworkByAny` function.
|
|
7094
7335
|
*
|
|
7336
|
+
* Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
|
|
7337
|
+
* resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
|
|
7338
|
+
* if you need to distinguish them.
|
|
7339
|
+
*
|
|
7095
7340
|
* @example
|
|
7096
7341
|
* ```ts
|
|
7097
7342
|
* import { networkByAny } from "@gfxlabs/oku-chains";
|
|
7098
7343
|
*
|
|
7099
|
-
* networkByAny(1) // by chain ID
|
|
7344
|
+
* networkByAny(1) // by chain ID (EVM)
|
|
7100
7345
|
* networkByAny("mainnet") // by internal name
|
|
7101
|
-
* networkByAny("eip155:1") // by CAIP-2
|
|
7102
|
-
* networkByAny("42161") // by chain ID string
|
|
7346
|
+
* networkByAny("eip155:1") // by CAIP-2 (EVM)
|
|
7347
|
+
* networkByAny("42161") // by chain ID string (EVM)
|
|
7348
|
+
* networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
|
|
7349
|
+
* networkByAny("bitcoin") // by internal name (non-EVM)
|
|
7103
7350
|
* ```
|
|
7104
7351
|
*
|
|
7105
7352
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
@@ -7108,7 +7355,8 @@ function networkByAny(v) {
|
|
|
7108
7355
|
return networkByAny$1(v, _idx);
|
|
7109
7356
|
}
|
|
7110
7357
|
/**
|
|
7111
|
-
* Look up a chain by its numeric chain ID.
|
|
7358
|
+
* Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
|
|
7359
|
+
* and are not resolvable here.
|
|
7112
7360
|
*
|
|
7113
7361
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
7114
7362
|
*/
|
|
@@ -7116,7 +7364,8 @@ function networkById(id) {
|
|
|
7116
7364
|
return networkById$1(id, _idx);
|
|
7117
7365
|
}
|
|
7118
7366
|
/**
|
|
7119
|
-
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet"
|
|
7367
|
+
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
|
|
7368
|
+
* "bitcoin").
|
|
7120
7369
|
*
|
|
7121
7370
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
7122
7371
|
*/
|
|
@@ -7135,25 +7384,120 @@ function networkByString(s) {
|
|
|
7135
7384
|
return networkByString$1(s, _idx);
|
|
7136
7385
|
}
|
|
7137
7386
|
/**
|
|
7138
|
-
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1"
|
|
7387
|
+
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
|
|
7388
|
+
* "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
|
|
7389
|
+
* non-EVM chains.
|
|
7139
7390
|
*
|
|
7140
7391
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
7141
7392
|
*/
|
|
7142
7393
|
function networkByCAIP2(caip2) {
|
|
7143
7394
|
return networkByCAIP2$1(caip2, _idx);
|
|
7144
7395
|
}
|
|
7396
|
+
/**
|
|
7397
|
+
* Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
|
|
7398
|
+
* `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
|
|
7399
|
+
*/
|
|
7400
|
+
function namespaceOfChainLike(c) {
|
|
7401
|
+
if (typeof c === "object") {
|
|
7402
|
+
return c.caip2Namespace;
|
|
7403
|
+
}
|
|
7404
|
+
if (typeof c === "string") {
|
|
7405
|
+
// Full CAIP-2 identifier (namespace:reference) — classify by namespace.
|
|
7406
|
+
const sep = c.indexOf(":");
|
|
7407
|
+
if (sep !== -1) {
|
|
7408
|
+
return c.slice(0, sep);
|
|
7409
|
+
}
|
|
7410
|
+
// Bare CAIP-2 namespace (e.g. "eip155", "bip122").
|
|
7411
|
+
if (Object.values(exports.ChainType).includes(c) && c !== "") {
|
|
7412
|
+
return c;
|
|
7413
|
+
}
|
|
7414
|
+
// Otherwise treat as an internal name or numeric id string: resolve it.
|
|
7415
|
+
try {
|
|
7416
|
+
return networkByString$1(c, _idx).caip2Namespace;
|
|
7417
|
+
}
|
|
7418
|
+
catch {
|
|
7419
|
+
return "";
|
|
7420
|
+
}
|
|
7421
|
+
}
|
|
7422
|
+
// Numeric chain id.
|
|
7423
|
+
try {
|
|
7424
|
+
return networkById$1(Math.trunc(c), _idx).caip2Namespace;
|
|
7425
|
+
}
|
|
7426
|
+
catch {
|
|
7427
|
+
return "";
|
|
7428
|
+
}
|
|
7429
|
+
}
|
|
7430
|
+
/**
|
|
7431
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
7432
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
7433
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
7434
|
+
*
|
|
7435
|
+
* @example
|
|
7436
|
+
* ```ts
|
|
7437
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
7438
|
+
* chainType(1) // => ChainType.EVM
|
|
7439
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
7440
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
7441
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
7442
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
7443
|
+
* ```
|
|
7444
|
+
*/
|
|
7445
|
+
function chainType(c) {
|
|
7446
|
+
return chainType$1(namespaceOfChainLike(c));
|
|
7447
|
+
}
|
|
7448
|
+
/**
|
|
7449
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
7450
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
7451
|
+
* internal name, or a numeric chain id.
|
|
7452
|
+
*
|
|
7453
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
7454
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
7455
|
+
*
|
|
7456
|
+
* @example
|
|
7457
|
+
* ```ts
|
|
7458
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
7459
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
7460
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
7461
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
7462
|
+
* ```
|
|
7463
|
+
*/
|
|
7464
|
+
function isNetworkType(type, c) {
|
|
7465
|
+
return isNetworkType$1(type, namespaceOfChainLike(c));
|
|
7466
|
+
}
|
|
7467
|
+
/**
|
|
7468
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
7469
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
7470
|
+
* chain id.
|
|
7471
|
+
*/
|
|
7472
|
+
function isEvmChain(c) {
|
|
7473
|
+
return isEvmChain$1(namespaceOfChainLike(c));
|
|
7474
|
+
}
|
|
7475
|
+
/**
|
|
7476
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
7477
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
7478
|
+
* numeric chain id.
|
|
7479
|
+
*/
|
|
7480
|
+
function isNonEvmChain(c) {
|
|
7481
|
+
return isNonEvmChain$1(namespaceOfChainLike(c));
|
|
7482
|
+
}
|
|
7145
7483
|
|
|
7484
|
+
exports.ALL_NETWORKS = ALL_NETWORKS;
|
|
7146
7485
|
exports.MAINNET_CHAINS = MAINNET_CHAINS;
|
|
7486
|
+
exports.NON_EVM_CHAINS = NON_EVM_CHAINS;
|
|
7487
|
+
exports.NON_EVM_CHAIN_ID = NON_EVM_CHAIN_ID;
|
|
7147
7488
|
exports.NetworkNotFoundError = NetworkNotFoundError;
|
|
7148
7489
|
exports.arbitrum = arbitrum;
|
|
7149
7490
|
exports.avalanche = avalanche;
|
|
7150
7491
|
exports.base = base;
|
|
7492
|
+
exports.bitcoin = bitcoin;
|
|
7151
7493
|
exports.blast = blast;
|
|
7152
7494
|
exports.bob = bob;
|
|
7153
7495
|
exports.boba = boba;
|
|
7154
7496
|
exports.bsc = bsc;
|
|
7155
7497
|
exports.buildNetworkIndex = buildNetworkIndex;
|
|
7498
|
+
exports.caip2Reference = caip2Reference;
|
|
7156
7499
|
exports.celo = celo;
|
|
7500
|
+
exports.chainType = chainType;
|
|
7157
7501
|
exports.corn = corn;
|
|
7158
7502
|
exports.etherlink = etherlink;
|
|
7159
7503
|
exports.filecoin = filecoin;
|
|
@@ -7164,11 +7508,15 @@ exports.gnosis = gnosis;
|
|
|
7164
7508
|
exports.goat = goat;
|
|
7165
7509
|
exports.hemi = hemi;
|
|
7166
7510
|
exports.hyperevm = hyperevm;
|
|
7511
|
+
exports.isEvmChain = isEvmChain;
|
|
7512
|
+
exports.isNetworkType = isNetworkType;
|
|
7513
|
+
exports.isNonEvmChain = isNonEvmChain;
|
|
7167
7514
|
exports.lens = lens;
|
|
7168
7515
|
exports.lightlink = lightlink;
|
|
7169
7516
|
exports.linea = linea;
|
|
7170
7517
|
exports.lisk = lisk;
|
|
7171
7518
|
exports.mainnet = mainnet;
|
|
7519
|
+
exports.makeConfig = makeConfig;
|
|
7172
7520
|
exports.manta = manta;
|
|
7173
7521
|
exports.mantle = mantle;
|
|
7174
7522
|
exports.matchain = matchain;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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 {
|
|
5
|
+
export { makeConfig } from "./util/index";
|
|
6
|
+
export { buildNetworkIndex, type NetworkIndex, NetworkNotFoundError, } from "./util/lookup";
|
|
5
7
|
import type { IChainInfo } from "./spec";
|
|
8
|
+
import { ChainType } from "./spec";
|
|
6
9
|
export declare const MAINNET_CHAINS: readonly [Readonly<{
|
|
7
10
|
name: "Arbitrum";
|
|
8
11
|
launchTime: 1688997600;
|
|
@@ -10762,6 +10765,19 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
|
|
|
10762
10765
|
} & {
|
|
10763
10766
|
caip2Namespace: string;
|
|
10764
10767
|
}>];
|
|
10768
|
+
/**
|
|
10769
|
+
* Non-EVM chains (e.g. Bitcoin). These share the {@link IChainInfo} shape as
|
|
10770
|
+
* EVM chains but use the `NON_EVM_CHAIN_ID` (`0`) placeholder id and are
|
|
10771
|
+
* resolvable only via CAIP-2 (or internal name). Kept as a separate array so
|
|
10772
|
+
* the EVM-only surface (and the Go codegen, which reads `MAINNET_CHAINS`) is
|
|
10773
|
+
* unaffected.
|
|
10774
|
+
*/
|
|
10775
|
+
export declare const NON_EVM_CHAINS: readonly IChainInfo[];
|
|
10776
|
+
/**
|
|
10777
|
+
* All networks, EVM and non-EVM. Use this when you need to enumerate every
|
|
10778
|
+
* supported chain regardless of type.
|
|
10779
|
+
*/
|
|
10780
|
+
export declare const ALL_NETWORKS: readonly IChainInfo[];
|
|
10765
10781
|
/**
|
|
10766
10782
|
* Resolve a chain from an arbitrary input. Accepts:
|
|
10767
10783
|
* - `number`: treated as chain ID
|
|
@@ -10771,27 +10787,35 @@ export declare const MAINNET_CHAINS: readonly [Readonly<{
|
|
|
10771
10787
|
*
|
|
10772
10788
|
* Mirrors the Go `NetworkByAny` function.
|
|
10773
10789
|
*
|
|
10790
|
+
* Non-EVM chains (e.g. Bitcoin) use a placeholder numeric id and can only be
|
|
10791
|
+
* resolved via their CAIP-2 identifier or internal name. Use `isNonEvmChain`
|
|
10792
|
+
* if you need to distinguish them.
|
|
10793
|
+
*
|
|
10774
10794
|
* @example
|
|
10775
10795
|
* ```ts
|
|
10776
10796
|
* import { networkByAny } from "@gfxlabs/oku-chains";
|
|
10777
10797
|
*
|
|
10778
|
-
* networkByAny(1) // by chain ID
|
|
10798
|
+
* networkByAny(1) // by chain ID (EVM)
|
|
10779
10799
|
* networkByAny("mainnet") // by internal name
|
|
10780
|
-
* networkByAny("eip155:1") // by CAIP-2
|
|
10781
|
-
* networkByAny("42161") // by chain ID string
|
|
10800
|
+
* networkByAny("eip155:1") // by CAIP-2 (EVM)
|
|
10801
|
+
* networkByAny("42161") // by chain ID string (EVM)
|
|
10802
|
+
* networkByAny("bip122:000000000019d6689c085ae165831e93") // by CAIP-2 (non-EVM)
|
|
10803
|
+
* networkByAny("bitcoin") // by internal name (non-EVM)
|
|
10782
10804
|
* ```
|
|
10783
10805
|
*
|
|
10784
10806
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
10785
10807
|
*/
|
|
10786
10808
|
export declare function networkByAny(v: string | number | IChainInfo): IChainInfo;
|
|
10787
10809
|
/**
|
|
10788
|
-
* Look up a chain by its numeric chain ID.
|
|
10810
|
+
* Look up a chain by its numeric chain ID. Non-EVM chains use a placeholder id
|
|
10811
|
+
* and are not resolvable here.
|
|
10789
10812
|
*
|
|
10790
10813
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
10791
10814
|
*/
|
|
10792
10815
|
export declare function networkById(id: number): IChainInfo;
|
|
10793
10816
|
/**
|
|
10794
|
-
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet"
|
|
10817
|
+
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
|
|
10818
|
+
* "bitcoin").
|
|
10795
10819
|
*
|
|
10796
10820
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
10797
10821
|
*/
|
|
@@ -10806,8 +10830,66 @@ export declare function networkByName(name: string): IChainInfo;
|
|
|
10806
10830
|
*/
|
|
10807
10831
|
export declare function networkByString(s: string): IChainInfo;
|
|
10808
10832
|
/**
|
|
10809
|
-
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1"
|
|
10833
|
+
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
|
|
10834
|
+
* "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
|
|
10835
|
+
* non-EVM chains.
|
|
10810
10836
|
*
|
|
10811
10837
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
10812
10838
|
*/
|
|
10813
10839
|
export declare function networkByCAIP2(caip2: string): IChainInfo;
|
|
10840
|
+
/**
|
|
10841
|
+
* Accepted input for the chain-family helpers ({@link chainType},
|
|
10842
|
+
* {@link isNetworkType}, etc.).
|
|
10843
|
+
*
|
|
10844
|
+
* - `IChainInfo`: classified by its `caip2Namespace`.
|
|
10845
|
+
* - CAIP-2 string (contains `:`, e.g. `"eip155:1"`) or bare namespace
|
|
10846
|
+
* (e.g. `"bip122"`): classified directly by the namespace, no lookup needed.
|
|
10847
|
+
* - internal name (e.g. `"bitcoin"`) or numeric id / id string: resolved to a
|
|
10848
|
+
* chain via the network index first, then classified.
|
|
10849
|
+
*/
|
|
10850
|
+
export type ChainLike = IChainInfo | string | number;
|
|
10851
|
+
/**
|
|
10852
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
10853
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
10854
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
10855
|
+
*
|
|
10856
|
+
* @example
|
|
10857
|
+
* ```ts
|
|
10858
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
10859
|
+
* chainType(1) // => ChainType.EVM
|
|
10860
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
10861
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
10862
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
10863
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
10864
|
+
* ```
|
|
10865
|
+
*/
|
|
10866
|
+
export declare function chainType(c: ChainLike): ChainType;
|
|
10867
|
+
/**
|
|
10868
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
10869
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
10870
|
+
* internal name, or a numeric chain id.
|
|
10871
|
+
*
|
|
10872
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
10873
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
10874
|
+
*
|
|
10875
|
+
* @example
|
|
10876
|
+
* ```ts
|
|
10877
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
10878
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
10879
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
10880
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
10881
|
+
* ```
|
|
10882
|
+
*/
|
|
10883
|
+
export declare function isNetworkType(type: ChainType, c: ChainLike): boolean;
|
|
10884
|
+
/**
|
|
10885
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
10886
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
10887
|
+
* chain id.
|
|
10888
|
+
*/
|
|
10889
|
+
export declare function isEvmChain(c: ChainLike): boolean;
|
|
10890
|
+
/**
|
|
10891
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
10892
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
10893
|
+
* numeric chain id.
|
|
10894
|
+
*/
|
|
10895
|
+
export declare function isNonEvmChain(c: ChainLike): boolean;
|