Skip to content

Add unified circuit-breaker safety layer: guardian-bot daemon, per-contract façade, auto-trip on health degradation, and zero-liquidity guard - #888

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
jerrydanzaria5-svg:main
Jul 29, 2026
Merged

Add unified circuit-breaker safety layer: guardian-bot daemon, per-contract façade, auto-trip on health degradation, and zero-liquidity guard#888
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
jerrydanzaria5-svg:main

Conversation

@jerrydanzaria5-svg

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a unified pause/circuit-breaker safety layer for
PropChain contracts. It consolidates previously ad-hoc pause governance into
a single trait-based façade, adds an off-chain guardian daemon that watches
oracle drift and chain health, wires automatic rate-limiter tripping into
that health signal, and hardens DEX liquidity queries against
division-by-zero on fresh/empty pools.

Changes

Circuit-breaker façade (propchain-traits)

  • Introduced propchain-traits::circuit_breaker::{CircuitBreaker, PauseReason}
    as a single uniform trait, replacing the per-contract PauseFlags,
    set_pause_state, and c.is_paused patterns.
  • Migrated existing contracts to implement the shared trait so pause
    behavior and monitoring are consistent across the codebase.

Guardian-bot daemon (scripts/)

  • Added a Rust binary at scripts/guardian-bot.rs that subscribes to chain
    events, watches oracle price feeds, and pauses the bridge automatically on
    detected drift.
  • Documented deployment (README) covering configuration, run modes, and
    operational expectations.

Automatic rate-limiter tripping

  • The bridge rate limiter now watches account_block_request_count and
    failed_signatures_window_count and automatically trips into a paused
    state when thresholds are breached.
  • Added a cooldown timer governing auto-recovery after a trip.

Zero-liquidity guard

  • Replaced unchecked division in DEX utilisation view functions with a
    guarded divide that returns an explicit ZeroLiquidity error instead of
    panicking/aborting on fresh or empty pools.

Closes

Testing

  • Unit tests covering circuit-breaker trait state transitions across
    migrated contracts.
  • Integration test simulating oracle drift to confirm guardian-bot triggers
    a pause.
  • Unit tests for rate-limiter auto-trip/cooldown/recovery cycle.
  • Unit tests covering empty-pool and zero-liquidity queries returning
    ZeroLiquidity rather than aborting.

…liquidity guard


- Introduce propchain-traits::circuit_breaker::{CircuitBreaker, PauseReason}
  and migrate contracts off ad-hoc PauseFlags/set_pause_state
- Add guardian-bot.rs daemon watching oracle drift, auto-pausing bridge
  on detected anomalies, with deployment docs
- Wire rate limiter to auto-trip on account_block_request_count and
  failed_signatures_window_count thresholds, with cooldown/recovery
- Add guarded divide returning ZeroLiquidity error for empty-pool
  DEX utilisation queries instead of aborting

Closes MettaChain#822, MettaChain#818, MettaChain#819, MettaChain#823
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@jerrydanzaria5-svg Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit d5f3a0f into MettaChain:main Jul 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants