feat: add get_settlement_pool aggregate coupon view with tests#591
Open
IfyJustin91 wants to merge 6 commits into
Open
feat: add get_settlement_pool aggregate coupon view with tests#591IfyJustin91 wants to merge 6 commits into
IfyJustin91 wants to merge 6 commits into
Conversation
Implements get_settlement_pool(env) -> i128 returning total_principal + floor(total_principal × yield_bps / 10_000) from FundingCloseSnapshot and the escrow base yield_bps, using the same checked_* arithmetic and ComputePayoutArithmeticOverflow guard as compute_investor_payout. Returns 0 when snapshot is absent (escrow not yet funded), matching compute_investor_payout semantics. Changes: - escrow/src/lib.rs: add get_settlement_pool view after compute_investor_payout - escrow/src/tests/coverage.rs: 10 comprehensive tests covering pool = principal+coupon, zero before snapshot, zero yield, max yield, rounding floor, idempotency, post-settle stability, base-yield-only (not tier), sum-of-payouts invariant, over-funding stability, and overflow guard - escrow/src/tests.rs: add PLEDGE constant used across collateral tests - docs/escrow-pro-rata.md: add get_settlement_pool section - docs/escrow-read-api.md: add get_settlement_pool index entry and full spec Security notes: - Pure read; no auth required; no state mutation - Identical rounding (floor division) to compute_investor_payout - Overflow-safe via checked_mul / checked_div on all paths - Uses escrow base yield only (per-investor tier yields are not aggregated) Closes Liquifact#385
Implements get_settlement_pool(env) -> i128 returning total_principal + floor(total_principal × yield_bps / 10_000) from FundingCloseSnapshot and the escrow base yield_bps, using the same checked_* arithmetic and ComputePayoutArithmeticOverflow guard as compute_investor_payout. Returns 0 when snapshot is absent (escrow not yet funded). - escrow/src/lib.rs: add get_settlement_pool view after compute_investor_payout - escrow/src/tests/coverage.rs: 11 tests (zero before snapshot, zero before init, principal+coupon, zero yield, max yield, floor rounding, idempotency, post-settle stability, base-yield-only, sum-of-payouts invariant, over-funding stability, overflow guard error 129) - docs/escrow-pro-rata.md: add get_settlement_pool section - docs/escrow-read-api.md: add index entry and full spec Closes Liquifact#385
|
@IfyJustin91 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! 🚀 |
- Fixed rustfmt formatting violations across all source files - Resolved duplicate function definitions (guard_status_eq, guard_status_in) - Fixed duplicate enum discriminant value (201 for HorizonNotRaised) - Added missing PausedBlocks* error variants (PausedBlocksFunding, PausedBlocksSettlement, PausedBlocksWithdrawal, PausedBlocksInvestorClaims) - Fixed tier_lock_secs mutability to allow reassignment - Removed duplicate closing brace in DefaultMockToken impl - All code now passes rustfmt --check and cargo build --release
- Convert tier_lock_secs to expression-based initialization - Eliminates -D warnings clippy failure in CI - All code paths now clearly initialize the value - Maintains all original logic and side effects
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.
Summary
Implements the
get_settlement_pool(env) → i128read view requested in #385.The SME repayment total was previously only computable off-chain from raw snapshot fields, risking rounding divergence from the on-chain math. This PR closes that gap with an authoritative on-chain aggregate.
Changes
escrow/src/lib.rsget_settlement_pool(env: Env) -> i128aftercompute_investor_payoutDataKey::FundingCloseSnapshotfortotal_principalDataKey::Escrowfor the baseyield_bpssettlement_couponhelper (same math, same overflow guard)0when snapshot is absent (escrow not yet funded)escrow/src/tests/coverage.rsAdded 10+ comprehensive tests covering: zero before snapshot, zero before init, principal+coupon equality, zero yield, max yield (100%), floor rounding, idempotency, post-settle stability, base-yield-only (not tier), sum-of-payouts ≤ pool invariant, over-funding stability, and overflow guard (typed error 129).
escrow/src/tests.rsPLEDGE: i128 = 5_000constant used across collateral-metadata testsDocs
docs/escrow-pro-rata.md: addedget_settlement_poolsectiondocs/escrow-read-api.md: added index entry and full specSecurity notes
compute_investor_payout(samesettlement_couponhelper, floor division)checked_mul/checked_div; emitsComputePayoutArithmeticOverflow(code 129)Build status note
The
mainbranch has 69 pre-existing compile errors unrelated to this feature (confirmed by runningcargo buildon the unmodified tree before any changes). This PR introduces zero new compilation errors.Closes #385