Skip to content

feat: implement rapid asset draining detection module#179

Closed
AbdulmujibOladayo wants to merge 7 commits into
MD-Creative-Production:mainfrom
AbdulmujibOladayo:feat/detect-rapid-asset-draining-143
Closed

feat: implement rapid asset draining detection module#179
AbdulmujibOladayo wants to merge 7 commits into
MD-Creative-Production:mainfrom
AbdulmujibOladayo:feat/detect-rapid-asset-draining-143

Conversation

@AbdulmujibOladayo

Copy link
Copy Markdown

Summary

Implements the Rapid Asset Draining detection module under src/modules/detection/draining/, following the same plain-TypeScript class pattern used by the existing ai/investigations module.

Files Added

File Purpose
interfaces/draining.interface.ts Types: BalanceSnapshot, DrainingEvent, DrainingAlert, DrainingDetectorOptions
draining.service.ts DrainingService — records balance snapshots, performs velocity analysis, detects drain events, generates emergency alerts with auto-escalated severity
draining.module.ts DrainingModule factory for creating configured service instances
draining.service.spec.ts Unit tests: no-drain cases, threshold detection, severity escalation, history pruning, multi-address isolation
index.ts Barrel export

Detection Logic

  • A drain event fires when the wallet balance drops by ≥ drainThreshold (default 50 %) within the windowMs window (default 5 min).
  • Severity escalation is automatic based on drain ratio and speed:
    • critical — ≥ 90 % drain in any speed, or ≥ 70 % within 60 s
    • high — ≥ 70 % drain at moderate speed, or ≥ 50 % within 60 s
    • medium — ≥ 50 % at slower pace
  • Each event carries a DrainingAlert with human-readable title, description, indicators, and recommended actions.
  • Injectable now clock for fully deterministic tests.

Acceptance Criteria Met

  • Draining events detected via recordBalance / evaluate
  • Alerts generated with indicators and recommended actions
  • Severity escalated automatically based on ratio and velocity

Closes #143

@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @AbdulmujibOladayo , thanks for your contribution, please kindly fix the lint, tests, typescript etc errors. You may pull from the main , fix and push back. Well done

@AbdulmujibOladayo AbdulmujibOladayo deleted the feat/detect-rapid-asset-draining-143 branch June 21, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect Rapid Asset Draining Events

2 participants