From 13052cd3d8f2d7d4da7eb749c1c5f6bb922b2498 Mon Sep 17 00:00:00 2001 From: Marcus Aurelius Date: Wed, 24 Apr 2024 10:14:38 -0500 Subject: [PATCH] Migrate to decentralized network subgraphs --- .github/workflows/deploy.yaml | 1 + k8s/base/deployment.yaml | 5 +++++ k8s/secret.properties.template | 1 + src/constants.py | 27 +++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 3b26d7f..2752b05 100755 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -39,6 +39,7 @@ jobs: needs: build-docker env: AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + GRAPH_API_KEY: ${{ secrets.GRAPH_API_KEY }} POLYGONSCAN_API_KEY: ${{ secrets.POLYGONSCAN_API_KEY }} WEB3_PROVIDER_ETH_URL: ${{ secrets.WEB3_PROVIDER_ETH_URL }} WEB3_PROVIDER_POLYGON_URL: ${{ secrets.WEB3_PROVIDER_POLYGON_URL }} diff --git a/k8s/base/deployment.yaml b/k8s/base/deployment.yaml index fc90230..594c69a 100644 --- a/k8s/base/deployment.yaml +++ b/k8s/base/deployment.yaml @@ -35,3 +35,8 @@ spec: secretKeyRef: name: discord-bots-secret key: POLYGONSCAN_API_KEY + - name: GRAPH_API_KEY + valueFrom: + secretKeyRef: + name: discord-bots-secret + key: GRAPH_API_KEY diff --git a/k8s/secret.properties.template b/k8s/secret.properties.template index 19d8c1c..55ea5c5 100644 --- a/k8s/secret.properties.template +++ b/k8s/secret.properties.template @@ -26,3 +26,4 @@ DISCORD_WEBHOOK_BROKEN_BOND_ALERT=${DISCORD_WEBHOOK_BROKEN_BOND_ALERT} POLYGONSCAN_API_KEY=${POLYGONSCAN_API_KEY} WEB3_PROVIDER_ETH_URL=${WEB3_PROVIDER_ETH_URL} WEB3_PROVIDER_POLYGON_URL=${WEB3_PROVIDER_POLYGON_URL} +GRAPH_API_KEY=${GRAPH_API_KEY} diff --git a/src/constants.py b/src/constants.py index cfb9cc7..28bf5e4 100755 --- a/src/constants.py +++ b/src/constants.py @@ -1,3 +1,5 @@ +import os + from web3 import Web3 # Hard-coded since Polygon block times have stabilized @@ -46,7 +48,24 @@ DAO_WALLET_ADDRESS = Web3.to_checksum_address('0x65a5076c0ba74e5f3e069995dc3dab9d197d995c') # Subgraphs -KLIMA_PROTOCOL_SUBGRAPH = 'https://api.thegraph.com/subgraphs/name/klimadao/klimadao-protocol-metrics' -KLIMA_CARBON_SUBGRAPH = 'https://api.thegraph.com/subgraphs/name/klimadao/polygon-bridged-carbon' -KLIMA_BONDS_SUBGRAPH = 'https://api.thegraph.com/subgraphs/name/klimadao/klimadao-bonds' -POLYGON_DIGITAL_CARBON_SUBGRAPH = 'https://api.thegraph.com/subgraphs/name/klimadao/polygon-digital-carbon' +GRAPH_API_KEY = os.environ.get('GRAPH_API_KEY') +GRAPH_BASE_URL = f'https://gateway-arbitrum.network.thegraph.com/api/{GRAPH_API_KEY}/subgraphs/id/' +GRAPH_DEV_BASE_URL = 'https://api.studio.thegraph.com/query/71975/' +GRAPH_VERSION_SUFFIX = '/version/latest' + +# TODO: upgrade all IDs to latest production versions once upgraded +PROTOCOL_SUBGRAPH_ID = 'AiHH7a5AJwnn8zAuENy3586m82fgosUs2346LWKgxmTJ' +CARBON_SUBGRAPH_ID = '9skh5pMQGRdyJcBe8PjWdDjLoYqoYTMLRDpFh6acSHUu' +BONDS_SUBGRAPH_ID = 'D7bejmu4JQ9mnnQhhrs6b3iEL17nviNuLhN5RJkeUDFn' +POLYGON_DIGITAL_CARBON_ID = 'ECLEwJKgujmiRCW1XbfbbUbpae2igeHa2KJ6BXNSWrZF' + +if os.environ.get('ENV') == 'production': + KLIMA_PROTOCOL_SUBGRAPH = GRAPH_BASE_URL + PROTOCOL_SUBGRAPH_ID + KLIMA_CARBON_SUBGRAPH = GRAPH_BASE_URL + CARBON_SUBGRAPH_ID + KLIMA_BONDS_SUBGRAPH = GRAPH_BASE_URL + BONDS_SUBGRAPH_ID + POLYGON_DIGITAL_CARBON_SUBGRAPH = GRAPH_BASE_URL + POLYGON_DIGITAL_CARBON_ID +else: + KLIMA_PROTOCOL_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-klimadao-protocol-metrics' + GRAPH_VERSION_SUFFIX + KLIMA_CARBON_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-polygon-bridged-carbon' + GRAPH_VERSION_SUFFIX + KLIMA_BONDS_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-klimadao-bonds' + GRAPH_VERSION_SUFFIX + POLYGON_DIGITAL_CARBON_SUBGRAPH = GRAPH_DEV_BASE_URL + 'staging-polygon-digital-carbon' + GRAPH_VERSION_SUFFIX