diff --git a/contracts/BorrowerOperations.sol b/contracts/BorrowerOperations.sol index 62b263a..6a8fa29 100644 --- a/contracts/BorrowerOperations.sol +++ b/contracts/BorrowerOperations.sol @@ -321,8 +321,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr } function collectVesselFee(address _asset, address _borrower) external { - uint256 collectedFee = _collectVesselFee(_asset, _borrower); - IActivePool(activePool).increaseDebt(_asset, collectedFee); + _collectVesselFee(_asset, _borrower); } /** @@ -344,9 +343,9 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr function _collectVesselFee( address _asset, address _borrower - ) internal returns (uint256) { + ) internal { if(_vesselAlreadyCollected(_asset, _borrower)) { - return 0; + return; } IVesselManager(vesselManager).applyPendingRewards(_asset, _borrower); @@ -354,7 +353,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr uint256 debtTokenFee = _triggerBorrowingFee(_asset, _borrower, debt); IVesselManager(vesselManager).increaseVesselDebt(_asset, _borrower, debtTokenFee); - return debtTokenFee; + IActivePool(activePool).increaseDebt(_asset, debtTokenFee); } function _getCurrentEpoch() internal view returns (uint256) { diff --git a/test/trinity/BorrowerOperations_FeesTest.js b/test/trinity/BorrowerOperations_FeesTest.js index 7587137..9c8c33c 100644 --- a/test/trinity/BorrowerOperations_FeesTest.js +++ b/test/trinity/BorrowerOperations_FeesTest.js @@ -365,6 +365,23 @@ contract("BorrowerOperations_Fees", async accounts => { assert.equal(newGlobalDebt.toString(), getDebtWithFee(initialTotalDebt).toString()) }) + it("adjust vessel adds to both vessel debt and global debt", async () => { + const { activePool, borrowerOperations, vesselManager, erc20 } = contracts.core + await openVessel(alice) + + const initialAliceDebt = await vesselManager.getVesselDebt(erc20.address, alice) + const initialTotalDebt = await activePool.getDebtTokenBalance(erc20.address) + + await skipToNextEpoch() + await borrowerOperations.adjustVessel(erc20.address, 0, 1, 0, false, alice, alice, { from: alice }) + + const newAliceDebt = await vesselManager.getVesselDebt(erc20.address, alice) + const newGlobalDebt = await activePool.getDebtTokenBalance(erc20.address) + + assert.equal(newAliceDebt.toString(), getDebtWithFee(initialAliceDebt).toString()) + assert.equal(newGlobalDebt.toString(), getDebtWithFee(initialTotalDebt).toString()) + }) + it('can close vessel if vesselDebt > activePoolDebt', async () => { const {activePool, borrowerOperations, vesselManager, debtToken, erc20} = contracts.core await openVessel(alice)