Feat/request loan - #1733
Open
Adediwura-dev wants to merge 4 commits into
Open
Conversation
mint() clamped initial_score against MAX_SCORE (850) but had no lower bound, allowing a token to be minted with a score of 0. Every other code path (decrease_score, update_score) treats MIN_CREDIT_SCORE (300) as an invariant floor. This created below-floor states the rest of the contract assumed were impossible. Added .clamp(MIN_CREDIT_SCORE, MAX_SCORE) in both mint and remint, replacing the ceiling-only .min(MAX_SCORE). Updated three tests that previously asserted below-floor scores to expect the correctly clamped values, and added a dedicated test that mints with initial_score=100 and asserts stored score is 300. Also fixed pre-existing cargo fmt violations in lending_pool. Closes LabsCrypt#1483 🤖 Generated with Codebuff Co-Authored-By: Codebuff <[email protected]>
…event borrower lockout cancel_loan and reject_loan now decrement BorrowerLoanCount when transitioning a loan out of Pending, so the borrower immediately regains a slot for new requests. Previously, only the admin-only purge_loan cleaned up the count for Cancelled/Rejected loans. After MaxLoansPerBorrower request-then-cancel cycles the count was permanently saturated, causing request_loan to return MaxLoansReached even with zero active loans — a persistent DoS against legitimate borrowers. Changes: - cancel_loan: call decrement_borrower_loan_count after setting Cancelled - reject_loan: call decrement_borrower_loan_count after setting Rejected - purge_loan: remove the Cancelled/Rejected branch that is no longer needed (avoids double-decrement) - Add three regression tests: - test_cancel_frees_slot_for_new_request (cap=1, request→cancel→request) - test_reject_frees_slot_for_new_request (cap=1, request→reject→request) - test_request_cancel_cycle_does_not_lock_borrower (cap=2, full cycle) The existing decrement_borrower_loan_count helper is already underflow-safe (no-ops when count == 0), so no arithmetic guard changes were needed. close LabsCrypt#1087
Keep the upstream's test_liquidate_decreases_score_and_records_default test alongside the three cancel/reject-frees-slot regression tests. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <[email protected]>
Add missing blank doc-comment line between list and paragraph to satisfy clippy --all-targets --all-features -- -D warnings in CI. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <[email protected]>
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.
Pull Request Checklist
CONTRIBUTING.mddocument.Closes #1087