Skip to content

Commit

Permalink
VAL-128 Fix 5.1 audit report issue. (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ams9198 authored Feb 13, 2023
1 parent 027ecfa commit a9e2596
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/libraries/LoanLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../interfaces/ILoan.sol";
import "../interfaces/IPool.sol";
import "../interfaces/IServiceConfiguration.sol";
import "../interfaces/IVault.sol";

Expand Down Expand Up @@ -282,6 +283,7 @@ library LoanLib {
uint256 amount
) public {
fundingVault.withdrawERC20(asset, amount, pool);
IPool(pool).onLoanPrincipalReturned(amount);
emit CanceledLoanPrincipalReturned(pool, amount);
}

Expand Down
30 changes: 30 additions & 0 deletions test/Loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,36 @@ describe("Loan", () => {
expect(await loan.state()).to.equal(2);
});

it("updates the pool accountings to reflect the principal returned", async () => {
const {
borrower,
pool,
liquidityAsset,
loan,
poolController,
poolAdmin
} = await loadFixture(deployFixture);
await collateralizeLoan(loan, borrower, liquidityAsset);

// Before funding, check that oustandingLoanPrincipals is zero
expect((await pool.accountings()).outstandingLoanPrincipals).to.equal(0);

// Fund loan
await fundLoan(loan, poolController, poolAdmin);

// Check that outstandingLoanPrincipals in the pool reflects the loan principal
expect((await pool.accountings()).outstandingLoanPrincipals).to.equal(
await loan.principal()
);

// Cancel loan
await time.increaseTo(await loan.dropDeadTimestamp());
await loan.connect(borrower).cancelFunded();

// Check that outstandingLoanPrincipals in the pool is back to zero
expect((await pool.accountings()).outstandingLoanPrincipals).to.equal(0);
});

it("reverts if protocol is paused", async () => {
const {
serviceConfiguration,
Expand Down

0 comments on commit a9e2596

Please sign in to comment.