fix(monitor): stop reporting v17 markets as a passing conservation check (#347) - #392
fix(monitor): stop reporting v17 markets as a passing conservation check (#347)#392dcccrypto wants to merge 1 commit into
Conversation
…eck (#347) MonitorService is the keeper's only off-chain fund-conservation tripwire. Its file header states the purpose: if the on-chain SPL balance falls below what the program thinks is in the vault, funds have leaked and we alert immediately. For v17 markets it bailed out BEFORE that check and recorded ok:true, with vaultTokenBalance/engineVault/shortfall all "0". Since the v17 cutover every production market is v17, so the invariant never ran anywhere — and /health's `invariants` block actively showed green for a check that was never computed. The ADL-staleness skip beside it is legitimate (ExecuteAdl was removed in v17). This one is not: v17 vaults still hold SPL tokens and the program still tracks accounting; only the source field changed (engine.vault is a v12 field). The code answered "the old formula doesn't apply" with "report healthy". Makes the unevaluated state representable and reports it: ok: boolean | null — null = NOT EVALUATED, no conclusion available balances null rather than "0" (a dashboard reading shortfall "0" concludes "checked, nothing missing" — the same false green in another field) Scope, stated plainly: this does NOT implement the v17 invariant. Deriving it (insurance fund + Σ portfolio capital/pnl backing vs getTokenAccountBalance) needs the v17 accounting model, and getting it subtly wrong would emit false shortfall alerts on a fund-leak detector — which trains on-call to ignore it, arguably worse than silence. That work stays open on #347 and wants someone with the v17 accounting model. What this fixes is the false signal. Safe to change: /health embeds monitorService.getStatus() verbatim and does not gate its status code on invariants[].ok, so no market flips the endpoint to 503. src/index.ts is the only consumer outside this file. Updates the existing v17 test, which asserted ok:true and so codified the bug. Adds two regressions per the issue: a v17 market must never report ok:true, and must not carry fabricated zero balances. Verified against the ORIGINAL monitor.ts, not a hand-rolled mutation: 3 of the 4 tests fail on the unfixed file and all 4 pass on the fix. Full keeper suite: 977 passed, 0 failures. tsc --noEmit clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe monitor now represents the v17 conservation invariant as unevaluated, using nullable status and balance fields. Tests verify that v17 markets are not reported as passing and do not receive fabricated zero values. ChangesV17 invariant correction
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing as superseded —
Verified rather than assumed: I merged this branch into current Closing rather than leaving a no-op PR in the queue. #390 and #391 stay open — both still apply ( |
Addresses #347 — the false signal. Deliberately does not claim to implement the v17 invariant; see Scope below.
The bug
MonitorServiceis the keeper's only off-chain fund-conservation tripwire. Its own header states the purpose: if the on-chain SPL balance falls below what the program thinks is in the vault, funds have leaked and we alert immediately.For v17 markets it bailed out before that check and recorded:
Since the v17 cutover every production market is v17, so the invariant never ran anywhere — and
/health'sinvariantsblock actively showed green for a check that was never computed.The ADL-staleness skip beside it is legitimate (
ExecuteAdlwas removed in v17). This one isn't: v17 vaults still hold SPL tokens and the program still tracks accounting; only the source field changed. The code answered "the old formula doesn't apply" with "report healthy".The change
Makes "unevaluated" representable, and reports it:
Balances become
nullrather than"0"— a dashboard readingshortfall: "0"concludes "checked, nothing missing", which is the same false green wearing a different hat.Scope — what this does NOT do
It does not implement the v17 invariant. Deriving it (insurance fund + Σ portfolio capital/pnl backing vs
getTokenAccountBalance) needs the v17 accounting model, and getting it subtly wrong would emit false shortfall alerts on a fund-leak detector — which trains on-call to ignore it, arguably worse than silence.That work stays open on #347 and wants someone with the v17 accounting model (anchor/SDK side). What this PR fixes is the part that is unambiguously wrong today: a monitor claiming a result it never computed.
Why it's safe to change the type
/healthembedsmonitorService.getStatus()verbatim and does not gate its status code oninvariants[].ok— I checked before touching it, since flipping every v17 market to non-truecould otherwise have turned the endpoint red fleet-wide.src/index.tsis the only consumer outside this file.Verification
The existing v17 test asserted
ok: true, codifying the bug — updated, with a comment saying so. Added the two regressions the issue asks for.Checked against the original
monitor.ts, not a hand-rolled mutation:npx tsc --noEmitcleanTouches only
src/services/monitor.ts+ its test — no collision with the open PRs onliquidation.ts/oracle.ts/crank.ts.🤖 Generated with Claude Code
Summary by CodeRabbit