API Reference

Overview

Borrowing and Lending

ThirdFi offers borrow and lend services on-chain with REST API. Currently we are connecting to Aave and Venus protocols to provide supply, borrow, repay and withdraw functions.

Lend

What is Lend?

Lend is supplying the assets to the protocols, earning the interest on your deposit. The interest is generated based on:

  1. The interest rate payment on loans: Suppliers share the interests paid by borrowers corresponding to the average borrow rate times the utilisation rate. The higher the utilisation of a reserve the higher the yield for suppliers.
  2. Flash Loan fees: Suppliers receive a share of the Flash Loan fees corresponding to certain percentage of the Flash Loan volume.

Each asset has its own market of supply and demand with its own APY (Annual Percentage Yield) which evolves with time.

📘

What is Flash Loan?

Flash loans are a feature designed for developers, due to the technical knowledge required to execute one. Flash Loans allow you to borrow any available amount of assets without putting up any collateral, as long as the liquidity is returned to the protocol within one block transaction. To do a Flash Loan, you will need to build a contract that requests a Flash Loan. The contract will then need to execute the instructed steps and pay back the loan + interest and fees all within the same transaction.

Why Lend?

The lend (supply) functions are important for developers and users interacting with Aave and Venus protocols, as they enable the core functionality of lending assets and earning interest on the supplied collateral. Including these functions in ThirdFi's API simplifies the integration process and provides easy access to DeFi lending features.

There are several reasons why developers and users might need lend functions:

  1. Passive income: Lending assets in DeFi protocols like Aave and Venus allows users to earn passive income in the form of interest. Users can capitalize on their idle assets by supplying them to the protocol and receiving interest payments over time.
  2. Collateralization: Supplying assets to the protocol can enable users to access borrowing or other features offered by the platform. For example, users may need to supply collateral to the protocol to borrow other assets, mint stablecoins, or participate in yield farming strategies.
  3. Risk management: Lending assets in DeFi protocols can be a relatively low-risk investment strategy compared to more speculative activities such as trading or participating in highly leveraged positions. By lending their assets, users can earn a steady return while maintaining exposure to their original investment.
  4. Asset diversification: By lending assets to Aave or Venus, users may receive interest-bearing tokens (e.g., aTokens in Aave) that are pegged to the value of the underlying asset. These tokens can be used for additional investment or risk management strategies, providing users with more options to diversify their portfolio.

By providing lend (supply) functions in ThirdFi's API, developers can build applications that leverage the lending capabilities of Aave and Venus protocols, enabling users to access these opportunities and strategies with ease. This allows for the creation of innovative and user-friendly platforms that cater to the growing demand for DeFi lending services, while simultaneously simplifying the process of integrating these powerful DeFi protocols into existing or new applications.

How does Lend work?

  1. Get the list of lending pools via https://thirdfi.readme.io/reference/get_lending_pools and choose which pools that want to lend.
  2. Use the asset address or symbol and chain to create supply request via https://thirdfi.readme.io/reference/supply_session.
  3. Redirect the user to webview URL provided from API.
  4. User is able to supply the asset amount requested to the protocol with Web3 wallets.
  5. The user wallet will receive the interest-bearing tokens (aToken from Aave or vToken from Venus) from the protocols. The user position can be found via https://thirdfi.readme.io/reference/get_lending_position.

Borrow

What is Borrow?

Borrow is borrowing the assets against your supplied collateral in the liquidity protocols. User creates a borrow balance which begins accumulating interest based on the Borrow APY for the asset.

📘

What is Borrow APY?

Borrow APY (Annual Percentage Yield) is the interest accrued from your borrowing position (debt). The APY varies depending on multiple factors such as the underlying asset, market demand, and utilisation rate on different lending protocols.

For Aave, the interest rate model is based on a set of predefined parameters, including the optimal utilization rate and interest rate slopes. When the utilization rate is low, the borrow APY tends to be lower, and it increases as the utilization rate approaches the optimal level. Aave also implements a variable and stable interest rate model, giving borrowers the option to choose between a rate that fluctuates with market conditions or a rate that remains relatively stable over the borrowing period.

For Venus, the interest rate model is also based on the supply and demand dynamics for each asset. Venus utilizes a target utilization rate and interest rate slopes to determine the borrow APY. As the utilization rate changes, the interest rate will adjust accordingly to maintain market equilibrium.

To obtain the current borrow APY for specific assets on Aave or Venus, you can use ThirdFi's API or refer to the respective protocol's documentation, dashboard, or other data sources like DeFi tracking websites. Keep in mind that interest rates are subject to change based on market conditions and protocol parameters.

Why Borrow?

The borrow functions are essential for developers and users interacting with Aave and Venus protocols as they enable the core functionality of borrowing assets against supplied collateral. Including these functions in ThirdFi's API simplifies the integration process and provides easy access to DeFi borrowing features.

There are several reasons why developers and users might need borrow functions:

  1. Leverage: Borrowing allows users to gain exposure to additional assets without selling their existing holdings. They can use the borrowed assets to invest in other opportunities, potentially amplifying their returns.
  2. Liquidity: Borrowing can provide users with additional liquidity to manage short-term cash flow needs or to take advantage of new investment opportunities without having to liquidate their long-term holdings.
  3. Yield farming: Borrow functions enable users to participate in yield farming strategies, where they can borrow assets, use them to provide liquidity to other protocols or platforms, and earn additional rewards or yield.
  4. Short selling: Users can borrow assets they believe will decrease in value, sell them in the market, and later repurchase them at a lower price to repay the loan, profiting from the difference.
  5. Arbitrage: Borrowing can facilitate arbitrage opportunities, where users can take advantage of price differences between different markets or platforms by borrowing assets on one platform and selling them on another.

By providing borrow functions in ThirdFi's API, developers can build applications that leverage the borrowing capabilities of Aave and Venus protocols, enabling users to access these opportunities and strategies with ease.

How does Borrow work?

  1. Get the list of lending pools via https://thirdfi.readme.io/reference/get_lending_pools and choose which pools that want to borrow.
  2. Use the asset address or symbol and chain to create borrow request via https://thirdfi.readme.io/reference/borrow_session.
  3. Redirect the user to webview URL provided from API.
  4. User is able to borrow the asset amount requested based on the collateral balance with Web3 wallets. The user collateral balance can be find via https://thirdfi.readme.io/reference/get_lending_position.
  5. The user wallet will receive the borrowed tokens from the protocols.

List of chains we supported

This is useful in all the borrow and lend APIs.

Blockchain NetworkMainnetTestnetProtocols Connected
Ethereum-goerliAave (version 2)
ArbitrumarbitrumarbitrumTestnetAave (version 3)
BNB chainbscbscTestnetVenus
PolygonpolygonmumbaiAave (version 3)
AvalancheavalanchefujiAave (version 3)
OptimismoptimismoptimismTestnetAave (version 3)

Testnet Faucet

For the Aave protocol, check https://app.aave.com/faucet/ for getting testing ERC20 tokens for testnet testing. Remember to enable the Testnet mode in the global settings on the top right side, as screenshot shown.

For the Venus protocol, check https://www.faucet.thirdfi.org/ for getting testing ERC20 tokens for testnet testing.