diff --git a/contracts/src/TroveManager.sol b/contracts/src/TroveManager.sol index 86e6b528f..3606182da 100644 --- a/contracts/src/TroveManager.sol +++ b/contracts/src/TroveManager.sol @@ -2,6 +2,8 @@ pragma solidity 0.8.24; +import "openzeppelin-contracts/contracts/utils/math/Math.sol"; + import "./Interfaces/ITroveManager.sol"; import "./Interfaces/IAddressesRegistry.sol"; import "./Interfaces/IStabilityPool.sol"; @@ -1793,7 +1795,7 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents { // To avoid rebasing issues, let’s make sure the ratio debt / shares is not too high _requireBelowMaxSharesRatio(currentBatchDebtShares, _batchDebt, _checkBatchSharesRatio); - batchDebtSharesDelta = currentBatchDebtShares * debtIncrease / _batchDebt; + batchDebtSharesDelta = Math.ceilDiv(currentBatchDebtShares * debtIncrease, _batchDebt); } Troves[_troveId].batchDebtShares += batchDebtSharesDelta; diff --git a/contracts/src/test/rebasingBatchShares.t.sol b/contracts/src/test/rebasingBatchShares.t.sol index 820c9d4c8..8ba3d4cc2 100644 --- a/contracts/src/test/rebasingBatchShares.t.sol +++ b/contracts/src/test/rebasingBatchShares.t.sol @@ -35,7 +35,7 @@ contract RebasingBatchShares is DevTestSetup { LatestBatchData memory b4Batch = troveManager.getLatestBatchData(address(B)); // TODO: Open A, Mint 1 extra (forgiven to A) - _addOneDebtAndEnsureItDoesntMintShares(ATroveId, A); + _addOneDebtAndEnsureItMintsShares(ATroveId, A); /// @audit MED impact LatestBatchData memory afterBatch = troveManager.getLatestBatchData(address(B)); @@ -178,6 +178,7 @@ contract RebasingBatchShares is DevTestSetup { closeTrove(A, ATroveId); // Close A (also remove from batch is fine) LatestTroveData memory troveAfter = troveManager.getLatestTroveData(BTroveId); + //assertGt(troveAfter.entireDebt, troveBefore.entireDebt, "we're rebasing"); assertEq(troveAfter.entireDebt, troveBefore.entireDebt, "rebasing is not working"); assertEq(troveAfter.entireDebt, 0, "trove B was closed"); } @@ -192,18 +193,8 @@ contract RebasingBatchShares is DevTestSetup { assertLt(b4BatchDebtShares, afterBatchDebtShares, "Shares should increase"); } - function _addDebtAndEnsureItDoesntMintShares(uint256 troveId, address caller, uint256 amt) internal { - (,,,,,,,,, uint256 b4BatchDebtShares) = troveManager.Troves(troveId); - - withdrawBold100pct(caller, troveId, amt); - - (,,,,,,,,, uint256 afterBatchDebtShares) = troveManager.Troves(troveId); - - assertEq(b4BatchDebtShares, afterBatchDebtShares, "Same Shares"); - } - - function _addOneDebtAndEnsureItDoesntMintShares(uint256 troveId, address caller) internal { - _addDebtAndEnsureItDoesntMintShares(troveId, caller, 1); + function _addOneDebtAndEnsureItMintsShares(uint256 troveId, address caller) internal { + _addDebtAndEnsureItMintsShares(troveId, caller, 1); } function _getLatestBatchDebt(address batch) internal view returns (uint256) { @@ -272,7 +263,7 @@ contract RebasingBatchShares is DevTestSetup { if (WITH_INTEREST) { vm.warp(block.timestamp + 12); } - _addOneDebtAndEnsureItDoesntMintShares(BTroveId, B); + _addOneDebtAndEnsureItMintsShares(BTroveId, B); (uint256 debtBefore,,,,,,, uint256 allBatchDebtSharesBefore) = troveManager.getBatch(B); uint256 sharesBeforeRepay = _getBatchDebtShares(BTroveId);