Skip to content

feat(niffyinsure): rolling claim cap per policy (ledger window) - #246

Merged
jhayniffy merged 3 commits into
InsurNiffy:mainfrom
favourawaku:feat/rolling-claim-cap
Mar 29, 2026
Merged

feat(niffyinsure): rolling claim cap per policy (ledger window)#246
jhayniffy merged 3 commits into
InsurNiffy:mainfrom
favourawaku:feat/rolling-claim-cap

Conversation

@favourawaku

Copy link
Copy Markdown
Contributor

feat(niffyinsure): rolling claim cap per policy (ledger-anchored window)

closes #189

Summary

Adds a configurable rolling cap on cumulative paid claim amounts per (holder, policy_id) within a ledger-sequence window (not wall clock). New filings that would exceed the cap revert with a clear contract error.

Behavior

  • Storage: Instance keys for global cap and window length (ledgers); persistent (window_start, cumulative_paid) per policy, reset when the ledger bucket changes.
  • file_claim: After existing validation, requires cumulative_paid + amount ≤ cap (skipped when cap is i128::MAX).
  • process_claim: After a successful payout, adds claim.amount to the accumulator; does not re-check the cap so in-flight approved claims still pay if the cap is lowered later.
  • Admin: set_rolling_claim_cap and set_rolling_claim_window_ledgers with min/max bounds; emit ClaimCapUpdated and RollingClaimWindowLedgersUpdated.
  • Read API: get_rolling_claim_cap, get_rolling_claim_window_ledgers, get_rolling_claim_remaining, get_rolling_claim_state for indexers/UI.
  • Errors: validate::Error::RollingClaimCapExceeded (49) and quote_error_message mapping; AdminError variants for out-of-bounds admin updates.

Product note

Cap applies to gross on-chain claim.amount (same field as payout); deductible/net policy is documented as a future product decision.

Tests

tests/rolling_claim_cap.rs: single claim at cap; two claims summing to cap; filing over cap; cap lowered after file still allows payout; window rollover allows another full cap. Window length is chosen so claim rate-limit advances do not roll the cap bucket unintentionally.

Other

  • Removed duplicate contractimpl file_claim / vote_on_claim / finalize_claim (panic variants).
  • tests/events.rs gated behind Cargo feature legacy-event-schema-tests until topics match current contractevent layout.
  • Claim.asset fixes in existing tests; Soroban test snapshots updated where regenerated.

Checklist

  • cargo test in contracts/niffyinsure passes

- Track cumulative paid per (holder, policy) with ledger-bucket rollover
- Enforce cap at file_claim; bump accumulator on payout only (no cap re-check)
- Admin setters with bounds; ClaimCapUpdated / window update events
- Read APIs for cap, window, remaining, raw state; quote_error 49
- Tests: at-cap, two claims to cap, over-cap, in-flight payout, rollover
- Gate legacy events schema tests behind legacy-event-schema-tests feature
- Fix Claim.asset in tests; remove duplicate contractimpl entrypoints

Made-with: Cursor
@drips-wave

drips-wave Bot commented Mar 27, 2026

Copy link
Copy Markdown

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

Resolve niffyinsure conflicts: combine Cargo features (legacy-event-schema-tests +
governance-token), union DataKey instance variants (rolling cap + governance
stubs), quarantine legacy events with opt-in feature gate, align claim asset
fields and snapshot with setup token, remove duplicate pub mod events in lib.rs.

Made-with: Cursor
@jhayniffy
jhayniffy merged commit 7ce3590 into InsurNiffy:main Mar 29, 2026
2 of 7 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.

Contract — Claim amount cap per policy period: rolling cumulative limit

3 participants