feat: implement ledger-bounded policy renewal with premium recalc, cl… - #173
Merged
Merged
Conversation
…aim enforcement, and event emission
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 guidancedto/renewal.dto.ts— request/response DTOs andPolicyRenewedEventinterfacerenewal.service.ts— core orchestration: window validation, premium recalc, open-claim enforcement, i128 overflow guard, event emissionrenewal.controller.ts—POST /policy/renewal/quoteandPOST /policy/renewal/build-transactionrenewal.service.spec.ts— 30 unit tests covering all boundary conditions and edge casesModified files
soroban.service.ts— addsbuildRenewPolicyTransaction()andBuildRenewalTransactionResulttypepolicy.module.ts— wiresRenewalControllerandRenewalServiceRenewal 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_EARLYorRENEWAL_TOO_LATEwith ledger numbers in the message.Open-claim rule
Renewal is blocked when any claim has status
PENDING(on-chain: Processing).APPROVED,PAID, andREJECTEDclaims do not block. ReturnsOPEN_CLAIM_BLOCKS_RENEWAL.Event emission
PolicyRenewedis emitted onrenewalBusexactly once per successfulbuildRenewalTransactioncall — never on quote-only calls or failed validations.Closes #9