Skip to content

Commit

Permalink
fixup! fix: Use last zombie trove first in a redemption sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Sep 17, 2024
1 parent 25f8d02 commit 4358aaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,12 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents {
if (newDebt > 0) {
lastZombieTroveId = _singleRedemption.troveId;
}
} else if (newDebt == 0) {
// Reset last zombie trove pointer if the previous one was fully redeemed now
lastZombieTroveId = 0;
}
} else {
// Reset last zombie trove pointer if the previous one was fully redeemed now
// Reset last zombie trove pointer if the previous one ended up above min debt
lastZombieTroveId = 0;
}
}
Expand Down
26 changes: 26 additions & 0 deletions contracts/src/test/redemptions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ contract Redemptions is DevTestSetup {

uint256 debt_A = troveManager.getTroveEntireDebt(troveIDs.A);
uint256 debt_B = troveManager.getTroveEntireDebt(troveIDs.B);
/*
console.log(troveIDs.A, "A id");
console.log(troveIDs.B, "B id");
console.log(sortedTroves.contains(troveIDs.B), "B is in list t0");
console.log(troveManager.getTroveEntireDebt(troveIDs.B), "A debt t0");
console.log(troveManager.getTroveEntireDebt(troveIDs.B), "B debt t0");
console.log(sortedTroves.getLast(), "first to redeem t0");
*/
uint256 debt_C = troveManager.getTroveEntireDebt(troveIDs.C);
uint256 debt_D = troveManager.getTroveEntireDebt(troveIDs.D);

Expand Down Expand Up @@ -369,6 +371,30 @@ contract Redemptions is DevTestSetup {
assertEq(troveManager.lastZombieTroveId(), 0, "Wrong last zombie trove pointer");
}

function testZombieTrovePointerGetsResetIfLastOneIsFullyRedemeed() public {
(,, ABCDEF memory troveIDs) = _setupForRedemptionAscendingInterest();

_redeemAndCreateZombieTrovesAAndB(troveIDs);

// Check last Zombie trove pointer
assertEq(troveManager.lastZombieTroveId(), troveIDs.B, "Wrong last zombie trove pointer before");

// Get B debt before 2nd redeem
uint256 debt_B = troveManager.getTroveEntireDebt(troveIDs.B);
assertGt(debt_B, 0, "B debt should be non zero");

uint256 redeemAmount = debt_B;
console2.log("redeem again");
console2.log(redeemAmount, "redeemAmount");
redeem(E, redeemAmount);

// Check B is empty now
assertEq(troveManager.getTroveEntireDebt(troveIDs.B), 0, "B debt should be zero");

// Check last Zombie trove pointer
assertEq(troveManager.lastZombieTroveId(), 0, "Wrong last zombie trove pointer after");
}

function testZombieTrovesCanReceiveRedistGains() public {
uint256 interestRate_E = 5e16; // 5%
uint256 troveDebtRequest_E = 2450e18;
Expand Down

0 comments on commit 4358aaa

Please sign in to comment.