Skip to content

fix: add insurance fund mechanism for protocol failures - #685

Open
Marskill65 wants to merge 8 commits into
Neurowealth:mainfrom
Marskill65:fix/issue-661-insurance-fund-for-protocol-failures
Open

fix: add insurance fund mechanism for protocol failures#685
Marskill65 wants to merge 8 commits into
Neurowealth:mainfrom
Marskill65:fix/issue-661-insurance-fund-for-protocol-failures

Conversation

@Marskill65

Copy link
Copy Markdown

Overview

This PR adds a configurable insurance fund mechanism that allocates a portion of protocol yield to a dedicated reserve pool. The reserve is stored as a separate vault balance and is used to backstop eligible user losses from protocol failures or smart contract exploits. It includes owner-managed contribution and payout settings, fund-level monitoring alerts, full test coverage, and documentation.

Related Issue

Closes the insurance fund for protocol failures bounty issue.

Changes

🛡️ Insurance Fund Core

  • [ADD] neurowealth-vault/contracts/vault/src/insurance.rs

    • Implements insurance fund balance storage, owner-configurable contribution rate in basis points, and configurable maximum payout per incident.
    • Backstops eligible user losses from protocol failures and smart contract exploits.
    • Emits InsuranceFundUpdatedEvent on configuration changes and payout events.
    • Exposes an insurance_fund_balance() getter for transparency.
  • [MODIFY] neurowealth-vault/contracts/vault/src/topics.rs

    • Adds InsuranceFundUpdatedEvent topics and supporting event constants.
  • [ADD] neurowealth-vault/contracts/vault/src/tests/test_insurance_fund.rs

    • Tests contribution allocation, payout cap enforcement, owner-only settings, insufficient-fund edge cases, and event emission.
  • [MODIFY] neurowealth-vault/contracts/vault/src/tests/mod.rs

    • Registers the new insurance fund test module.

🖥️ Admin, Monitoring & Docs

  • [ADD] packages/admin-panel/src/components/InsuranceConfiguration.tsx

    • Admin UI to view the fund balance and configure contribution rate + maximum payout per incident.
  • [MODIFY] packages/monitoring/src/monitor.ts

    • Monitors insurance fund level and alerts when the balance falls below the configured minimum threshold.
  • [ADD] docs/INSURANCE.md

    • Documents the insurance mechanism, configuration, payout flow, and monitoring setup.

Verification Results

cargo test -p neurowealth-vault --lib insurance_fund
✅ 8/8 passed

Live acceptance check:
✅ Contribution rate applies only to new yield accrual
✅ Insurance fund balance is separate from user vault balances
✅ Payouts are capped by the per-incident maximum
✅ Owner-only configuration updates emit InsuranceFundUpdatedEvent
✅ Fund balance getter available for transparency
✅ Monitor raises alert below minimum threshold
✅ docs/INSURANCE.md covers configuration and payout flow
Acceptance Criteria Status
Configurable insurance contribution rate (owner setting, basis points) ✅ Owner-only setter with basis-point precision
Insurance fund stored as separate balance in vault ✅ Dedicated insurance fund balance field exposed via getter
Fund used to backstop user losses from protocol failures ✅ Payout path restricted to verified failure/exploit incidents
Maximum insurance payout per incident (configurable) ✅ Per-incident cap configurable by owner and enforced on payout
Fund level monitoring and alerts (minimum threshold) ✅ Monitor alerts when balance drops below threshold
Event: InsuranceFundUpdatedEvent ✅ Emitted on contribution rate change, max payout change, and payout
Transparency: fund balance visible via getter insurance_fund_balance() getter returns current reserve
Test coverage for contribution, payout, and edge cases ✅ 8/8 unit and integration tests pass
Document in docs/INSURANCE.md ✅ Added usage, configuration, and incident flow guide

Closes #661

@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@Marskill65 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

orebams pushed a commit to orebams/NeuroWealth-Smartcontract that referenced this pull request Aug 29, 2026
…owealth#686, Neurowealth#687)

- AuditTrail: hoist useMemo above the loading-gated early return so hook
  order stays stable across the loading -> loaded transition
- global-error.tsx: catch render-time throws above RootLayout (e.g. in
  ClientProviders) with the app's branded ErrorPage instead of Next's
  default unbranded error page
- useNotificationPreferences: guard the localStorage JSON.parse with a
  try/catch that falls back to DEFAULT_PREFERENCES and repairs corrupted
  storage, matching useNotifications
- StrategySelector: add an AbortController to the fetch-on-mount effect,
  surface failures via an error banner with retry instead of silently
  treating them as "no strategy saved", and log via lib/logger

Closes Neurowealth#684
Closes Neurowealth#685
Closes Neurowealth#686
Closes Neurowealth#687
orebams pushed a commit to orebams/NeuroWealth-Smartcontract that referenced this pull request Aug 29, 2026
@Abidoyesimze

Copy link
Copy Markdown
Contributor

Pls fix conflict

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.

Insurance fund for protocol failures

3 participants