#!/usr/bin/env node
// Re-poll BaseScan for current verification status of all 15 contracts.
// Source of truth = the API itself, not our local guesses.

const API_KEY = process.env.ETHERSCAN_API_KEY || process.env.BASESCAN_API_KEY;
if (!API_KEY) { console.error('Set ETHERSCAN_API_KEY'); process.exit(1); }

const ALL = {
  ERC8004IdentityRegistry: '0xa7BD20bf5De63df949cA5Be2F20835978eCba81A',
  AIPartnershipBondsV2: '0x01C479F0c039fEC40c0Cf1c5C921bab457d57441',
  AIAccountabilityBondsV2: '0x6750D28865434344e04e1D0a6044394b726C3dfE',
  FlourishingMetricsOracle: '0xf7B2dC73Ec69528F171F4a0ded62da557866BaA5',
  ProductionBeliefAttestationVerifier: '0x2a46B5932e9559176241056A04a608B8fEbCc5A7',
  ERC8004ReputationRegistry: '0x98afd1440B2238D73c1394720277a6d031fCbbD0',
  ERC8004ValidationRegistry: '0x8D3495772EAcAdB7dC09F1784eF06F2D109fb8a5',
  VaultfireERC8004Adapter: '0x8bEFe7411AecddA6E1Aea8F031fedD293Ca7372E',
  MultisigGovernance: '0x34a19C7298aCA59e185F1ecfB352AC566bB4B4A9',
  PrivacyGuarantees: '0x2711AA5f1934Fe97825F02e51cB5Da58d1759625',
  MissionEnforcement: '0xBc4208A7A59af3B7E438d3308C3dc0d299d739a7',
  AntiSurveillance: '0xaaC44F1396f3F5b3C06048a1F819DC9b0f86D90c',
  BeliefAttestationVerifier: '0x32211773C8266774A704aeD471f8eF073f34bA79',
  DilithiumAttestor: '0xef703bBe9b21960ede3e96abBB0Bbd0c525Fe050',
  VaultfireTeleporterBridge: '0x62edf0cBc8Fa3d98B6A07197DFE9cb1c128a7eC7',
};

const sleep = (ms) => new Promise(r => setTimeout(r, ms));

let verified = 0, unverified = 0;
for (const [name, addr] of Object.entries(ALL)) {
  const url = `https://api.etherscan.io/v2/api?chainid=8453&module=contract&action=getsourcecode&address=${addr}&apikey=${API_KEY}`;
  const r = await fetch(url);
  const j = await r.json();
  const item = j.result?.[0] || {};
  const cn = item.ContractName || '';
  const ok = cn && cn !== '';
  if (ok) verified++; else unverified++;
  console.log(`${ok ? '✅' : '❌'} ${name.padEnd(40)} ${addr}  ${cn || 'UNVERIFIED'}`);
  await sleep(220);
}

console.log(`\n${verified} verified, ${unverified} unverified`);
