Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
f608f86
feat: add Liquidation Threshold in Core Pool on BNB
Debugger022 Jul 9, 2025
294f79e
fix: minor fix
Debugger022 Jul 10, 2025
fae7c2a
fix: fix test
Debugger022 Jul 15, 2025
e139b03
fix: fix test for liquidation threshold setter
Debugger022 Jul 15, 2025
7ba7bac
fix: spelling correction
Debugger022 Jul 18, 2025
624c961
test: add tests for borrow and user liquidation state
Debugger022 Jul 18, 2025
10d7785
test: add liquidation functionality test for Liquidator contract
Debugger022 Jul 19, 2025
b04a893
test: add test for XVS rewards claiming functionality
Debugger022 Jul 19, 2025
cb5a5db
feat: add market liquidation incentive and update liquidity calculations
Debugger022 Jul 23, 2025
a6d1926
refactor: add liquidation threshold and incentive params to Market st…
Debugger022 Jul 25, 2025
f16a9b5
feat!: migrate markets and Comptroller to Solidity 0.8.25
kkirka Jul 25, 2025
caeea51
refactor: update references to Market with new params
Debugger022 Jul 28, 2025
cf0354b
feat: add function to calculate health factor of an account
Debugger022 Jul 28, 2025
da9ef57
refactor: getter function for account health factors
Debugger022 Jul 28, 2025
8a38506
feat: add Toxic liquidation check in liquidate hook
Debugger022 Jul 28, 2025
ff22d54
feat: add dynamic liquidation incentive per asset
Debugger022 Jul 28, 2025
c4786ce
feat: update Liquidator contract to use dynamic liquidation incentive
Debugger022 Jul 28, 2025
1e8f708
refactor: update calculate SeizeTokens params
Debugger022 Jul 28, 2025
f7e3f53
fix: minor fix
Debugger022 Jul 28, 2025
91316bb
fix: lint
Debugger022 Jul 28, 2025
dc16c67
feat: add external Liquidation Manager contract
Debugger022 Jul 29, 2025
b526832
feat: setter for Liquidation Manager
Debugger022 Jul 29, 2025
348fbb3
feat: using Liquidation Manager functions
Debugger022 Jul 29, 2025
7eeeaa2
fix: fix comptroller unit tests
Debugger022 Jul 30, 2025
69f820e
refactor: update markets return params
Debugger022 Jul 30, 2025
4ea3457
fix: fix VAI tests
Debugger022 Jul 30, 2025
626f13a
Merge branch 'feat/solidity-0.8' into feat/VEN-3321
Debugger022 Jul 30, 2025
7b4fa89
feat: update solidity version of Liquidation manager
Debugger022 Jul 30, 2025
7e5a754
fix: minor fixes
Debugger022 Jul 30, 2025
9833f7b
refactor: update setter to include liquidation threshold
Debugger022 Jul 30, 2025
a5e7c7c
fix: setCollateralFactor and used constants
Debugger022 Jul 30, 2025
66ef1b5
test: fix comptroller tests
Debugger022 Jul 31, 2025
be83b61
test: fix tests
Debugger022 Jul 31, 2025
c90aa01
test: fix fork tests
Debugger022 Aug 1, 2025
1837cc7
feat: added natspec comments
Debugger022 Aug 4, 2025
4e8fa35
refactor: rename some functions and remove _setCollateralFactor
Debugger022 Aug 4, 2025
6dbb217
test: refactor tests to call updated functions
Debugger022 Aug 4, 2025
24aca7f
refactor: update treasury percent calculation
Debugger022 Aug 4, 2025
a06802b
refactor: consistent return statements
Debugger022 Aug 4, 2025
f65e34d
refactor: refactored struct and other calculations
Debugger022 Aug 4, 2025
b0705ce
refactor: remove healthFactorThreshold and liquidationIncentiveAvg
Debugger022 Aug 4, 2025
5868274
refactor: update close factor and dynamic incentive calculation
Debugger022 Aug 4, 2025
17be54c
feat: move calculation of seize tokens logic to comptrollerLens
Debugger022 Aug 4, 2025
c23fe60
refactor: rename averageLT to liquidationThresholdAvg
Debugger022 Aug 4, 2025
9955fb2
feat: Introduced weight function to replicate both CF and LT
Debugger022 Aug 5, 2025
2cf8104
refactor: fix health factor computation
Debugger022 Aug 5, 2025
ab6d0ae
refactor: consistent external function names
Debugger022 Aug 5, 2025
57e92f4
fix: remove comment
Debugger022 Aug 5, 2025
8b37991
refactor: move functions to FacetBase
Debugger022 Aug 5, 2025
6868164
refactor: deprecate old attributes
Debugger022 Aug 5, 2025
d653b5f
refactor: using revert
Debugger022 Aug 5, 2025
de84582
refactor: remove close factor settter and update liquidation incentiv…
Debugger022 Aug 5, 2025
5c84b79
refactor: update dynamic incentive calculation
Debugger022 Aug 5, 2025
800f8b6
feat: using reverts with custom errors
Debugger022 Aug 6, 2025
fe5c158
feat: optimized account position calculation
Debugger022 Aug 6, 2025
022a11d
feat: introduced baseCloseFactor and targetHealthFactor
Debugger022 Aug 6, 2025
7860cd6
feat: using baseCloseFactor to avoid zero incentive condition
Debugger022 Aug 6, 2025
56c25c2
refactor: update getHypotheticalHealthSnapshot to return shortfall too
Debugger022 Aug 7, 2025
0510348
feat: add baseCloseFactor, target HF and toggle mappings for dynamic …
Debugger022 Aug 7, 2025
f2f1034
refactor: remove baseCloseFactor and targetHealthFactor from comptroller
Debugger022 Aug 7, 2025
f091f37
feat: added events
Debugger022 Aug 7, 2025
107ead8
refactor: use generic ActionNotPaused error
Debugger022 Aug 7, 2025
3025a69
fix: update vTokenBalance after redeem
Debugger022 Aug 7, 2025
50a256f
refactor: remove setLiquidationIncentive and its alias
Debugger022 Aug 7, 2025
61ed23f
fix: remove setLiquidationIncentive and closeFactor references
Debugger022 Aug 7, 2025
a7b4206
fix: minor fix
Debugger022 Aug 7, 2025
e2f29c0
Revert "feat: using reverts with custom errors"
Debugger022 Aug 8, 2025
2fc0c2e
fix: stack too deep
Debugger022 Aug 8, 2025
13605fd
Merge branch 'feat/solidity-0.8' into feat/VEN-3321
Debugger022 Aug 8, 2025
0f6be8f
refactor: adjust baseCloseFactor to be dynamic
Debugger022 Aug 8, 2025
02dc4e7
refactor: remove unused constants and events
Debugger022 Aug 11, 2025
dfdf581
feat: optimization by reducing getHealthSnapshot calls
Debugger022 Aug 12, 2025
a17ef99
refactor: using weight in _calculateAccountPosition internally
Debugger022 Aug 12, 2025
3c6248c
refactor: update initialization of access control
Debugger022 Aug 12, 2025
b13414e
test: fix tests
Debugger022 Aug 12, 2025
768e5d2
feat: add dynamicLiquidationIncentive in AccountSnapshot struct
Debugger022 Aug 13, 2025
dd31a2c
refactor: extract non-risk fields from AccountSnapshot into new struct
Debugger022 Aug 13, 2025
5f0b4f8
refactor: revert VBNB changes
Debugger022 Aug 13, 2025
53b7562
fix: fix liquidator tests
Debugger022 Aug 14, 2025
9bc16b4
fix: fix VAI tests
Debugger022 Aug 18, 2025
ee861ff
refactor: fork tests
Debugger022 Aug 26, 2025
9ed3422
feat: update shares calculation in liquiator
Debugger022 Aug 28, 2025
c5aa0db
refactor: add liquidateCalculateSeizeTokens getter function
Debugger022 Aug 28, 2025
eb0c632
fix: fix setup and tests
Debugger022 Aug 28, 2025
151b14b
fix: fix unit tests
Debugger022 Aug 29, 2025
2339b40
Merge branch 'feat/VEN-3343' into feat/VEN-3321
Debugger022 Sep 3, 2025
0eee583
refactor: using WeightFunction in account snapshot calculation
Debugger022 Sep 3, 2025
26436f4
feat: add pool-level market liquidation incentive setter
Debugger022 Sep 3, 2025
13ec325
feat: add getter for VAISeizeTokens
Debugger022 Sep 3, 2025
bfac079
test: fix unit and fork tests
Debugger022 Sep 4, 2025
c3ce6f4
test: fix emode test
Debugger022 Sep 5, 2025
79ead60
Merge branch 'feat/VEN-3343' into feat/VEN-3321
Debugger022 Sep 5, 2025
6b30587
fix: minor fix
Debugger022 Sep 5, 2025
9d0d46b
refactor: moved getDynamicLiquidationIncentive to Market facet
Debugger022 Sep 8, 2025
78d3bf8
feat: reduced VBep20Delegate size
Debugger022 Sep 9, 2025
6254eaa
feat: add Liquidation Manager deployment script
Debugger022 Sep 9, 2025
fb48338
feat: add deployments for bsctestnet
Debugger022 Sep 9, 2025
1bd7262
feat: update repayAmount logic
Debugger022 Nov 3, 2025
d8edaa0
Merge branch 'feat/VEN-2985' into feat/VEN-3321
Debugger022 Nov 11, 2025
6758363
fix: minor fixes
Debugger022 Nov 11, 2025
c21100f
refactor: upgrade comptroller storage to ComptrollerV19Storage
Debugger022 Nov 13, 2025
bd5d35f
test: add fork test for dynamic liquidation mechanism
Debugger022 Nov 17, 2025
4c541a4
refactor: update liquidation calculations to use 1e18 for precision
Debugger022 Nov 18, 2025
4605b3b
Merge branch 'feat/VPD-233' into feat/VEN-3321
Debugger022 Nov 20, 2025
0297580
refactor: minor fixes
Debugger022 Nov 21, 2025
9ce8a5a
test: update TokenRedeemer test
Debugger022 Nov 26, 2025
1560cc2
test: add tests for liquidation scenario
Debugger022 Dec 1, 2025
5ad06f6
Merge branch 'develop' into feat/VEN-3321
Debugger022 Dec 2, 2025
1659da4
fix: lint
Debugger022 Dec 2, 2025
8b972e1
feat: updating deployment files
Debugger022 Dec 2, 2025
da82294
fix: minor fixes
Debugger022 Dec 2, 2025
f9d6dc0
feat: update bsctestnet deployment files
Debugger022 Dec 3, 2025
b29d11a
feat: update liquidationManager deployment
Debugger022 Dec 3, 2025
44b4d88
feat: updating deployment files
Debugger022 Dec 3, 2025
2361f5e
refactor: rename borrows to totalBorrows and update related logic
Debugger022 Dec 15, 2025
fff566c
refactor: update dynamic liquidation mechanism with respect to e-mode
Debugger022 Dec 15, 2025
9072738
refactor: remove liquidateVAICalculateSeizeTokens unused variant
Debugger022 Dec 15, 2025
545cd00
Merge branch 'develop' into feat/VEN-3321
Debugger022 Dec 15, 2025
b008927
fix: lint and prettier
Debugger022 Dec 16, 2025
f83afff
feat: updating deployment files
Debugger022 Dec 16, 2025
7dd2804
refactor: update tests for new liquidation changes
Debugger022 Dec 16, 2025
6fa0386
refactor: update fork tests for dynamic liquidation mechanism
Debugger022 Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions contracts/Comptroller/ComptrollerInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ResilientOracleInterface } from "@venusprotocol/oracle/contracts/interf

import { VToken } from "../Tokens/VTokens/VToken.sol";
import { VAIControllerInterface } from "../Tokens/VAI/VAIControllerInterface.sol";
import { LiquidationManager } from "../LiquidationManager.sol";
import { ComptrollerLensInterface } from "./ComptrollerLensInterface.sol";
import { WeightFunction } from "./Diamond/interfaces/IFacetBase.sol";

enum Action {
Expand Down Expand Up @@ -75,6 +77,15 @@ interface ComptrollerInterface {
uint repayAmount
) external returns (uint);

function liquidateBorrowAllowed(
address vTokenBorrowed,
address vTokenCollateral,
address liquidator,
address borrower,
uint repayAmount,
ComptrollerLensInterface.AccountSnapshot memory snapshot
) external returns (uint);

function liquidateBorrowVerify(
address vTokenBorrowed,
address vTokenCollateral,
Expand Down Expand Up @@ -107,23 +118,25 @@ interface ComptrollerInterface {
/*** Liquidity/Liquidation Calculations ***/

function liquidateCalculateSeizeTokens(
address borrower,
address vTokenBorrowed,
address vTokenCollateral,
uint repayAmount
) external view returns (uint, uint);

function liquidateCalculateSeizeTokens(
address borrower,
address vTokenBorrowed,
address vTokenCollateral,
uint repayAmount
uint repayAmount,
uint liquidationIncentiveMantissa
) external view returns (uint, uint);

function setMintedVAIOf(address owner, uint amount) external returns (uint);

function liquidateVAICalculateSeizeTokens(
address vTokenCollateral,
uint repayAmount
uint repayAmount,
uint liquidationIncentiveMantissa
) external view returns (uint, uint);

function getXVSAddress() external view returns (address);
Expand All @@ -132,6 +145,8 @@ interface ComptrollerInterface {

function oracle() external view returns (ResilientOracleInterface);

function liquidationManager() external view returns (LiquidationManager);

function getAccountLiquidity(address) external view returns (uint, uint, uint);

function getAssetsIn(address) external view returns (VToken[] memory);
Expand Down Expand Up @@ -168,8 +183,33 @@ interface ComptrollerInterface {

function vaiMintRate() external view returns (uint);

function getDynamicLiquidationIncentive(address borrower, address market) external view returns (uint256);

function getDynamicLiquidationIncentive(
address market,
address borrower,
uint256 liquidationThresholdAvg,
uint256 healthFactor
) external view returns (uint256);

function getCollateralFactor(address vToken) external view returns (uint256);

function getLiquidationThreshold(address vToken) external view returns (uint256);

function getHypotheticalHealthSnapshot(
address account,
VToken vTokenModify,
uint redeemTokens,
uint borrowAmount
) external view returns (uint256, ComptrollerLensInterface.AccountSnapshot memory);

function authorizedFlashLoan(address account) external view returns (bool);

function delegateAuthorizationFlashloan(
address account,
address market,
address delegate
) external view returns (bool);
function userPoolId(address account) external view returns (uint96);

function getLiquidationIncentive(address vToken) external view returns (uint256);
Expand Down
51 changes: 41 additions & 10 deletions contracts/Comptroller/ComptrollerLensInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,64 @@ import { VToken } from "../Tokens/VTokens/VToken.sol";
import { WeightFunction } from "./Diamond/interfaces/IFacetBase.sol";

interface ComptrollerLensInterface {
struct AccountSnapshot {
// Total collateral value supplied by the account (USD, scaled by 1e18)
uint256 totalCollateral;
// Collateral value weighted by each asset's liquidation threshold or collateral factor (USD, scaled by 1e18)
uint256 weightedCollateral;
// Total borrowed value by the account (USD, scaled by 1e18)
uint256 totalBorrows;
// Amount of excess collateral available for borrowing (USD, scaled by 1e18)
uint256 liquidity;
// Amount by which the account is undercollateralized (USD, scaled by 1e18)
uint256 shortfall;
// Average liquidation threshold across all supplied assets (scaled by 1e18)
uint256 liquidationThresholdAvg;
// Health factor of the account, used to assess liquidation risk (scaled by 1e18)
uint256 healthFactor;
// Dynamic liquidation incentive factor applied during liquidations (scaled by 1e18)
uint256 dynamicLiquidationIncentiveMantissa;
}

// Just need to make borrower first then comptroller
function liquidateCalculateSeizeTokens(
address borrower,
address comptroller,
address vTokenBorrowed,
address vTokenCollateral,
uint actualRepayAmount
) external view returns (uint, uint);
uint256 actualRepayAmount
) external view returns (uint256, uint256);

function liquidateCalculateSeizeTokens(
address borrower,
address comptroller,
address vTokenBorrowed,
address vTokenCollateral,
uint actualRepayAmount
) external view returns (uint, uint);
uint256 actualRepayAmount,
uint256 liquidationIncentiveMantissa
) external view returns (uint256, uint256);

function liquidateVAICalculateSeizeTokens(
address comptroller,
address vTokenCollateral,
uint actualRepayAmount
) external view returns (uint, uint);
uint256 actualRepayAmount,
uint256 liquidationIncentiveMantissa
) external view returns (uint256, uint256);

function getHypotheticalAccountLiquidity(
address comptroller,
address account,
VToken vTokenModify,
uint redeemTokens,
uint borrowAmount,
uint256 redeemTokens,
uint256 borrowAmount,
WeightFunction weightingStrategy
) external view returns (uint256, uint256, uint256);

function getAccountHealthSnapshot(
address comptroller,
address account,
VToken vTokenModify,
uint256 redeemTokens,
uint256 borrowAmount,
WeightFunction weightingStrategy
) external view returns (uint, uint, uint);
) external view returns (uint256, AccountSnapshot memory);
}
12 changes: 9 additions & 3 deletions contracts/Comptroller/ComptrollerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { VToken } from "../Tokens/VTokens/VToken.sol";
import { VAIControllerInterface } from "../Tokens/VAI/VAIControllerInterface.sol";
import { ComptrollerLensInterface } from "./ComptrollerLensInterface.sol";
import { IPrime } from "../Tokens/Prime/IPrime.sol";
import { LiquidationManager } from "../LiquidationManager.sol";

contract UnitrollerAdminStorage {
/**
Expand Down Expand Up @@ -39,9 +40,9 @@ contract ComptrollerV1Storage is UnitrollerAdminStorage {
ResilientOracleInterface public oracle;

/**
* @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow
* @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow (deprecated)
*/
uint256 public closeFactorMantissa;
uint256 private __oldCloseFactorMantissaSlot;

/**
* @notice Multiplier representing the discount on collateral that a liquidator receives (deprecated)
Expand Down Expand Up @@ -78,7 +79,7 @@ contract ComptrollerV1Storage is UnitrollerAdminStorage {
*/
uint256 liquidationThresholdMantissa;
/// @notice discount on collateral that a liquidator receives when liquidating a borrow in this market
uint256 liquidationIncentiveMantissa;
uint256 maxLiquidationIncentiveMantissa;
/// @notice The pool ID this market is associated with, Used to support pools/emodes
uint96 poolId;
/// @notice Flag to restrict borrowing in certain pools/emodes.
Expand Down Expand Up @@ -328,3 +329,8 @@ contract ComptrollerV18Storage is ComptrollerV17Storage {
/// @notice Whether flash loans are paused system-wide
bool public flashLoanPaused;
}

contract ComptrollerV19Storage is ComptrollerV18Storage {
/// @notice The LiquidationManager contract address
LiquidationManager public liquidationManager;
}
6 changes: 3 additions & 3 deletions contracts/Comptroller/Diamond/Diamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pragma solidity 0.8.25;

import { IDiamondCut } from "./interfaces/IDiamondCut.sol";
import { Unitroller } from "../Unitroller.sol";
import { ComptrollerV18Storage } from "../ComptrollerStorage.sol";
import { ComptrollerV19Storage } from "../ComptrollerStorage.sol";

/**
* @title Diamond
* @author Venus
* @notice This contract contains functions related to facets
*/
contract Diamond is IDiamondCut, ComptrollerV18Storage {
contract Diamond is IDiamondCut, ComptrollerV19Storage {
/// @notice Emitted when functions are added, replaced or removed to facets
event DiamondCut(IDiamondCut.FacetCut[] _diamondCut);

Expand Down Expand Up @@ -72,7 +72,7 @@ contract Diamond is IDiamondCut, ComptrollerV18Storage {
*/
function facetAddress(
bytes4 functionSelector
) external view returns (ComptrollerV18Storage.FacetAddressAndPosition memory) {
) external view returns (ComptrollerV19Storage.FacetAddressAndPosition memory) {
return _selectorToFacetAndPosition[functionSelector];
}

Expand Down
97 changes: 89 additions & 8 deletions contracts/Comptroller/Diamond/facets/FacetBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { VToken } from "../../../Tokens/VTokens/VToken.sol";
import { ComptrollerErrorReporter } from "../../../Utils/ErrorReporter.sol";
import { ExponentialNoError } from "../../../Utils/ExponentialNoError.sol";
import { IVAIVault, Action } from "../../../Comptroller/ComptrollerInterface.sol";
import { ComptrollerV18Storage } from "../../../Comptroller/ComptrollerStorage.sol";
import { ComptrollerLensInterface } from "../../../Comptroller/ComptrollerLensInterface.sol";
import { ComptrollerV19Storage } from "../../../Comptroller/ComptrollerStorage.sol";
import { PoolMarketId } from "../../../Comptroller/Types/PoolMarketId.sol";
import { IFacetBase, WeightFunction } from "../interfaces/IFacetBase.sol";

Expand All @@ -19,17 +20,14 @@ import { IFacetBase, WeightFunction } from "../interfaces/IFacetBase.sol";
* @author Venus
* @notice This facet contract contains functions related to access and checks
*/
contract FacetBase is IFacetBase, ComptrollerV18Storage, ExponentialNoError, ComptrollerErrorReporter {
contract FacetBase is IFacetBase, ComptrollerV19Storage, ExponentialNoError, ComptrollerErrorReporter {
using SafeERC20 for IERC20;

/// @notice The initial Venus index for a market
uint224 public constant venusInitialIndex = 1e36;

// poolId for core Pool
uint96 public constant corePoolId = 0;
// closeFactorMantissa must be strictly greater than this value
uint256 internal constant closeFactorMinMantissa = 0.05e18; // 0.05
// closeFactorMantissa must not exceed this value
uint256 internal constant closeFactorMaxMantissa = 0.9e18; // 0.9

/// @notice Emitted when an account enters a market
event MarketEntered(VToken indexed vToken, address indexed account);
Expand Down Expand Up @@ -134,9 +132,9 @@ contract FacetBase is IFacetBase, ComptrollerV18Storage, ExponentialNoError, Com
}

/**
* @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed
* @param vTokenModify The market to hypothetically redeem/borrow in
* @notice Determine what the liquidity would be if the given amounts were redeemed/borrowed on the basis of collateral factor or liquidation threshold
* @param account The account to determine liquidity for
* @param vTokenModify The market to hypothetically redeem/borrow in
* @param redeemTokens The number of tokens to hypothetically redeem
* @param borrowAmount The amount of underlying to hypothetically borrow
* @param weightingStrategy The weighting strategy to use:
Expand Down Expand Up @@ -166,6 +164,37 @@ contract FacetBase is IFacetBase, ComptrollerV18Storage, ExponentialNoError, Com
return (Error(err), liquidity, shortfall);
}

/**
* @notice Internal function to get a snapshot of the health of an account
* @param account The account to get the health snapshot for
* @param vTokenModify The market to hypothetically redeem/borrow in
* @param redeemTokens The number of tokens to hypothetically redeem
* @param borrowAmount The amount of underlying to hypothetically borrow
* @param weightingStrategy The weighting strategy to use:
* - `WeightFunction.USE_COLLATERAL_FACTOR` to use collateral factor
* - `WeightFunction.USE_LIQUIDATION_THRESHOLD` to use liquidation threshold
* @return err Error code
* @return snapshot Snapshot of the account's health and collateral status
* @dev Note that we calculate the exchangeRateStored for each collateral vToken using stored data,
* without calculating accumulated interest.
*/
function _getHypotheticalHealthSnapshotInternal(
address account,
VToken vTokenModify,
uint256 redeemTokens,
uint256 borrowAmount,
WeightFunction weightingStrategy
) internal view returns (uint256 err, ComptrollerLensInterface.AccountSnapshot memory snapshot) {
(err, snapshot) = comptrollerLens.getAccountHealthSnapshot(
address(this),
account,
vTokenModify,
redeemTokens,
borrowAmount,
weightingStrategy
);
}

/**
* @notice Add the market to the borrower's "assets in" for liquidity calculations
* @param vToken The market to enter
Expand Down Expand Up @@ -235,6 +264,20 @@ contract FacetBase is IFacetBase, ComptrollerV18Storage, ExponentialNoError, Com
return xvs;
}

/**
* @notice Get the Effective Liquidation Incentive for a given account and market
* @dev The incentive is determined by the pool entered by the account and the specified vToken via
* `getLiquidationParams()`. If the pool is inactive, or if the vToken is not configured in the
* account's pool and `allowCorePoolFallback` is enabled, the core pool (poolId = 0) values are used
* @param account The account whose pool is used to determine the market's risk parameters
* @param vToken The address of the vToken market
* @return The liquidation Incentive for the vToken, scaled by 1e18
*/
function getEffectiveLiquidationIncentive(address account, address vToken) external view returns (uint256) {
(, , uint256 li) = getLiquidationParams(userPoolId[account], vToken);
return li;
}

/**
* @notice Returns the unique market index for the given poolId and vToken pair
* @dev Computes a unique key for a (poolId, market) pair used in the `_poolMarkets` mapping
Expand Down Expand Up @@ -283,4 +326,42 @@ contract FacetBase is IFacetBase, ComptrollerV18Storage, ExponentialNoError, Com

return (uint256(err), liquidity, shortfall);
}

/**
* @notice Returns only the core risk parameters (CF, LI, LT) for a vToken in a specific pool.
* @dev If the pool is inactive, or if the vToken is not configured in the given pool and
* `allowCorePoolFallback` is enabled, falls back to the core pool (poolId = 0) values.
* @return collateralFactorMantissa The max borrowable percentage of collateral, in mantissa.
* @return liquidationThresholdMantissa The threshold at which liquidation is triggered, in mantissa.
* @return maxLiquidationIncentiveMantissa The max liquidation incentive allowed for this market, in mantissa.
*/
function getLiquidationParams(
uint96 poolId,
address vToken
)
internal
view
returns (
uint256 collateralFactorMantissa,
uint256 liquidationThresholdMantissa,
uint256 maxLiquidationIncentiveMantissa
)
{
PoolData storage pool = pools[poolId];
Market storage market;

if (poolId == corePoolId || !pool.isActive) {
market = getCorePoolMarket(vToken);
} else {
PoolMarketId poolKey = getPoolMarketIndex(poolId, vToken);
Market storage poolMarket = _poolMarkets[poolKey];
market = (!poolMarket.isListed && pool.allowCorePoolFallback) ? getCorePoolMarket(vToken) : poolMarket;
}

return (
market.collateralFactorMantissa,
market.liquidationThresholdMantissa,
market.maxLiquidationIncentiveMantissa
);
}
}
Loading
Loading