Executing a Rollover
Similar to the borrow flow, there are various approvals that must be done before executing the rollover function on the contracts. Additionally, some values must be calculated first before executing the calls and the checks.
Calculations
Calculating the maxPrincipalPerCollateral
maxPrincipalPerCollateral
To avoid any issues with decimals and to ensure that we are using the correct values in the case that there are multiple hops required for a swap, we have to compute the amount using uniswap data and use the minimum between the computed amount below and the maxPrincipalPerCollateralAmount.
First query the contract to get the required routes
Then query the contract to get the price ratio
Then query the contract to get ltv ratio
Finally compute the
maxCollateralPerPrincipal
priceRatio * ltvRatio / 10000
use min between computed amount and maxPrincipalPerCollateralAmount
Calculating the borrow amount for the loan
In case the new loan requires a payment, the borrowerAmount must be queried.
If the borrowerAmount
is positive - then the new loan requires a payment, if it's negative the new loan will reimburse the user.
Arguments:
rolloverCommitment?.forwarderAddress:
forwarder address that comes from the subgraph querybidId
: id of the previous bid that comes from subgraphacceptCommitmentArgs
: a tuple that is defined below"9"
: the flash loan premium percentage, hard coded as 9 for aavefuture15Mins
: the current time plus 15 minutes.
This function returns 2 values, the first one is the flashLoanAmount
and the second one is the borrowAmount
acceptCommitmentArgs
acceptCommitmentArgs
This tuple is also used for executing the rollover.
The parameters are below, and these are all of the future commitment that will be used to rollover the previous loan
Approvals
Once these 2 values have been calculated, you can proceed with the approvals
Allowance for the borrowAmount
on the principal token
borrowAmount
on the principal tokenCheck the amount
If the amount is less than the collateral amount, then approve the amount
Allowance for the collateralAmount
on the collateral token
collateralAmount
on the collateral tokenCheck the amount
If the amount is less than the collateral amount, then approve the amount
Approve market forwarder
Check if already approved
If not, then approve
Approve extension
Check if already approved
If not, then approve
Execute the rollover
Once all the checks have been completed and there is enough allowance, the rolloverLoanWithFlash
function can be called from the contract.
Arguments:
forwarderAddress
: queried from the subgraphloanId
: id of the current loanflashLoanAmount
: first item from the response ofcalculateRolloverAmount
borrowerAmount
: second item from the response ofcalculateRolloverAmount
acceptCommitmentArgs
: same as the argument forcalculateRolloverAmount
Last updated