# Protocol Maintenance SOP :: Subgraph Deployment # Overview This guide will explain how to (1) deploy subgraphs to each network the DAOhaus protocol supports AND (2) how to fund the studio subgraph query fees. This is not a guide for developing subgraphs and/or how to use them within the DAOhaus protocol. You can find more info on that in other docs sections and here: - [The Graph development docs](https://thegraph.com/docs/en/quick-start/) Find code and deployed subgraphs here: - [Monorepo subgraph code](https://github.com/HausDAO/monorepo/tree/develop/apps/moloch-v3-subgraph) - There are 2 places these subgraphs are deployed depending on the chain: - Hosted service - Optimism, Arbitrum, Polygon, Sepolia and Goerli - These live in under the hausdao account linked to the [hausdao github org](https://github.com/HausDAO) - [Here is the Polygon explorer for example](https://thegraph.com/hosted-service/subgraph/hausdao/daohaus-v3-polygon) - Studio/decentralized network - Eth mainnet, Base mainnet, and Gnosis chain - These are owned by a mainnet [gnosis safe multisig](https://app.safe.global/home?safe=eth:0x374c8E00B5fb9358F80d93367150EA2D97a994B1) - 0x374c8E00B5fb9358F80d93367150EA2D97a994B1 - [All urls here](https://docs.daohaus.club/subgraphs) ## Key Considerations ***DANGER ZONE*** Because these subgraphs are deep in the foundation of the DAOhaus protocol, changes can reverberate throughout the SDK and all apps built with it, so we need to be careful when making updates. It's usually best not to make subgraph code changes unless absolutely necessary. If you do make changes, all side effects should be assessed and tested before propagating throughout the protocol! **Dangerous changes include** - Removing fields that the SDK or apps might be relying on - Changing field types **Safer changes include** - Adding fields or tables Deployment to non-test subgraphs should happen all at the same time. The SDK and apps are makingthe same queries, so if a change happens in one subgraph and a query is updated, it'll break in the subgraph that isn't deployed. # How to So you've made your subgrpah code changes, tested and are ready to deploy? You first should familiarize yourself with the [deployment docs The Graph provides.](https://thegraph.com/docs/en/deploying/subgraph-studio/) Graph tooling installation instructions [are here](https://thegraph.com/docs/en/quick-start/#2-install-the-graph-cli) - make sure to install the Graph CLI. ```bash npm install -g @graphprotocol/graph-cli ``` You will need to deploy to both the hosted service and the studio/decentralized service. ### **HOSTED** **Step 1: Authenticate into the hosted service** Subgraph deployment is done with The Graph CLI. The DAOhaus monorepo wraps some of the commands, but you'll need to authenticate with the CLI directly. - To do this you'll need to be a member of the HausDAO github organization. - Then visit the [hosted service website](https://thegraph.com/hosted-service) - And log in with your github user account - Then you can visit your [dashboard](https://thegraph.com/hosted-service/dashboard) and navigate to the HausDAO account ![Screenshot from 2024-04-10 16-04-40](https://hackmd.io/_uploads/ByIQ6Y4xA.png) - This will reveal an ACCESS TOKEN that you need for authentication in the CLI ```bash graph auth https://api.thegraph.com/deploy/ <ACCESS TOKEN> ``` **Step 2: Prepare and deploy subgraph code** The Graph CLI generates and builds all the code needed for deployment. This will need to be done for each network: - generate subgraph.yaml ```bash nx run moloch-v3-subgraph:generate-config --network=sepolia ``` - generate/build code ```bash nx run moloch-v3-subgraph:generate-code ``` - deploy code ```bash nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-sepolia-2 --network=sepolia ``` - Success print out looks like: ![Screenshot from 2024-04-11 13-08-16](https://hackmd.io/_uploads/HJ4rrnHlA.png) - Repeat for each chain: generate subgraph.yaml, generate/build code and deploy. <iframe src="https://giphy.com/embed/l0Iyl55kTeh71nTXy" width="480" height="320" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/quizizz-l0Iyl55kTeh71nTXy">via GIPHY</a></p> ### **STUDIO** **Step 1: Authenticate into the studio and get DEPLOY KEY** You will need to sign into the subgraph studio with the multisig that owns the account. To do this you need to be a signer on that safe. Visit the [studio here](https://thegraph.com/studio/) Connect with the multisig: 0x374c8E00B5fb9358F80d93367150EA2D97a994B1 ![Screenshot from 2024-04-11 10-41-07](https://hackmd.io/_uploads/B1VeBcrx0.png) ![Screenshot from 2024-04-11 10-41-12](https://hackmd.io/_uploads/S1cXHqSgA.png) ![Screenshot from 2024-04-11 10-42-08](https://hackmd.io/_uploads/HJ_Er5BgR.png) ![Screenshot from 2024-04-11 10-42-18](https://hackmd.io/_uploads/B1KUBqHl0.png) When connected the dashboard will look like this: ![Screenshot from 2024-04-11 10-43-37](https://hackmd.io/_uploads/ryqwS9Bx0.png) Then you can click into one of the subgraphs to find the DEPLOY KEY. Save that to use later. https://thegraph.com/studio/subgraph/daohaus-v3/ https://thegraph.com/studio/subgraph/daohaus-v3-gnosis/ https://thegraph.com/studio/subgraph/daohaus-v3-base/ Also note the name and current version of each subgraph so you can bump that when you deploy. ![Screenshot from 2024-04-11 10-46-54](https://hackmd.io/_uploads/rJ2VL9HlA.png) **Step 2: Authenticate into the CLI with the DEPLOY KEY** Back in your terminal go into the monorepo directory and run: ```bash graph auth --studio <DEPLOY KEY> ``` **Step 3: Prepare and deploy subgraph code** The Graph CLI generates and builds all the code needed for deployment. This will need to be done in order for each network. - generate subgraph.yaml ```bash nx run moloch-v3-subgraph:generate-config --network=mainnet ``` - generate/build code ```bash nx run moloch-v3-subgraph:generate-code ``` - deploy code - you need to use the subgraph name here (seenin the urls from the dashboard) and bump the version number you looked at for each network here. ```bash nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3 --network=mainnet --semver=0.6.9 ``` - Success print out looks like: ![Screenshot from 2024-04-11 11-24-28](https://hackmd.io/_uploads/BkMJaqrlA.png) Repeat for the other networks (base and gnosis/xdai in this case). Note the config generation step uses the name 'xdai' while the studio deployment uses the name 'gnosis'. You can see commands for [all networks here](https://github.com/HausDAO/monorepo/tree/develop/apps/moloch-v3-subgraph#deployment) **Step 4: Publish the new version in the studio** Note that as of writing this we only need to do this step on Mainnet and Gnosis. The Base subgraph doesn't require publishing just yet. Go back to the studio dashboard and navigate to your subgraph and select the new version. ![Screenshot from 2024-04-11 11-34-06](https://hackmd.io/_uploads/rJNmNjrl0.png) Use the publish button and initiate the publishing transaction. Select the Ethereum network in the publish form. This will create a proposal in the multisig that will publish once executed. ![Screenshot from 2024-04-11 11-49-54](https://hackmd.io/_uploads/SkOsNiHxA.png) ### **STUDIO SUBGRAPH HAUSKEEPING** **API keys** You can manage API keys from the studio dashboard at - https://thegraph.com/studio/apikeys/ - create new keys - restrict keys by domain - view key usage and fees assocaited to it **Billing** Manage billing at - https://thegraph.com/studio/billing/ - Monitor GRT balance - Add GRT if query balance is low ___ <iframe src="https://giphy.com/embed/iPB5nYr5pWPdK" width="480" height="269" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/iPB5nYr5pWPdK">via GIPHY</a></p> ### Command reference ### Subgraph yaml Generation ```bash nx run moloch-v3-subgraph:generate-config --network=goerli nx run moloch-v3-subgraph:generate-config --network=xdai nx run moloch-v3-subgraph:generate-config --network=mainnet nx run moloch-v3-subgraph:generate-config --network=optimism nx run moloch-v3-subgraph:generate-config --network=arbitrum-one nx run moloch-v3-subgraph:generate-config --network=matic nx run moloch-v3-subgraph:generate-config --network=sepolia nx run moloch-v3-subgraph:generate-config --network=base ``` ### Deployment ```bash nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-goerli --network=goerli nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-optimism --network=optimism nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-arbitrum --network=arbitrum-one nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-polygon --network=matic nx run moloch-v3-subgraph:graph-deploy --name=hausdao/daohaus-v3-sepolia-2 --network=sepolia ``` #### mainnet and gnosis chain deployment to studio ```bash nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3 --network=mainnet --semver=<version label> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-gnosis --network=gnosis --semver=<version label> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-base --network=base --semver=<version label> ```