diff --git a/AGENTS.md b/AGENTS.md index 4ce4ac8..153a458 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,9 +60,9 @@ When modifying components: ## 6. Data Management -The app fetches data from Chainstack API: +The app fetches data from Chainstack's public pricing catalog: -* **API endpoint**: `https://console.chainstack.com/api/core/v1/calc/` +* **Catalog URL**: `https://static.chainstack.com/pricing/pricing_current.json` * **Data processing**: `src/helpers/getData.js` * **Caching**: Consider localStorage for performance * **Error handling**: Display user-friendly messages diff --git a/README.md b/README.md index 1495cfb..3b2806e 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,9 @@ Production URL: [https://chainstats.org](https://chainstats.org) ## Data Source -- API endpoint: `https://console.chainstack.com/api/core/v1/calc/` -- Source path: `Enterprise.protocols` -- Inclusion rule in UI: - - Use only `dedicated` entries - - Include only nodes where `type === "public"` - - Skip entries without `node_info.storage.size_required` +- Catalog: `https://static.chainstack.com/pricing/pricing_current.json`, also used by the Chainstack pricing page. +- Read full and archive entries from `blockchains` with at least one dedicated cloud and a positive `total_storage_gb`. +- Display the largest estimate when the catalog lists several configurations for the same protocol, network, node type, and client. The catalog uses requested volume capacity or configuration defaults. ## Features @@ -25,7 +22,7 @@ Production URL: [https://chainstats.org](https://chainstats.org) ## Stack - React 19 -- Vite 7 +- Vite 8 - Ant Design 6 - Sass - Axios @@ -57,7 +54,7 @@ Open [http://localhost:5173](http://localhost:5173). - `npm run build`: create production build in `dist/`. - `npm run preview`: preview built app locally. - `npm run test`: run Vitest (`--passWithNoTests`). -- `npm run check:protocol-icons`: compare visible API protocols to icon map coverage. +- `npm run check:protocol-icons`: validate the pricing catalog and report custom icon coverage and fallback badge usage. - `npm run deploy`: publish `dist/` to GitHub Pages. ## CI @@ -65,6 +62,7 @@ Open [http://localhost:5173](http://localhost:5173). Workflow: `.github/workflows/ci.yml` Runs: + 1. `npm ci` 2. `npm run check:protocol-icons` 3. `npm run build` diff --git a/index.html b/index.html index 59d0e1e..8a79d66 100644 --- a/index.html +++ b/index.html @@ -5,25 +5,25 @@ - Blockchain Size - How Much Storage Does A Blockchain Use? + Blockchain Size | Estimated Node Storage @@ -31,11 +31,11 @@ diff --git a/scripts/check-protocol-icons.js b/scripts/check-protocol-icons.js index 5766c1d..31a6dcf 100644 --- a/scripts/check-protocol-icons.js +++ b/scripts/check-protocol-icons.js @@ -5,10 +5,6 @@ const path = require('path'); const https = require('https'); const http = require('http'); -const API_URL = - process.env.CHAINSTACK_CALC_API || - 'https://console.chainstack.com/api/core/v1/calc/'; - const projectRoot = path.resolve(__dirname, '..'); const protocolMetadataPath = path.join( projectRoot, @@ -86,58 +82,29 @@ const fetchJson = (url) => { }); }; -const getVisibleProtocolDisplayNames = (protocols) => { - const visibleProtocols = new Set(); - - Object.entries(protocols).forEach(([protocolSlug, networks]) => { - Object.values(networks).forEach((networkData) => { - if (networkData && networkData.dedicated) { - const hasPublicNode = ['full', 'archive'].some((nodeType) => { - const nodes = networkData.dedicated[nodeType]; - - if (!nodes) { - return false; - } - - return Object.values(nodes).some((nodeConfig) => { - const sizeRequired = nodeConfig?.node_info?.storage?.size_required; - return nodeConfig?.type === 'public' && sizeRequired != null; - }); - }); - - if (hasPublicNode) { - visibleProtocols.add(formatProtocolDisplayName(protocolSlug)); - } - } - }); - }); - - return visibleProtocols; -}; - const main = async () => { - const payload = await fetchJson(API_URL); - const protocols = payload?.Enterprise?.protocols; - - if (!protocols) { - throw new Error('Unexpected API response: missing Enterprise.protocols'); - } + const { PRICING_CATALOG_URL, parsePricingCatalog } = await import( + '../src/helpers/pricingCatalog.mjs' + ); + const payload = await fetchJson(process.env.CHAINSTACK_CALC_API || PRICING_CATALOG_URL); + const networks = parsePricingCatalog(payload); const iconKeys = extractIconKeys(); - const visibleProtocolNames = getVisibleProtocolDisplayNames(protocols); + const visibleProtocolNames = new Set( + networks.map(({ protocol }) => formatProtocolDisplayName(protocol)) + ); - const missingIconProtocols = Array.from(visibleProtocolNames) + const fallbackNames = [...visibleProtocolNames] .filter((protocolName) => !iconKeys.has(protocolName)) .sort(); + const mappedCount = visibleProtocolNames.size - fallbackNames.length; - if (missingIconProtocols.length) { - console.error('Protocol icons missing for one or more visible protocols.'); - process.exitCode = 1; - return; + if (fallbackNames.length) { + console.warn(`Fallback badges used for ${fallbackNames.join(', ')}.`); } console.log( - `Protocol icon check passed for ${visibleProtocolNames.size} visible protocols` + `Custom icons available for ${mappedCount} of ${visibleProtocolNames.size} visible protocols.` ); }; diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index 2c7f0b4..2388c86 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -24,7 +24,7 @@ export default function Header(props) {

Blockchain size

- What is total amount of data stored within a blockchain network? + Storage estimates for full and archive nodes by network and client

diff --git a/src/components/ProtocolIcon/ProtocolIcon.jsx b/src/components/ProtocolIcon/ProtocolIcon.jsx index 907347f..d24c6c8 100644 --- a/src/components/ProtocolIcon/ProtocolIcon.jsx +++ b/src/components/ProtocolIcon/ProtocolIcon.jsx @@ -1,39 +1,66 @@ import React from 'react'; +import AdiChain from './adichain.svg'; import Aptos from './aptos.svg?react'; import Arbitrum from './arbitrum.svg?react'; +import Arc from './arc.png?no-inline'; +import Astar from './astar.svg'; import Aurora from './aurora.svg?react'; import Avalanche from './avalanche.svg?react'; import Base from './base.svg?react'; +import Berachain from './berachain.svg'; import Bitcoin from './bitcoin.svg?react'; +import Bittensor from './bittensor.svg?react'; import Bnb from './bnb.svg?react'; +import Cardano from './cardano.svg'; import Cronos from './cronos.svg?react'; +import Elysium from './elysium.svg'; import Ethereum from './ethereum.svg?react'; +import Etherlink from './etherlink.svg'; import Fantom from './fantom.svg?react'; import Filecoin from './filecoin.svg?react'; import Fuse from './fuse.svg?react'; import Gnosis from './gnosis.svg?react'; import Harmony from './harmony.svg?react'; +import Ink from './ink.svg'; +import Jovay from './jovay.svg'; +import Kaia from './kaia.svg'; +import Katana from './katana.jpg?no-inline'; +import Linea from './linea.svg'; +import Litecoin from './litecoin.svg'; +import Mind from './mind.svg'; import Near from './near.svg?react'; +import NeoX from './neox.svg'; import Optimism from './optimism.svg?react'; +import Pharos from './pharos.svg'; +import Plume from './plume.svg'; import PolygonPOS from './polygonPOS.svg?react'; import PolygonZkEvm from './polygonZkEvm.svg?react'; +import Robinhood from './robinhood.svg'; import Ronin from './ronin.svg?react'; import Scroll from './scroll.svg?react'; import Solana from './solana.svg?react'; import Starknet from './starknet.svg?react'; +import Stellar from './stellar.png?no-inline'; +import Sui from './sui.svg'; +import Tac from './tac.png?no-inline'; +import Taiko from './taiko.svg'; import Tezos from './tezos.svg?react'; import ZkSync from './zkSync.svg?react'; import Tron from './tron.svg?react'; import Sonic from './sonic.svg?react'; import Celo from './celo.svg?react'; import Hyperliquid from './hyperliquid.svg?react'; -import Klaytn from './klaytn.svg?react'; import Megaeth from './megaeth.svg?react'; import Monad from './monad.svg?react'; import Plasma from './plasma.svg?react'; import Tempo from './tempo.svg?react'; import Unichain from './unichain.svg?react'; +import Xdc from './xdc.svg'; +import XLayer from './xlayer.png?no-inline'; +import XrpLedger from './xrpl.png?no-inline'; +import Zcash from './zcash.svg'; +import ZkLink from './zklink.svg'; import './ProtocolIcon.scss'; const TextBadgeIcon = ({ label, color }) => ( @@ -48,40 +75,67 @@ const TextBadgeIcon = ({ label, color }) => ( ); const iconTypes = { + 'ADI Chain': , Aptos: , Arbitrum: , + Arc: , + Astar: , Aurora: , Avalanche: , Base: , + Berachain: , Bitcoin: , + Bittensor: , 'BNB Smart Chain': , + Cardano: , Cronos: , + Elysium: , Ethereum: , + Etherlink: , Fantom: , Filecoin: , Fuse: , - Gnosis: , + 'Gnosis Chain': , Harmony: , + Ink: , + Jovay: , + Kaia: , + Katana: , + Linea: , + Litecoin: , + Mind: , Near: , + 'Neo X': , Optimism: , + Pharos: , + Plume: , 'Polygon PoS': , 'Polygon zkEVM': , + 'Robinhood Chain': , Ronin: , Scroll: , Solana: , Starknet: , + Stellar: , + Sui: , + TAC: , + Taiko: , Tezos: , - zkSync: , TRON: , Sonic: , Celo: , - Klaytn: , Hyperliquid: , - Megaeth: , + MegaETH: , Monad: , Plasma: , Tempo: , Unichain: , + 'XDC Network': , + 'X Layer': , + 'XRP Ledger': , + Zcash: , + zkLink: , + 'ZKsync Era': , }; const ProtocolIcon = ({ protocolName = '' }) => { diff --git a/src/components/ProtocolIcon/ProtocolIcon.scss b/src/components/ProtocolIcon/ProtocolIcon.scss index ff664f2..9e8beb5 100644 --- a/src/components/ProtocolIcon/ProtocolIcon.scss +++ b/src/components/ProtocolIcon/ProtocolIcon.scss @@ -2,14 +2,17 @@ display: inline-flex; width: 18px; height: 18px; + flex: 0 0 18px; align-items: center; justify-content: center; color: var(--color-typo-primary); - svg { + svg, + img { width: 18px; height: 18px; display: block; + object-fit: contain; } } diff --git a/src/components/ProtocolIcon/ProtocolIcon.test.jsx b/src/components/ProtocolIcon/ProtocolIcon.test.jsx index 9527df7..dd849b5 100644 --- a/src/components/ProtocolIcon/ProtocolIcon.test.jsx +++ b/src/components/ProtocolIcon/ProtocolIcon.test.jsx @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'; import ProtocolIcon from './ProtocolIcon'; describe('ProtocolIcon', () => { - it.each(['Megaeth', 'Monad', 'Plasma', 'Tempo', 'Unichain'])( + it.each(['MegaETH', 'Monad', 'Plasma', 'Tempo', 'Unichain', 'ZKsync Era'])( 'renders an SVG icon for %s', (protocolName) => { const { container } = render(); @@ -11,6 +11,11 @@ describe('ProtocolIcon', () => { } ); + it.each(['Kaia', 'XRP Ledger'])('renders a bundled logo for %s', (protocolName) => { + const { container } = render(); + expect(container.querySelector('img')?.getAttribute('src')).toBeTruthy(); + }); + it('renders a fallback badge for unknown protocols', () => { render(); expect(screen.getByText('UP')).toBeTruthy(); diff --git a/src/components/ProtocolIcon/adichain.svg b/src/components/ProtocolIcon/adichain.svg new file mode 100644 index 0000000..8e72ab7 --- /dev/null +++ b/src/components/ProtocolIcon/adichain.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/components/ProtocolIcon/arc.png b/src/components/ProtocolIcon/arc.png new file mode 100644 index 0000000..8259673 Binary files /dev/null and b/src/components/ProtocolIcon/arc.png differ diff --git a/src/components/ProtocolIcon/astar.svg b/src/components/ProtocolIcon/astar.svg new file mode 100644 index 0000000..504ce10 --- /dev/null +++ b/src/components/ProtocolIcon/astar.svg @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/berachain.svg b/src/components/ProtocolIcon/berachain.svg new file mode 100644 index 0000000..4e071a0 --- /dev/null +++ b/src/components/ProtocolIcon/berachain.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/components/ProtocolIcon/bittensor.svg b/src/components/ProtocolIcon/bittensor.svg new file mode 100644 index 0000000..cbe2bb7 --- /dev/null +++ b/src/components/ProtocolIcon/bittensor.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/cardano.svg b/src/components/ProtocolIcon/cardano.svg new file mode 100644 index 0000000..2d9b7a4 --- /dev/null +++ b/src/components/ProtocolIcon/cardano.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/elysium.svg b/src/components/ProtocolIcon/elysium.svg new file mode 100644 index 0000000..d33717a --- /dev/null +++ b/src/components/ProtocolIcon/elysium.svg @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/etherlink.svg b/src/components/ProtocolIcon/etherlink.svg new file mode 100644 index 0000000..8522f92 --- /dev/null +++ b/src/components/ProtocolIcon/etherlink.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/components/ProtocolIcon/ink.svg b/src/components/ProtocolIcon/ink.svg new file mode 100644 index 0000000..e3e3b7d --- /dev/null +++ b/src/components/ProtocolIcon/ink.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/jovay.svg b/src/components/ProtocolIcon/jovay.svg new file mode 100644 index 0000000..e2b0b42 --- /dev/null +++ b/src/components/ProtocolIcon/jovay.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/kaia.svg b/src/components/ProtocolIcon/kaia.svg new file mode 100644 index 0000000..251da8b --- /dev/null +++ b/src/components/ProtocolIcon/kaia.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/katana.jpg b/src/components/ProtocolIcon/katana.jpg new file mode 100644 index 0000000..ad1fb95 Binary files /dev/null and b/src/components/ProtocolIcon/katana.jpg differ diff --git a/src/components/ProtocolIcon/klaytn.svg b/src/components/ProtocolIcon/klaytn.svg deleted file mode 100644 index 120584d..0000000 --- a/src/components/ProtocolIcon/klaytn.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - diff --git a/src/components/ProtocolIcon/linea.svg b/src/components/ProtocolIcon/linea.svg new file mode 100644 index 0000000..32b12a8 --- /dev/null +++ b/src/components/ProtocolIcon/linea.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/components/ProtocolIcon/litecoin.svg b/src/components/ProtocolIcon/litecoin.svg new file mode 100644 index 0000000..5466b76 --- /dev/null +++ b/src/components/ProtocolIcon/litecoin.svg @@ -0,0 +1,5 @@ + + + Artboard 26 + + diff --git a/src/components/ProtocolIcon/mind.svg b/src/components/ProtocolIcon/mind.svg new file mode 100644 index 0000000..27707e2 --- /dev/null +++ b/src/components/ProtocolIcon/mind.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/neox.svg b/src/components/ProtocolIcon/neox.svg new file mode 100644 index 0000000..eced178 --- /dev/null +++ b/src/components/ProtocolIcon/neox.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/ProtocolIcon/pharos.svg b/src/components/ProtocolIcon/pharos.svg new file mode 100644 index 0000000..66d73fc --- /dev/null +++ b/src/components/ProtocolIcon/pharos.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/plume.svg b/src/components/ProtocolIcon/plume.svg new file mode 100644 index 0000000..d64fe80 --- /dev/null +++ b/src/components/ProtocolIcon/plume.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/robinhood.svg b/src/components/ProtocolIcon/robinhood.svg new file mode 100644 index 0000000..b75598d --- /dev/null +++ b/src/components/ProtocolIcon/robinhood.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/stellar.png b/src/components/ProtocolIcon/stellar.png new file mode 100644 index 0000000..967984b Binary files /dev/null and b/src/components/ProtocolIcon/stellar.png differ diff --git a/src/components/ProtocolIcon/sui.svg b/src/components/ProtocolIcon/sui.svg new file mode 100644 index 0000000..197f644 --- /dev/null +++ b/src/components/ProtocolIcon/sui.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/tac.png b/src/components/ProtocolIcon/tac.png new file mode 100644 index 0000000..3e609f4 Binary files /dev/null and b/src/components/ProtocolIcon/tac.png differ diff --git a/src/components/ProtocolIcon/taiko.svg b/src/components/ProtocolIcon/taiko.svg new file mode 100644 index 0000000..407debf --- /dev/null +++ b/src/components/ProtocolIcon/taiko.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/xdc.svg b/src/components/ProtocolIcon/xdc.svg new file mode 100644 index 0000000..9c2a60b --- /dev/null +++ b/src/components/ProtocolIcon/xdc.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/components/ProtocolIcon/xlayer.png b/src/components/ProtocolIcon/xlayer.png new file mode 100644 index 0000000..71dbb4a Binary files /dev/null and b/src/components/ProtocolIcon/xlayer.png differ diff --git a/src/components/ProtocolIcon/xrpl.png b/src/components/ProtocolIcon/xrpl.png new file mode 100644 index 0000000..5b9343d Binary files /dev/null and b/src/components/ProtocolIcon/xrpl.png differ diff --git a/src/components/ProtocolIcon/zcash.svg b/src/components/ProtocolIcon/zcash.svg new file mode 100644 index 0000000..24f037a --- /dev/null +++ b/src/components/ProtocolIcon/zcash.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/ProtocolIcon/zklink.svg b/src/components/ProtocolIcon/zklink.svg new file mode 100644 index 0000000..0ee2ae0 --- /dev/null +++ b/src/components/ProtocolIcon/zklink.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/components/TableWrapper/TableWrapper.jsx b/src/components/TableWrapper/TableWrapper.jsx index 314882c..62cf825 100644 --- a/src/components/TableWrapper/TableWrapper.jsx +++ b/src/components/TableWrapper/TableWrapper.jsx @@ -226,7 +226,7 @@ const TableWrapper = ({ data }) => { sortOrder: activeSorter?.field === 'client' ? activeSorter.order : null, }, { - title: 'Data stored, GB', + title: 'Storage\u00a0(GB)', dataIndex: 'size_required', align: 'right', sorter: true, diff --git a/src/helpers/clientDisplay.js b/src/helpers/clientDisplay.js index dc90a44..8973c3f 100644 --- a/src/helpers/clientDisplay.js +++ b/src/helpers/clientDisplay.js @@ -1,8 +1,33 @@ const CLIENT_DISPLAY_NAMES = { - bitcoind: 'Bitcoin Core', - 'zkevm-node': 'zkEVM Node', + aldaba_light: 'Aldaba Light', + 'aptos-core': 'Aptos Core', + 'arc-node': 'Arc Node', + 'astar-collator': 'Astar Collator', avalanchego: 'AvalancheGo', + bitcoind: 'Bitcoin Core', + 'cardano-node': 'Cardano Node', + 'cdk-erigon': 'CDK Erigon', + 'conduit-op-reth': 'Conduit OP Reth', + 'java-tron': 'java-tron', + litecoind: 'Litecoin Core', + 'mind-nitro': 'Mind Nitro', + nanoreth: 'NanoReth', + 'op-erigon': 'OP Erigon', + 'op-geth': 'OP Geth', + 'op-node': 'OP Node', + 'op-reth': 'OP Reth', + pharos_light: 'Pharos Light', + 'plume-nitro': 'Plume Nitro', + 'stellar-core': 'Stellar Core', + 'sui-node': 'Sui Node', + 'taiko-geth': 'Taiko Geth', 'tezos-node': 'Octez', + xdc: 'XDC', + xrpld: 'xrpld', + zebrad: 'Zebra', + 'zkevm-node': 'zkEVM Node', + zklink: 'zkLink', + 'zksync-era': 'ZKsync Era', }; const formatClientName = (clientName = '') => { diff --git a/src/helpers/getData.js b/src/helpers/getData.js index ee1333a..0dcf24c 100644 --- a/src/helpers/getData.js +++ b/src/helpers/getData.js @@ -1,83 +1,9 @@ import axios from 'axios'; - -const fetchProtocolData = async () => { - try { - const response = await axios.get( - 'https://console.chainstack.com/api/core/v1/calc/' - ); - return response.data.Enterprise.protocols; - } catch (error) { - console.error('Error fetching data: ', error); - throw error; - } -}; - -const parseProtocolData = (protocols) => { - const parsedData = []; - - for (const protocol of Object.keys(protocols)) { - for (const network of Object.keys(protocols[protocol])) { - const { dedicated: dedicatedData } = protocols[protocol][network]; - - if (dedicatedData) { - const { full, archive } = dedicatedData; - const fullParsed = full ? parseNodeData(full) : []; - const archiveParsed = archive ? parseNodeData(archive) : []; - - const protocolItem = { - protocol, - network, - ...(fullParsed.length && { full: fullParsed }), - ...(archiveParsed.length && { archive: archiveParsed }), - }; - - if (protocolItem.full || protocolItem.archive) { - parsedData.push(protocolItem); - } - } - } - } - - return parsedData; -}; - -const parseNodeData = (nodeData) => { - const parsedNodeData = []; - for (const client in nodeData) { - if (Object.hasOwn(nodeData, client)) { - const clientData = nodeData[client]; - const sizeRequired = clientData?.node_info?.storage?.size_required; - - if ( - clientData?.type !== 'public' || - sizeRequired === null || - sizeRequired === undefined - ) { - continue; - } - - const normalizedSize = Number(sizeRequired); - - if (!Number.isFinite(normalizedSize)) { - continue; - } - - parsedNodeData.push({ - node_data: { - client, - size_required: normalizedSize, - }, - }); - } - } - - return parsedNodeData; -}; +import { PRICING_CATALOG_URL, parsePricingCatalog } from './pricingCatalog.mjs'; const processData = async () => { - const protocolData = await fetchProtocolData(); - const parsedProtocolData = parseProtocolData(protocolData); - return parsedProtocolData; + const { data } = await axios.get(PRICING_CATALOG_URL); + return parsePricingCatalog(data); }; export default processData; diff --git a/src/helpers/getData.test.js b/src/helpers/getData.test.js index affc537..1cef1c5 100644 --- a/src/helpers/getData.test.js +++ b/src/helpers/getData.test.js @@ -8,106 +8,107 @@ vi.mock('axios', () => ({ }, })); +const catalogEntry = (overrides = {}) => ({ + protocol: { name: 'Polygon', title: 'Polygon' }, + network: { name: 'polygon-pos-mainnet', title: 'Mainnet' }, + client: { name: 'bor', title: 'Bor' }, + mode: 'full', + clouds: { example: {} }, + total_storage_gb: 850, + storage_package_gb: 20, + ...overrides, +}); + describe('processData', () => { beforeEach(() => { - vi.clearAllMocks(); + vi.resetAllMocks(); }); - it('keeps only dedicated public nodes that have storage size data', async () => { + it('groups dedicated storage sizes by network, node type and client', async () => { axios.get.mockResolvedValue({ data: { - Enterprise: { - protocols: { - foo: { - 'foo-mainnet': { - dedicated: { - full: { - 'foo-public': { - type: 'public', - node_info: { - storage: { - size_required: 100, - }, - }, - }, - 'foo-private': { - type: 'consortium', - node_info: { - storage: { - size_required: 200, - }, - }, - }, - 'foo-no-size': { - type: 'public', - node_info: { - storage: {}, - }, - }, - 'foo-null-size': { - type: 'public', - node_info: { - storage: { - size_required: null, - }, - }, - }, - }, - archive: { - 'foo-archive': { - type: 'public', - node_info: { - storage: { - size_required: 300, - }, - }, - }, - }, - }, - }, - }, - bar: { - 'bar-mainnet': { - shared: { - full: { - 'bar-public': { - type: 'public', - node_info: { - storage: { - size_required: 500, - }, - }, - }, - }, - }, - }, - }, - }, + blockchains: { + full: catalogEntry(), + largerEstimate: catalogEntry({ total_storage_gb: 920 }), + smallerEstimate: catalogEntry({ total_storage_gb: 810 }), + archive: catalogEntry({ + client: { name: 'erigon', title: 'Erigon' }, + mode: 'archive', + total_storage_gb: 7600, + }), + anotherClient: catalogEntry({ + client: { name: 'reth', title: 'Reth' }, + total_storage_gb: 600, + }), + unavailable: catalogEntry({ + client: { name: 'geth', title: 'Geth' }, + clouds: {}, + }), + missingSize: catalogEntry({ + client: { name: 'unknown', title: 'Unknown' }, + total_storage_gb: null, + }), + unsupportedMode: catalogEntry({ mode: 'other' }), }, }, }); await expect(processData()).resolves.toEqual([ { - protocol: 'foo', - network: 'foo-mainnet', + protocol: 'polygon-pos', + network: 'polygon-pos-mainnet', full: [ - { - node_data: { - client: 'foo-public', - size_required: 100, - }, - }, - ], - archive: [ - { - node_data: { - client: 'foo-archive', - size_required: 300, - }, - }, + { node_data: { client: 'bor', size_required: 920 } }, + { node_data: { client: 'reth', size_required: 600 } }, ], + archive: [{ node_data: { client: 'erigon', size_required: 7600 } }], }, ]); }); + + it.each([ + ['ADI Chain', 'adichain'], + ['X Layer', 'xlayer'], + ['XDC Network', 'xdc'], + ['ZKsync Era', 'zksync'], + ])('maps %s to the stable protocol slug %s', async (name, slug) => { + axios.get.mockResolvedValue({ + data: { + blockchains: { + entry: catalogEntry({ + protocol: { name, title: name }, + network: { name: `${slug}-mainnet`, title: 'Mainnet' }, + }), + }, + }, + }); + + await expect(processData()).resolves.toMatchObject([{ protocol: slug }]); + }); + + it('keeps the catalog network identifier for rebranded protocols', async () => { + axios.get.mockResolvedValue({ + data: { + blockchains: { + kaia: catalogEntry({ + protocol: { name: 'Kaia', title: 'Kaia' }, + network: { name: 'klaytn-mainnet', title: 'Mainnet' }, + client: { name: 'ken', title: 'Ken' }, + }), + }, + }, + }); + + await expect(processData()).resolves.toMatchObject([ + { protocol: 'klaytn', network: 'klaytn-mainnet' }, + ]); + }); + + it('rejects a catalog with no usable storage sizes', async () => { + axios.get.mockResolvedValue({ + data: { blockchains: { missingSize: catalogEntry({ total_storage_gb: 0 }) } }, + }); + + await expect(processData()).rejects.toThrow('No dedicated node sizes'); + }); }); diff --git a/src/helpers/pricingCatalog.mjs b/src/helpers/pricingCatalog.mjs new file mode 100644 index 0000000..da6eb95 --- /dev/null +++ b/src/helpers/pricingCatalog.mjs @@ -0,0 +1,77 @@ +const PRICING_CATALOG_URL = 'https://static.chainstack.com/pricing/pricing_current.json'; + +const protocolSlugs = new Map([ + ['adi chain', 'adichain'], + ['bnb smart chain', 'bsc'], + ['gnosis chain', 'gnosis'], + ['kaia', 'klaytn'], + ['neo x', 'neox'], + ['polygon', 'polygon-pos'], + ['robinhood chain', 'robinhood'], + ['x layer', 'xlayer'], + ['xdc network', 'xdc'], + ['xrp ledger', 'xrpl'], + ['zksync era', 'zksync'], +]); + +const parsePricingCatalog = (data) => { + const blockchains = data?.blockchains; + if ( + !blockchains || + typeof blockchains !== 'object' || + Array.isArray(blockchains) + ) { + throw new Error('Invalid Chainstack pricing catalog.'); + } + + const networks = new Map(); + + for (const entry of Object.values(blockchains)) { + if (!entry) continue; + + const { clouds, mode, total_storage_gb: size } = entry; + const protocolName = entry.protocol?.name; + const network = entry.network?.name; + const client = entry.client?.name; + + if ( + !clouds || + typeof clouds !== 'object' || + !Object.keys(clouds).length || + (mode !== 'full' && mode !== 'archive') || + !Number.isFinite(size) || + size <= 0 || + typeof protocolName !== 'string' || + !protocolName.trim() || + !network || + !client + ) { + continue; + } + + const name = protocolName.trim().toLowerCase(); + const protocol = protocolSlugs.get(name) || name.replace(/[^a-z0-9]+/g, '-'); + const networkKey = JSON.stringify([protocol, network]); + + if (!networks.has(networkKey)) { + networks.set(networkKey, { protocol, network }); + } + + const networkData = networks.get(networkKey); + const clients = networkData[mode] ??= []; + const existing = clients.find(({ node_data }) => node_data.client === client); + if (existing) { + existing.node_data.size_required = Math.max(existing.node_data.size_required, size); + } else { + clients.push({ node_data: { client, size_required: size } }); + } + } + + if (!networks.size) { + throw new Error('No dedicated node sizes in the Chainstack pricing catalog.'); + } + + return [...networks.values()]; +}; + +export { PRICING_CATALOG_URL, parsePricingCatalog }; diff --git a/src/helpers/protocolDisplay.js b/src/helpers/protocolDisplay.js index 2b693f5..e973013 100644 --- a/src/helpers/protocolDisplay.js +++ b/src/helpers/protocolDisplay.js @@ -46,7 +46,7 @@ const formatNetworkLabel = (networkName, protocolSlug) => { return tokens.filter((token) => token.toLowerCase() !== 'testnet').join(' '); } - return cleanedLabel; + return cleanedLabel.replace(/^testnet(\d+)$/, 'testnet $1'); }; const formatNetworkDisplayName = (networkName, protocolSlug, nodeType) => { diff --git a/src/helpers/protocolDisplay.test.js b/src/helpers/protocolDisplay.test.js index 8572d2a..3a1aa64 100644 --- a/src/helpers/protocolDisplay.test.js +++ b/src/helpers/protocolDisplay.test.js @@ -8,7 +8,10 @@ import { describe('protocolDisplay', () => { it('formats known protocol slugs to display names', () => { expect(formatProtocolDisplayName('bsc')).toBe('BNB Smart Chain'); - expect(formatProtocolDisplayName('zksync')).toBe('zkSync'); + expect(formatProtocolDisplayName('klaytn')).toBe('Kaia'); + expect(formatProtocolDisplayName('megaeth')).toBe('MegaETH'); + expect(formatProtocolDisplayName('xrpl')).toBe('XRP Ledger'); + expect(formatProtocolDisplayName('zksync')).toBe('ZKsync Era'); }); it('formats unknown protocol slugs by capitalizing', () => { @@ -31,6 +34,9 @@ describe('protocolDisplay', () => { expect( formatNetworkDisplayName('bitcoin-signet-testnet', 'bitcoin', 'full') ).toBe('Signet full'); + expect( + formatNetworkDisplayName('bitcoin-testnet4', 'bitcoin', 'full') + ).toBe('Testnet 4 full'); }); it('creates search aliases for slug and display variants', () => { @@ -42,5 +48,8 @@ describe('protocolDisplay', () => { 'bnb-smart-chain' ]) ); + expect(getProtocolSearchAliases('klaytn')).toEqual( + expect.arrayContaining(['klaytn', 'kaia']) + ); }); }); diff --git a/src/helpers/protocolMetadata.json b/src/helpers/protocolMetadata.json index d4d97f7..2eb2e88 100644 --- a/src/helpers/protocolMetadata.json +++ b/src/helpers/protocolMetadata.json @@ -1,10 +1,24 @@ { "protocolDisplayNames": { + "adichain": "ADI Chain", "bsc": "BNB Smart Chain", + "gnosis": "Gnosis Chain", + "klaytn": "Kaia", + "megaeth": "MegaETH", + "neox": "Neo X", "polygon-pos": "Polygon PoS", "polygon-zkevm": "Polygon zkEVM", + "robinhood": "Robinhood Chain", + "tac": "TAC", "tron": "TRON", - "zksync": "zkSync" + "xdc": "XDC Network", + "xlayer": "X Layer", + "xrpl": "XRP Ledger", + "zklink": "zkLink", + "zksync": "ZKsync Era" + }, + "protocolSearchAliases": { + "xrpl": ["XRP"] }, "networkPrefixOverrides": { "bsc": "bsc-",