diff --git a/packages/contracts/contracts/TestContracts/invariants/TargetFunctions.sol b/packages/contracts/contracts/TestContracts/invariants/TargetFunctions.sol index db1f2f890..827daec45 100644 --- a/packages/contracts/contracts/TestContracts/invariants/TargetFunctions.sol +++ b/packages/contracts/contracts/TestContracts/invariants/TargetFunctions.sol @@ -226,7 +226,7 @@ abstract contract TargetFunctions is Properties { _before(_cdpId); uint256 _icrToLiq = cdpManager.getSyncedICR(_cdpId, priceFeedMock.getPrice()); - + (success, returnData) = actor.proxy( address(cdpManager), abi.encodeWithSelector(CdpManager.liquidate.selector, _cdpId) @@ -235,10 +235,11 @@ abstract contract TargetFunctions is Properties { _after(_cdpId); if (success) { - // SURPLUS-CHECK-1 | The surplus is capped at 4 wei | NOTE: Proxy of growth, storage var would further refine - gte(vars.collSurplusPoolBefore + 4, vars.collSurplusPoolAfter, "SURPLUS-CHECK-1"); - gte(vars.userSurplusBefore + 4, vars.userSurplusAfter, "SURPLUS-CHECK-2"); + if (_icrToLiq <= cdpManager.MCR()) { + gte(vars.collSurplusPoolBefore + 4, vars.collSurplusPoolAfter, "SURPLUS-CHECK-1"); + gte(vars.userSurplusBefore + 4, vars.userSurplusAfter, "SURPLUS-CHECK-2"); + } // if ICR >= TCR then we ignore // We could check that Liquidated is not above TCR diff --git a/packages/contracts/foundry_test/EchidnaToFoundry.t.sol b/packages/contracts/foundry_test/EchidnaToFoundry.t.sol index 05a53a78a..ff898e284 100644 --- a/packages/contracts/foundry_test/EchidnaToFoundry.t.sol +++ b/packages/contracts/foundry_test/EchidnaToFoundry.t.sol @@ -25,13 +25,16 @@ contract EToFoundry is { modifier setup() override { _; + address sender = uint160(msg.sender) % 3 == 0 ? address(USER1) : uint160(msg.sender) % 3 == 1 + ? address(USER2) + : address(USER3); + actor = actors[sender]; } function setUp() public { _setUp(); _setUpActors(); - actor = actors[USER1]; - vm.startPrank(address(actor)); + actor = actors[address(USER1)]; } function _checkTotals() internal { @@ -221,9 +224,17 @@ contract EToFoundry is function _logStakes() internal { bytes32 currentCdp = sortedCdps.getFirst(); + console2.log("=== LogStakes ==="); + + uint256 currentPrice = priceFeedMock.fetchPrice(); + uint256 currentPricePerShare = collateral.getPooledEthByShares(1 ether); + console2.log("currentPrice", currentPrice); + console2.log("currentPricePerShare", currentPricePerShare); + while (currentCdp != bytes32(0)) { emit DebugBytes32(currentCdp); console2.log("CdpId", vm.toString(currentCdp)); + console2.log("==============================="); console2.log("cdpManager.getCdpStake(currentCdp)", cdpManager.getCdpStake(currentCdp)); console2.log( "cdpManager.getSyncedCdpCollShares(currentCdp)", @@ -239,7 +250,16 @@ contract EToFoundry is "cdpManager.getSyncedNominalICR(currentCdp)", cdpManager.getSyncedNominalICR(currentCdp) ); + console2.log( + "cdpManager.getCachedICR(currentCdp, currentPrice)", + cdpManager.getCachedICR(currentCdp, currentPrice) + ); + console2.log( + "cdpManager.getSyncedICR(currentCdp, currentPrice)", + cdpManager.getSyncedICR(currentCdp, currentPrice) + ); currentCdp = sortedCdps.getNext(currentCdp); + console2.log(""); } console2.log( @@ -1655,6 +1675,23 @@ contract EToFoundry is assertTrue(invariant_CSP_01(collateral, collSurplusPool), CSP_01); } + function test_debugTheLiquidation() public { + openCdp(3979204251130340497718654781931317513776851992409413887935202910391326, 1000); + openCdp( + 3306424426048366109580062000503759874070670921097371866772152350788399154439, + 1069959377727045012 + ); + _logStakes(); + setEthPerShare(0); + _logStakes(); + liquidateCdps(0); + vm.warp(block.timestamp + 902); + liquidateCdps(0); + _logStakes(); + + _checkTotals(); + } + function testGeneral17() public { setPrice(113290725923451524724356926138082459205154590681450821768273750342902011457932); openCdp(