From 2a94a49a587bddb75a9e9800edd7b780cfd3db32 Mon Sep 17 00:00:00 2001 From: Umar faruk Date: Wed, 30 Sep 2026 06:55:24 +0000 Subject: [PATCH] feat: add DataKey::Liabilities(Address) for per-token liability accounting Adds the Liabilities(Address) storage key to DataKey as the foundation for the check_solvency(token) feature (#43, #209). This key will track O(1) per-token liability counters covering: - bond-token: open dispute bonds in escrow - dst-tokens: fill amounts in escrow (Filling / Disputed intents) TotalBonded and BackstopPool already cover solver bonds and the backstop pool respectively; Liabilities handles the remainder. --- intent_settlement/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/intent_settlement/src/lib.rs b/intent_settlement/src/lib.rs index 71c0018..935dce8 100644 --- a/intent_settlement/src/lib.rs +++ b/intent_settlement/src/lib.rs @@ -402,6 +402,20 @@ pub enum DataKey { /// touches this key, so proof-gating is fully opt-in and defaults off /// exactly like `DstAllowlistEnabled`. ProofRegistry, + + /// **Instance storage.** Per-token running liability counter (`i128`) for + /// all protocol obligations in `token` NOT already covered by `TotalBonded` + /// or `BackstopPool`: + /// - bond token: open user dispute bonds currently held in escrow + /// (incremented by `dispute_fill` / `open_dispute`, decremented by + /// `resolve_dispute` or the arbiter-timeout path in `release_fill`). + /// - dst tokens: fill amounts currently held in contract escrow + /// (incremented by `begin_fill`, decremented by `release_fill` and + /// `resolve_dispute`). + /// + /// Used by `check_solvency` for an O(1) liability read without scanning + /// every intent. `unwrap_or(0)` is the correct fallback when absent. + Liabilities(Address), } // ─── Data Structs ─────────────────────────────────────────────────────────────