Skip to content

fix(contracts): approve_loan honours borrower-requested term#34

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
david87131:feat/issues-3-5
Jun 20, 2026
Merged

fix(contracts): approve_loan honours borrower-requested term#34
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
david87131:feat/issues-3-5

Conversation

@david87131

@david87131 david87131 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Narrowed-scope re-spin per review: only the #5 approve-time term fix remains in this PR. The redeem-math hardening I had under #3 has been dropped in favour of #33's version, which the maintainer is landing as the lead.

  • [Contracts] LoanManager approve_loan overrides the borrower-requested term with the default term #5approve_loan overrode the borrower-requested term: loan_manager/src/lib.rs now honours the loan's stored term_ledgers (falling back to read_default_term() only when 0 / unset), so the min_term / max_term limits checked at request time actually govern the approved due_date. New regression test asserts that requesting a non-default term and approving produces a due_date derived from the requested term.

Test plan

Closes #5

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic is correct and ci is green. issue #5: approve_loan now honors the borrower's stored term (term_ledgers = if loan.term_ledgers == 0 { read_default_term } else { loan.term_ledgers }) instead of overwriting it with the default, and i confirmed request_loan does store term_ledgers and due_date derives from it at approve time, so it's coherent end to end. issue #3: calc_assets_to_redeem no longer expect()-panics, it returns typed PoolError (InvalidAmount / InsufficientLiquidity) with the view callers using unwrap_or(0). good.

the blocker is a collision with #33, not a bug in your code:

  1. #33 and your pr edit the same code in incompatible ways, both rewrite calc_assets_to_redeem into a Result-returning fn and both gate the loan term by loan.term_ledgers. they can't both merge as-is. your changes are actually complementary (yours = approval-time term, theirs = accrual-time term plus the donation guard and redeem hardening), so i'm landing #33 first as the lead. once it's in, please rebase on main and keep just your approval-time term change, adopting #33's calc_assets_to_redeem signature so the two line up. one small divergence to reconcile while you're there: you map total_assets <= 0 to InsufficientLiquidity, #33 maps only < 0 to InvalidAmount, yours is the more informative mapping for a drained pool so call that out in the rebase if you keep it.

  2. you'll need the rebase regardless because #31 just merged and reworked the redeem path in lending_pool/src/lib.rs, so your green ci predates the current main.

separately, not for this pr: neither this nor main enforces the configured min_term/max_term inside request_loan, it only rejects term == 0. since approval now faithfully uses the borrower term, that gap is reachable, might be worth a follow-up issue.

i'll re-review as soon as #33 is in and you've rebased.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

LoanManager.approve_loan now uses the loan's stored term_ledgers (falling
back to read_default_term() only when 0 / unset), instead of overwriting
the borrower-requested term with the contract-wide default. The
min_term/max_term limits checked at request time now actually govern the
approved due_date.

Regression test asserts that requesting a non-default term and approving
produces a due_date derived from the requested term.

Scope narrowed: the redeem-math hardening (LabsCrypt#3) has been dropped in favour
of LabsCrypt#33's version, which the maintainer is landing as the lead. This PR
keeps only the approve-time term fix from LabsCrypt#5; the redeem hardening will
arrive via LabsCrypt#33 and is no longer duplicated here.

cargo test -p lending_pool -p loan_manager green (50 + 89).

Closes LabsCrypt#5
@david87131 david87131 changed the title fix(contracts): use borrower term on approval; guard redeem math fix(contracts): approve_loan honours borrower-requested term Jun 19, 2026

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly the focused change i was hoping for, you dropped the calc_assets_to_redeem overlap and kept just the approval-term fix, so it no longer collides with #33. approve_loan now honors the borrower's stored term_ledgers (falling back to the default only when it's 0 for legacy loans) instead of overwriting it with the contract default, which is the issue #5 fix. ci is green, and your change is in approve_loan while #33's is in the accrual path, so they don't overlap. merging.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

@ogazboiz ogazboiz merged commit 2011656 into LabsCrypt:main Jun 20, 2026
1 check 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.

[Contracts] LoanManager approve_loan overrides the borrower-requested term with the default term

2 participants