tradingstrategy-ai/web3-ethereum-defi

Get Aave lending and borrow rates directly from on-chain

Closed this issue · 0 comments

Aave has deployed its v3 version on Ethereum mainnet and Polygon.

See Ethereum markets - MetaMask required

image

The market has two sides

  • What lenders receive as a payment, called supply APR
  • What borrowers must pay for having a loan, called borrow APR

Business use case

  • Aave lending markets can be used to build a short position of tokens
  • By knowing how much borrowing costs, we know what is the cost of maintaining a short position

We need to be able to answer the questions

  • How much having a loan for a token e.g. ETH would have cost us historically

    • Opening amoun
    • Opening date
    • Closing date
    • Interest payments accumulated (how to calculate?)
  • How much having a loan for a token would cost us right now (current interest rate)

Note that the interest rate is paid in the pool native token. E.g. ETH will accrue ETH interest and needs to be converted to US Dollar in some point.

Task

  • Create a proof of concept Aave lending and borrow rate fetcher in Python
  • It must be a self-contained notebook similar to Uniswap v3 price example
  • Study how Aave v3 lending and borrow rates are reported. The rates are variable over time.
  • Make short README documentation of available events
  • Use a event reader Python module to read this data to a CSV file
  • Plot a graph using Plotly for the lending and borrow rate of one market, e.g. ETH
  • The graph matches what we have on the Aave website

References

Aave displays borrow rate on its main UI:

image

Aave is internally displaying this information on its website using RatesHistory API.

Aave internal MongoDB schema is here. It is using a cron job to update rates by reading them from Subgraph.

Aave Subgraph code is an undocumented mess.

The rate is probably determined by this event. See GithubSearch for ReserveDataUpdated.