StreamingFacts — Understanding the Costs of Upgrading a Subgraph

StreamingFast
3 min readAug 25, 2021

As a subgraph developer, you are creating the building blocks that make up the foundation of The Graph. While the subgraphs you carefully craft may meet the needs of today, they may have to be upgraded to meet the needs of tomorrow. Before upgrading your subgraph, it’s best to understand the true costs associated.

Gas Costs — Ethereum Network Fees

When deploying a brand new subgraph, you will consume between 125,000 and 150,000 gas. This transaction would involve no curation share minting, no transfer of GRT, simply the creation of the subgraph:

  • setting the account
  • deployment ID
  • version metadata
  • subgraph metadata

Then, once the initial Curator comes to signal on this subgraph, that transaction will

  • initialize the curation share tokens
  • initialize the bonding curve
  • transfer tokens into the Graph Proxy
  • burn 2.5% of those tokens
  • issue the curation shares

This will consume roughly 1,300,000 gas, so about 10 times the amount of simply deploying. Subsequently, others who curate on this subgraph will consume approximately 240,000 gas.

When upgrading a subgraph, you will pay a similar amount of gas as the initial curator (1,300,000 gas). This cost can only be paid by the owner of the subgraph. This will

  • burn the curation shares on the existing deployment
  • set up the bonding curve on the new deployment
  • move the auto-migrate signal from the old version to the new version

It’s worthwhile noting here that there is work being done to allow for the subgraph developer, should they choose to do so, to both deploy and signal on the subgraph in one transaction. In this case, you’d be performing a more gas-intensive transaction.

Upgrade Tax — Graph Network Fees

When upgrading a subgraph, there are two taxes that occur: the subgraph developer will need to pay 1.25% of all GRT that is currently being signalled in the bonding curve’s reserve of GRT tokens, as well as a burning of 2.5% of all GRT in the reserve after their deposit (effectively 1.25% that the subgraph developer pays, and 1.25% that the reserve pays). The amount of GRT that the subgraph developer will need to deposit is actually slightly above 1.25%, as they will need to account for burning 2.5% of the amount they will now add into the reserve. For those who want to understand this from the source code itself, let’s take a look.

In the GNS.sol smart contract, you’ll find the relevant code for this calculation. If we were to rewrite the calculation in a more readable way, it would look like this:

PPM = 1,000,000 (100% in parts per million)
curation% = 25,000 (2.5% in parts per million)
owner% = 500,000 (50% in parts per million, this is 50% of the 2.5%, or 1.25%)

Below, we have included sample calculations so that you can see both the cost to the Subgraph Developer, as well as the cost to the Curators through the amount that is burned from the reserve.

Prices taken from CoinGecko.com and Gas Price as found from gasnow.org, both on August 18, 2021

Understanding both the cost to yourself, as well as the impact it will have on the Curators of your subgraph, you’ll need to decide on a balance between constant innovation and economic costs. There is no correct answer, although communication directly with Curators will probably help.

--

--

StreamingFast

StreamingFast is a protocol infrastructure company that provides a massively scalable architecture for streaming blockchain data.