Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent funding the same loan 2x #152

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Prevent funding an already-funded loan
Adrian Soghoian committed Dec 9, 2022

Unverified

No user is associated with the committer email.
commit 1e620518bd533d1fecefc12991f9881e554876c0
3 changes: 2 additions & 1 deletion contracts/Pool.sol
Original file line number Diff line number Diff line change
@@ -251,6 +251,8 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyPoolController
onlyCrankedPool
{
require(!_fundedLoans[addr], "Pool: already funded");
_fundedLoans[addr] = true;
ILoan loan = ILoan(addr);
uint256 principal = loan.principal();

@@ -260,7 +262,6 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
loan.fund();

_accountings.outstandingLoanPrincipals += principal;
_fundedLoans[addr] = true;

emit LoanFunded(addr, principal);
}
29 changes: 29 additions & 0 deletions test/controllers/PoolController.test.ts
Original file line number Diff line number Diff line change
@@ -969,6 +969,35 @@ describe("PoolController", () => {
poolController.connect(otherAccount).fundLoan(otherAccount.address)
).to.be.revertedWith("Pool: caller is not admin");
});

it.only("reverts if trying to fund the same loan again", async () => {
const {
pool,
liquidityAsset,
otherAccount,
borrower,
poolAdmin,
loan,
poolController
} = await loadFixture(loadPoolFixture);

await activatePool(pool, poolAdmin, liquidityAsset);
await collateralizeLoan(loan, borrower, liquidityAsset);
await depositToPool(
pool,
otherAccount,
liquidityAsset,
DEFAULT_LOAN_SETTINGS.principal * 3
);

// fund loan 1 time
await fundLoan(loan, poolController, poolAdmin);

// Try again, even though there's technically enough money to cover the loan
await expect(
poolController.connect(poolAdmin).fundLoan(loan.address)
).to.be.revertedWith("Pool: already funded");
});
});

describe("defaultLoan()", () => {