From 51295d63564f8751ec5f02dad377ab959250a3d3 Mon Sep 17 00:00:00 2001 From: nezouse Date: Fri, 17 May 2024 11:36:27 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=87=20Move=20active=20pool=20increace?= =?UTF-8?q?=20debt=20to=20internal=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/BorrowerOperations.sol | 9 ++++----- test/trinity/BorrowerOperations_FeesTest.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) 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..a57e722 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)