Developers
Mainnet AlphaContribute-2-Earn
  • Introduction
  • Permissible CDR
  • Automated Liquidity Provision
  • Slippage Control
  • Integrations
  • Proxy/Upgrade Structure
  • Mainnet Deployed Contracts
  • Frontend Tech Stack
  • 💰Supply and Borrow
    • Introduction
    • Supply
    • Borrow
      • Use Cases
      • Isolated margin
      • Debt management
      • Health factor
  • 🤝Contribute
    • Hashstack Layer 3 Integration
    • Creating Proposals on Github
  • Additional Documentation
    • 🏰Document Hub
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Supply and Borrow

Supply

PreviousIntroductionNextBorrow

Last updated 1 year ago

Was this helpful?

When a user supplies funds to the protocol, they receive rTokens. We use the following formula (as per EIP 4626) to calculate the number of tokens minted to the user.

rTokensnew=Assetnew⋅rTokenstotalAssettotal rTokens_{new} = \frac{Asset_{new} \cdot rTokens_{total}}{Asset_{total}}rTokensnew​=Assettotal​Assetnew​⋅rTokenstotal​​

The formula uses existing total rTokens supply and Total asset supply to decide the quantity of rTokens to be minted as per the user deposit.

Assettotal=Asset.balanceOf(contract)+Assetslent+InterestaccruedAsset_{total} = Asset.balanceOf(contract) + Assets_{lent} + Interest_{accrued}Assettotal​=Asset.balanceOf(contract)+Assetslent​+Interestaccrued​

// Definitions
Assets_lent => Assets borrowed by borrower contract to issue loans to the user
Interest_accrued => Interest recievable by suppliers since last update

The contract exposes the following features for user and open contracts to interact with:

  1. User: Technically, a user can usually perform 3 main actions with supplier contract: Deposit, Withdraw & Transfer. User can further use the received rTokens as collateral to borrow or stake to earn higher yield.

  1. Open: The supply contract provides special privileges to the Open contract to allow it for some book-keeping. These options include:

  • Accrue the interest

  • Lock/unlock supply - to prevent the transfer of collateralised supply

  • Transfer & withdraw supplied funds on the users behalf - to liquidate the loan

  • Borrow and repay - to utilise funds to issue & close loans

💰
Fig. 2 - Supply use-cases