#!/usr/bin/env node /** * Sync forge broadcast output into z-chain-deployed.v1.json and hybx cross-chain lines. * Usage: node scripts/deployment/sync-z-chain-deployed-addresses.mjs [broadcast-run.json] */ import { readFileSync, writeFileSync, existsSync } from 'fs'; import { resolve, dirname } from 'path'; import { fileURLToPath } from 'url'; const __dirname = dirname(fileURLToPath(import.meta.url)); const root = resolve(__dirname, '../..'); const broadcastPath = process.argv[2] || resolve(root, 'broadcast/DeployZChainEmoney.s.sol/900002/run-latest.json'); if (!existsSync(broadcastPath)) { console.error(`Broadcast file not found: ${broadcastPath}`); console.error('Deploy first: bash scripts/deployment/deploy-z-chain-contracts.sh'); process.exit(1); } const broadcast = JSON.parse(readFileSync(broadcastPath, 'utf8')); const txs = broadcast.transactions || []; let cUsdc = null; let registry = null; for (const tx of txs) { const name = tx.contractName; const addr = tx.contractAddress; if (!addr) continue; if (name === 'ZChainUSDC') cUsdc = addr; if (name === 'AccountWalletRegistry' || name === 'AccountWalletRegistryZ') registry = addr; } if (!cUsdc || !registry) { console.error('Could not find ZChainUSDC and AccountWalletRegistry in broadcast'); process.exit(1); } const deployedPath = resolve(root, 'config/z-chain-deployed.v1.json'); const deployed = JSON.parse(readFileSync(deployedPath, 'utf8')); deployed.updated = new Date().toISOString().slice(0, 10); deployed.status = 'active'; deployed.contracts.cUSDC = cUsdc; deployed.contracts.accountWalletRegistry = registry; writeFileSync(deployedPath, `${JSON.stringify(deployed, null, 2)}\n`); const integrationPath = resolve(root, 'config/z-chain-integration.v1.json'); const integration = JSON.parse(readFileSync(integrationPath, 'utf8')); integration.contracts.cUSDC = cUsdc; integration.contracts.accountWalletRegistry = registry; writeFileSync(integrationPath, `${JSON.stringify(integration, null, 2)}\n`); const hybxPath = resolve(root, 'config/hybx-omnl-cross-chain-lines.json'); const hybx = JSON.parse(readFileSync(hybxPath, 'utf8')); for (const line of hybx.lines || []) { if (line.chains?.['900002']) { line.chains['900002'].tokenM1 = cUsdc; } } writeFileSync(hybxPath, `${JSON.stringify(hybx, null, 2)}\n`); console.log('Updated:'); console.log(' cUSDC:', cUsdc); console.log(' AccountWalletRegistry:', registry); console.log(' config/z-chain-deployed.v1.json'); console.log(' config/z-chain-integration.v1.json'); console.log(' config/hybx-omnl-cross-chain-lines.json (chains.900002.tokenM1)');