diff --git a/contracts/src/TroveManager.sol b/contracts/src/TroveManager.sol index 44e58f97..b259dbb0 100644 --- a/contracts/src/TroveManager.sol +++ b/contracts/src/TroveManager.sol @@ -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; } } diff --git a/contracts/src/test/redemptions.t.sol b/contracts/src/test/redemptions.t.sol index 0e6ac638..779d9217 100644 --- a/contracts/src/test/redemptions.t.sol +++ b/contracts/src/test/redemptions.t.sol @@ -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); @@ -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;