Skip to content

Commit

Permalink
274 change the subgraph api to use new graph network endpoints (#275)
Browse files Browse the repository at this point in the history
* Updated conditional_tokens subgraph | added api_key to env

* Bumped version

* Fixed isort

* Added missing subgraph URLs

* Small fixes

* Retrieving secret_value from SecretStr

* Added missing ENV vars
  • Loading branch information
gabrielfior authored Jun 12, 2024
1 parent 2d5e14d commit f1b020b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MANIFOLD_API_KEY=
BET_FROM_PRIVATE_KEY=
OPENAI_API_KEY=
OPENAI_API_KEY=
GRAPH_API_KEY=
1 change: 1 addition & 0 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
BET_FROM_PRIVATE_KEY: ${{ secrets.BET_FROM_PRIVATE_KEY }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GNOSIS_RPC_URL: ${{ secrets.GNOSIS_RPC_URL }}
GRAPH_API_KEY: ${{ secrets.GRAPH_API_KEY }}

jobs:
mypy:
Expand Down
7 changes: 7 additions & 0 deletions prediction_market_agent_tooling/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class APIKeys(BaseSettings):
BET_FROM_PRIVATE_KEY: t.Optional[PrivateKey] = None
SAFE_ADDRESS: t.Optional[ChecksumAddress] = None
OPENAI_API_KEY: t.Optional[SecretStr] = None
GRAPH_API_KEY: t.Optional[SecretStr] = None

GOOGLE_SEARCH_API_KEY: t.Optional[SecretStr] = None
GOOGLE_SEARCH_ENGINE_ID: t.Optional[SecretStr] = None
Expand Down Expand Up @@ -72,6 +73,12 @@ def openai_api_key(self) -> SecretStr:
self.OPENAI_API_KEY, "OPENAI_API_KEY missing in the environment."
)

@property
def graph_api_key(self) -> SecretStr:
return check_not_none(
self.GRAPH_API_KEY, "GRAPH_API_KEY missing in the environment."
)

@property
def google_search_api_key(self) -> SecretStr:
return check_not_none(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eth_typing import ChecksumAddress
from subgrounds import FieldPath, Subgrounds

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.gtypes import HexAddress, HexBytes, Wei, wei_type
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.markets.agent_market import FilterBy, SortBy
Expand All @@ -29,13 +30,11 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
Class responsible for handling interactions with Omen subgraphs (trades, conditionalTokens).
"""

OMEN_TRADES_SUBGRAPH = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai"
CONDITIONAL_TOKENS_SUBGRAPH = (
"https://api.thegraph.com/subgraphs/name/gnosis/conditional-tokens-gc"
)
REALITYETH_GRAPH_URL = (
"https://api.thegraph.com/subgraphs/name/realityeth/realityeth-gnosis"
)
OMEN_TRADES_SUBGRAPH = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz"

CONDITIONAL_TOKENS_SUBGRAPH = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/7s9rGBffUTL8kDZuxvvpuc46v44iuDarbrADBFw5uVp2"

REALITYETH_GRAPH_URL = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/E7ymrCnNcQdAAgLbdFWzGE5mvr5Mb5T9VfT43FqA7bNh"

INVALID_ANSWER = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"

Expand All @@ -49,12 +48,24 @@ def __init__(self) -> None:
after=lambda x: logger.debug(f"query_json failed, {x.attempt_number=}."),
)(self.sg.query_json)

keys = APIKeys()

# Load the subgraph
self.trades_subgraph = self.sg.load_subgraph(self.OMEN_TRADES_SUBGRAPH)
self.trades_subgraph = self.sg.load_subgraph(
self.OMEN_TRADES_SUBGRAPH.format(
graph_api_key=keys.graph_api_key.get_secret_value()
)
)
self.conditional_tokens_subgraph = self.sg.load_subgraph(
self.CONDITIONAL_TOKENS_SUBGRAPH
self.CONDITIONAL_TOKENS_SUBGRAPH.format(
graph_api_key=keys.graph_api_key.get_secret_value()
)
)
self.realityeth_subgraph = self.sg.load_subgraph(
self.REALITYETH_GRAPH_URL.format(
graph_api_key=keys.graph_api_key.get_secret_value()
)
)
self.realityeth_subgraph = self.sg.load_subgraph(self.REALITYETH_GRAPH_URL)

def _get_fields_for_bets(self, bets_field: FieldPath) -> list[FieldPath]:
markets = bets_field.fpmm
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.36.0"
version = "0.37.0"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down

0 comments on commit f1b020b

Please sign in to comment.