Math done in _calculateInterest
function calculates the interest based on loan debt amount not on the acutal amount of tokens received by borrower.
Borrower calls borrow
with the desired parameters (poolId, debt, collateral). Function sets debt
as the debt
value provided by the borrrower in the input (debt: debt
).
The function calculates the fee based on debt
and borrowerFee
. The amount of tokens transfered to user is equal to debt - fees
. debt - fees
is the actual token amount borrowed by the user, not the debt
that the borrower wanted to borrow.
When it comes to repaying the debt the interest is calculated based on l.debt
not the amount that the borrower received. It means that the user is paying interest on the full amount of debt
that he did not received.
To add up _calculateInterest
is called in 4 other functions which also make them faulty of this calculation.
getLoanDebt
giveLoan
buyLoan
refinance
As the result borrower ends up paying more interest than he should be.
Manual Analysis, VScode
I think the solution to this situation could be sending the full amount of tokens to to user and charge the borrowerFee
when the borrower repays the loan. To ensure that the borrowerFee
will be paid, the extra amount of collateral can be transfered from the borrower while borrowing the tokens.
Another solution might be refactoring _calculateInterest
function to calculate interest based on the actual amount of tokens received by the borrower.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.