Architecture of Earn
The Earn product consists of multiple key components. The roles of the various components are described below:
The factory is responsible for creating new loan pools and maintaining a registry of loan pools created by the factory.
The factory creates a minimal proxy of the LoanPool and a registered CreditLineTemplate to create new pools.
The LoanPool contract is responsible for interacting with the lenders and borrower directly. Borrowers will be able to drawdown on the funds when the pool is successfully funded as well as repaying their loans. Lenders will be able to fund the pools when they are available for funding as well as withdrawing their share of repayments when the borrower has made them.
Every LoanPool will own its own credit line contract which accounts for the loan.
The CreditLineTemplate is a class of contracts that is responsible for accounting for the loan. Its main responsibility is to determine the repayment schedule against the initial principal amount and other parameters. It will also account for any extra fees such as late payment fees.
There are different implementations of the CreditLineTemplate such as the CreditLineAmortized or CreditLineBalloon
This is a flavour of the CreditLineTemplate which allows the borrower to pay back the loan with equal payments during each payment period towards both the principal and interest amount.
This is a flavour of the CreditLineTemplate which allows the borrower to pay back the loan with only interest payments until the final payment period where both the interest and principal is repaid together. Another name for this style of repayment is Bullet loan.
The viewer contract is a utility contract that frontends can use to quickly access information on the loan pool. It returns data from the loan pool, credit line, and funding asset.
The router contract provides a single interface for lenders to fund the different loan pools and separately acts as an indexer of all the loan pools participated by the lender. It also allow relayers to help lenders execute a funding transaction if the lender has approved it off-chain.
The metadata contract allows borrowers to register a metadata URI to the loan pool. The metadata URI is used to populate the data on the product information page of the loan pool.