Skip to content

Feat/policy expired event - #248

Merged
jhayniffy merged 2 commits into
InsurNiffy:mainfrom
favourawaku:feat/policy-expired-event
Mar 29, 2026
Merged

Feat/policy expired event#248
jhayniffy merged 2 commits into
InsurNiffy:mainfrom
favourawaku:feat/policy-expired-event

Conversation

@favourawaku

Copy link
Copy Markdown
Contributor

Summary

Adds an on-chain PolicyExpired event and keeper hook so indexers and the notification service can detect policy expiry without scanning every policy’s end_ledger. Expiry is recorded at most once per policy term (per end_ledger).
closes #200

Changes

  • PolicyExpired contract event: topics holder, policy_id; data expiry_ledger, reported_at_ledger. Documented that reported_at_ledger may be after expiry_ledger (keeper / caller delay).
  • process_expired(holder, policy_id): emits when ledger >= end_ledger if not already recorded; NotFound if no policy; NotYetExpired if now < end_ledger**; idempotent Ok if already notified for this term.
  • renew_policy: if already expired, runs the same emit/dedupe path, then returns Ok(RenewPolicyOutcome::Lapsed) (not Err), so Soroban does not roll back instance storage and the event can persist. Successful renewal returns Ok(Renewed(Policy)).
  • Dedupe: instance key stores the end_ledger for which expiry was already emitted (new term after renewal can emit again).
  • get_pol_exp_evt_end_ledger: read-only helper for tests/indexers (name shortened for the 32-character Soroban export limit).
  • Tests in contracts/niffyinsure/tests/policy_expired.rs** (keeper, renew Lapsed, open-claim rejection, full initiate+ duration +process_expired`).

Notes for integrators

  • Backend should treat renew_policy success + Lapsed as “no renewal; expiry notice may have been recorded,” and regenerate client bindings from the updated spec.
  • PolicyError::Expired (118) is kept for ABI stability but is not returned from renew_policy anymore.
  • Notification layer should still dedupe on policy_id (and holder) as documented on the event.

Testing

cargo test in contracts/niffyinsure (all tests passing).

… outcome

- Emit PolicyExpired (holder, policy_id, expiry_ledger, reported_at_ledger) once per term
- Instance storage dedupe keyed by holder + policy_id + end_ledger term
- process_expired keeper: NotFound / NotYetExpired / idempotent Ok
- renew_policy: Ok(Lapsed) when expired so Soroban does not roll back emission
- RenewPolicyOutcome enum (Renewed | Lapsed); PolicyError::Expired reserved
- Read API get_pol_exp_evt_end_ledger (32-char export limit)
- Tests for keeper, renew path, natural initiate + expiry

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

@jhayniffy
jhayniffy merged commit 7fac45b 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 — Policy expiry event: on-chain signal for renewal reminder pipeline

3 participants