Skip to content

Feature/solvency monitoring - #277

Merged
jhayniffy merged 4 commits into
InsurNiffy:mainfrom
Mimah97:feature/solvency-monitoring
Mar 29, 2026
Merged

Feature/solvency monitoring#277
jhayniffy merged 4 commits into
InsurNiffy:mainfrom
Mimah97:feature/solvency-monitoring

Conversation

@Mimah97

@Mimah97 Mimah97 commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

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

  • New read-only entrypoint get_treasury_balance returning 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 via SOLVENCY_CRON_EXPRESSION), Prisma/raw SQL aggregate for approved claims, structured logs + optional webhook (SOLVENCY_ALERT_WEBHOOK_URL).
  • RPC or DB failure → snapshot status: unknown, rpcError / error detail — no low-buffer alert or webhook (avoids false positives).
  • Redis key 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, optional SOLVENCY_TENANT_ID for scoped sums. Documented in .env.example and Joi validation.

Tests

  • Unit tests: mocked Soroban, Prisma, Redis; degraded vs ok vs unknown paths; admin route reads cache only.
  • Jest testMatch extended to include **/*.spec.ts.

Deploy notes

  • Redeploy contract WASM that includes get_treasury_balance before relying on the job in that environment.
  • Set SOLVENCY_SIMULATION_SOURCE_ACCOUNT to a funded account on the target network for simulations.

@drips-wave

drips-wave Bot commented Mar 28, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@jhayniffy
jhayniffy merged commit c692da7 into InsurNiffy:main Mar 29, 2026
1 of 6 checks passed
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.

Backend — Solvency monitoring job: treasury balance alerts and dashboard feed

2 participants