Files
proxmox/scripts/export-aggregator-route-matrix-csv.mjs
defiQUG bad8fdc98c
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
scripts: portal login, PMM mesh install, ops template audit, NPM verify, route matrix export
Made-with: Cursor
2026-03-27 18:46:42 -07:00

101 lines
2.3 KiB
JavaScript

#!/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}`);