Skip to content

[VPD-675]: Repay Logic Improvement#676

Merged
fred-venus merged 9 commits intomainfrom
feat/VPD-675
Mar 3, 2026
Merged

[VPD-675]: Repay Logic Improvement#676
fred-venus merged 9 commits intomainfrom
feat/VPD-675

Conversation

@Debugger022
Copy link
Contributor

@Debugger022 Debugger022 commented Feb 27, 2026

VIP-597: VToken Repayment Logic Improvement

Description

This proposal updates the repayment logic in VToken to automatically cap repayments at the borrower's outstanding debt. The change improves safety, simplifies repayment flows, and prevents unintended over-repayment.

Context

Currently, only a repayment of type(uint256).max is treated as a full repayment. All other over-estimates are processed as-is, which can cause wasteful transactions and requires users to calculate exact debt amounts.

This update generalises the logic so that any repayment exceeding the borrower's debt is capped, improving safety and user experience across repayment and liquidation scenarios.

Proposed Change

Update in VToken.sol (repayBorrowFresh):

Before:

if (repayAmount == type(uint256).max) {
    vars.repayAmount = vars.accountBorrows;
} else {
    vars.repayAmount = repayAmount;
}

After:

vars.repayAmount = repayAmount >= vars.accountBorrows ? vars.accountBorrows : repayAmount;

Impact

  • Repayment Functions: Users can safely over-estimate repayments for repayBorrow and repayBorrowBehalf
  • Liquidations: Repayments are capped, avoiding overpayment during liquidation
  • Events: RepayBorrow events now reflect the actual repaid amount
  • Math Safety: Prevents underflow in repayment calculations

Scope

  • Contract: VToken
  • Function: repayBorrowFresh
  • Change Type: Single-line logic update
  • Code Impact: Minimal (2 additions, 6 deletions)

Summary

If approved, this VIP will:

  • Cap repayments at the borrower's outstanding debt
  • Simplify repayment logic and improve user safety
  • Prevent overpayment during normal or liquidation flows
  • Maintain backward compatibility for standard repayment scenarios

Upgrade VBep20Delegate for all core pool markets on BSC testnet
to cap repayment amounts to actual borrow balance
Upgrade VBep20Delegate for all core pool markets on BSC mainnet
to cap repayment amounts to actual borrow balance
@Debugger022 Debugger022 self-assigned this Feb 27, 2026
Reassign VIP number from 596 to 610 for the vToken implementation
upgrade proposal, updating directory names and import paths.
Copy link
Contributor

@GitGuru7 GitGuru7 left a comment

Choose a reason for hiding this comment

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

overall LGTM, I think we should also upgrade vXAUM on mainnet. The VIP is currently in the queue, we can still include this upgrade and avoid creating an additional VIP for it later.

Comment on lines +10 to +11
// TODO: Set the correct block number
const BLOCK_NUMBER = 92753245;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO: Set the correct block number
const BLOCK_NUMBER = 92753245;
const BLOCK_NUMBER = 93334375;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add vXAUM underlying address, reorder all core pool markets
alphabetically in both mainnet and testnet VIP definitions,
and update all references from vip596 to vip610.
import { ProposalType } from "src/types";
import { makeProposal } from "src/utils";

export const NEW_VBEP20_DELEGATE_IMPL = "0x469E286EA3a0A38358004AADbD54E52097aeD9B3";
Copy link
Contributor

Choose a reason for hiding this comment

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

from claude code

VIP description does not disclose flash loan removal. The new implementation completely removes all flash loan infrastructure (~6 functions including transferOutUnderlyingFlashLoan, setFlashLoanEnabled, calculateFlashLoanFee, etc). Flash loans are currently enabled (isFlashLoanEnabled=true) on at least vUSDT, vUSDC, vBTC, vETH, vXVS. Although flashLoanFeeMantissa=0 suggests limited active use, this is a material behavioral change that must be disclosed. Additional undisclosed changes: borrowFresh simplified (removed shouldTransfer param), event emission ordering fixed in _setComptrollerFresh/_setInterestRateModelFresh.

Copy link
Contributor

Choose a reason for hiding this comment

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

i checked, seems yes

existing on-chain

Image

new

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 8fd80b2

Debugger022 and others added 5 commits March 2, 2026 16:48
Point to the latest deployed implementations and update simulation
fork blocks to match the new deployment state.
- Rename vip610 to vip597 in VIP and simulation files
- Update title to "VIP-597 [BNB Chain] VToken Repayment Logic Improvement"
- Replace description with content from Notion community post
  (Context, Proposed Change, Impact, Scope, Summary sections)
- Keep Security, Deployed contracts, and References sections

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ibility

- Remove inline code backticks and code blocks that don't render
  in the governance UI
- Remove Proposed Change and Scope sections (code-heavy)
- Link to community post for technical details
- Add community post to References

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fred-venus
Copy link
Contributor

venus.io#/governance/proposal/597?chainId=56

@fred-venus fred-venus merged commit d0ee9db into main Mar 3, 2026
2 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.

3 participants