Skip to content

Commit

Permalink
Merge pull request #786 from ebtc-protocol/feat-surplus-invariant-fixed
Browse files Browse the repository at this point in the history
Feat surplus invariant fixed
  • Loading branch information
dapp-whisperer authored Mar 6, 2024
2 parents c49e5f1 + 6990b14 commit b322029
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
41 changes: 39 additions & 2 deletions packages/contracts/foundry_test/EchidnaToFoundry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)",
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b322029

Please sign in to comment.