From 7016d490b02c628cd200eef2f69a5911ef56e70e Mon Sep 17 00:00:00 2001 From: nezouse Date: Tue, 23 Apr 2024 13:32:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=AC=20Add=20fee=20to=20both=20vessel?= =?UTF-8?q?=20and=20global=20debt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/BorrowerOperations.sol | 8 +++++--- test/trinity/BorrowerOperations_FeesTest.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) 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()) + }) }) })