Skip to content

feat(backstop): expose solvency and coverage-ratio health views with threshold alert events (#239) - #501

Merged
techisigu merged 1 commit into
Refract-Protocol:mainfrom
umpireboulianne-design:feat/issue-239-backstop-health-views
Oct 24, 2026
Merged

techisigu merged 1 commit into
Refract-Protocol:mainfrom
umpireboulianne-design:feat/issue-239-backstop-health-views

Conversation

@umpireboulianne-design

Copy link
Copy Markdown
Contributor

Summary

Exposes first-class solvency and coverage-ratio health views on RefractBackstop alongside a permissionless check_health evaluator that emits threshold crossing and recovery events with configurable hysteresis.

Closes #239


Changes

  • Pool Coverage View (pool/src/lib.rs):
    • Added aggregate_in_force_coverage(env) as a cheap single-read view returning the pool's active in-force coverage from PoolAccounting.
  • Backstop Solvency & Coverage-Ratio Health Views (backstop/src/lib.rs):
    • total_staked_capital(env): pure read-only view returning total staked capital across tranches.
    • aggregate_in_force_coverage(env): pulls live coverage from RefractPool::aggregate_in_force_coverage via try_invoke_contract and degrades gracefully to the cached coverage counter (DataKey::CachedCoverage) when the pool read is unavailable.
    • encumbered_capital(env) and idle_capital(env): pure read-only views for capital encumbered by in-force coverage vs. unencumbered capital.
    • solvency_ratio_bps(env), coverage_ratio_bps(env), and feed_utilization_bps(env, feed): pure read-only views computed via the 1e7 fixed-point helper (FP_SCALE), returning Ok(None) (never panicking) when the denominator is zero.
    • health_snapshot(env): consolidated read-only view returning BackstopHealthSnapshot.
  • Threshold Alert Events with Hysteresis (backstop/src/lib.rs):
    • set_health_thresholds(env, caller, min_solvency_bps, max_coverage_bps, hysteresis_bps): admin-gated configuration for alert thresholds and recovery hysteresis band.
    • check_health(env): permissionless evaluator that checks solvency and coverage ratios against configured thresholds and emits HLTHALRT / HLTHRECV events only on state transitions across the threshold / hysteresis band.
  • Unit Tests (backstop/src/test.rs):
    • Zero-coverage and zero-capital edge cases returning None without panicking
    • 100% utilization and >100% under-collateralized edge cases
    • Precision/overflow tests at i128 upper bounds (1e30)
    • Threshold alert emission on breach, suppression on repeated checks, hysteresis band holding, and recovery emission once ratios cross back beyond the hysteresis band

Checklist

  • Zero unwrap(), expect(), or panic!() calls in non-test contract code
  • Pure read-only health views with no state mutation
  • Unit tests covering edge cases, overflow bounds, and hysteresis event transitions

@techisigu
techisigu merged commit cb2eb89 into Refract-Protocol:main Oct 24, 2026
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.

Expose Backstop Solvency and Coverage-Ratio Health Views with Threshold Alert Events

2 participants