Skip to content

Loan Creation

Lucas Manuel edited this page Dec 20, 2021 · 6 revisions

Borrower - Creating a Loan

Creating a Loan in Maple requires the following transactions (assuming that the Maple protocol is in a fresh, newly deployed state).

Governor Transactions (all one-time transactions, prerequisite to the creation of a Loan)

  1. Deploy LoanFactory
  2. Deploy CollateralLockerFactory
  3. Deploy FundingLockerFactory
  4. Deploy RepaymentCalc
  5. Deploy LateFeeCalc
  6. Deploy PremiumCalc
  7. globals.setValidLoanFactory(address(loanFactory), true); - Validate LoanFactory
  8. globals.setValidSubFactory(address(loanFactory), address(clFactory), true); - Validate CollateralLockerFactory
  9. globals.setValidSubFactory(address(loanFactory), address(flFactory), true); - Validate FundingLockerFactory
  10. globals.setCalc(address(repaymentCalc), true); - Validate RepaymentCalc
  11. globals.setCalc(address(lateFeeCalc), true); - Validate LateFeeCalc
  12. globals.setCalc(address(premiumCalc), true); - Validate PremiumCalc
  13. globals.setPriceOracle(WETH, address(wethOracle)); - Set collateralAsset oracle (example: WETH collateral)
  14. globals.setPriceOracle(USDC, address(usdcOracle)); - Set liquidityAsset oracle (example: USDC liquidityAsset)
  15. globals.setCollateralAsset(WETH, true); - Validate WETH as a collateralAsset
  16. globals.setLiquidityAsset(USDC, true); - Validate USDC as a liquidityAsset

Borrower Transactions

  1. Create a Loan from the LoanFactory:
function createLoan(
    address liquidityAsset,
    address collateralAsset,
    address flFactory,
    address clFactory,
    uint256[5] memory specs,
    address[3] memory calcs
)

The calcs array should be set to [RepaymentCalc, LateFeeCalc, PremiumCalc] The specs array should be as follows:

specs[0] = apr (basis points)
specs[1] = termDays
specs[2] = paymentIntervalDays
specs[3] = requestAmount (denominated in liquidityAsset precision)
specs[4] = collateralRatio (basis points)

For example:

uint256[5] memory specs = [500, 180, 30, 1000 * 10 ** 6, 2000];
address[3] memory calcs = [address(repaymentCalc), address(lateFeeCalc), address(premiumCalc)];

Loan loan = loanFactory.createLoan(address(USDC, WETH, address(flFactory), address(clFactory), specs, calcs);

This would create a Loan with:

  • 5% APR
  • 180 day term length
  • 30 day interest payment intervals
  • 1000 USDC requested amount
  • 20% collateralized with WETH