Repository navigation
[VEN-3321]: Liquidation Threshold and repay Improvements in Core Pool on BNB #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f608f86
294f79e
fae7c2a
e139b03
7ba7bac
624c961
10d7785
b04a893
cb5a5db
a6d1926
f16a9b5
caeea51
cf0354b
da9ef57
8a38506
ff22d54
c4786ce
1e8f708
f7e3f53
91316bb
dc16c67
b526832
348fbb3
7eeeaa2
69f820e
4ea3457
626f13a
7b4fa89
7e5a754
9833f7b
a5e7c7c
66ef1b5
be83b61
c90aa01
1837cc7
4e8fa35
6dbb217
24aca7f
a06802b
f65e34d
b0705ce
5868274
17be54c
c23fe60
9955fb2
2cf8104
ab6d0ae
57e92f4
8b37991
6868164
d653b5f
de84582
5c84b79
800f8b6
fe5c158
022a11d
7860cd6
56c25c2
0510348
f2f1034
f091f37
107ead8
3025a69
50a256f
61ed23f
a7b4206
e2f29c0
2fc0c2e
13605fd
0f6be8f
02dc4e7
dfdf581
a17ef99
3c6248c
b13414e
768e5d2
dd31a2c
5f0b4f8
53b7562
9bc16b4
ee861ff
9ed3422
c5aa0db
eb0c632
151b14b
2339b40
0eee583
26436f4
13ec325
bfac079
c3ce6f4
79ead60
6b30587
9d0d46b
78d3bf8
6254eaa
fb48338
1bd7262
d8edaa0
6758363
c21100f
bd5d35f
4c541a4
4605b3b
0297580
9ce8a5a
1560cc2
5ad06f6
1659da4
8b972e1
da82294
f9d6dc0
b29d11a
44b4d88
2361f5e
fff566c
9072738
545cd00
b008927
f83afff
7dd2804
6fa0386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -467,22 +467,24 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| * @dev Calculates incentive based on provided health factor and liquidation threshold average, | ||
| * without reading borrower's account state from storage | ||
| * @param vToken The address of the vToken to be seized | ||
| * @param borrower The address of the borrower | ||
| * @param liquidationThresholdAvg The average liquidation threshold for the borrower | ||
| * @param healthFactor The health factor of the borrower | ||
| * @return incentive The dynamic liquidation incentive for the borrower, scaled by 1e18 | ||
| */ | ||
| function getDynamicLiquidationIncentive( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variant of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| address vToken, | ||
| address borrower, | ||
| uint256 liquidationThresholdAvg, | ||
| uint256 healthFactor | ||
| ) external view returns (uint256 incentive) { | ||
| Market storage market = getCorePoolMarket(vToken); | ||
| uint256 effectiveLiquidationIncentive = this.getEffectiveLiquidationIncentive(borrower,vToken); | ||
|
|
||
| incentive = liquidationManager.calculateDynamicLiquidationIncentive( | ||
| vToken, | ||
| healthFactor, | ||
| liquidationThresholdAvg, | ||
| market.maxLiquidationIncentiveMantissa | ||
| effectiveLiquidationIncentive | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -498,7 +500,7 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| address borrower, | ||
| address vToken | ||
| ) external view returns (uint256 incentive) { | ||
| Market storage market = getCorePoolMarket(vToken); | ||
| uint256 effectiveLiquidationIncentive = this.getEffectiveLiquidationIncentive(borrower,vToken); | ||
| ( | ||
| uint256 err, | ||
| ComptrollerLensInterface.AccountSnapshot memory snapshot | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required, but it might be cleaner to define
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can keep AccountSnapshot as it is for now . |
||
|
|
@@ -517,7 +519,7 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| vToken, | ||
| snapshot.healthFactor, | ||
| snapshot.liquidationThresholdAvg, | ||
| market.maxLiquidationIncentiveMantissa | ||
| effectiveLiquidationIncentive | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -575,20 +577,6 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| else revert InvalidWeightingStrategy(weightingStrategy); | ||
| } | ||
|
|
||
| /** | ||
| * @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 full list of vTokens for a given pool ID. | ||
| * @param poolId The ID of the pool whose vTokens are being queried. | ||
|
|
@@ -786,41 +774,4 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| emit PoolMarketInitialized(poolId, vToken); | ||
| } | ||
|
|
||
| /** | ||
| * @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 | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,14 +305,14 @@ contract PolicyFacet is IPolicyFacet, XVSRewardsHelper { | |
| return uint256(Error.INSUFFICIENT_SHORTFALL); | ||
| } | ||
|
|
||
| Market storage marketCollateral = getCorePoolMarket(vTokenCollateral); | ||
| uint256 effectiveLiquidationIncentive = this.getEffectiveLiquidationIncentive(borrower, vTokenCollateral); | ||
| uint256 closeFactor = liquidationManager.calculateDynamicCloseFactor( | ||
| vTokenBorrowed, | ||
| borrowBalance, | ||
| snapshot.liquidationThresholdAvg, | ||
| snapshot.totalCollateral, | ||
| snapshot.dynamicLiquidationIncentiveMantissa, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we calculating
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The liquidateBorrowAllowed function is externally called by liquidateBorrow function which can only be called from liquidator contract by the liquidator. In this function, we calculate the snapshot.dynamicLiquidationIncentiveMantissa internally . |
||
| marketCollateral.maxLiquidationIncentiveMantissa | ||
| effectiveLiquidationIncentive | ||
| ); | ||
|
|
||
| // The liquidator may not repay more than what is allowed by the closeFactor | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can expand the comment to include why the
borrowerparameter is needed