Skip to content

feat: metrics service, emergency pause, upgrade pattern & insurance fund - #501

Merged
nayt9 merged 1 commit into
stowp:mainfrom
jahswillb-dev:feat/423-428-429-435
Oct 23, 2026
Merged

nayt9 merged 1 commit into
stowp:mainfrom
jahswillb-dev:feat/423-428-429-435

Conversation

@jahswillb-dev

@jahswillb-dev jahswillb-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Create metrics collection service #423 — Metrics collection service: Prometheus-based metrics with HTTP request tracking (duration histogram, request counter, active connections gauge), business metrics (deposits, withdrawals, goals, groups, insurance claims), GET /metrics endpoint, and global middleware. Uses prom-client.
  • Implement emergency pause mechanism #428 — Emergency pause mechanism: Admin-controlled emergency mode that blocks deposits while allowing withdrawals. Includes emergency_withdraw for locked plans that bypasses timelocks with no penalty.
  • Add contract upgrade pattern #429 — Contract upgrade pattern: Timelock-based upgrade workflow with propose_upgrade / execute_upgrade / cancel_upgrade, configurable delay, version tracking, and a migrate hook for post-upgrade state migrations.
  • Add savings insurance fund #435 — Savings insurance fund: Insurance pool funded by configurable premium (basis points) collected on deposits. Admin approves claims (capped by max_claim_bps of fund balance), claimants redeem approved claims. Full event trail for off-chain indexing.

Closes #423, Closes #428, Closes #429, Closes #435

Changes

Contract (contracts/savings-vault/src/)

File What changed
types.rs Added UpgradeProposal, InsuranceClaimRecord structs and 8 new DataKey variants
events.rs 8 new event topic constants for emergency, upgrade, and insurance events
admin.rs Emergency mode (set/check/require), upgrade pattern (propose/execute/cancel/delay/version/migrate)
insurance.rs New — full insurance fund: premium config, funding, collection, claim approval & redemption
flexible.rs Emergency guard + insurance premium collection on deposit
locked.rs emergency_withdraw function for locked plans
lib.rs All new public entrypoints wired up
test.rs 17 new tests covering all three contract features

Backend (backend/src/)

File What changed
metrics/metrics.service.ts New — Prometheus registry, HTTP + business metric definitions, helper methods
metrics/metrics.controller.ts New — GET /metrics endpoint with @Public() decorator
metrics/metrics.middleware.ts New — HTTP request duration/count tracking middleware
metrics/metrics.module.ts New — @Global() module exporting MetricsService
metrics/metrics.service.spec.ts New — unit tests for MetricsService
metrics/metrics.controller.spec.ts New — unit tests for MetricsController
app.module.ts Registered MetricsModule
package.json Added prom-client ^15.1.3

Test plan

  • Contract tests pass (cargo test in contracts/savings-vault/)
  • Backend tests pass (pnpm test in backend/)
  • Emergency mode blocks deposits but allows flexible withdrawals and locked emergency withdrawals
  • Upgrade propose → execute respects timelock delay
  • Insurance premium is collected on deposit and fund balance updates correctly
  • Insurance claim approval respects max_claim_bps cap
  • /metrics endpoint returns Prometheus-formatted text
  • Non-admin callers are rejected for all admin-only operations

…rance fund

- stowp#423: Prometheus metrics collection service with HTTP request tracking,
  business metrics (deposits, withdrawals, goals, groups, insurance claims),
  and /metrics endpoint
- stowp#428: Emergency pause mechanism with admin-controlled emergency mode,
  withdrawal-only operations, and locked plan emergency withdrawal
- stowp#429: Contract upgrade pattern with timelock delay, propose/execute/cancel
  workflow, version tracking, and migration hooks
- stowp#435: Savings insurance fund with premium collection on deposits, admin
  claim approval, claimant redemption, and configurable coverage limits

Includes unit tests for all four features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Oct 22, 2026

Copy link
Copy Markdown

@jahswillb-dev 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

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
stow Error Error Oct 22, 2026 12:35pm UTC

@nayt9
nayt9 merged commit 611f3da into stowp:main Oct 23, 2026
1 of 9 checks passed

This branch had an error being deployed

1 failed deployment
Preview — e6a1578d Deployed Oct 22, 2026 by vercel[bot]
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.

Add savings insurance fund Add contract upgrade pattern Implement emergency pause mechanism Create metrics collection service

2 participants