// Check deployer balance on all 4 production chains
// Usage: node scripts/check-balances.js
// PRIVATE_KEY env var is NOT required — we hardcode the public deployer address.
const { ethers } = require('ethers');

const DEPLOYER = '0xfA15Ee28939B222B0448261A22156070f0A7813C';

const NETWORKS = [
  { name: 'Base',      rpc: 'https://mainnet.base.org',                 symbol: 'ETH',  chainId: 8453  },
  { name: 'Avalanche', rpc: 'https://api.avax.network/ext/bc/C/rpc',    symbol: 'AVAX', chainId: 43114 },
  { name: 'Arbitrum',  rpc: 'https://arb1.arbitrum.io/rpc',             symbol: 'ETH',  chainId: 42161 },
  { name: 'Polygon',   rpc: 'https://polygon-rpc.com',                  symbol: 'POL',  chainId: 137   },
];

function withTimeout(promise, ms, label) {
  return Promise.race([
    promise,
    new Promise((_, reject) => setTimeout(() => reject(new Error(`timeout after ${ms}ms (${label})`)), ms)),
  ]);
}

async function checkOne(n) {
  try {
    const provider = new ethers.JsonRpcProvider(n.rpc, n.chainId, { staticNetwork: true });
    const bal = await withTimeout(provider.getBalance(DEPLOYER), 10000, n.name);
    const human = ethers.formatEther(bal);
    console.log(`${n.name.padEnd(10)} ${human.padStart(20)} ${n.symbol}`);
  } catch (e) {
    console.log(`${n.name.padEnd(10)} ERROR: ${e.message}`);
  }
}

async function main() {
  console.log(`Deployer: ${DEPLOYER}\n`);
  await Promise.all(NETWORKS.map(checkOne));
}

main().catch((e) => { console.error(e); process.exit(1); });
