Executing a Loan
Executing a loan requires the calculation of specific values and calling the function acceptCommitment
on the LenderCommitmentForwarderAlpha
contract.
Approval checks
Before executing the loan on chain 2 approvals must be completed.
Collateral token Allowance
The collateral token's allowance must be higher that the desired collateral for the transaction. The allowance must be set on the collateralManagerAddress
.
To check the collateral token allowance
To write the collateral token allowance:
The collateralManagerAddress
can be found in the introduction of this guide
Market Forwarder
The MarketForwarder
for the offer's marketplace must be approved by the user.
To check if the MarketForwarder
has been approved
To approve the market forwarder
marketplaceId
and commitmentForwarderAddress
both come from the loan offer query response.
Executing the loan
Once there is enough allowance on the collateral token and the MarketForwarder
has been approved, the loan can be executed.
The function lives in the LenderCommitmentForwarderAlpha
contract.
Detailed arguments
commitmentId
: The id of the commitment being accepted.principalAmount
: The amount of currency to borrow for the loan.This is is calculated as specified in this section:
collateralAmount
: The amount of collateral to use for the loan.This is inputted by the user
collateralTokenId
: The tokenId of collateral to use for the loan if ERC721 or ERC1155.For tokens, this is
0
collateralTokenAddress
: The contract address to use for the loan collateral token.sinterestRate
: The interest rate APY to use for the loan in basis points.loanDuration
: The overall duration for the loan. Must be longer than market payment cycle duration.
Calculating principalAmount
principalAmount
To calculate the principalAmount
from the maxPrincipalPerCollateral
that comes from the offer query, all you need to do is multiply the collateralAmount
by the maxPrincipalPerCollateral
and then divide it by 10^18 since it's the expansion factor.
Last updated