diff --git a/contracts/src/HintHelpers.sol b/contracts/src/HintHelpers.sol index 0cb4f1208..a624a9087 100644 --- a/contracts/src/HintHelpers.sol +++ b/contracts/src/HintHelpers.sol @@ -236,11 +236,7 @@ contract HintHelpers is IHintHelpers { IActivePool _activePool, LatestTroveData memory _trove, LatestBatchData memory _batch - ) - internal - view - returns (uint256) - { + ) internal view returns (uint256) { TroveChange memory newBatchTroveChange; newBatchTroveChange.appliedRedistBoldDebtGain = _trove.redistBoldDebtGain; newBatchTroveChange.batchAccruedManagementFee = _batch.accruedManagementFee; @@ -265,7 +261,7 @@ contract HintHelpers is IHintHelpers { if ( _newInterestRate == batch.annualInterestRate - || block.timestamp >= batch.lastInterestRateAdjTime + INTEREST_RATE_ADJ_COOLDOWN + || block.timestamp >= trove.lastInterestRateAdjTime + INTEREST_RATE_ADJ_COOLDOWN ) { return 0; } diff --git a/contracts/src/test/TestContracts/InvariantsTestHandler.t.sol b/contracts/src/test/TestContracts/InvariantsTestHandler.t.sol index 6ffd1ce4d..30c16b7fa 100644 --- a/contracts/src/test/TestContracts/InvariantsTestHandler.t.sol +++ b/contracts/src/test/TestContracts/InvariantsTestHandler.t.sol @@ -468,7 +468,7 @@ contract InvariantsTestHandler is BaseHandler, BaseMultiCollateralTest { address batchManager = _batchManagerOf[j][troveId]; Trove storage trove = _troves[j][troveId]; - if (batchManager == address(0)) _timeSinceLastTroveInterestRateAdjustment[j][troveId] += timeDelta; + _timeSinceLastTroveInterestRateAdjustment[j][troveId] += timeDelta; if (isShutdown[j]) continue; // shutdown branches stop accruing interest & batch management fees uint256 interest = trove.accrueInterest(timeDelta); @@ -872,8 +872,11 @@ contract InvariantsTestHandler is BaseHandler, BaseMultiCollateralTest { v.trove = _troves[i][v.troveId]; v.wasActive = _isActive(i, v.troveId); v.premature = _timeSinceLastTroveInterestRateAdjustment[i][v.troveId] < INTEREST_RATE_ADJ_COOLDOWN; - v.upfrontFee = hintHelpers.predictAdjustInterestRateUpfrontFee(i, v.troveId, newInterestRate); - if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + + if (v.batchManager == address(0)) { + v.upfrontFee = hintHelpers.predictAdjustInterestRateUpfrontFee(i, v.troveId, newInterestRate); + if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + } info("upper hint: ", _hintToString(i, v.upperHint)); info("lower hint: ", _hintToString(i, v.lowerHint)); @@ -1875,8 +1878,11 @@ contract InvariantsTestHandler is BaseHandler, BaseMultiCollateralTest { v.wasOpen = _isOpen(i, v.troveId); v.wasActive = _isActive(i, v.troveId); v.premature = _timeSinceLastTroveInterestRateAdjustment[i][v.troveId] < INTEREST_RATE_ADJ_COOLDOWN; - v.upfrontFee = hintHelpers.predictJoinBatchInterestRateUpfrontFee(i, v.troveId, v.newBatchManager); - if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + + if (_batchManagerOf[i][v.troveId] == address(0)) { + v.upfrontFee = hintHelpers.predictJoinBatchInterestRateUpfrontFee(i, v.troveId, v.newBatchManager); + if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + } info("batch manager: ", vm.getLabel(v.newBatchManager)); info("upper hint: ", _hintToString(i, v.upperHint)); @@ -1991,11 +1997,12 @@ contract InvariantsTestHandler is BaseHandler, BaseMultiCollateralTest { v.batchManager = _batchManagerOf[i][v.troveId]; v.batchManagementFee = v.c.troveManager.getLatestBatchData(v.batchManager).accruedManagementFee; v.wasActive = _isActive(i, v.troveId); - v.premature = _timeSinceLastBatchInterestRateAdjustment[i][v.batchManager] < INTEREST_RATE_ADJ_COOLDOWN; - v.upfrontFee = v.batchManager != address(0) - ? hintHelpers.predictRemoveFromBatchUpfrontFee(i, v.troveId, newInterestRate) - : 0; - if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + v.premature = _timeSinceLastTroveInterestRateAdjustment[i][v.troveId] < INTEREST_RATE_ADJ_COOLDOWN; + + if (v.batchManager != address(0)) { + v.upfrontFee = hintHelpers.predictRemoveFromBatchUpfrontFee(i, v.troveId, newInterestRate); + if (v.upfrontFee > 0) assertTrue(v.premature, "Only premature adjustment should incur upfront fee"); + } Trove memory trove = _troves[i][v.troveId]; Batch storage batch = _batches[i][v.batchManager]; @@ -2035,6 +2042,7 @@ contract InvariantsTestHandler is BaseHandler, BaseMultiCollateralTest { trove.interestRate = newInterestRate; trove.batchManagementRate = 0; _troves[i][v.troveId] = trove; + _timeSinceLastTroveInterestRateAdjustment[i][v.troveId] = 0; delete _batchManagerOf[i][v.troveId]; // Effects (batch)