`Goldilend.liquidate()` might revert due to underflow
In `repay()`, there would be a rounding during the `interest` calculation.\\n```\\n  function repay(uint256 repayAmount, uint256 _userLoanId) external {\\n      Loan memory userLoan = loans[msg.sender][_userLoanId];\\n      if(userLoan.borrowedAmount < repayAmount) revert ExcessiveRepay();\\n      if(block.timestamp > userLoan.endDate) revert LoanExpired();\\n      uint256 interestLoanRatio = FixedPointMathLib.divWad(userLoan.interest, userLoan.borrowedAmount);\\nL425  uint256 interest = FixedPointMathLib.mulWadUp(repayAmount, interestLoanRatio); //@audit rounding issue\\n      outstandingDebt -= repayAmount - interest > outstandingDebt ? outstandingDebt : repayAmount - interest;\\n      // rest of code\\n  }\\n// rest of code\\n  function liquidate(address user, uint256 _userLoanId) external {\\n      Loan memory userLoan = loans[msg.sender][_userLoanId];\\n      if(block.timestamp < userLoan.endDate || userLoan.liquidated || userLoan.borrowedAmount == 0) revert Unliquidatable();\\n      loans[user][_userLoanId].liquidated = true;\\n      loans[user][_userLoanId].borrowedAmount = 0;\\nL448  outstandingDebt -= userLoan.borrowedAmount - userLoan.interest;\\n      // rest of code\\n  }\\n```\\n\\nHere is a possible scenario.\\nThere are 2 borrowers of `borrowedAmount = 100, `interest` = 10`. And `outstandingDebt = 2 * (100 - 10) = 180`.\\nThe first borrower calls `repay()` with `repayAmount = 100`.\\nDue to the rounding issue at L425, `interest` is 9 instead of 10. And `outstandingDebt = 180 - (100 - 9) = 89`.\\nIn `liquidate()` for the second borrower, it will revert at L448 because `outstandingDebt = 89 < borrowedAmount - `interest` = 90`.
In `liquidate()`, `outstandingDebt` should be updated like the below.\\n```\\n  /// @inheritdoc IGoldilend\\n  function liquidate(address user, uint256 _userLoanId) external {\\n    Loan memory userLoan = loans[msg.sender][_userLoanId];\\n    if(block.timestamp < userLoan.endDate || userLoan.liquidated || userLoan.borrowedAmount == 0) revert Unliquidatable();\\n    loans[user][_userLoanId].liquidated = true;\\n    loans[user][_userLoanId].borrowedAmount = 0;\\n// Add the line below\\n  uint256 debtToRepay = userLoan.borrowedAmount - userLoan.interest;\\n// Add the line below\\n  outstandingDebt -= debtToRepay > outstandingDebt ? outstandingDebt : debtToRepay;\\n   // rest of code\\n  }\\n```\\n
`liquidate()` might revert due to underflow.
```\\n  function repay(uint256 repayAmount, uint256 _userLoanId) external {\\n      Loan memory userLoan = loans[msg.sender][_userLoanId];\\n      if(userLoan.borrowedAmount < repayAmount) revert ExcessiveRepay();\\n      if(block.timestamp > userLoan.endDate) revert LoanExpired();\\n      uint256 interestLoanRatio = FixedPointMathLib.divWad(userLoan.interest, userLoan.borrowedAmount);\\nL425  uint256 interest = FixedPointMathLib.mulWadUp(repayAmount, interestLoanRatio); //@audit rounding issue\\n      outstandingDebt -= repayAmount - interest > outstandingDebt ? outstandingDebt : repayAmount - interest;\\n      // rest of code\\n  }\\n// rest of code\\n  function liquidate(address user, uint256 _userLoanId) external {\\n      Loan memory userLoan = loans[msg.sender][_userLoanId];\\n      if(block.timestamp < userLoan.endDate || userLoan.liquidated || userLoan.borrowedAmount == 0) revert Unliquidatable();\\n      loans[user][_userLoanId].liquidated = true;\\n      loans[user][_userLoanId].borrowedAmount = 0;\\nL448  outstandingDebt -= userLoan.borrowedAmount - userLoan.interest;\\n      // rest of code\\n  }\\n```\\n