Skip to content

Commit

Permalink
🥇 Move active pool increace debt to internal function (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
nezouse authored May 27, 2024
1 parent 526469b commit 7022d48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 4 additions & 5 deletions contracts/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -344,17 +343,17 @@ 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);
uint256 debt = IVesselManager(vesselManager).getVesselDebt(_asset, _borrower);

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) {
Expand Down
17 changes: 17 additions & 0 deletions test/trinity/BorrowerOperations_FeesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7022d48

Please sign in to comment.