Skip to content

Commit

Permalink
Organize
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcertora committed Jan 5, 2025
1 parent 59e6ddf commit d82e269
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 105 deletions.
120 changes: 26 additions & 94 deletions Quorum/apis/governance/aave_governance.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,9 @@
import requests
from typing import Optional, List
from pydantic import BaseModel, Field
import json5 as json
from Quorum.apis.governance.data_models import BGDProposalData, PayloadAddresses

# ==============================
# Constants / Endpoints
# ==============================
BASE_BGD_CACHE_REPO = 'https://raw.githubusercontent.com/bgd-labs/v3-governance-cache/refs/heads/main/cache'
PROPOSALS_URL = f'{BASE_BGD_CACHE_REPO}/1/0x9AEE0B04504CeF83A65AC3f0e838D0593BCb2BC7/proposals'
BASE_SEATBELT_REPO = 'https://github.com/bgd-labs/seatbelt-gov-v3/blob/main/reports'
SEATBELT_PAYLOADS_URL = f'{BASE_SEATBELT_REPO}/payloads'


# ==============================
# Chain Info Model
# ==============================
class ChainInfo(BaseModel):
name: str
block_explorer_link: str


# ==============================
# Data Models for BGD JSON
# ==============================
class IPFSData(BaseModel):
title: Optional[str] = None
discussions: Optional[str] = None


class PayloadData(BaseModel):
chain: str
payloads_controller: str = Field(alias='payloadsController')
payload_id: int = Field(alias='payloadId')

class Config:
allow_population_by_alias = True


class ProposalData(BaseModel):
payloads: list[PayloadData] = Field(default_factory=list)
votingPortal: Optional[str] = None
ipfsHash: Optional[str] = None


class EventArgs(BaseModel):
creator: Optional[str] = None
accessLevel: Optional[int] = None
ipfsHash: Optional[str] = None


class EventData(BaseModel):
transactionHash: Optional[str] = None
args: EventArgs = Field(default_factory=EventArgs)


class BGDProposalData(BaseModel):
"""
Represents the entire JSON structure returned by the BGD cache
for a given proposal.
"""
ipfs: Optional[IPFSData] = None
proposal: Optional[ProposalData] = None
events: List[EventData] = Field(default_factory=list)


class PayloadAddresses(BaseModel):
chain: str
addresses: List[str]


# ==============================
# Mapping for Chains
# ==============================
AAVE_CHAIN_MAPPING = {
'1': ChainInfo(name='Ethereum', block_explorer_link='https://etherscan.io/address'),
'137': ChainInfo(name='Polygon', block_explorer_link='https://polygonscan.com/address'),
'43114': ChainInfo(name='Avalanche', block_explorer_link='https://snowtrace.io/address'),
'8453': ChainInfo(name='Base', block_explorer_link='https://basescan.org/address'),
'42161': ChainInfo(name='Arbitrum One', block_explorer_link='https://arbiscan.io/address'),
'1088': ChainInfo(name='Metis', block_explorer_link='https://explorer.metis.io/address'),
'10': ChainInfo(name='OP Mainnet', block_explorer_link='https://optimistic.etherscan.io/address'),
'56': ChainInfo(name='BNB Smart Chain',block_explorer_link='https://bscscan.com/address'),
'100': ChainInfo(name='Gnosis', block_explorer_link='https://gnosisscan.io/address'),
'534352':ChainInfo(name='Scroll', block_explorer_link='https://scrollscan.com/address'),
'324': ChainInfo(name='zkSync Era', block_explorer_link='https://era.zksync.network/address'),
'59144': ChainInfo(name='Linea', block_explorer_link='https://lineascan.build/')
}


# ==============================
# AaveGovernanceAPI
# ==============================
class AaveGovernanceAPI:
"""
A utility class to interact with the BGD governance cache and retrieve
Expand All @@ -102,8 +15,13 @@ def __init__(self) -> None:

def get_proposal_data(self, proposal_id: int) -> BGDProposalData:
"""
Fetches the proposal data from the BGD governance cache and
returns a pydantic-validated object.
Fetches and returns the data for a given proposal.
Args:
proposal_id: The ID of the proposal to fetch.
Returns:
A BGDProposalData object.
"""
proposal_data_link = f'{PROPOSALS_URL}/{proposal_id}.json'
resp = self.session.get(proposal_data_link)
Expand All @@ -113,9 +31,17 @@ def get_proposal_data(self, proposal_id: int) -> BGDProposalData:
# Parse into our data model
return BGDProposalData(**raw_json)

def get_payload_addresses(self, chain_id: str, controller: str, payload_id: int) -> List[str]:
def get_payload_addresses(self, chain_id: str, controller: str, payload_id: int) -> list[str]:
"""
Fetches and returns the addresses from a given chain/payload.
Retrieves a list of payload addresses for a given payload ID, chain, and controller.
Args:
chain_id: The chain ID for the proposal.
controller: The controller for the proposal.
payload_id: The ID of the payload to fetch.
Returns:
A list of addresses that are part of the payload.
"""
url = f'{BASE_BGD_CACHE_REPO}/{chain_id}/{controller}/payloads/{payload_id}.json'
resp = self.session.get(url)
Expand All @@ -125,9 +51,15 @@ def get_payload_addresses(self, chain_id: str, controller: str, payload_id: int)
# We only need the 'target' field from each action
return [a['target'] for a in payload_data['payload']['actions']]

def get_all_payload_addresses(self, proposal_id: int) -> List[PayloadAddresses]:
def get_all_payloads_addresses(self, proposal_id: int) -> list[PayloadAddresses]:
"""
Retrieves a list of payload addresses for each chain in the proposal.
Retrieves all payload addresses for a given proposal.
Args:
proposal_id: The ID of the proposal to fetch.
Returns:
A list of PayloadAddresses objects, each containing a chain ID and a list of addresses.
"""
data = self.get_proposal_data(proposal_id)
results = []
Expand Down
47 changes: 47 additions & 0 deletions Quorum/apis/governance/data_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import List, Optional
from pydantic import BaseModel, Field

class IPFSData(BaseModel):
title: Optional[str] = None
discussions: Optional[str] = None


class PayloadData(BaseModel):
chain: str
payloads_controller: str = Field(alias='payloadsController')
payload_id: int = Field(alias='payloadId')

class Config:
allow_population_by_alias = True


class ProposalData(BaseModel):
payloads: list[PayloadData] = Field(default_factory=list)
votingPortal: Optional[str] = None
ipfsHash: Optional[str] = None


class EventArgs(BaseModel):
creator: Optional[str] = None
accessLevel: Optional[int] = None
ipfsHash: Optional[str] = None


class EventData(BaseModel):
transactionHash: Optional[str] = None
args: EventArgs = Field(default_factory=EventArgs)


class BGDProposalData(BaseModel):
"""
Represents the entire JSON structure returned by the BGD cache
for a given proposal.
"""
ipfs: Optional[IPFSData] = None
proposal: Optional[ProposalData] = None
events: List[EventData] = Field(default_factory=list)


class PayloadAddresses(BaseModel):
chain: str
addresses: List[str]
39 changes: 28 additions & 11 deletions Quorum/auto_report/aave_tags.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import json5 as json
from pydantic import BaseModel
from typing import Any, Dict

# Import the data models and API
from Quorum.apis.governance.aave_governance import (
AaveGovernanceAPI,
AAVE_CHAIN_MAPPING,
BASE_SEATBELT_REPO,
SEATBELT_PAYLOADS_URL,
BGDProposalData,
IPFSData,
ProposalData,
EventData,
)
from Quorum.apis.governance.aave_governance import AaveGovernanceAPI
from Quorum.apis.governance.data_models import BGDProposalData, IPFSData, ProposalData, EventData


BASE_SEATBELT_REPO = 'https://github.com/bgd-labs/seatbelt-gov-v3/blob/main/reports'
SEATBELT_PAYLOADS_URL = f'{BASE_SEATBELT_REPO}/payloads'


class ChainInfo(BaseModel):
name: str
block_explorer_link: str


AAVE_CHAIN_MAPPING = {
'1': ChainInfo(name='Ethereum', block_explorer_link='https://etherscan.io/address'),
'137': ChainInfo(name='Polygon', block_explorer_link='https://polygonscan.com/address'),
'43114': ChainInfo(name='Avalanche', block_explorer_link='https://snowtrace.io/address'),
'8453': ChainInfo(name='Base', block_explorer_link='https://basescan.org/address'),
'42161': ChainInfo(name='Arbitrum One', block_explorer_link='https://arbiscan.io/address'),
'1088': ChainInfo(name='Metis', block_explorer_link='https://explorer.metis.io/address'),
'10': ChainInfo(name='OP Mainnet', block_explorer_link='https://optimistic.etherscan.io/address'),
'56': ChainInfo(name='BNB Smart Chain',block_explorer_link='https://bscscan.com/address'),
'100': ChainInfo(name='Gnosis', block_explorer_link='https://gnosisscan.io/address'),
'534352':ChainInfo(name='Scroll', block_explorer_link='https://scrollscan.com/address'),
'324': ChainInfo(name='zkSync Era', block_explorer_link='https://era.zksync.network/address'),
'59144': ChainInfo(name='Linea', block_explorer_link='https://lineascan.build/')
}


def get_aave_tags(proposal_id: int) -> Dict[str, Any]:
Expand Down

0 comments on commit d82e269

Please sign in to comment.