Skip to content

Commit

Permalink
Fix reduceDebt and use it in SelfLiquidateLoan
Browse files Browse the repository at this point in the history
  • Loading branch information
aviggiano committed Jan 5, 2024
1 parent ec8ba6b commit be188d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
10 changes: 4 additions & 6 deletions src/libraries/actions/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ library Common {

function reduceDebt(State storage state, uint256 loanId, uint256 amount) public {
Loan storage loan = state.loans[loanId];
Loan storage fol = getFOL(state, loan);
if (amount > loan.getCredit()) {
revert Errors.NOT_ENOUGH_CREDIT(loan.getCredit(), amount);
}

loan.faceValue -= amount;
state.tokens.debtToken.burn(fol.borrower, amount);

if (loan.isFOL()) {
// @audit Check this logic
state.tokens.debtToken.burn(loan.borrower, amount);
} else {
Loan storage fol = state.loans[loan.folId];
loan.faceValue -= amount;
if (!loan.isFOL()) {
fol.faceValue -= amount;
fol.faceValueExited -= amount;
}
Expand Down
18 changes: 1 addition & 17 deletions src/libraries/actions/SelfLiquidateLoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ library SelfLiquidateLoan {

uint256 assignedCollateral = state.getProRataAssignedCollateral(params.loanId);
state.tokens.collateralToken.transferFrom(fol.borrower, msg.sender, assignedCollateral);
state.tokens.debtToken.burn(fol.borrower, credit);

if (loan.isFOL()) {
// loan.faceValue := loan.faceValueExited
// = 0, if no exits
// >= state.config.minimumCredit, if at least 1 exit
loan.faceValue -= credit;
} else {
// same
loan.faceValue -= credit;

// deducting faceValue and faceValueExited by the same amount does not change the credit,
// since it is the difference between these two values
// so fol.getCredit() >= state.config.minimumCredit still
fol.faceValue -= credit;
fol.faceValueExited -= credit;
}
state.reduceDebt(params.loanId, credit);
}
}

0 comments on commit be188d9

Please sign in to comment.