Skip to content

feat: emergency dispatch to liquidity-monitoring on HIGH/CRITICAL alerts#142

Open
spalen0 wants to merge 3 commits intomainfrom
feat/emergency-dispatch
Open

feat: emergency dispatch to liquidity-monitoring on HIGH/CRITICAL alerts#142
spalen0 wants to merge 3 commits intomainfrom
feat/emergency-dispatch

Conversation

@spalen0
Copy link
Collaborator

@spalen0 spalen0 commented Feb 27, 2026

Summary

  • Adds structured alert system (utils/alert.py) with severity levels (LOW/MEDIUM/HIGH/CRITICAL) and hook support
  • Adds utils/dispatch.py that sends repository_dispatch to tapired/liquidity-monitoring when a HIGH or CRITICAL alert fires for a configured protocol
  • Migrates infinifi/main.py from raw send_telegram_message to send_alert(Alert(...)) and registers the dispatch hook
  • Adds GITHUB_PAT_DISPATCH secret to workflow env
  • Per-protocol 60-minute cooldown prevents duplicate dispatches

How it works

  1. Infinifi detects liquid reserves < $15M → fires send_alert(Alert(AlertSeverity.HIGH, ...))
  2. Alert hook invokes dispatch_emergency_withdrawal
  3. GitHub API POST /repos/tapired/liquidity-monitoring/dispatches with {protocol, severity}
  4. CRITICAL: liquidity-monitoring zeros caps, commits to main, runs reallocation immediately
  5. HIGH: liquidity-monitoring opens a PR with zeroed caps for team review. After merge, manually trigger reallocation.

Companion PR

Receiving side: https://github.com/tapired/liquidity-monitoring/pull/139

Setup required

  1. Create fine-grained PAT with actions:write scoped to tapired/liquidity-monitoring
  2. Add secret GITHUB_PAT_DISPATCH to this repo

Test plan

  • 9 unit tests for dispatch (payload, severity filtering, cooldown, missing PAT, request errors)
  • Alert system tests (emoji, severity defaults, hook invocation, exception swallowing)
  • Manual end-to-end: gh api repos/tapired/liquidity-monitoring/dispatches -f event_type=emergency_withdrawal -f 'client_payload={"protocol":"infinifi","severity":"HIGH"}'

🤖 Generated with Claude Code

… alerts

When infinifi fires a HIGH or CRITICAL alert (e.g. liquid reserves drop),
dispatch a repository_dispatch event to liquidity-monitoring so it can
zero affected market caps and run reallocation immediately.

- Add utils/alert.py: structured alert system with severity levels and hooks
- Add utils/dispatch.py: GitHub API dispatch with per-protocol cooldown
- Update infinifi/main.py: migrate to alert system, register dispatch hook
- Add GITHUB_PAT_DISPATCH to workflow env
- Add tests for alert system and dispatch logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@spalen0 spalen0 self-assigned this Feb 27, 2026
Copy link
Collaborator

@tapired tapired left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no alerts for alert4 and alert5? Alert4 looks legit to be a "high" too, no?

Also fix MEDIUM silent default in alert tests to match code behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@spalen0
Copy link
Collaborator Author

spalen0 commented Mar 2, 2026

no alerts for alert4 and alert5? Alert4 looks legit to be a "high" too, no?

For alert4 and alert5, alert level is set to high: https://github.com/yearn/monitoring-scripts-py/pull/142/changes#diff-82e25bc51cb58224e74ebaac9ac5355b2c0e5bef96527575455fa86e0d849c3bR59

@spalen0 spalen0 marked this pull request as ready for review March 2, 2026 18:55
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.

2 participants