diff --git a/contracts/BorrowerOperations.sol b/contracts/BorrowerOperations.sol index b847325..74d5614 100644 --- a/contracts/BorrowerOperations.sol +++ b/contracts/BorrowerOperations.sol @@ -334,7 +334,8 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr } function collectVesselFee(address _asset, address _borrower) external { - _collectVesselFee(_asset, _borrower); + uint256 collectedFee = _collectVesselFee(_asset, _borrower); + IActivePool(activePool).increaseDebt(_asset, collectedFee); } /** @@ -356,9 +357,9 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr function _collectVesselFee( address _asset, address _borrower - ) internal { + ) internal returns (uint256) { if(_vesselAlreadyCollected(_asset, _borrower)) { - return; + return 0; } IVesselManager(vesselManager).applyPendingRewards(_asset, _borrower); @@ -366,6 +367,7 @@ contract BorrowerOperations is TrinityBase, ReentrancyGuardUpgradeable, UUPSUpgr uint256 debtTokenFee = _triggerBorrowingFee(_asset, _borrower, debt); IVesselManager(vesselManager).increaseVesselDebt(_asset, _borrower, debtTokenFee); + return debtTokenFee; } function _getCurrentEpoch() internal view returns (uint256) { diff --git a/test/trinity/BorrowerOperations_FeesTest.js b/test/trinity/BorrowerOperations_FeesTest.js index c3f9c8f..ed61e85 100644 --- a/test/trinity/BorrowerOperations_FeesTest.js +++ b/test/trinity/BorrowerOperations_FeesTest.js @@ -280,5 +280,24 @@ contract("BorrowerOperations_Fees", async accounts => { const expectedTimestamp = currentTimestamp.sub(currentTimestamp.mod(toBN(SECONDS_IN_ONE_WEEK))) assert.isTrue(epoch.eq(expectedTimestamp)) }) + + it('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.collectVesselFee(erc20.address, 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()) + }) }) })