stones/scripts/moloch_dao/explore_daohaus_subgraph.py

227 lines
5.4 KiB
Python

#!/usr/bin/env python3
"""
Explore DAOhaus v3 Subgraph
This script explores the DAOhaus v3 subgraph and lists all available DAOs.
It can also search for DAOs by name or ID.
"""
import sys
import requests
import json
import argparse
# Constants
SUBGRAPH_URL = "https://api.thegraph.com/subgraphs/id/HouDe2pTdyKM9CTG1aodnPPPhm7U148BCH7eJ4HHwpdQ"
def list_daos(limit=100, skip=0):
"""
List all DAOs in the subgraph
Args:
limit: Maximum number of DAOs to return
skip: Number of DAOs to skip
Returns:
List of DAOs
"""
# GraphQL query to list all DAOs
query = """
query {
daos(first: %d, skip: %d, orderBy: createdAt, orderDirection: desc) {
id
name
createdAt
totalShares
totalLoot
activeMemberCount
}
}
""" % (limit, skip)
# Make request to subgraph
response = requests.post(
SUBGRAPH_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")
return daos
def search_daos_by_name(name, limit=100):
"""
Search for DAOs by name
Args:
name: Name to search for
limit: Maximum number of DAOs to return
Returns:
List of matching DAOs
"""
# GraphQL query to search for DAOs by name
query = """
query {
daos(first: %d, where: {name_contains_nocase: "%s"}, orderBy: createdAt, orderDirection: desc) {
id
name
createdAt
totalShares
totalLoot
activeMemberCount
}
}
""" % (limit, name)
# Make request to subgraph
response = requests.post(
SUBGRAPH_URL,
json={"query": query}
)
# Check for errors
if response.status_code != 200:
print(f"Error searching DAOs: {response.text}")
return []
data = response.json()
# Check if DAOs exist
if not data.get("data") or not data["data"].get("daos"):
print(f"No DAOs found with name containing '{name}'")
return []
# Get DAOs
daos = data["data"]["daos"]
print(f"Found {len(daos)} DAOs with name containing '{name}'")
return daos
def get_dao_by_id(dao_id):
"""
Get a DAO by ID
Args:
dao_id: ID of the DAO to get
Returns:
DAO data if found, None otherwise
"""
# GraphQL query to get a DAO by ID
query = """
query {
dao(id: "%s") {
id
name
createdAt
totalShares
totalLoot
activeMemberCount
members {
id
memberAddress
shares
loot
createdAt
}
}
}
""" % dao_id.lower()
# Make request to subgraph
response = requests.post(
SUBGRAPH_URL,
json={"query": query}
)
# Check for errors
if response.status_code != 200:
print(f"Error getting DAO: {response.text}")
return None
data = response.json()
# Check if DAO exists
if not data.get("data") or not data["data"].get("dao"):
print(f"DAO not found with ID: {dao_id}")
return None
# Get DAO
dao = data["data"]["dao"]
print(f"Found DAO with 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(f"Member count: {len(dao['members'])}")
return dao
def print_dao_info(dao):
"""
Print information about a DAO
Args:
dao: DAO data to print
"""
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)
def main():
"""Main function"""
parser = argparse.ArgumentParser(description="Explore DAOhaus v3 Subgraph")
parser.add_argument("--list", action="store_true", help="List all DAOs")
parser.add_argument("--search", type=str, help="Search for DAOs by name")
parser.add_argument("--id", type=str, help="Get a DAO by ID")
parser.add_argument("--limit", type=int, default=100, help="Maximum number of DAOs to return")
parser.add_argument("--skip", type=int, default=0, help="Number of DAOs to skip")
args = parser.parse_args()
if args.id:
# Get a DAO by ID
dao = get_dao_by_id(args.id)
if dao:
print_dao_info(dao)
elif args.search:
# Search for DAOs by name
daos = search_daos_by_name(args.search, args.limit)
for dao in daos:
print_dao_info(dao)
elif args.list:
# List all DAOs
daos = list_daos(args.limit, args.skip)
for dao in daos:
print_dao_info(dao)
else:
# Default to listing all DAOs
print("Listing all DAOs...")
daos = list_daos(args.limit, args.skip)
for dao in daos:
print_dao_info(dao)
return 0
if __name__ == "__main__":
sys.exit(main())