Skip to content

Commit

Permalink
feat(cross-currency-rollover): cleanup amounts.amounttoborrower and a…
Browse files Browse the repository at this point in the history
…dd script with fees
  • Loading branch information
Mouzayan committed Jun 6, 2024
1 parent 5d9291a commit 3dabfe9
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 10 deletions.
20 changes: 10 additions & 10 deletions contracts/rollover/CrossCurrencyRollover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -336,29 +336,29 @@ contract CrossCurrencyRollover is ICrossCurrencyRollover, OriginationController,
// calculate the repay amount to settle the original loan
repayAmount = oldLoanData.terms.principal + interestAmount;

LoanLibrary.FeeSnapshot memory feeSnapshot = LoanLibrary.FeeSnapshot({
lenderInterestFee: oldLoanData.lenderInterestFee,
lenderPrincipalFee: oldLoanData.lenderPrincipalFee
});

OriginationLibrary.RolloverAmounts memory amounts = rolloverAmounts(
oldLoanData.terms.principal,
interestAmount,
swappedAmount,
lender,
oldLender,
0,
0
feeSnapshot.lenderInterestFee,
feeSnapshot.lenderPrincipalFee
);

// borrower owes
if (amounts.needFromBorrower > 0) {
IERC20(oldLoanData.terms.payableCurrency).safeTransferFrom(borrower, address(this), amounts.needFromBorrower);
}

// amount = original loan repayment amount - leftover principal
uint256 amount = amounts.amountFromLender - amounts.leftoverPrincipal;

if (swappedAmount > amount) {
uint256 remainingFunds = swappedAmount - amount;

// if funds remain, send to the borrower
IERC20(oldLoanData.terms.payableCurrency).safeTransfer(borrower, remainingFunds);
// if there are extra funds, send to the borrower
if (amounts.amountToBorrower > 0) {
IERC20(oldLoanData.terms.payableCurrency).safeTransfer(borrower, amounts.amountToBorrower);
}
}

Expand Down
Loading

0 comments on commit 3dabfe9

Please sign in to comment.