#!/usr/bin/env node import fs from 'fs'; import path from 'path'; const projectRoot = process.cwd(); const inputPath = path.resolve(projectRoot, 'config/aggregator-route-matrix.json'); const outputPath = path.resolve(projectRoot, 'config/aggregator-route-matrix.csv'); const matrix = JSON.parse(fs.readFileSync(inputPath, 'utf8')); const rows = []; function csvEscape(value) { const text = value == null ? '' : String(value); if (text.includes('"') || text.includes(',') || text.includes('\n')) { return `"${text.replace(/"/g, '""')}"`; } return text; } function pushRouteRow(kind, route) { rows.push([ kind, route.routeId, route.status, route.routeType, route.fromChainId, route.toChainId, route.tokenInSymbol || route.assetSymbol || '', route.tokenInAddress || route.assetAddress || '', route.tokenOutSymbol || route.assetSymbol || '', route.tokenOutAddress || route.assetAddress || '', route.hopCount || '', route.bridgeType || '', route.bridgeAddress || '', (route.aggregatorFamilies || []).join('|'), (route.tags || []).join('|'), (route.intermediateSymbols || []).join('|'), (route.legs || []).map((leg) => leg.poolAddress || leg.executorAddress || leg.protocol || leg.kind).join('|'), (route.notes || []).join(' | '), ]); } for (const route of matrix.liveSwapRoutes || []) { pushRouteRow('liveSwapRoute', route); } for (const route of matrix.liveBridgeRoutes || []) { pushRouteRow('liveBridgeRoute', route); } for (const route of matrix.blockedOrPlannedRoutes || []) { rows.push([ 'blockedOrPlannedRoute', route.routeId, route.status, route.routeType, route.fromChainId, route.toChainId, (route.tokenInSymbols || []).join('|'), '', '', '', '', '', '', '', '', '', '', route.reason || '', ]); } const header = [ 'kind', 'routeId', 'status', 'routeType', 'fromChainId', 'toChainId', 'tokenInSymbol', 'tokenInAddress', 'tokenOutSymbol', 'tokenOutAddress', 'hopCount', 'bridgeType', 'bridgeAddress', 'aggregatorFamilies', 'tags', 'intermediateSymbols', 'legRefs', 'notesOrReason', ]; const csv = [header, ...rows].map((row) => row.map(csvEscape).join(',')).join('\n') + '\n'; fs.writeFileSync(outputPath, csv, 'utf8'); console.log(`Wrote ${rows.length} rows to ${outputPath}`);