Skip to content

Commit

Permalink
⚡️ auditor: add close factor mul incentives term
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez committed Oct 14, 2022
1 parent 17e8286 commit ad51fa4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
40 changes: 20 additions & 20 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AuditorTest:testAccountShortfall() (gas: 133980)
AuditorTest:testAccountShortfallRevert() (gas: 157751)
AuditorTest:testBorrowMPValidation() (gas: 133487)
AuditorTest:testBorrowMPValidationRevert() (gas: 157278)
AuditorTest:testDynamicCloseFactor() (gas: 963668)
AuditorTest:testDynamicCloseFactor() (gas: 963959)
AuditorTest:testEnableEnterExitMultipleMarkets() (gas: 900174)
AuditorTest:testEnableMarket() (gas: 100478)
AuditorTest:testEnableMarketAlreadyListed() (gas: 96654)
Expand All @@ -27,7 +27,7 @@ MarketTest:testBorrowAtMaturity() (gas: 406309)
MarketTest:testBorrowAtMaturityUpdatesFloatingDebtAndFloatingAssets() (gas: 640709)
MarketTest:testBorrowDisagreement() (gas: 170576)
MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 783608)
MarketTest:testCappedLiquidation() (gas: 722154)
MarketTest:testCappedLiquidation() (gas: 722445)
MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 631013)
MarketTest:testChargeTreasuryToFixedBorrows() (gas: 682722)
MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 1026667)
Expand All @@ -42,13 +42,13 @@ MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 760020)
MarketTest:testCollectTreasuryFreeLunchToEarlyWithdrawsWithZeroFees() (gas: 270505)
MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 708411)
MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 476220)
MarketTest:testCrossMaturityLiquidation() (gas: 1211326)
MarketTest:testCrossMaturityLiquidation() (gas: 1211617)
MarketTest:testDepositAtMaturity() (gas: 156968)
MarketTest:testDepositDisagreement() (gas: 30877)
MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 471745)
MarketTest:testDepositToSmartPool() (gas: 157883)
MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 590769)
MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2084894)
MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2085360)
MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 1410321)
MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 633523)
MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 807912)
Expand All @@ -63,25 +63,25 @@ MarketTest:testFlexibleBorrowFromAnotherUserWithAllowance() (gas: 345842)
MarketTest:testFlexibleBorrowFromAnotherUserWithoutAllowance() (gas: 179372)
MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 549254)
MarketTest:testInsufficientProtocolLiquidity() (gas: 931603)
MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 1015005)
MarketTest:testLiquidateAndDistributeLosses() (gas: 1211698)
MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 1137918)
MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 635875)
MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 1547500)
MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 1203634)
MarketTest:testLiquidateFlexibleBorrow() (gas: 1137299)
MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 772003)
MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 876082)
MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 1370242)
MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 900868)
MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 635845)
MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 1396786)
MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 943321)
MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 1015296)
MarketTest:testLiquidateAndDistributeLosses() (gas: 1211989)
MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 1138209)
MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 636166)
MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 1547732)
MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 1204507)
MarketTest:testLiquidateFlexibleBorrow() (gas: 1137881)
MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 772294)
MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 876395)
MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 1370824)
MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 901159)
MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 636136)
MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 1397077)
MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 943612)
MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 901304)
MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 632664002)
MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 632664293)
MarketTest:testMultipleDepositsToSmartPool() (gas: 329411)
MarketTest:testMultipleFixedBorrowsRepays() (gas: 763640)
MarketTest:testMultipleLiquidationSameUser() (gas: 1335165)
MarketTest:testMultipleLiquidationSameUser() (gas: 1336038)
MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 666701)
MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 875262)
MarketTest:testRepayAtMaturity() (gas: 354868)
Expand Down
9 changes: 8 additions & 1 deletion contracts/Auditor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Market } from "./Market.sol";

contract Auditor is Initializable, AccessControlUpgradeable {
using FixedPointMathLib for uint256;
using FixedPointMathLib for uint128;

uint256 public constant TARGET_HEALTH = 1.25e18;
uint256 public constant ASSETS_THRESHOLD = type(uint256).max / 1e18;
Expand Down Expand Up @@ -216,7 +217,13 @@ contract Auditor is Initializable, AccessControlUpgradeable {
usd.adjustedDebt.mulWadUp(usd.totalCollateral)
);
uint256 closeFactor = (TARGET_HEALTH - usd.adjustedCollateral.divWadUp(usd.adjustedDebt)).divWadUp(
TARGET_HEALTH - adjustFactor.mulWadDown(1e18 + memIncentive.liquidator + memIncentive.lenders)
TARGET_HEALTH -
adjustFactor.mulWadDown(
1e18 +
memIncentive.liquidator +
memIncentive.lenders +
memIncentive.liquidator.mulWadDown(memIncentive.lenders)
)
);
maxRepayAssets = Math.min(
Math
Expand Down
4 changes: 2 additions & 2 deletions test/solidity/Market.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ contract MarketTest is Test {
// partial liquidation
vm.prank(BOB);
market.liquidate(address(this), type(uint256).max, marketWETH);
uint256 assetsRepaid = 3685589519650655024000;
uint256 assetsRepaid = 3690811453759904844000;

(, uint256 remainingDebt) = market.accountSnapshot(address(this));
(uint256 remainingCollateral, ) = marketWETH.accountSnapshot(address(this));
Expand Down Expand Up @@ -1179,7 +1179,7 @@ contract MarketTest is Test {
// bob is allowed to repay 2970
vm.prank(BOB);
market.liquidate(address(this), type(uint256).max, marketWETH);
uint256 lendersIncentive = 29694323144104803448;
uint256 lendersIncentive = 29736395599013451260;

assertApproxEqRel(market.previewDebt(address(this)), 1_430 ether, 1e18);
assertApproxEqRel(market.floatingDebt(), 1_430 ether, 1e18);
Expand Down

0 comments on commit ad51fa4

Please sign in to comment.