Lender - Refinance a loan
New lender: refinance a called loan (Dutch auction)
This function lets a new lender buy out a called loan during the auction window.
function transfer(uint256 _loanId, uint256 _newRate) external;Note
Collateral stays inside the PolyLend contract for the entire refinancing; only ownership of the loan (and USDC) changes.
Flow
Check loan is valid.
Check loan is called.
Check that
AUCTION_DURATIONhas not elapsed since the auction startedCheck
_newRateis betweenInterestLib.ONEandMAX_INTEREST.Compute target auction rate based on how much of the 24-hour window has elapsed. In the original PolyLend spec, the interest rate linearly increases from 0% to a maximum over 24 hours; here, MAX_INTEREST caps the per-second rate.
Enforce that
_newRateis at least the target auction rate.Verify msg.sender has sufficient USDC and allowance to pay amountOwed to the old lender plus protocol fee.
Calculate
amountOwed.Create and store a new Loan for the same borrower with the new lender
loanAmount = amountOwed(principal rolls into new loan).rate = _newRate.startTime = block.timestamp.minimumDuration = 0(the new lender can call after 0 seconds unless you change semantics)
Cancel the old loan by zeroing
loan.borrower.Pay the previous lender and fee:
Calcualte protocol
fee.Calculate
lenderAmount = amountOwed - fee.Transfer
lenderAmountfrom new lender to old lender.Transfer
feeto protocol fee recipient.
Emit
LoanTransferred.
Last updated
