Skip to content

Commit

Permalink
Merge pull request #47 from ohmzeus/08-2023-Sherlock-Issue-119
Browse files Browse the repository at this point in the history
Fix Issue 119
  • Loading branch information
ohmzeus authored Sep 11, 2023
2 parents 499e805 + 8be2146 commit 4171368
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Cooler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ contract Cooler is Clone {
/// @return defaulted debt by the borrower, collateral kept by the lender, elapsed time since expiry.
function claimDefaulted(uint256 loanID_) external returns (uint256, uint256, uint256) {
Loan memory loan = loans[loanID_];
delete loans[loanID_];

if (block.timestamp <= loan.expiry) revert NoDefault();

loans[loanID_].amount = 0;
loans[loanID_].collateral = 0;

// Transfer defaulted collateral to the lender.
collateral().safeTransfer(loan.lender, loan.collateral);

Expand Down
16 changes: 9 additions & 7 deletions src/test/Cooler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,14 @@ contract CoolerTest is Test {
) = cooler.loans(loanID);

// check: loan storage
// - only amount and collateral are cleared
assertEq(0, loanAmount);
assertEq(0, loanUnclaimed);
assertEq(0, loanCollat);
assertEq(0, loanExpiry);
assertEq(address(0), loanLender);
assertEq(false, loanDirect);
// - the rest of the variables are untouched
assertEq(0, loanUnclaimed);
assertEq(block.timestamp - 1, loanExpiry);
assertEq(lender, loanLender);
assertEq(true, loanDirect);
assertEq(false, loanCallback);
}

Expand Down Expand Up @@ -707,9 +709,9 @@ contract CoolerTest is Test {
assertEq(0, loanAmount1, "loanAmount1");
assertEq(0, loanUnclaimed1, "loanUnclaimed1");
assertEq(0, loanCollat1, "loanCollat1");
assertEq(0, loanExpiry1, "loanExpiry1");
assertEq(address(0), loanLender1, "loanLender1");
assertEq(false, loanDirect1, "loanDirect1");
assertEq(block.timestamp - 1, loanExpiry1, "loanExpiry1");
assertEq(lender, loanLender1, "loanLender1");
assertEq(true, loanDirect1, "loanDirect1");
assertEq(false, loanCallback1, "loanCallback1");
}
{
Expand Down

0 comments on commit 4171368

Please sign in to comment.