Skip to content

Commit

Permalink
style: refactor stay healthy liquidate
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Jul 5, 2024
1 parent 4263c9b commit d1e81ed
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions certora/specs/Health.spec
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ filtered {
assert !priceChanged => stillHealthy;
}

rule stayHealthy_liquidate(env e)
{
MorphoHarness.MarketParams marketParams;
// The general case of liquidate for the stayHealthy rule
// - the user checked is not the borrower,
// - the market of the liquidation is the market of the user,
// - there is still some borrow on the market after liquidation,
// - there was no bad debt realization.
rule stayHealthyLiquidate(env e, MorphoHarness.MarketParams marketParams, address borrower, uint256 seizedAssets, bytes data) {
MorphoHarness.Id id = libId(marketParams);
address user;

Expand All @@ -94,32 +97,21 @@ rule stayHealthy_liquidate(env e)
require lastUpdate(id) == e.block.timestamp;

priceChanged = false;

MorphoHarness.MarketParams marketParams2;
address borrower;
uint256 seizedAssets;
uint256 repaidShares;
bytes data;
require marketParams2 == marketParams;

liquidate(e, marketParams2, borrower, seizedAssets, 0, data);
liquidate(e, marketParams, borrower, seizedAssets, 0, data);
require !priceChanged;

// Safe require because of the invariant sumBorrowSharesCorrect.
require borrowShares(id, user) <= totalBorrowShares(id);

// the case where not everything was repaid
// Handle the case where not everything was repaid.
require totalBorrowAssets(id) > 0;
// user has collateral left
// Handle the case where the user has some collateral left.
require collateral(id, borrower) > 0;

assert user != borrower;
assert debtSharesBefore == borrowShares(id, user);
assert debtAssetsBefore >= summaryMulDivUp(debtSharesBefore, virtualTotalBorrowAssets(id), virtualTotalBorrowShares(id));

bool stillHealthy = isHealthy(marketParams, user);
require !priceChanged;

// assert !priceChanged => stillHealthy;
assert stillHealthy;
}

Expand Down

0 comments on commit d1e81ed

Please sign in to comment.