Pool

The Pool contract is a core element of the LombardFi protocol that contains assets and governs their accounting logic.

Overview

This smart contract is a "pool" contract that allows lenders to deposit a specific type of ERC20 token and borrowers to borrow the deposited tokens with collateral. The pool has a defined loan-to-value ratio, coupon yield, and origination fee. The contract also includes functionality for borrowers to withdraw redundant coupons if the maximum capacity of the pool is not reached and for lenders to withdraw their deposited assets after the pool matures. The contract is written in Solidity and uses the OpenZeppelin framework for its ERC20 functionality.

Lenders and borrowers

The borrower is the party that takes a loan from the lenders on a specific predefined loan-to-value ratio against collateral. The lender is the party that provides the loan to the borrower. In the smart contract, the borrower is defined by the "borrower" address, and the lenders are defined by the "whitelistedLender" address (if the pool is open to everyone, the lender address is set to zero). The lender deposits the "lentAsset" ERC20 token, which the borrower borrows. The borrower must repay the loan before the pool matures, or the pool will default.

Lifecycle of a pool

The lifecycle of a pool in Lombard starts with its creation by a borrower who wants to take out a loan. The borrower specifies the terms of the loan, including the type of asset that will be borrowed, the collateral assets that will be used to secure the loan, the loan-to-value ratio, the origination fee, the minimum and maximum amounts of the borrowed asset, and the duration of the loan.

Once the pool is created, lenders can start depositing the specified borrowed asset into the pool. The pool remains open for deposits until the predetermined "startsAt" timestamp, at which point the pool becomes active and borrowers can start taking out loans. The borrower must provide collateral assets that are equal in value to the borrowed amount multiplied by the loan-to-value ratio specified in the pool's terms.

Once the pool is active, borrowers can take out loans and lenders can earn yield on their deposited assets. The yield is determined by the "coupon" rate specified in the pool's terms and accrues until the "maturesAt" timestamp, at which point the pool reaches maturity.

After the pool matures, lenders can withdraw their deposited assets and any accrued yield. If the borrower has not repaid their loan by this point, the pool defaults and the collateral assets are liquidated to repay the lenders.

Additionally, if the minimum amount of the borrowed asset specified in the pool's terms is not reached, borrowers are not able to take out loans and lenders can withdraw their deposited assets without accruing yield. The borrower can also withdraw any unused coupon in this case.

Risks for lenders

The risks for lenders when interacting with this contract include the potential for the borrower to default on their loan, which would result in a loss of their deposited funds. Additionally, the loan-to-value ratio (LTV) of the pool is fixed and if the value of the collateral decreases, the lender may be at risk of losing their deposited funds if the collateral is liquidated to repay the loan. There is also a potential risk of the pool not reaching the minimum amount of lentAsset required to activate borrowing functionality, in which case the lenders would not be able to earn yield on their deposited funds.

Depositing assets

The deposit function allows lenders to deposit a specified amount of the "lentAsset" ERC20 token into the pool. The function checks that the caller is a whitelisted lender (if the pool has a whitelisted lender) and that the pool is still in the deposit phase (before the "activeAt" timestamp). If these conditions are met, the function transfers the specified amount of "lentAsset" from the caller to the pool contract.

Redeeming the deposit

A lender uses the redeem function in the Pool smart contract to withdraw their deposited lentAsset from the pool. This can only be done after the pool has matured, as specified by the maturesAt timestamp. If the pool was successful the lender will also receive accrued yield.

Default logic

The _default function is used by lenders to trigger the default functionality of the pool contract. This occurs when the borrower fails to repay their loan before the pool matures. When this happens, the lenders can call the _default function to seize the collateral that the borrower has posted. This collateral is then distributed to the lenders in proportion to their contribution to the pool. This allows the lenders to recoup their losses and ensures that the terms of the loan are upheld.

Borrowing

To borrow from the pool, a borrower must also provide enough collateral according to the requirements specified in the pool contract. Once these requirements are met, the borrower can call the borrow function on the pool contract with the desired amount of the loan and the corresponding collateral. The contract will then transfer the borrowed funds to the borrower's address and update the borrower's loan balance.

Repaying a loan

To repay a loan, the borrower can call the repay function on the pool contract with the amount they wish to repay. The contract will then transfer the repaid funds to the pool and return all or part of the previously pledged collateral to the borrower.

Last updated