# 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 manage the studio subgraph billing account. 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) All subgraphs are deployed to The Graph's decentralized network on Arbitrum. - The account that owns/manages theses is a [Safe on Arbitrum](https://app.safe.global/home?safe=arb1:0x08678A8d65D8d81bD13db617211F1E9CE176B2fB) - [All subgraphs urls can be found here](https://docs.daohaus.club/subgraphs) ## DEPLOYING SUBGRAPHS ***Who? How often?** ### 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 **Prepare** So you've made your subgraph 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 ``` **Step 1: Authenticate into the studio and get the DEPLOY KEY** You will need to sign into the subgraph studio with the safe 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 Arbitrum safe that owns the account: 0x08678A8d65D8d81bD13db617211F1E9CE176B2fB ![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. 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 (seen in 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 ``` - Successful output: ![Screenshot from 2024-04-11 11-24-28](https://hackmd.io/_uploads/BkMJaqrlA.png) Repeat for the other networks. Note the config generation step uses the name 'xdai' while the studio deployment uses the name 'gnosis'. Command cheat sheet for copy and paste [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 Arbitrum network in the publish form. This will create a proposal in the safe that will publish once signed by enough safe owners and executed. ![Screenshot from 2024-04-11 11-49-54](https://hackmd.io/_uploads/SkOsNiHxA.png) ## MANAGING STUDIO BILLING ACCOUNT ***Who? How often?** **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 **Each month** we should check the `dh v3 dev` key to ensure it has not gone over it's alloted usage. This key is not restrained to a domain and if leaked could be missued. If it's over the limit, delete that key and create a new dev key with the same monthly limit. **Billing** Manage billing at - https://thegraph.com/studio/billing/ - Monitor GRT balance - Add GRT if query balance is low To add Balance 1. Visit https://thegraph.com/studio/billing/ 2. Click `Manage Plan` 3. Click `Deposit from Wallet` 4. Adjust the amount and follow the prompts to add balance. This will create a new transaction in the safe that will add GRT when executed. ___ <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> ## REFERENCE **Commands used in deployment** ### 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-studio --name=daohaus-v3 --network=mainnet --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-base --network=base --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-sepolia-2 --network=sepolia --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-polygon --network=matic --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-arbitrum --network=arbitrum-one --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-optimism --network=optimism --semver=<NEW VERSION NUMBER> nx run moloch-v3-subgraph:graph-deploy-studio --name=daohaus-v3-gnosis --network=xdai --semver=<NEW VERSION NUMBER> ``` ```