Skip to content

feat: implement ledger-bounded policy renewal with premium recalc, cl… - #173

Merged
jhayniffy merged 1 commit into
InsurNiffy:mainfrom
GoodnessJohn:feat/policy-renewal
Mar 27, 2026
Merged

feat: implement ledger-bounded policy renewal with premium recalc, cl…#173
jhayniffy merged 1 commit into
InsurNiffy:mainfrom
GoodnessJohn:feat/policy-renewal

Conversation

@GoodnessJohn

Copy link
Copy Markdown
Contributor

Implements the full policy renewal flow, enforcing strict ledger-bounded windows, deterministic premium recalculation, open-claim blocking, checked arithmetic, and structured event emission.

Changes

New files

  • renewal.constants.ts — window constants with full inline docs on inclusive/exclusive semantics and server-client skew guidance
  • dto/renewal.dto.ts — request/response DTOs and PolicyRenewedEvent interface
  • renewal.service.ts — core orchestration: window validation, premium recalc, open-claim enforcement, i128 overflow guard, event emission
  • renewal.controller.tsPOST /policy/renewal/quote and POST /policy/renewal/build-transaction
  • renewal.service.spec.ts — 30 unit tests covering all boundary conditions and edge cases

Modified files

  • soroban.service.ts — adds buildRenewPolicyTransaction() and BuildRenewalTransactionResult type
  • policy.module.ts — wires RenewalController and RenewalService

Renewal window semantics

Half-open interval [windowOpen, windowClose):

  • windowOpen = endLedger - RENEWAL_OPEN_LEDGERS_BEFORE_EXPIRY (inclusive, ~7 days before expiry)
  • windowClose = endLedger + RENEWAL_GRACE_LEDGERS_AFTER_EXPIRY (exclusive, ~1 day grace after expiry)

Violations return RENEWAL_TOO_EARLY or RENEWAL_TOO_LATE with ledger numbers in the message.

Open-claim rule

Renewal is blocked when any claim has status PENDING (on-chain: Processing). APPROVED, PAID, and REJECTED claims do not block. Returns OPEN_CLAIM_BLOCKS_RENEWAL.

Event emission

PolicyRenewed is emitted on renewalBus exactly once per successful buildRenewalTransaction call — never on quote-only calls or failed validations.

Closes #9

@drips-wave

drips-wave Bot commented Mar 27, 2026

Copy link
Copy Markdown

@GoodnessJohn 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 e0eaeee into InsurNiffy:main Mar 27, 2026
2 of 4 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 — renew_policy: renewal windows, repricing, and interaction with open claims

2 participants