Skip to content

Feat/request loan - #1733

Open
Adediwura-dev wants to merge 4 commits into
LabsCrypt:mainfrom
Adediwura-dev:feat/request_loan
Open

Feat/request loan#1733
Adediwura-dev wants to merge 4 commits into
LabsCrypt:mainfrom
Adediwura-dev:feat/request_loan

Conversation

@Adediwura-dev

Copy link
Copy Markdown

Pull Request Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation accordingly.
  • I have verified the changes locally.

Closes #1087

Adediwura-dev and others added 4 commits August 30, 2026 12:47
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]>
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.

[Contracts] cancel_loan/reject_loan do not decrement the borrower loan count, letting a borrower lock themselves out of new loans

1 participant