Skip to content

Commit

Permalink
VAL-133 Send late fees to the FL Vault (not the Pool) (#177)
Browse files Browse the repository at this point in the history
* Update test to reflect that late fees should go to the FL vault.

* Update Loan/Lib implementation so that fees go to the FL Vault

* Loan.CompleteFullPayment() - dont send late fees back to the pool

* Add test for Loan.completeFullPayment() to verify that late fees incurred go back to FL vault.
  • Loading branch information
ams9198 authored Feb 14, 2023
1 parent ea34237 commit b24aac9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
10 changes: 2 additions & 8 deletions contracts/Loan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,7 @@ contract Loan is ILoan, BeaconImplementation {
_fees
);

LoanLib.completePayment(
liquidityAsset,
_pool,
_fees.interestPayment + _fees.latePaymentFee
);
LoanLib.completePayment(liquidityAsset, _pool, _fees.interestPayment);
paymentsRemaining -= 1;
paymentDueDate += settings.paymentPeriod * 1 days;
return payment;
Expand Down Expand Up @@ -499,9 +495,7 @@ contract Loan is ILoan, BeaconImplementation {
LoanLib.completePayment(
liquidityAsset,
_pool,
outstandingPrincipal.add(_fees.interestPayment).add(
_fees.latePaymentFee
)
outstandingPrincipal.add(_fees.interestPayment)
);
IPool(_pool).onLoanPrincipalReturned(outstandingPrincipal);

Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/LoanLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ library LoanLib {
IERC20(asset).safeTransferFrom(
msg.sender,
firstLossVault,
fees.firstLossFee
fees.firstLossFee + fees.latePaymentFee
);
}

Expand Down
64 changes: 61 additions & 3 deletions test/Loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ describe("Loan", () => {
await poolController.connect(poolAdmin).fundLoan(loan.address);
await loan.connect(borrower).drawdown(await loan.principal());

// Advance time to drop dead timestamp
// Advance time to payment due date
const foo = await loan.paymentDueDate();
await time.increaseTo(foo.add(100));

Expand All @@ -1306,13 +1306,71 @@ describe("Loan", () => {
const tx = loan.connect(borrower).completeNextPayment();
await expect(tx).to.not.be.reverted;
await expect(tx).to.changeTokenBalance(liquidityAsset, borrower, -3083);
await expect(tx).to.changeTokenBalance(liquidityAsset, pool, 1979 + 1000);
await expect(tx).to.changeTokenBalance(liquidityAsset, firstLoss, 104);
await expect(tx).to.changeTokenBalance(liquidityAsset, pool, 1979);
await expect(tx).to.changeTokenBalance(
liquidityAsset,
firstLoss,
104 + 1000
);
expect(await loan.paymentsRemaining()).to.equal(5);
const newDueDate = await loan.paymentDueDate();
expect(newDueDate).to.equal(dueDate.add(THIRTY_DAYS));
});

it("paying off the entire loan, late, incurs one late fee", async () => {
const {
borrower,
collateralAsset,
liquidityAsset,
loan,
pool,
poolController,
poolAdmin
} = await loadFixture(deployFixtureWithLateFees);

// Setup
await collateralAsset.connect(borrower).approve(loan.address, 100);
await loan
.connect(borrower)
.postFungibleCollateral(collateralAsset.address, 100);
await poolController.connect(poolAdmin).fundLoan(loan.address);
await loan.connect(borrower).drawdown(await loan.principal());

// Mint additional tokens to cover the interest payments + late fee
const interestWithLateFees = 12498 + 1000;
await liquidityAsset.mint(borrower.address, interestWithLateFees);

// Advance past payment due date
const dueDate = await loan.paymentDueDate();
await time.increaseTo(dueDate.add(100));

// Make payment
await liquidityAsset
.connect(borrower)
.approve(loan.address, interestWithLateFees + 500_000);
const tx = loan.connect(borrower).completeFullPayment();
await expect(tx).to.not.be.reverted;
await expect(tx).to.changeTokenBalance(
liquidityAsset,
borrower,
-12498 - 500_000 - 1000 // interest + principal + late fee
);
await expect(tx).to.changeTokenBalance(
liquidityAsset,
pool,
12498 + 500_000 - 624 // interest + principal - protocol-wide FL fee of 5%
);
const firstLoss = await pool.firstLossVault();
await expect(tx).to.changeTokenBalance(
liquidityAsset,
firstLoss,
624 + 1000 // protocol-wise FL fee + late fee
);

expect(await loan.paymentsRemaining()).to.equal(0);
expect(await loan.state()).to.equal(5);
});

it("can payoff the entire loan at once", async () => {
const {
borrower,
Expand Down

0 comments on commit b24aac9

Please sign in to comment.