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