-
Notifications
You must be signed in to change notification settings - Fork 22
Liquidation Improvements based on Health-Factor #535
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
base: develop
Are you sure you want to change the base?
Changes from 35 commits
d2f5cd0
1f2d92b
a2ac784
39c970d
5aac9d2
083a1f7
8c964fa
7c65f24
32bf187
2716fec
e1f58da
0921fce
dec2414
f2ef6fd
27cf44c
47ba38e
876e44e
5860efe
fc9c6a7
691c424
bebf45d
2811258
8876c29
e6e906f
749dbb6
e8ea512
c4a5768
fe24745
bfd294f
232421a
fbde27d
438695d
58e2678
2413962
c5564d9
525f1cf
c825a8e
c907123
b6f0e5e
d072b0a
d86ccaa
ebcd3e4
8451373
d8bc0ce
dbf5739
3177bf8
ec585af
1dc088c
91c22c3
b7ad5ae
e7285d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,10 @@ contract ComptrollerStorage { | |
| uint256 effects; | ||
| uint256 liquidity; | ||
| uint256 shortfall; | ||
| uint256 averageLT; // Average liquidation threshold of all assets in the snapshot | ||
| uint256 healthFactor; // Health factor of the account, calculated as (weightedCollateral / borrows) | ||
| uint256 healthFactorThreshold; // Health factor threshold for liquidation, calculated as (averageLT * (1e18 + LiquidationIncentiveAvg) / 1e18) | ||
| uint256 liquidationIncentiveAvg; // Average liquidation incentive of all assets in the snapshot | ||
| } | ||
|
|
||
| struct RewardSpeeds { | ||
|
|
@@ -48,6 +52,8 @@ contract ComptrollerStorage { | |
| uint256 liquidationThresholdMantissa; | ||
| // 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; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -60,11 +66,6 @@ contract ComptrollerStorage { | |
| */ | ||
| uint256 public closeFactorMantissa; | ||
|
|
||
| /** | ||
| * @notice Multiplier representing the discount on collateral that a liquidator receives | ||
| */ | ||
| uint256 public liquidationIncentiveMantissa; | ||
|
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. Maintain the attribute, to not break the storage layout. Simply rename it to "deprecatedLiquidationIncentiveMantissa"?
Collaborator
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. |
||
|
|
||
| /** | ||
| * @notice Per-account mapping of "assets you are in" | ||
| */ | ||
|
|
||
|
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. I would avoid changes in the VToken contract, if it's doable. Because vBNB cannot be upgraded |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| pragma solidity 0.8.25; | ||
|
|
||
| import { EXP_SCALE as EXP_SCALE_, MANTISSA_ONE as MANTISSA_ONE_ } from "./constants.sol"; | ||
|
|
||
| library ExponentialNoError { | ||
| struct Exp { | ||
| uint256 mantissa; | ||
| } | ||
|
|
||
| struct Double { | ||
| uint256 mantissa; | ||
| } | ||
|
|
||
| uint256 internal constant EXP_SCALE = EXP_SCALE_; | ||
| uint256 internal constant DOUBLE_SCALE = 1e36; | ||
| uint256 internal constant HALF_EXP_SCALE = EXP_SCALE / 2; | ||
| uint256 internal constant MANTISSA_ONE = MANTISSA_ONE_; | ||
|
|
||
| function truncate(Exp memory exp) internal pure returns (uint256) { | ||
| return exp.mantissa / EXP_SCALE; | ||
| } | ||
|
|
||
| function mul_ScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (uint256) { | ||
| Exp memory product = mul_(a, scalar); | ||
| return truncate(product); | ||
| } | ||
|
|
||
| function mul_ScalarTruncateAddUInt(Exp memory a, uint256 scalar, uint256 addend) internal pure returns (uint256) { | ||
| Exp memory product = mul_(a, scalar); | ||
| return add_(truncate(product), addend); | ||
| } | ||
|
|
||
| function lessThanExp(Exp memory left, Exp memory right) internal pure returns (bool) { | ||
| return left.mantissa < right.mantissa; | ||
| } | ||
|
|
||
| function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224) { | ||
| require(n <= type(uint224).max, errorMessage); | ||
| return uint224(n); | ||
| } | ||
|
|
||
| function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { | ||
| require(n <= type(uint32).max, errorMessage); | ||
| return uint32(n); | ||
| } | ||
|
|
||
| function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { | ||
| return Exp(add_(a.mantissa, b.mantissa)); | ||
| } | ||
|
|
||
| function add_(Double memory a, Double memory b) internal pure returns (Double memory) { | ||
| return Double(add_(a.mantissa, b.mantissa)); | ||
| } | ||
|
|
||
| function add_(uint256 a, uint256 b) internal pure returns (uint256) { | ||
| return a + b; | ||
| } | ||
|
|
||
| function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { | ||
| return Exp(sub_(a.mantissa, b.mantissa)); | ||
| } | ||
|
|
||
| function sub_(Double memory a, Double memory b) internal pure returns (Double memory) { | ||
| return Double(sub_(a.mantissa, b.mantissa)); | ||
| } | ||
|
|
||
| function sub_(uint256 a, uint256 b) internal pure returns (uint256) { | ||
| return a - b; | ||
| } | ||
|
|
||
| function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { | ||
| return Exp(mul_(a.mantissa, b.mantissa) / EXP_SCALE); | ||
| } | ||
|
|
||
| function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) { | ||
| return Exp(mul_(a.mantissa, b)); | ||
| } | ||
|
|
||
| function mul_(uint256 a, Exp memory b) internal pure returns (uint256) { | ||
| return mul_(a, b.mantissa) / EXP_SCALE; | ||
| } | ||
|
|
||
| function mul_(Double memory a, Double memory b) internal pure returns (Double memory) { | ||
| return Double(mul_(a.mantissa, b.mantissa) / DOUBLE_SCALE); | ||
| } | ||
|
|
||
| function mul_(Double memory a, uint256 b) internal pure returns (Double memory) { | ||
| return Double(mul_(a.mantissa, b)); | ||
| } | ||
|
|
||
| function mul_(uint256 a, Double memory b) internal pure returns (uint256) { | ||
| return mul_(a, b.mantissa) / DOUBLE_SCALE; | ||
| } | ||
|
|
||
| function mul_(uint256 a, uint256 b) internal pure returns (uint256) { | ||
| return a * b; | ||
| } | ||
|
|
||
| function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { | ||
| return Exp(div_(mul_(a.mantissa, EXP_SCALE), b.mantissa)); | ||
| } | ||
|
|
||
| function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) { | ||
| return Exp(div_(a.mantissa, b)); | ||
| } | ||
|
|
||
| function div_(uint256 a, Exp memory b) internal pure returns (uint256) { | ||
| return div_(mul_(a, EXP_SCALE), b.mantissa); | ||
| } | ||
|
|
||
| function div_(Double memory a, Double memory b) internal pure returns (Double memory) { | ||
| return Double(div_(mul_(a.mantissa, DOUBLE_SCALE), b.mantissa)); | ||
| } | ||
|
|
||
| function div_(Double memory a, uint256 b) internal pure returns (Double memory) { | ||
| return Double(div_(a.mantissa, b)); | ||
| } | ||
|
|
||
| function div_(uint256 a, Double memory b) internal pure returns (uint256) { | ||
| return div_(mul_(a, DOUBLE_SCALE), b.mantissa); | ||
| } | ||
|
|
||
| function div_(uint256 a, uint256 b) internal pure returns (uint256) { | ||
| return a / b; | ||
| } | ||
|
|
||
| function fraction(uint256 a, uint256 b) internal pure returns (Double memory) { | ||
| return Double(div_(mul_(a, DOUBLE_SCALE), b)); | ||
| } | ||
| } |
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.
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.
525f1cf