// Shared by the public read endpoints (stats, supply, explorer): Neon's HTTP SQL endpoint over Node's fetch, the // same pattern as live.mjs. Returns rows. A file starting with an underscore is not deployed as a function by Vercel. export function neon(url = process.env.DATABASE_URL) { if (!url) throw new Error('DATABASE_URL is not set'); const host = new URL(url).hostname.replace('-pooler', ''); return async (query, params = []) => { const r = await fetch(`https://${host}/sql`, { method: 'POST', headers: { 'Neon-Connection-String': url, 'Content-Type': 'application/json' }, body: JSON.stringify({ query, params }), }); const j = await r.json(); if (!r.ok) throw new Error(j.message || JSON.stringify(j)); return j.rows || []; }; } export const num = v => (v === null || v === undefined ? null : Number(v)); export const tablePrefix = () => (process.env.LIVE_TABLE_PREFIX || '').replace(/[^a-z0-9_]/gi, ''); /** EVM chain id from the network name (docs/design/execution-layer.md 8.1: 4461 mainnet, 4462 testnet, 4463 devnet). */ export function chainIdOf(network) { const n = String(network || ''); if (n.includes('devnet')) return 4463; if (n.includes('testnet')) return 4462; if (n.includes('simnet')) return null; return 4461; }