Skip to content

Contract Overview

Thomas Spofford edited this page May 26, 2019 · 9 revisions

The Contracts

Basically there are some singleton contracts Ours:

  • StudentLoansTermContract
  • StudentLoansCrowdfundFactory
  • StudentLoansStorage

Dharma (the ones that are directly called):

  • DebtKernel
  • RepaymentRouter

And then, each loan is represented by:

  • StudentLoansCrowdfund instance
  • AgreementID in Dharma, which stores param pointer
  • Actual data in StudentLoanStorage

Diagram

Flow

Step 1: The borrower creates a new Crowdfund contract via the CrowdfundFactory

  • We require the factory because we need to keep track of loan params via an index (see below). We also may want to approve who can create loan requests (you need a Bloom ID, or w/e).

  • In dharma, you only have 32 bytes to store loan params, and 108 of the 256 bits are taken up by collateral information, which I want to preserve as that logic is baked into the Collateralizer contract.

  • The simple loan example encodes all it’s parameters in the 148 bits remaining.

  • I didn’t see it as enough space for our complex loans, so I’m storing a pointer to an index in a known contract address in the parameters to load the data from.

Step 2: Lenders Fund Crowdfund.

This is custom and based on the BlankDAO ERC20 crowdfund

Step 3: Funding Complete

Now, the borrower sends a message to the Crowdfund accepting the money. This automatically generates and submits the debt order to dharma DebtKernel from the contract. The user also signs a message as part of that call for the debt order (which can be deterministically generated from a read call beforehand) so dharma is happy. Dharma handles the transfer of funds and issues the singular NFT "Debt Token" to the Crowdfund contract.

Step 4: Repayments

Repayments are send to the RepaymentRouter and are forwarded to the "Debt Token" holder by dharma (which is the Crowdfund contract). This also triggers a contract call to the TermsContract for the loan which can update data as needed. The Crowdfund can distribute earnings among its' fractional holders.

Note: The TermsContract contains all logic for a given type of loan (StudentLoan in our case). The specific data from an instance is loaded based on it's agreementID in dharam, which stores the params. In our case, the params have a pointer to an index to load from a known 'data contract' which stores all loan data. This is because the data is too large to store in 148 bytes directly.