Uniswap Data x The Graph
This high-level post will explore how Uniswap and other defi community members use The Graph for tracking on-chain data. Towards the end we’ll dive into some new features of the Uniswap V3 Subgraph and The Graph Network.
Subgraphs and Uniswap Data
Subgraphs have always been an important tool for providing Uniswap data. The Graph’s hosted service makes it easy to write logic and track information on all Uniswap pools, even as more pools get created over time. Since Uniswap V1, subgraphs have powered multiple Uniswap analytics sites like Uniswap Info.
Subgraphs have been created for other Uniswap related initiatives as well like governance and advanced LP data. These have been used to power analytics sites such as Sybil, Pools.fyi, Croco Finance and more. Most of these subgraphs are open sourced, and an emerging community is being formed around Uniswap data specifically. Just searching for “Uniswap” on The Graph Explorer will give you pages of results.
The Graph allows developers to rapidly iterate on tracking solutions without having to spin up custom chain indexers, backends, or API endpoints. This, plus the open source nature of many subgraphs, has helped bootstrap a large percentage of Uniswap analytics so far.
Uniswap Data is Important
Obviously it is important to have accessible data for the current state and historical usage of a protocol like Uniswap. Uniswap data is consumed by multiple user-types, each with their own goals.
Aggregate data for all Uniswap pools gives key insights into how Uniswap is working in relation to other AMMs and DeFi projects in general. Things like total aggregate liquidity and volume are key metrics that can be used to evaluate where Uniswap fits in the broader context.
Liquidity providers need data to identify which pools are performing best. LPs can use things like historical volume, current projected APY, and more to help inform the decisions they make around providing liquidity.
Governance participants use Uniswap data to view information on both delegates and proposals. Exposing this data on sites like Sybil makes it more clear what is happening in the sphere of Uniswap governance.
All of this data is important to expose for the Uniswap community, and especially important in Uniswap V3. Without subgraphs, providing this data would require a lot of custom infrastructure, and the community would move slower as a result.
Subgraphs in Uniswap V3
Like other versions of Uniswap, it’s important to provide a public endpoint for data on Uniswap V3. Uniswap subgraphs work by following a few key patterns. First, events are tracked on the factory contract that track when new pools are created. Then, a template is used to start tracking events on the new pool itself. Entities are created for various things like tokens, pools, LPs, Uniswap as a whole, and more. Many tracked entities on Uniswap V3 are similar to V2, but there are also a lot of new entities that need to exist in order to provide necessary data for analytics services.
One new requirement in V3 is tracking tick data. Ticks are the boundaries that separate areas in price space. For any liquidity position that is created in V3, there is an upper and lower tick that represents the price range where the position is active. As a result of this, there is a non-uniform distribution of liquidity across ticks in every pool. Tracking this data is useful for things like visualizing the distribution of liquidity around certain prices and tracking per-position data as positions move in and out of range.
V3 also uses a new position manager contract for simplifying the process of adding and removing liquidity. This contract interacts with the core V3 contracts, and emits its own set up events as users update liquidity positions. The V3 subgraph uses the events emitted on this contract to track data around user positions.
Another powerful feature of V3 is the ability to set and execute range orders. Range orders basically simulate a limit order and are created by adding liquidity at the minimum range size. These types of orders would be another interesting data point to track and could be monitored using logic in the V3 subgraph. (Coming soon!).
These new techniques along with the standard entities (pools, tokens, interval datas, etc) power sites like Uniswap Info and give a glimpse into the current and historical state of Uniswap V3.
Community Approach to Data
Building the V3 subgraph and analytics sites has been the most collaborative process so far. Various teams like Croco Finance and Sommelier Finance have contributed so far. This has allowed the V3 subgraph to support a lot of useful features in just a short amount of time following V3 launch.
This V3 subgraph is currently being used on the Uniswap Info site, but also for new features like LP position simulation shown here
The community around data in defi has been growing at a fast pace. We’re seeing this through organizations like Uniswap Grants funding analytics related projects, and with teams forking and improving subgraphs. This type of collaboration will allow the defi community to rapidly improve the data services that exists around these core protocols.
Uniswap x The Graph Network — What’s Next
The Graph Network is gaining more momentum and the hosted service is beginning to wind down. The network allows for Indexers, Curators, Delgators, and subgraph creators to work together to host subgraphs. This migration will allow more individuals to play a role in how Uniswap data is indexed and hosted.
First, it creates a streamlined way for indexers to compete to index the Uniswap subgraphs. Hopefully this competition drives indexers to create new solutions to address outstanding issues such as indexing speed and log availability.
Next, the network should incentivize subgraph developers to create their own use-case specific subgraphs (as they now earn rewards for queries made against their subgraphs). This would address another issue with the current Uniswap subgraphs — they tend to hold a lot of data and can become bulky and slow to index very quickly. New feature-specific subgraphs could be used to power various analytics features like
- Advanced LP position data
- In-depth tick data
- ROI simulators
- Position comparisons and top performance rankings
Since launch, The Graph has helped visualize and explore Uniswap V3. As the community grows and more research is done, subgraphs will certainly be used to power a variety of tools used by defi enthusiasts, LPs, developers and more. The Graph network will create new incentive mechanisms and we’ll see what new subgraphs get created as a result. There are still so many gaps when it comes to filling needs around data, and developers should jump on this oppurtunity to build solutions.
Resources
Uniswap V3 Subgraph code — https://github.com/Uniswap/uniswap-v3-subgraph
Uniswap Info — https://info.uniswap.org/#/
About Uniswap
Uniswap is a decentralized trading protocol that empowers developers, liquidity providers and traders to participate in a financial marketplace that is open and accessible to all.
Anyone can contribute to Uniswap. To learn more visit https://uniswap.org/
About The Graph
The Graph is the indexing and query layer of the decentralized web. Developers build and publish open APIs, called subgraphs, that applications can query using GraphQL. The Graph currently supports indexing data from Ethereum, IPFS, and PoA with more networks coming soon. To date, over 11,000 subgraphs have been deployed by ~17,000 developers for applications, such as Uniswap, Synthetix, Aragon, Gnosis, Balancer, Livepeer, DAOstack, AAVE, Decentraland, and many others.
If you are a developer building an application or Web3 application, you can use subgraphs for indexing and querying data from blockchains. The Graph allows applications to efficiently and performantly present data in a UI and allows other developers to use your subgraph too! You can deploy a subgraph or query existing subgraphs that are in the Graph Explorer. The Graph would love to welcome you to be Indexers, Curators and/or Delegators on The Graph’s mainnet. Join The Graph community by introducing yourself in The Graph Discord for technical discussions, join The Graph’s Telegram chat, or follow The Graph on Twitter! The Graph’s developers and members of the community are always eager to chat with you, and The Graph ecosystem has a growing community of developers who support each other.