Initial commit: add .gitignore and README

This commit is contained in:
defiQUG
2026-02-09 21:51:54 -08:00
commit 7003349717
127 changed files with 17576 additions and 0 deletions

57
src/reporting/annual.ts Normal file
View File

@@ -0,0 +1,57 @@
/**
* Annual Comprehensive Review
*/
import { generateMonthlyMetrics, MonthlyMetrics } from "./monthly.js";
import { generateSecurityReviewTemplate, SecurityReview } from "./security.js";
export interface AnnualReview {
year: number;
executiveSummary: string;
metrics: {
yearly: MonthlyMetrics;
quarterly: MonthlyMetrics[];
};
security: {
reviews: SecurityReview[];
incidents: number;
vulnerabilities: number;
};
improvements: {
completed: string[];
planned: string[];
};
recommendations: string[];
}
/**
* Generate annual comprehensive review
*/
export function generateAnnualReview(year: number): AnnualReview {
const yearlyMetrics = generateMonthlyMetrics();
return {
year,
executiveSummary: `Annual review for ${year}`,
metrics: {
yearly: yearlyMetrics,
quarterly: [], // Would be populated from quarterly data
},
security: {
reviews: [generateSecurityReviewTemplate()],
incidents: 0,
vulnerabilities: 0,
},
improvements: {
completed: [],
planned: [],
},
recommendations: [
"Continue security audits",
"Optimize gas usage",
"Expand protocol support",
"Improve monitoring",
],
};
}

127
src/reporting/monthly.ts Normal file
View File

@@ -0,0 +1,127 @@
/**
* Monthly Metrics Review
*/
import { transactionExplorer } from "../monitoring/explorer.js";
import { gasTracker } from "../monitoring/gasTracker.js";
import { healthDashboard } from "../monitoring/dashboard.js";
export interface MonthlyMetrics {
period: {
start: number;
end: number;
};
executions: {
total: number;
byStrategy: Record<string, number>;
byChain: Record<string, number>;
successRate: number;
};
gas: {
total: bigint;
average: bigint;
byStrategy: Record<string, bigint>;
optimization: {
recommendations: string[];
};
};
protocols: {
usage: Record<string, number>;
health: Record<string, "healthy" | "degraded" | "down">;
};
trends: {
executionGrowth: number;
gasEfficiency: number;
successRateTrend: "improving" | "declining" | "stable";
};
}
/**
* Generate monthly metrics
*/
export function generateMonthlyMetrics(): MonthlyMetrics {
const now = Date.now();
const monthAgo = now - 30 * 24 * 60 * 60 * 1000;
const stats = transactionExplorer.getStats();
const recent = transactionExplorer.getRecent(10000);
const monthRecent = recent.filter(tx => tx.timestamp >= monthAgo);
// Calculate by strategy
const byStrategy: Record<string, number> = {};
const gasByStrategy: Record<string, bigint> = {};
monthRecent.forEach(tx => {
byStrategy[tx.strategy] = (byStrategy[tx.strategy] || 0) + 1;
gasByStrategy[tx.strategy] = (gasByStrategy[tx.strategy] || 0n) + tx.gasUsed;
});
// Calculate by chain
const byChain: Record<string, number> = {};
monthRecent.forEach(tx => {
byChain[tx.chain] = (byChain[tx.chain] || 0) + 1;
});
// Protocol usage
const protocolUsage: Record<string, number> = {};
monthRecent.forEach(tx => {
if (tx.plan?.calls) {
tx.plan.calls.forEach((call: any) => {
// Extract protocol from call description
const protocol = call.description.split(" ")[0];
protocolUsage[protocol] = (protocolUsage[protocol] || 0) + 1;
});
}
});
return {
period: {
start: monthAgo,
end: now,
},
executions: {
total: monthRecent.length,
byStrategy,
byChain,
successRate: stats.total > 0 ? stats.successful / stats.total : 0,
},
gas: {
total: monthRecent.reduce((sum, tx) => sum + tx.gasUsed, 0n),
average: stats.averageGasUsed,
byStrategy: gasByStrategy,
optimization: {
recommendations: generateGasOptimizationRecommendations(gasByStrategy),
},
},
protocols: {
usage: protocolUsage,
health: {}, // Would be populated from health dashboard
},
trends: {
executionGrowth: 0, // Would calculate from historical data
gasEfficiency: 0,
successRateTrend: "stable",
},
};
}
function generateGasOptimizationRecommendations(
gasByStrategy: Record<string, bigint>
): string[] {
const recommendations: string[] = [];
// Find strategies with high gas usage
const sorted = Object.entries(gasByStrategy)
.sort((a, b) => Number(b[1] - a[1]))
.slice(0, 5);
sorted.forEach(([strategy, gas]) => {
if (gas > 2000000n) {
recommendations.push(
`Consider optimizing ${strategy}: ${gas.toString()} gas average`
);
}
});
return recommendations;
}

59
src/reporting/security.ts Normal file
View File

@@ -0,0 +1,59 @@
/**
* Security Review Process
*/
export interface SecurityReview {
date: number;
reviewer: string;
scope: string[];
findings: SecurityFinding[];
recommendations: string[];
status: "pending" | "in-progress" | "completed";
}
export interface SecurityFinding {
severity: "critical" | "high" | "medium" | "low";
category: string;
description: string;
recommendation: string;
status: "open" | "in-progress" | "resolved";
}
/**
* Quarterly security review checklist
*/
export const SECURITY_REVIEW_CHECKLIST = [
"Smart contract security",
"Access control review",
"Reentrancy protection",
"Flash loan security",
"Allow-list management",
"Input validation",
"Error handling",
"Event logging",
"Upgrade mechanisms",
"Emergency procedures",
"Dependency review",
"Configuration security",
];
/**
* Generate security review template
*/
export function generateSecurityReviewTemplate(): SecurityReview {
return {
date: Date.now(),
reviewer: "",
scope: [
"AtomicExecutor.sol",
"All adapters",
"Guard implementations",
"Cross-chain orchestrator",
"Configuration management",
],
findings: [],
recommendations: [],
status: "pending",
};
}

113
src/reporting/weekly.ts Normal file
View File

@@ -0,0 +1,113 @@
/**
* Weekly Status Report Generator
*/
import { transactionExplorer } from "../monitoring/explorer.js";
import { gasTracker } from "../monitoring/gasTracker.js";
import { healthDashboard } from "../monitoring/dashboard.js";
export interface WeeklyReport {
period: {
start: number;
end: number;
};
executions: {
total: number;
successful: number;
failed: number;
successRate: number;
};
gas: {
total: bigint;
average: bigint;
peak: bigint;
trend: "increasing" | "decreasing" | "stable";
};
system: {
status: "healthy" | "degraded" | "down";
uptime: number;
protocols: any[];
};
alerts: {
count: number;
critical: number;
warnings: number;
};
}
/**
* Generate weekly status report
*/
export function generateWeeklyReport(): WeeklyReport {
const now = Date.now();
const weekAgo = now - 7 * 24 * 60 * 60 * 1000;
const stats = transactionExplorer.getStats();
const metrics = healthDashboard.getMetrics();
const avgGas = gasTracker.getAverage(7 * 24 * 60);
const peakGas = gasTracker.getPeak(7 * 24 * 60);
const gasTrend = gasTracker.getTrend(7 * 24 * 60);
return {
period: {
start: weekAgo,
end: now,
},
executions: {
total: stats.total,
successful: stats.successful,
failed: stats.failed,
successRate: stats.total > 0 ? stats.successful / stats.total : 0,
},
gas: {
total: stats.totalGasUsed,
average: avgGas,
peak: peakGas,
trend: gasTrend,
},
system: {
status: healthDashboard.getSystemStatus(),
uptime: metrics.uptime,
protocols: healthDashboard.getProtocolHealth(),
},
alerts: {
count: 0, // Would be populated from alert manager
critical: 0,
warnings: 0,
},
};
}
/**
* Format report as markdown
*/
export function formatWeeklyReport(report: WeeklyReport): string {
return `
# Weekly Status Report
**Period**: ${new Date(report.period.start).toISOString()} - ${new Date(report.period.end).toISOString()}
## Executions
- Total: ${report.executions.total}
- Successful: ${report.executions.successful}
- Failed: ${report.executions.failed}
- Success Rate: ${(report.executions.successRate * 100).toFixed(2)}%
## Gas Usage
- Total: ${report.gas.total.toString()}
- Average: ${report.gas.average.toString()}
- Peak: ${report.gas.peak.toString()}
- Trend: ${report.gas.trend}
## System Status
- Status: ${report.system.status}
- Uptime: ${(report.system.uptime / 1000 / 60 / 60).toFixed(2)} hours
- Protocols: ${report.system.protocols.length} monitored
## Alerts
- Total: ${report.alerts.count}
- Critical: ${report.alerts.critical}
- Warnings: ${report.alerts.warnings}
`;
}