tradingstrategy-ai/web3-ethereum-defi

Investigate Uniswap v3 and getting historical price data in good format

Closed this issue · 6 comments

  • Github and other searches to find Python (and JavaScript) open source examples for getting data out from Uniswap v3
  • Data structure how to store this data in the (SQL) database for historical queries

Question that needs to be answered:

  • Given (chain id, Uniswap v3 deployment address)
  • What is the historical price for buy/sell (timestamp, trading pair, token0 quantity in) -> token1 quantity out

Can be a single pool price at milestone 1, later expanded to cover auto routing and multi-hop trades.

Search on Github and PyPI about Python and Uniswap v3 reveals that there isn't any one library that could do this at the moment. In short the code to get data out of Uniswap v3 is very fragmented for the time being.
Some notable ones are:

GraphQL based solution can use existing subgraphs like:

There are several onchain oracle solutions too, might not be very useful for above purpose:

We need to decide if we take JSON-RPC event-based approach or GraphQL based approach.

  • GraphQL might be more generic and we can reuse existing graphs
  • GraphQL adds very complex dependency if we want (and we want) to be able to run locally

Let's tackle the Uni v3 deployment first.

  • We are currently only hosting Sushiswap contracts so we need to recreate the workflow to build in Uni v3 contracts compield
  • The same approach that we use for Sushiswap contracts likely works for Uniswap contracts as well - we pull them in as Git submodules, then use their native tooltchain to compile contracts and then copy over the compiled binary artifacts to our abi folder