Skip to content

Conversation

@Debugger022
Copy link
Collaborator

@Debugger022 Debugger022 commented Jul 7, 2025

Description

[VEN-3319]: Dynamic Liquidation Incentive and Close Factor in IL.
[VEN-3320]: Define maximum Liquidation Incentive per seized asset in IL.

This PR introduces a dynamic liquidation mechanism that adjusts the close factor and liquidation incentive based on the borrower's Health Factor (HF).

  • If HF > 1 → no liquidation

  • If HF ≤ 1 and > HFTTL:

    • Use max liquidation incentive (LI)
    • Compute close factor to restore HF to 1 (capped at 100%)
  • If HF ≤ HFTTL:

    • Use 100% close factor
    • Compute incentive dynamically:
    • LiquidationIncentive = min(LI, (HF / AvgLT) - 1)

Note: The Comptroller contract has grown beyond 24KB due to the introduced logic.

Checklist

  • I have updated the documentation to account for the changes in the code.
  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a test preventing this bug from silently reappearing again.
  • My contribution follows Venus contribution guidelines.

@Debugger022 Debugger022 self-assigned this Jul 7, 2025
/**
* @notice Multiplier representing the discount on collateral that a liquidator receives
*/
uint256 public liquidationIncentiveMantissa;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maintain the attribute, to not break the storage layout. Simply rename it to "deprecatedLiquidationIncentiveMantissa"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

// Per-market mapping of "accounts in this asset"
mapping(address => bool) accountMembership;
// discount on collateral that a liquidator receives when liquidating a borrow in this market
uint256 liquidationIncentiveMantissa;
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
uint256 liquidationIncentiveMantissa;
uint256 maxLiquidationIncentiveMantissa;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid changes in the VToken contract, if it's doable. Because vBNB cannot be upgraded

import { Comptroller } from "../Comptroller.sol";
import { VToken } from "../VToken.sol";

library Liquidation {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be a contract, to be deployed externally and then set in the Comptroller with a new privileged function. That would allow us to update the Liquidation logic on runtime. Just to review it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

event DelegateUpdated(address indexed approver, address indexed delegate, bool approved);

/// @notice Emitted when the liquidation manager is set
event LiquidationModuleSet(address indexed ILiquidationManager);
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
event LiquidationModuleSet(address indexed ILiquidationManager);
event NewLiquidationManager(ILiquidationManager indexed oldLiquidationManager, ILiquidationManager indexed newLiquidationManager);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


uint256 closeFactor;
unchecked {
if (snapshot.healthFactor >= 1e18) revert InsufficientShortfall();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use MANTISSA_ONE instead of 1e18?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Debugger022 Debugger022 marked this pull request as ready for review July 28, 2025 08:50

uint256 closeFactor;
unchecked {
if (snapshot.healthFactor >= 1e18) revert InsufficientShortfall();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this check, because if healthFactor is greater than 1, then the snapshot.shortfall should be 0, and the TX would have been reverted in the line 727

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 740 to 748
if (snapshot.healthFactor >= snapshot.healthFactorThreshold) {
uint256 numerator = borrowBalance * 1e18 - wtAvg * snapshot.totalCollateral;
uint256 denominator = borrowBalance *
(1e18 - ((wtAvg * (1e18 + marketCollateral.maxLiquidationIncentiveMantissa)) / 1e18));
closeFactor = (numerator * 1e18) / denominator;
closeFactor = closeFactor > 1e18 ? 1e18 : closeFactor;
} else {
closeFactor = 1e18;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could also move the calculation of the variable close factor to the LiquidationManager

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Health
contracts 83% 69%
contracts.Gateway 98% 68%
contracts.Gateway.Interfaces 100% 100%
contracts.Lens 95% 69%
contracts.Lens.legacy 0% 0%
contracts.Pool 100% 92%
contracts.Rewards 96% 70%
contracts.Shortfall 100% 85%
contracts.legacy.RiskFund 0% 0%
contracts.lib 100% 89%
Summary 71% (1583 / 2216) 62% (506 / 822)

@fred-venus fred-venus force-pushed the develop branch 4 times, most recently from 5beda80 to 6ab87cb Compare December 12, 2025 05:48
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