Summary
This proposal introduces a minor but important improvement to the repayment logic in the VToken contract, ensuring that repayments are automatically capped at the borrower’s outstanding debt.
This updates the repayAmount calculation in VToken.sol to ensure repayments are automatically capped at the borrower’s outstanding debt. Any repayAmount >= accountBorrows is now treated as a full repayment, preventing over-repayment and simplifying the user experience.
Context
Currently, the repayment logic only caps repayments when repayAmount is set to type(uint256).max. In all other cases, if a user submits a repayment amount greater than their outstanding debt, the full amount may be processed, resulting in over-repayment.
This behavior introduces unnecessary complexity for users and integrators, who must calculate the exact debt amount or rely on specific sentinel values to safely repay in full.
This proposal generalizes the repayment logic by capping the repayment amount whenever it exceeds the borrower’s outstanding debt, ensuring consistent and safe behavior across all repayment scenarios.
Description
This change standardizes how repayments are handled across the protocol. Previously, only type(uint256).max was treated as a “repay full debt” signal. Any other value greater than the borrower’s debt could result in over-repayment.
With this update, all repayment amounts are capped at accountBorrows, ensuring users never repay more than what is owed. This removes the need for users and integrators to calculate exact debt amounts and allows safe over-estimation of repayment values.
Key Change
Before:
if (repayAmount == type(uint256).max) {
vars.repayAmount = vars.accountBorrows;
} else {
vars.repayAmount = repayAmount;
}
After:
vars.repayAmount = repayAmount >= vars.accountBorrows ? vars.accountBorrows : repayAmount;
Impact
- Liquidations: Repayments in liquidation flows are now capped, ensuring no excess repayment beyond the borrower’s debt
- Event Accuracy:
RepayBorrowevents now reflect the actual amount repaid
Conclusion
This is a minimal, single-line change that improves safety, consistency, and usability across all repayment flows by enforcing a strict cap on repayment amounts.