Smart Contract

EVAA's protocol is structured around a master contract and individual user contracts, each playing a critical role in the system's operations and implemented in FunC language.

Master Contract

The Master Contract serves as the central hub of the EVAA, managing and storing global data such as total asset amounts, configurations, and system settings. It ensures consistency and reliability across the platform by aggregating and managing data that impacts all users.

The Master Contract also maintains cumulative rates, sRate and bRate, which represent the total interest accrued for each asset since the protocol's inception. These rates are shared across all users for a specific asset.

User Contracts

User Contracts handle individual user data, including the balance of supplied and borrowed assets, referred to as "principals."

Principals are stored on the User Contract and are updated only when the user takes action, such as depositing, withdrawing, or undergoing liquidation. Positive principals indicate supplies, while negative principals indicate loans. For a given asset, a user cannot simultaneously have both a supply and a borrow position.

  • Supply Balance is calculated by multiplying the cumulative supply rate by the amount of assets a user has supplied.

  • Borrow Balance is calculated by multiplying the cumulative borrow rate by the amount of assets a user has borrowed.

Core Functionalities Explained

Supply

Users add assets to the platform, which are recorded in their user contract. This increases their principal amount and enhances the liquidity of the system.

Withdraw

Users can retrieve assets they have supplied, assuming they have sufficient balance not tied up in loans. This reduces their principal in the system.

Borrow

Borrowing in EVAA is integrated with the withdraw functions. When users withdraw more than their available balance, it leads to a negative principal balance, effectively creating a borrowing scenario.

User principals are tracked using a dictionary that maps assets to balances. These balances can be positive (representing deposits) or negative (representing debts). When a user withdraws more than their available balance of an asset, their principal for that asset becomes negative, indicating that they have borrowed from the protocol.

Users must carefully monitor this balance to avoid potential liquidation risks.

Repay

Essentially a form of supply, but specifically used to reduce or clear a negative principal. For example, if a user owes 10 USDt, supplying 20 USDt would first clear the debt and then add the remainder to their principal.

Liquidate

In cases where a borrower fails to maintain the required collateral, other users can liquidate the borrower's position. This involves paying off the borrower’s debt and receiving their collateral, effectively reducing the borrower's principal and possibly turning it negative if the collateral does not cover the entire debt.

Last updated