Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ChainsModule } from './modules/chains/chains.module';
import { RiskAnalyzerModule } from './modules/soroban/risk/risk-analyzer.module';
import { NotesModule } from './modules/cases/notes/notes.module';
import { AlertsModule } from './modules/alerts/alerts.module';
import { ProtocolHealthModule } from './modules/protocol-health/protocol-health.module';

import { ReportsModule } from '../../../src/modules/reports/reports.module';
import { ProfileModule } from './modules/profile/profile.module';
Expand All @@ -34,6 +35,7 @@ import { IncidentsModule } from './modules/incidents/incidents.module';
AlertsModule,
ProfileModule,
IncidentsModule,
ProtocolHealthModule,
],
controllers: [AppController],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export interface ProtocolHealthMetric {
chainId: string;
timestamp: Date;
transactionCount: number;
failedTransactionCount: number;
contractCallCount: number;
contractDeployCount: number;
uniqueSenders: number;
monitorHealthy: boolean;
}

export interface MetricsWindow {
chainId: string;
transactionCount: number;
failedTransactionCount: number;
contractCallCount: number;
contractDeployCount: number;
uniqueSenders: Set<string>;
eventCount: number;
}

export interface AnomalyDetectionThresholds {
throughputDropPercent: number;
failedTxRatePercent: number;
contractCallSpikeMultiplier: number;
contractDeploySpikeMultiplier: number;
eventGapMinutes: number;
networkErrorCount: number;
}

export const DEFAULT_ANOMALY_THRESHOLDS: AnomalyDetectionThresholds = {
throughputDropPercent: 50,
failedTxRatePercent: 15,
contractCallSpikeMultiplier: 3,
contractDeploySpikeMultiplier: 5,
eventGapMinutes: 5,
networkErrorCount: 10,
};

export interface HealthSnapshotResponse {
chainId: string;
status: 'healthy' | 'degraded' | 'unhealthy';
timestamp: string;
metrics: {
transactionCount: number;
failedTransactionCount: number;
successRate: number;
contractCallCount: number;
contractDeployCount: number;
uniqueSenders: number;
monitorHealthy: boolean;
};
anomalies: string[];
}

export interface ProtocolHealthAlertResponse {
id: string;
chainId: string;
alertType: string;
severity: string;
status: string;
message: string;
metadata?: unknown;
createdAt: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller, Get, HttpCode, HttpStatus, Param, Query } from '@nestjs/common';
import { ProtocolHealthService } from './protocol-health.service';
import {
HealthSnapshotResponse,
ProtocolHealthAlertResponse,
} from './interfaces/protocol-health-metric.interface';

@Controller('protocol-health')
export class ProtocolHealthController {
constructor(private readonly protocolHealthService: ProtocolHealthService) {}

@Get()
@HttpCode(HttpStatus.OK)
async getAllChainsHealth(): Promise<HealthSnapshotResponse[]> {
return this.protocolHealthService.getAllChainsHealth();
}

@Get(':chainId')
@HttpCode(HttpStatus.OK)
async getChainHealth(@Param('chainId') chainId: string): Promise<HealthSnapshotResponse> {
return this.protocolHealthService.getHealthSnapshot(chainId);
}

@Get('alerts')
@HttpCode(HttpStatus.OK)
async getAlerts(@Query('chainId') chainId?: string): Promise<ProtocolHealthAlertResponse[]> {
return this.protocolHealthService.getAlerts(chainId);
}
}
15 changes: 15 additions & 0 deletions apps/backend/src/modules/protocol-health/protocol-health.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { ProtocolHealthController } from './protocol-health.controller';
import { ProtocolHealthService } from './protocol-health.service';
import { ProtocolHealthRepository } from './repositories/protocol-health.repository';
import { ChainsModule } from '../../modules/chains/chains.module';
import { NotificationsModule } from '../notifications/notifications.module';
import { IncidentsModule } from '../incidents/incidents.module';

@Module({
imports: [ChainsModule, NotificationsModule, IncidentsModule],
controllers: [ProtocolHealthController],
providers: [ProtocolHealthService, ProtocolHealthRepository],
exports: [ProtocolHealthService],
})
export class ProtocolHealthModule {}
Loading
Loading