Lend&Borrow

Technical description of Equilibria first version, including the Compound fork and the Analytics dashboard.

Introduction

We strongly believe that Equilibria has the potential to become a leader in DeFi industry innovation. However, to leverage the protocol's features, we need user data and a thriving community. That is why we have developed a roadmap that outlines how we plan to structure the development of Equilibria based on the available data and community growth.

Protocol Architecture

Lending Pool architecture is a common design pattern used by many decentralized lending protocols in the DeFi ecosystem. This architecture allows users to lend and borrow digital assets in a secure and efficient manner, utilizing smart contracts to automate processes and ensure transparency. Here's a detailed explanation of the Lending Pool architecture:

A Lending Pool is a smart contract that aggregates liquidity for a specific asset. Users can supply their assets into the pool which then becomes available for borrowing by other users. While on the other side, users can deposit a collateral in order to access to the funds deposited by the first ones. The first category of user are called lenders the second one are called borrowers. They are the main actor of the scenario described. Their interaction is regulated under the Lending Pools smart contract throught different parameters: the interest related to the loan agreed by those two parties (borrower and lender) is determined by the interest rate mechanism. Also, the protocol must ensure the safety of lenders' fund. The mechanism that ensures it is called liquidation. In the following flowchart we will briefly display how the two parties will interacts, while the next paragraphs will explain in details the roles played by the two parties and how it's influenced by the two mentioned mechanisms.

Suppliers

Suppliers i.e. Lenders play a simple but crucial role in lending protocols by supplying liquidity, which enables borrowers to access funds. They contribute to Equilibria by depositing their assets into the respective Lending Pools and, in return, earn interest on their deposits. When a depositor supplies funds into a lending protocol, the following functions are executed on the smart contract:

  1. Deposit: The deposit function is called when a user deposits their assets into a Lending Pool. This function transfers the user's assets from their wallet to the Lending Pool's smart contract.

  2. Update Interest Rates: The smart contract recalculates the borrowing and lending interest rates based on the new liquidity provided by the deposit. This update ensures that interest rates remain aligned with the current supply and demand dynamics.

  3. Mint Interest-Bearing Tokens: Upon a successful deposit, the smart contract mints interest-bearing tokens proportional to the depositor's share in the Lending Pool. These tokens are then transferred to the depositor's wallet. The interest-bearing tokens continuously accrue interest, allowing depositors to track and claim their earnings.

  4. Update User Data: The smart contract updates the depositor's user data, such as the amount deposited, the current balance of interest-bearing tokens, and the accrued interest.

  5. Emit Events: The smart contract emits relevant events, such as Deposit or Transfer, to notify external systems or applications of the deposit transaction. This allows for better tracking and monitoring of the protocol's activity.

Borrowers

Also borrowers play an essential role by utilizing the liquidity provided by depositors. They borrow assets for various purposes such as trading, investing, or leveraging their positions. Here's a detailed explanation of the functions executed on the smart contract when they take out a loan on Equilibria:

  1. Collateral Deposit: When a borrower wants to borrow assets, they first send a transaction to the Compound smart contract to deposit their chosen collateral. This transaction includes the collateral assets and the borrower's address.

  2. Collateral Marking: After depositing, the borrower must "enter the market" for the deposited asset, effectively marking it as collateral. This is done by calling a function in the smart contract. Once an asset is marked as collateral, the borrower can take a loan up to the allowed borrowing limit.

  3. Borrowing Limit Calculation: The borrowing limit is determined by the 'collateral factor' of each asset, which is a value between 0 and 1 set by the protocol's governance. For instance, if the collateral factor is 0.75 (or 75%), a borrower could borrow up to 75% of the value of their collateral. The value of the collateral is calculated in terms of the underlying asset price, which is sourced from price feeds.

  4. Loan Origination: When the borrower sends a transaction to borrow an asset, the smart contract checks their borrowing limit. If the requested amount doesn't exceed the borrowing limit, the smart contract will execute the loan.

  5. Health Check: The protocol continually monitors the health of all loans. If the value of the collateral drops too much (because of price fluctuations), and the borrower becomes undercollateralized (the value of the borrowed amount exceeds the collateral value plus some buffer), then the smart contract allows other users to liquidate the borrower's collateral according to the formulas we'll later explain in the liquidation paragraph.

Interests Rates Mechanism

The interest rates for lenders and borrowers are determined algorithmically based on supply and demand for each crypto asset, ensuring the optimal rates for both parties involved. The general idea is that as liquidity (supply of funds to lend) decreases or demand for borrowing increases, interest rates go up, and vice versa. Therefore, interest rates are a parameters as a function of demand; when demand is low, interest rates decrease. When demand is high, interest rate increases. For this first version of the model we are going to use the Interest Model used in Compound V1, which is much easier to apply but less sophisticated.

To correctyl determine the value of the interest rate, we will start by unifying supply and demand into a single variable, called utilization rate, i.e. the total borrowed amount divided by the total supplied amount, calculated as follows:

U(a) = Borrows(a) / (Cash(a) + Borrows(a))

The second and thir d parameters are called base rate and multiplier, which areset per market by the protocol administrators, not by a governance process. Those three parameters allow us to calculate the borrow interest rate, as well as a linear function of the utilization rate, calculated as follows:

Borrow Rate = Base Rate + Utilization Rate * Multiplier

For an optimized and community-driven value of interest rates, our aim is to implement an optimized version of the Compound V2 interest rate model, once we develop a strong community, implementing a Governance Token, we will introduce a more sophisticated mechanism.

Liquidation Mechanism

Suppliers and borrowers are the actors that interact throught Lending Pools, and the terms of their loans are determined block-by-block with an interest rate model. Although, the protocol needs to implement mechanisms that ensure the safety of funds deposited in the smart contract. This is the reason behind the development of the liquidation feature. It basically works in this way: If the value of the collateral falls below a certain threshold (known as the liquidation threshold), the protocol will liquidate the borrower's collateral to ensure the loan is repaid. This is typically done by selling the collateral on the open market.

The formula used by Compound to determine when a loan should be liquidated is:

Collateral Value * Liquidation Threshold < Loan Value

The liquidation thresold is a factor that increases the amount of collateral that needs to be maintained relative to the loan value. This provides a buffer to protect lenders against market volatility. It is not calculated but rather it is a predefined parameter. Different assets can have different collateral factors due to their varying risk profiles. More volatile assets generally have lower collateral factors to account for potential price swings, whereas less volatile assets may have higher collateral factors.

If this condition is met, then the loan can be liquidated. If the borrower doesn't add more collateral or repay the loan to reduce its size, a liquidator can repay a portion of the borrower's loan, and in return, they receive a proportion of the borrower's collateral, with a liquidation bonus applied.

Smart Contract Auditing

Smart contract auditing is the process of thoroughly reviewing and analyzing a smart contract's code to identify potential vulnerabilities, security issues, and design flaws. It aims to ensure that the smart contract behaves as intended and adheres to best practices, minimizing the risk of potential attacks or failures. Smart contract audits are particularly important for decentralized applications for several reasons:

  1. Security: Smart contracts handle digital assets, often worth millions or billions of dollars, and a single vulnerability can lead to significant financial losses. Auditing a smart contract helps to identify and fix security issues before deployment, reducing the risk of hacks, exploits, or other malicious activities.

  2. Trust and Credibility: A thorough audit by a reputable auditing firm or independent experts can instill trust and confidence in a dApp's user base. Knowing that the smart contract has undergone a rigorous review process gives users peace of mind and encourages wider adoption.

  3. Compliance: Smart contract auditing can help ensure that the contract complies with relevant regulations, industry standards, and best practices. Compliance is essential for maintaining a good reputation and avoiding potential legal issues or penalties.

  4. Bug Detection and Prevention: Auditing a smart contract allows developers to identify and fix bugs, logic errors, or inefficiencies in the code. This results in a more robust and reliable dApp, reducing the likelihood of failures or unexpected behavior.

  5. Performance Optimization: A smart contract audit can help identify areas where the contract's performance can be optimized, such as reducing gas costs or improving execution efficiency. Optimized smart contracts are more cost-effective and attractive to users, contributing to the dApp's overall success.

Our aim is to audit the smart contract of Equilibria at a major and recognized Smart Contract Auiditings companies such as Certik. Consiudering the reasons described above we consider this to be a key-step.

Last updated