Feature/solvency monitoring - #277
Merged
Merged
Conversation
Made-with: Cursor
|
@Mimah97 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds scheduled solvency monitoring so the protocol does not silently assume it can pay approved claims: we compare on-chain payout reserve (simulated
get_treasury_balance) to the sum of APPROVED (unpaid) claim amounts, alert when the buffer falls below an env-configured threshold, and expose the latest result from Redis for the admin dashboard without hitting RPC on each read.closes #208
Contract
get_treasury_balancereturning the default token balance held by the insurance contract (payout reserve).Backend
SorobanService.simulateGetTreasuryBalance— simulation-only; throws on failure (no silent fallback).SolvencyMonitoringService— cron (default every 15 minutes, overridable viaSOLVENCY_CRON_EXPRESSION), Prisma/raw SQL aggregate for approved claims, structured logs + optional webhook (SOLVENCY_ALERT_WEBHOOK_URL).status: unknown,rpcError/ error detail — no low-buffer alert or webhook (avoids false positives).solvency:snapshot:v1(7d TTL, refreshed each run).GET /api/admin/solvency— returns{ snapshot }from Redis only.Configuration (env, no code change)
SOLVENCY_BUFFER_THRESHOLD_STROOPS,SOLVENCY_SIMULATION_SOURCE_ACCOUNT,SOLVENCY_MONITORING_ENABLED,SOLVENCY_CRON_EXPRESSION, optional webhook + secret, optionalSOLVENCY_TENANT_IDfor scoped sums. Documented in.env.exampleand Joi validation.Tests
testMatchextended to include**/*.spec.ts.Deploy notes
get_treasury_balancebefore relying on the job in that environment.SOLVENCY_SIMULATION_SOURCE_ACCOUNTto a funded account on the target network for simulations.