Skip to content

Commit

Permalink
🚬 Add fee to both vessel and global debt
Browse files Browse the repository at this point in the history
  • Loading branch information
nezouse committed Apr 23, 2024
1 parent a4b4fe8 commit 7016d49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contracts/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

uint256 debtTokenFee = _triggerBorrowingFee(_asset, _borrower, debt);
IVesselManager(vesselManager).increaseVesselDebt(_asset, _borrower, debtTokenFee);
return debtTokenFee;
}

function _getCurrentEpoch() internal view returns (uint256) {
Expand Down
19 changes: 19 additions & 0 deletions test/trinity/BorrowerOperations_FeesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
})

0 comments on commit 7016d49

Please sign in to comment.