UNPKG

@sushiswap/chain

Version:
311 lines 10 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.chainName = exports.chainShortName = exports.chainShortNameToChainId = exports.chainIds = exports.chainsL2 = exports.chains = exports.Chain = exports.ChainKey = exports.ChainId = exports.Type = exports.Network = exports.Standard = void 0; const generated_1 = __importDefault(require("./generated")); exports.Standard = { Eip3091: 'EIP3091', None: 'none', }; exports.Network = { Iorachain: 'iorachain', Mainnet: 'mainnet', Testnet: 'testnet', }; exports.Type = { L2: 'L2', Shard: 'shard', }; exports.ChainId = { ETHEREUM: 1, ROPSTEN: 3, RINKEBY: 4, GÖRLI: 5, KOVAN: 42, POLYGON: 137, POLYGON_TESTNET: 80001, FANTOM: 250, FANTOM_TESTNET: 4002, GNOSIS: 100, BSC: 56, BSC_TESTNET: 97, ARBITRUM: 42161, ARBITRUM_NOVA: 42170, ARBITRUM_TESTNET: 79377087078960, AVALANCHE: 43114, AVALANCHE_TESTNET: 43113, HECO: 128, HECO_TESTNET: 256, HARMONY: 1666600000, HARMONY_TESTNET: 1666700000, OKEX: 66, OKEX_TESTNET: 65, CELO: 42220, PALM: 11297108109, MOONRIVER: 1285, FUSE: 122, TELOS: 40, MOONBEAM: 1284, OPTIMISM: 10, KAVA: 2222, METIS: 1088, BOBA: 288, BOBA_AVAX: 43288, BOBA_BNB: 56288, BTTC: 199, // SEPOLIA: 11155111, // CONSENSUS_ZKEVM_TESTNET: 59140, // SCROLL_ALPHA_TESTNET: 534353, // BASE_TESTNET: 84531, POLYGON_ZKEVM: 1101, THUNDERCORE: 108, // FILECOIN: 314, }; // export const isChainId = (chainId: number): chainId is ChainId => Object.values(ChainId).includes(chainId as ChainId) exports.ChainKey = { [exports.ChainId.ARBITRUM]: 'arbitrum', [exports.ChainId.ARBITRUM_NOVA]: 'arbitrum-nova', [exports.ChainId.ARBITRUM_TESTNET]: 'arbitrum-testnet', [exports.ChainId.AVALANCHE]: 'avalanche', [exports.ChainId.AVALANCHE_TESTNET]: 'avalance-testnet', [exports.ChainId.BSC]: 'bsc', [exports.ChainId.BSC_TESTNET]: 'bsc-testnet', [exports.ChainId.CELO]: 'celo', [exports.ChainId.ETHEREUM]: 'ethereum', [exports.ChainId.FANTOM]: 'fantom', [exports.ChainId.FANTOM_TESTNET]: 'fantom-testnet', [exports.ChainId.FUSE]: 'fuse', [exports.ChainId.GÖRLI]: 'goerli', [exports.ChainId.HARMONY]: 'harmony', [exports.ChainId.HARMONY_TESTNET]: 'harmony-testnet', [exports.ChainId.HECO]: 'heco', [exports.ChainId.HECO_TESTNET]: 'heco-testnet', [exports.ChainId.KOVAN]: 'kovan', [exports.ChainId.ROPSTEN]: 'ropsten', [exports.ChainId.POLYGON]: 'polygon', [exports.ChainId.POLYGON_TESTNET]: 'matic-testnet', [exports.ChainId.MOONBEAM]: 'moonbeam', // [ChainId.MOONBEAM_TESTNET]: 'moonbeam-testnet', [exports.ChainId.MOONRIVER]: 'moonriver', [exports.ChainId.OKEX]: 'okex', [exports.ChainId.OKEX_TESTNET]: 'okex-testnet', [exports.ChainId.PALM]: 'palm', // [ChainId.PALM_TESTNET]: 'palm-testnet', [exports.ChainId.RINKEBY]: 'rinkeby', [exports.ChainId.TELOS]: 'telos', [exports.ChainId.GNOSIS]: 'gnosis', [exports.ChainId.OPTIMISM]: 'optimism', [exports.ChainId.KAVA]: 'kava', [exports.ChainId.METIS]: 'metis', [exports.ChainId.BOBA]: 'boba', [exports.ChainId.BOBA_AVAX]: 'boba-avax', [exports.ChainId.BOBA_BNB]: 'boba-bnb', [exports.ChainId.BTTC]: 'bttc', // [ChainId.CONSENSUS_ZKEVM_TESTNET]: 'consensus-zkevm-testnet', // [ChainId.SCROLL_ALPHA_TESTNET]: 'scroll-alpha-testnet', // [ChainId.BASE_TESTNET]:'base-testnet', [exports.ChainId.POLYGON_ZKEVM]: 'polygon-zkevm', [exports.ChainId.THUNDERCORE]: 'thundercore', // [ChainId.FILECOIN]: 'filecoin', // [ChainId.SEPOLIA]: 'sepolia', }; const additional = [ // { // name: 'Scroll Alpha Testnet', // chain: 'Scroll', // rpc: ['https://alpha-rpc.scroll.io/l2'], // faucets: [], // features: [], // nativeCurrency: { // name: 'Ethereum', // symbol: 'ETH', // decimals: 18, // }, // infoURL: 'https://scroll.io', // shortName: 'scrollalpha', // chainId: 534353, // networkId: 534353, // explorers: [ // { // name: 'Scroll Alpha Explorer', // url: 'https://blockscout.scroll.io', // standard: Standard.None, // }, // ], // }, // { // name: 'ConsenSys zkEVM Goreli', // chain: 'ConsenSys zkEVM', // rpc: ['https://consensys-zkevm-goerli-prealpha.infura.io/v3/53fca4c2b95a43cca82a11e8b573256b'], // faucets: [], // nativeCurrency: { // name: 'Ethereum', // symbol: 'ETH', // decimals: 18, // }, // infoURL: 'https://docs.zkevm.consensys.net', // shortName: 'consensuszkevmgoerli', // chainId: 59140, // networkId: 59140, // explorers: [ // { // name: 'ConsenSys zkEVM Goreli Explorer', // url: 'https://explorer.goerli.zkevm.consensys.net', // standard: Standard.None, // }, // ], // }, // { // name: 'Base Goreli', // chain: 'Base', // rpc: ['https://goerli.base.org'], // faucets: [], // nativeCurrency: { // name: 'Ethereum', // symbol: 'ETH', // decimals: 18, // }, // infoURL: 'https://docs.base.org', // shortName: 'basegoerli', // chainId: 84531, // networkId: 84531, // explorers: [ // { // name: 'Base Goreli Explorer', // url: 'https://goerli.basescan.org', // standard: Standard.Eip3091, // }, // ], // }, // { // name: 'ThunderCore', // chain: 'ThunderCore', // rpc: [ // 'https://mainnet-rpc.thundercore.io', // 'https://mainnet-rpc.thundercore.com', // 'https://mainnet-rpc.thundertoken.net', // ], // faucets: [], // nativeCurrency: { // name: 'Thunder Token', // symbol: 'TT', // decimals: 18, // }, // infoURL: 'https://docs.developers.thundercore.com', // shortName: 'thundercore', // chainId: 108, // networkId: 108, // explorers: [ // { // name: 'ThunderCore Explorer', // url: 'https://viewblock.io/thundercore', // standard: Standard.None, // }, // ], // }, ]; const RAW = [...generated_1.default, ...additional]; const EIP3091_OVERRIDE = [exports.ChainId.OPTIMISM, exports.ChainId.BOBA]; class Chain { static fromRaw(data) { return new Chain(data); } static from(chainId) { return exports.chains[chainId]; } static fromShortName(shortName) { const chainId = exports.chainShortNameToChainId[shortName]; if (!chainId) throw new Error(`Unknown chain short name: ${shortName}`); return Chain.from(chainId); } static fromChainId(chainId) { return Chain.from(chainId); } static txUrl(chainId, txHash) { return Chain.fromChainId(chainId).getTxUrl(txHash); } static blockUrl(chainId, blockHashOrHeight) { return Chain.fromChainId(chainId).getBlockUrl(blockHashOrHeight); } static tokenUrl(chainId, tokenAddress) { return Chain.fromChainId(chainId).getTokenUrl(tokenAddress); } static accountUrl(chainId, accountAddress) { return Chain.fromChainId(chainId).getAccountUrl(accountAddress); } constructor(data) { Object.assign(this, data); // process name overrides const targets = ['Mainnet', 'Opera', 'Mainnet Shard 0']; for (const target of targets) { if (data.name.includes(target)) { this.name = data.name.replace(target, '').trim(); } } if (data.name === 'Boba Network') { this.name = 'Boba Eth'; } // process explorer overrides etc... } getTxUrl(txHash) { if (!this.explorers) return ''; for (const explorer of this.explorers) { if (explorer.standard === exports.Standard.Eip3091 || EIP3091_OVERRIDE.includes(this.chainId)) { return `${explorer.url}/tx/${txHash}`; } } return ''; } getBlockUrl(blockHashOrHeight) { if (!this.explorers) return ''; for (const explorer of this.explorers) { if (explorer.standard === exports.Standard.Eip3091) { return `${explorer.url}/block/${blockHashOrHeight}`; } } return ''; } getTokenUrl(tokenAddress) { if (!this.explorers) return ''; for (const explorer of this.explorers) { if (explorer.standard === exports.Standard.Eip3091 || EIP3091_OVERRIDE.includes(this.chainId)) { return `${explorer.url}/token/${tokenAddress}`; } } return ''; } getAccountUrl(accountAddress) { if (!this.explorers) return ''; for (const explorer of this.explorers) { if (explorer.standard === exports.Standard.Eip3091 || EIP3091_OVERRIDE.includes(this.chainId)) { return `${explorer.url}/address/${accountAddress}`; } } return ''; } } exports.Chain = Chain; // Chain Id => Chain mapping exports.chains = Object.fromEntries(RAW.map((data) => [data.chainId, new Chain(data)])); // Chain Id => Chain mapping exports.chainsL2 = Object.fromEntries(RAW.filter((data) => 'parent' in data && data.parent.type === exports.Type.L2).map((data) => [ data.chainId, new Chain(data), ])); // ChainId array exports.chainIds = RAW.map((chain) => chain.chainId); // Chain Short Name => Chain Id mapping exports.chainShortNameToChainId = Object.fromEntries(RAW.map((data) => [data.shortName, data.chainId])); // Chain Id => Short Name mapping exports.chainShortName = Object.fromEntries(RAW.map((data) => [data.chainId, Chain.fromRaw(data).shortName])); // Chain Id => Chain Name mapping exports.chainName = Object.fromEntries(RAW.map((data) => [data.chainId, Chain.fromRaw(data).name])); exports.default = exports.chains; //# sourceMappingURL=index.js.map