stones/scripts/moloch_dao/check_subgraph.py

147 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""
Check DAOhaus v3 Subgraph
This script checks if the DAOhaus v3 subgraph on Optimism is responding
and lists any available DAOs without filtering.
"""
import requests
import json
# Constants
SUBGRAPH_URLS = [
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-optimism",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-goerli",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-gnosis",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-arbitrum",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-polygon",
"https://api.thegraph.com/subgraphs/name/hausdao/daohaus-v3-celo"
]
def check_subgraph(url):
"""
Check if a subgraph is responding
Args:
url: The subgraph URL to check
Returns:
True if responding, False otherwise
"""
# Simple query to check if subgraph is responding
query = """
query {
_meta {
block {
number
}
deployment
hasIndexingErrors
}
}
"""
try:
# Make request to subgraph
response = requests.post(
url,
json={"query": query}
)
# Check for errors
if response.status_code != 200:
print(f"Error checking subgraph: {response.text}")
return False
data = response.json()
# Check if response has data
if not data.get("data") or not data["data"].get("_meta"):
print(f"Invalid response from subgraph: {data}")
return False
# Get meta data
meta = data["data"]["_meta"]
print(f"Subgraph is responding at {url}")
print(f"Block number: {meta['block']['number']}")
print(f"Deployment: {meta['deployment']}")
print(f"Has indexing errors: {meta['hasIndexingErrors']}")
print("-" * 50)
return True
except Exception as e:
print(f"Exception checking subgraph: {e}")
return False
def list_daos(url):
"""
List all DAOs in a subgraph
Args:
url: The subgraph URL to query
"""
# GraphQL query to list all DAOs
query = """
query {
daos(first: 10) {
id
name
createdAt
totalShares
totalLoot
activeMemberCount
}
}
"""
try:
# Make request to subgraph
response = requests.post(
url,
json={"query": query}
)
# Check for errors
if response.status_code != 200:
print(f"Error listing DAOs: {response.text}")
return
data = response.json()
# Check if DAOs exist
if not data.get("data") or not data["data"].get("daos"):
print("No DAOs found")
return
# Get DAOs
daos = data["data"]["daos"]
print(f"Found {len(daos)} DAOs")
# Print results
for dao in daos:
print(f"ID: {dao['id']}")
print(f"Name: {dao['name']}")
print(f"Created: {dao['createdAt']}")
print(f"Members: {dao['activeMemberCount']}")
print(f"Shares: {dao['totalShares']}")
print(f"Loot: {dao['totalLoot']}")
print("-" * 50)
except Exception as e:
print(f"Exception listing DAOs: {e}")
def main():
"""Main function"""
print("Checking DAOhaus v3 subgraphs...")
for url in SUBGRAPH_URLS:
print(f"\nChecking subgraph at {url}...")
if check_subgraph(url):
print("\nListing DAOs in subgraph...")
list_daos(url)
return 0
if __name__ == "__main__":
main()