Decentralised synthetic assets

Major Subgraph Improvements

Major Subgraph Improvements

We're excited to announce that we've recently released a major update to our subgraphs. This will allow for easier and more accurate queries of data from the Synthetix protocol via The Graph. If you're a developer who would like to start using them right away, head over to the synthetix-subgraph repository on GitHub.

This is the culmination of work over the last few months which includes data quality improvements, tooling updates for a superior developer experience, and infrastructure modifications that will streamline our support and maintenance.

All the data in one place

Previously, due to the scale and complexity of the Synthetix protocol, we've deployed multiple subgraphs to separate endpoints. This made it easier to manage modular updates and improved subgraph sync times, but it increased complexity for end users and internal maintenance. [1]

Now, we deploy a single subgraph that consolidates all of the indexed data into one endpoint per network. These are available on The Graph's hosted service for mainnet, kovan, optimism, and optimism-kovan.

The subgraph that indexes mainnet can also found be on The Graph's decentralized network. We plan to migrate the official dapps to rely on the network once it indexes Optimism and has improved support for frequently updated subgraphs.

There are a couple important caveats to keep in mind:

  • The subgraphs on the hosted service may be subject to breaking changes, as they don't currently support pinning versions.
  • Some of the data from the Optimism networks is incomplete due to the regenesis which occurred on November 11th, 2021.

Superior tooling

In the past, we’ve provided a package @synthetixio/data (and it's predecessor, synthetix-data) as a convenience for accessing data from the subgraphs in frontend applications and scripts. These are now both deprecated in favor of codegen-graph-ts and @synthetixio/queries.

codegen-graph-ts generates a TypeScript (or JavaScript) file with functions that query the data provided by the The Graph. In addition to providing types for the returned data, the generated functions automatically paginate requests. This library is not built specifically for Synthetix; you can use it with any subgraph endpoint available on the The Graph.

For example, you can use the following code snippet to generate a synthetix-subgraph.ts file:

npm i --save codegen-graph-ts
npx codegen-graph-ts gen -u -o synthetix-subgraph.ts

@synthetixio/queries wraps Synthetix's output from the codegen and adds some additional functionality for front-end applications built with React, including the ability to subscribe to real-time data updates. Our core and ecosystem applications are being migrated to rely on this library.

Improved data structures

We’ve added some new fields and filters to the subgraphs. These additions include:

  • Total.newExchanger field, which tracks a count of first-time users.
  • Hour, week, month, quarter, and year aggregations for the Total entity, in addition to the existing daily and fifteen minute aggregations.
  • Filters for synth exchanges and their aggregations, including which synth is being exchanged (SynthExchange_filter.toSynth and SynthExchange_filter.fromSynth) and the magnitude of the trade (Exchanger_filter.bucketMagnitude and Total_filter.bucketMagnitude).
  • SNXHolder.balanceOf field, which stores user balances.

Visit the playground in The Graph's web application to explore the data provided by the Synthetix subgraph.

More to come

We're excited to improve our core and ecosystem apps with this release, while making it easier for partners and external developers to access Synthetix's data. We have more improvements on the horizon as well, including new subgraph entities, fields, and filters.

If you have any questions or feedback about our subgraphs, reach out in the #dev-portal channel on the Synthetix Discord server or open an issue in the synthetix-subgraph repository.


[1] We will still maintain the ability to deploy individual subgraph modules for development and test purposes, but these deployments will not be recommended for official use.

Noah Litvin

Noah Litvin

Noah is a Core Contributor at Synthetix.