Skip to content

Commit

Permalink
Merge pull request #362 from liquity/fix-underflow-close
Browse files Browse the repository at this point in the history
fix: underflow when closing Trove that has pending batch management fees
  • Loading branch information
danielattilasimon authored Aug 26, 2024
2 parents 813d4b0 + 13abd60 commit 4b62153
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contracts/src/ActivePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ contract ActivePool is IActivePool {
{
_requireCallerIsBOorTroveM();

// Batch management fees
if (_batchAddress != address(0)) {
_mintBatchManagementFeeAndAccountForChange(boldToken, _troveChange, _batchAddress);
}

// Do the arithmetic in 2 steps here to avoid overflow from the decrease
uint256 newAggRecordedDebt = aggRecordedDebt; // 1 SLOAD
newAggRecordedDebt += _mintAggInterest(boldToken, _troveChange.upfrontFee); // adds minted agg. interest + upfront fee
Expand All @@ -238,11 +243,6 @@ contract ActivePool is IActivePool {
newAggWeightedDebtSum += _troveChange.newWeightedRecordedDebt;
newAggWeightedDebtSum -= _troveChange.oldWeightedRecordedDebt;
aggWeightedDebtSum = newAggWeightedDebtSum; // 1 SSTORE

// Batch management fees
if (_batchAddress != address(0)) {
_mintBatchManagementFeeAndAccountForChange(boldToken, _troveChange, _batchAddress);
}
}

function mintAggInterest() external override {
Expand Down

0 comments on commit 4b62153

Please sign in to comment.