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
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
{
commitmentId: id of the future loan
principalAmount: result of calculating collateralAmount x maxPrincipalPerCollateral / 18 (expansion factor)
collateralAmount: amount inputted by the user
collateralTokenId: hard coded to "0" since this is for a token
collateralTokenAddress: address of the collateral token
interestRate: interest rate of the commitment
loanDuration: duration of the commitment
}
functionName: "hasApprovedMarketForwarder",
arguments: [marketplaceId, forwarderAddress, userAddress] # marketplaceId and forwarderAddress both come from subgraph
contract: LenderCommitmentForwarderAlpha