LoanManager Contracts

The "lifecycle" of a loan through the Teller protocol

The LoanManager contract holds all the main borrower-oriented actions of the Teller protocol.

There are 2 types of loans. Loans with Ether as collateral and loans with an ERC20 token as collateral. The main difference is how the loans are created and collateral paid out.

Below are the key methods that reside in the contract. For the complete source code, check out LoanManager.sol on GitHub.

{1} createLoanWithTerms()

function createLoanWithTerms( TellerCommon.LoanRequest calldata request, TellerCommon.LoanResponse[] calldata responses, uint256 collateral )

Creates an instance of a loan with terms on the protocol that has been accepted by a consensus of nodes. There are two special parameters in this method, that are structs specific to the Teller protocol.

TellerCommon.LoanRequest is a request struct/object that is sent to the Teller Nodes and subsequently on-chain, with all the required entries such as:

TellerCommon.LoanResponse[] is an array of signed response structs/objects that are returned from registered Teller nodes that need to be passed on-chain in order to register the loan terms on-chain.

The last param collateral is the amount of collateral that needs to be deposited into the protocol in order to be able to take out the funds of the loan.

{2} depositCollateral()

function( address borrower, uint256 loanID, uint256 amount )

In situations where a borrower's collateral drops in value (e.g. price drops 90% in value), the borrower would need to deposit more collateral to keep the loan Active and out of liquidation. This can be done with the depositCollateral() method called by the borrower or developer dApp.

{3} takeOutLoan()

function( uint256 loanID, uint256 amountBorrow )

Once a loan with terms has been created on-chain with createLoanWithTerms() and collateral deposited, a borrower can now take out the loan.

{4} repay()

function( uint256 amount, uint256 loanID )

Once the borrower has used the loan he will also need to pay back the loan. This can be done with the repay() method on the respective loan contract.

One thing to note: if a loan is repaid in full with the repay() method, the borrower's collateral is automatically sent to their wallet, no additional calls are needed!

{5} withdrawCollateral()

function( uint256 amount, uint256 loanID )

In situations where the value of the borrower's collateral has risen (hello there new ATH!), a borrower can withdraw a portion of their collateral and still keep the loan active by calling the withdrawCollateral() method on-chain.

Last updated