Gate a vault on headroom
Pause an action when headroom or coverage gets thin, or the feed goes stale.
A live example any vault can copy is on mainnet: coverage-guard-cached reads coverage-cache through the trait and answers ok or paused. The same pattern, adapted to headroom:
(define-constant MIN_HEADROOM_BPS u5000) ;; pause when the pool could fall less than 50%
(define-public (deposit (feed <risk-feed>) (amount uint))
(begin
;; pin the feed before calling it: an unchecked trait argument runs the caller's contract
(asserts! (is-eq (contract-of feed) TRUSTED_FEED) ERR_UNTRUSTED_FEED)
(let ((s (try! (contract-call? feed get-coverage-summary))))
(asserts! (match (get headroom-bps s) h (>= h MIN_HEADROOM_BPS) true) ERR_PAUSED)
;; ... your deposit logic
(ok amount))))Choosing thresholds
- Headroom is currently 75.8% onchain (block 976,724); coverage is 4.13× onchain (block 976,724).
- 2.0× coverage equals 50% headroom.
- Always check staleness with
updated-at. Mirrored feeds post once per distribution (about weekly). - Pin the trusted feed (
contract-of) before calling it, so a caller cannot pass in a contract that returns whatever it likes, or that runs code of its own.