Skip to content

Feat/borrow interest overflow error#135

Merged
Smartdevs17 merged 9 commits intoSmartdevs17:mainfrom
Abidoyesimze:feat/borrow-interest-overflow-error
Mar 24, 2026
Merged

Feat/borrow interest overflow error#135
Smartdevs17 merged 9 commits intoSmartdevs17:mainfrom
Abidoyesimze:feat/borrow-interest-overflow-error

Conversation

@Abidoyesimze
Copy link
Copy Markdown
Contributor

Summary

Make interest conversion overflow explicit in calculate_interest:
Change return type to Result<i128, BorrowError>.
Convert with to_i128().ok_or(BorrowError::Overflow)? instead of capping to i128::MAX.
Propagate/handle the new error at call sites (borrow, repay, and get_user_debt).
Add tests to validate overflow behavior and keep non-overflow math checks intact.
Motivation
Previously, an I256→i128 conversion overflow would silently clamp to i128::MAX, masking arithmetic errors and potentially distorting accounting. This change makes overflow explicit, preventing silent state corruption.
What’s Changed
stellar-lend/contracts/lending/src/borrow.rs
calculate_interest(...) -> Result<i128, BorrowError>
Use ok_or(BorrowError::Overflow)? on I256→i128 conversion.
Propagate errors in borrow and repay.
Keep get_user_debt non-fallible by ignoring overflow (preserves method signature).
Tests
lending/src/borrow_test.rs: add test_interest_overflow_returns_error.
lending/src/math_safety_test.rs: adapt to Result, keep a non-overflow assertion path.
Acceptance Criteria
Overflow in interest conversion returns BorrowError::Overflow.
Tests verify overflow is surfaced and callers propagate the error correctly.
No panics on overflow.

closes #16

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@Abidoyesimze is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@Abidoyesimze 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! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit 887f309 into Smartdevs17:main Mar 24, 2026
8 of 9 checks 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.

Bug: Interest calculation overflow uses unwrap_or(i128::MAX) instead of error

2 participants