Lido Subgraph Deployed on The Graph

in Ethereum by Nikolay P

We are happy to announce that our Subgraph is now deployed, indexed and ready to serve requests on the decentralized The Graph network.

 

Subgraph

Subgraph is a project which contains instructions how to index contract events. In simple terms, it tells an indexer which events to process, what data should be stored and how to store it.

 

It’s deployed to an indexer node, to which you make GraphQL queries like this to get the data:

 

{
      lidoTransfers(first: 100, where: { to: "0x123" }) {
        to
        value
        block
      }
}

 

As data served is pre-indexed, Subgraphs have major advantages compared to fetching events from an ETH node:

  • Faster responses.
  • Improved data formatting.
  • You only query parts of data you actually need.
  • No need to deal with ABIs and contract addresses.
  • No required dependencies, but a GraphQL-ready http fetching library is recommended for convenience.

 

Our Subgraph is open source on GitHub and has many example code snippets, mostly in Node.js.

 

It has some advanced indexing logic, which allows us to keep track of values like totalPooledEther and totalShares with precision of event index inside a transaction. This allows us to keep track of data missing from contract events (eg share amounts of transfers) and to calculate things like daily staking rewards with perfect Wei accuracy.

 

Currently, we index the following contracts:

  • Lido
  • Oracle
  • Node Operators Registry
  • Voting
  • EasyTrack
  • Deposit Security Module

 

 

The Graph Decentralized Network

Initially, our Subgraph was being hosted on The Graph Hosted Service. However, decentralized network is a clear major upgrade in terms of stability and request processing quality, so for us it was only a matter of time until we migrate:

 

  • Query fees are paid for requests, which allows sustainable economics.
  • Anyone can stake GRT to become an indexer.
  • There are many indexers indexing our Subgraph (13 currently), which are automatically selected for serving requests.
  • Indexers are rewarded, so they are motivated to maintain indexing quality and keep indexing in the long term.
  • There is no limit in the amount of skip variable in requests, so all available entities can be fetched.

 

How to Migrate Queries

Hosted Service version will still work for the time being, but we strongly advise you to migrate to the new version at your own pace.

 

You’ll need to get an API key and start paying for queries with GRT, but it’s quite straightforward:

  1. Get GRT tokens.
  2. Migrate GRT to Polygon (where billing is done) using the Subgraph Studio.
  3. Get an API token on the API keys page.

 

Then, change the endpoint you are making requests t0 to the following:

https://gateway.thegraph.com/api/KEY_HERE/subgraphs/id/HXfMc1jPHfFQoccWd7VMv66km75FoxVHDMvsJj5vG5vf

 

That’s it!

 

Periodically, make sure your GRT balance is sufficient. Fees are deducted weekly.

 

Usage Examples

  • Reward History: Daily staking rewards are calculated and displayed with transaction history.
  • Staking Widget: Our ETH staking widget displays statistics like the amount of stETH holders from our Subgraph.
  • EasyTracks: Archive motions are loaded from the Subgraph.
  • TokenTerminal: Daily statistics are loaded from our Subgraph to display protocol revenue and important metrics.