@crypto-dex-sdk/chain
Version:
Zenlink Chain
184 lines (183 loc) • 7.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SUBSTRATE_NETWORKS = exports.EVM_NETWORKS = exports.chainsChainIdToParachainId = exports.chainsParachainIdToChainId = exports.chains = exports.chainName = exports.chainShortName = exports.chainShortNameToChainId = exports.chainIds = exports.Chain = exports.PARACHAIN_ID_MAP = exports.CHAIN_NAMES = exports.ChainKey = exports.ParachainId = exports.EthereumChainId = exports.Type = exports.Network = exports.Standard = void 0;
exports.isEvmNetwork = isEvmNetwork;
exports.isSubstrateNetwork = isSubstrateNetwork;
const chains_json_1 = __importDefault(require("./chains.json"));
const parachains_json_1 = __importDefault(require("./parachains.json"));
var Standard;
(function (Standard) {
Standard["Eip3091"] = "EIP3091";
Standard["None"] = "none";
})(Standard || (exports.Standard = Standard = {}));
var Network;
(function (Network) {
Network["Iorachain"] = "iorachain";
Network["Mainnet"] = "mainnet";
Network["Testnet"] = "testnet";
})(Network || (exports.Network = Network = {}));
var Type;
(function (Type) {
Type["L2"] = "L2";
Type["Shard"] = "shard";
})(Type || (exports.Type = Type = {}));
var EthereumChainId;
(function (EthereumChainId) {
EthereumChainId[EthereumChainId["ASTAR"] = 592] = "ASTAR";
EthereumChainId[EthereumChainId["MOONRIVER"] = 1285] = "MOONRIVER";
EthereumChainId[EthereumChainId["MOONBEAM"] = 1284] = "MOONBEAM";
EthereumChainId[EthereumChainId["ARBITRUM_ONE"] = 42161] = "ARBITRUM_ONE";
EthereumChainId[EthereumChainId["SCROLL"] = 534352] = "SCROLL";
EthereumChainId[EthereumChainId["SCROLL_ALPHA"] = 534353] = "SCROLL_ALPHA";
EthereumChainId[EthereumChainId["BASE"] = 8453] = "BASE";
})(EthereumChainId || (exports.EthereumChainId = EthereumChainId = {}));
var ParachainId;
(function (ParachainId) {
ParachainId[ParachainId["ASTAR"] = 2006] = "ASTAR";
ParachainId[ParachainId["MOONRIVER"] = 2023] = "MOONRIVER";
ParachainId[ParachainId["MOONBEAM"] = 2004] = "MOONBEAM";
ParachainId[ParachainId["BIFROST_KUSAMA"] = 2001] = "BIFROST_KUSAMA";
ParachainId[ParachainId["BIFROST_POLKADOT"] = 2030] = "BIFROST_POLKADOT";
ParachainId[ParachainId["ARBITRUM_ONE"] = 42161] = "ARBITRUM_ONE";
ParachainId[ParachainId["SCROLL"] = 534352] = "SCROLL";
ParachainId[ParachainId["SCROLL_ALPHA"] = 534353] = "SCROLL_ALPHA";
ParachainId[ParachainId["BASE"] = 8453] = "BASE";
ParachainId[ParachainId["AMPLITUDE"] = 2124] = "AMPLITUDE";
ParachainId[ParachainId["PENDULUM"] = 2094] = "PENDULUM";
})(ParachainId || (exports.ParachainId = ParachainId = {}));
var ChainKey;
(function (ChainKey) {
ChainKey["ASTAR"] = "Astar";
ChainKey["MOONBEAM"] = "Moonbeam";
ChainKey["MOONRIVER"] = "Moonriver";
ChainKey["BIFROST_KUSAMA"] = "Bifrost Kusama";
ChainKey["BIFROST_POLKADOT"] = "Bifrost Polkadot";
ChainKey["ARBITRUM_ONE"] = "Arbitrum One";
ChainKey["SCROLL"] = "Scroll";
ChainKey["SCROLL_ALPHA"] = "Scroll Alpha";
ChainKey["BASE"] = "Base";
ChainKey["AMPLITUDE"] = "Amplitude";
ChainKey["PENDULUM"] = "Pendulum";
})(ChainKey || (exports.ChainKey = ChainKey = {}));
exports.CHAIN_NAMES = [
'Astar',
'Moonbeam',
'Moonriver',
'Bifrost Kusama',
'Bifrost Polkadot',
'Arbitrum One',
'Scroll',
'Scroll Alpha',
'Base',
'Amplitude',
'Pendulum',
];
exports.PARACHAIN_ID_MAP = {
'Astar': 2006,
'Moonriver': 2023,
'Moonbeam': 2004,
'Bifrost Kusama': 2001,
'Bifrost Polkadot': 2030,
'Arbitrum One': 42161,
'Scroll': 534352,
'Scroll Alpha': 534353,
'Base': 8453,
'Amplitude': 2124,
'Pendulum': 2094,
};
const CHAINS = [...chains_json_1.default, ...parachains_json_1.default]
.filter(chain => exports.CHAIN_NAMES.includes(chain.name))
.map(chain => ({ ...chain, parachainId: exports.PARACHAIN_ID_MAP[chain.name] }));
class Chain {
static from(chainId) {
return exports.chains[chainId];
}
static fromShortName(shortName) {
return exports.chains[exports.chainShortName[shortName]];
}
static fromChainId(chainId) {
return exports.chains[chainId];
}
constructor(data) {
Object.assign(this, data);
}
getTxUrl(txHash) {
if (!this.explorers)
return '';
for (const explorer of this.explorers) {
if (explorer)
return `${explorer.url}/tx/${txHash}`;
}
return '';
}
getBlockUrl(blockHashOrHeight) {
if (!this.explorers)
return '';
for (const explorer of this.explorers) {
if (explorer.standard === Standard.Eip3091)
return `${explorer.url}/block/${blockHashOrHeight}`;
}
return '';
}
getTokenUrl(tokenAddress) {
if (!this.explorers)
return '';
for (const explorer of this.explorers) {
if (explorer)
return `${explorer.url}/token/${tokenAddress}`;
}
return '';
}
getAccountUrl(accountAddress) {
if (!this.explorers)
return '';
for (const explorer of this.explorers) {
if (explorer) {
if (explorer.name === 'subscan')
return `${explorer.url}/account/${accountAddress}`;
return `${explorer.url}/address/${accountAddress}`;
}
}
return '';
}
}
exports.Chain = Chain;
// ChainId array
exports.chainIds = CHAINS.map(chain => chain.parachainId);
// Parachain Short Name => Chain Id mapping
exports.chainShortNameToChainId = Object.fromEntries(CHAINS.map((data) => [data.shortName, data.parachainId]));
// Parachain Id => Short Name mapping
exports.chainShortName = Object.fromEntries(CHAINS.map((data) => [data.parachainId, data.shortName]));
// Parachain Id => Chain Name mapping
exports.chainName = Object.fromEntries(CHAINS.map((data) => [data.parachainId, data.name]));
// Parachain Id => Chain mapping
exports.chains = Object.fromEntries(CHAINS.map((data) => [data.parachainId, new Chain(data)]));
// Parachain Id => Ethereum ChainId mapping
exports.chainsParachainIdToChainId = Object.fromEntries(CHAINS.map((data) => [data.parachainId, data.chainId]));
// Ethereum ChainId => Parachain Id mapping
exports.chainsChainIdToParachainId = Object.fromEntries(CHAINS.map((data) => [data.chainId, data.parachainId]));
exports.default = exports.chains;
exports.EVM_NETWORKS = [
ParachainId.ASTAR,
ParachainId.MOONRIVER,
ParachainId.MOONBEAM,
ParachainId.ARBITRUM_ONE,
ParachainId.SCROLL,
ParachainId.SCROLL_ALPHA,
ParachainId.BASE,
];
exports.SUBSTRATE_NETWORKS = [
ParachainId.BIFROST_KUSAMA,
ParachainId.BIFROST_POLKADOT,
ParachainId.AMPLITUDE,
ParachainId.PENDULUM,
];
function isEvmNetwork(chainId) {
return exports.EVM_NETWORKS.includes(chainId);
}
function isSubstrateNetwork(chainId) {
return exports.SUBSTRATE_NETWORKS.includes(chainId);
}