Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into certora/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Dec 1, 2023
2 parents 3646c4d + 9f4fc70 commit c716556
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/forge/integration/LiquidateIntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ contract LiquidateIntegrationTest is BaseTest {
uint256 lltv;
}

function testLiquidateMargin(LiquidateTestParams memory params, uint256 amountSeized, uint256 elapsed) public {
_setLltv(_boundTestLltv(params.lltv));
(params.amountCollateral, params.amountBorrowed, params.priceCollateral) =
_boundHealthyPosition(params.amountCollateral, params.amountBorrowed, 1e36);

elapsed = bound(elapsed, 0, 365 days);

params.amountSupplied =
bound(params.amountSupplied, params.amountBorrowed, params.amountBorrowed + MAX_TEST_AMOUNT);
_supply(params.amountSupplied);

amountSeized = bound(amountSeized, 1, params.amountCollateral);

oracle.setPrice(params.priceCollateral);

loanToken.setBalance(LIQUIDATOR, params.amountBorrowed);
collateralToken.setBalance(BORROWER, params.amountCollateral);

vm.startPrank(BORROWER);
morpho.supplyCollateral(marketParams, params.amountCollateral, BORROWER, hex"");
morpho.borrow(marketParams, params.amountBorrowed, 0, BORROWER, BORROWER);
vm.stopPrank();

// We have to estimate the ratio after borrowing because the borrow rate depends on the utilization.
uint256 maxRatio = WAD + irm.borrowRate(marketParams, morpho.market(id)).wTaylorCompounded(elapsed);
// Sanity check: multiply maxBorrow by 2.
uint256 maxBorrow = _maxBorrow(marketParams, BORROWER).wDivDown(maxRatio);
// Should not omit too many tests because elapsed is reasonably bounded.
vm.assume(params.amountBorrowed < maxBorrow);

vm.warp(block.timestamp + elapsed);

vm.prank(LIQUIDATOR);
vm.expectRevert(bytes(ErrorsLib.HEALTHY_POSITION));
morpho.liquidate(marketParams, BORROWER, amountSeized, 0, hex"");
}

function testLiquidateSeizedInputNoBadDebtRealized(LiquidateTestParams memory params, uint256 amountSeized)
public
{
Expand Down

0 comments on commit c716556

Please sign in to comment.