prediction-market-agent-tooling 0.61.1.dev483__py3-none-any.whl → 0.61.1.dev485__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,10 +11,8 @@ from prediction_market_agent_tooling.gtypes import (
11
11
  ChecksumAddress,
12
12
  HexAddress,
13
13
  HexBytes,
14
- Probability,
15
14
  )
16
15
  from prediction_market_agent_tooling.markets.data_models import Resolution
17
- from prediction_market_agent_tooling.markets.seer.price_manager import PriceManager
18
16
  from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
19
17
  SeerParentMarket,
20
18
  )
@@ -158,11 +156,6 @@ class SeerMarket(BaseModel):
158
156
  def created_time(self) -> DatetimeUTC:
159
157
  return DatetimeUTC.to_datetime_utc(self.block_timestamp)
160
158
 
161
- @property
162
- def current_p_yes(self) -> Probability:
163
- p = PriceManager(self)
164
- return p.current_market_p_yes
165
-
166
159
  @property
167
160
  def url(self) -> str:
168
161
  chain_id = RPCConfig().chain_id
@@ -1,7 +1,7 @@
1
1
  from web3 import Web3
2
2
 
3
- from prediction_market_agent_tooling.gtypes import ChecksumAddress
4
- from prediction_market_agent_tooling.gtypes import Probability, xdai_type
3
+ from prediction_market_agent_tooling.gtypes import ChecksumAddress, xdai_type
4
+ from prediction_market_agent_tooling.gtypes import Probability
5
5
  from prediction_market_agent_tooling.loggers import logger
6
6
  from prediction_market_agent_tooling.markets.seer.data_models import (
7
7
  SeerMarket,
@@ -19,36 +19,18 @@ from prediction_market_agent_tooling.tools.web3_utils import xdai_to_wei
19
19
 
20
20
 
21
21
  class PriceManager:
22
- def __init__(self, market: SeerMarket):
23
- self.seer_market = market
24
- self.subgraph_handler = SeerSubgraphHandler()
22
+ def __init__(self, seer_market: SeerMarket, seer_subgraph: SeerSubgraphHandler):
23
+ self.seer_market = seer_market
24
+ self.seer_subgraph = seer_subgraph
25
25
 
26
- def fetch_outcome_price_for_seer_market(self) -> float:
26
+ @property
27
+ def current_p_yes(self) -> Probability:
27
28
  price_data = {}
28
- for idx in range(len(self.seer_market.outcomes)):
29
- wrapped_token = self.seer_market.wrapped_tokens[idx]
29
+ for idx, wrapped_token in enumerate(self.seer_market.wrapped_tokens):
30
30
  price = self.get_price_for_token(
31
- token=Web3.to_checksum_address(wrapped_token)
31
+ token=Web3.to_checksum_address(wrapped_token),
32
32
  )
33
- price_data[idx] = price
34
-
35
- if sum(price_data.values()) == 0:
36
- logger.warning(
37
- f"Could not get p_yes for market {self.seer_market.id.hex()}, all price quotes are 0."
38
- )
39
- return Probability(0)
40
-
41
- yes_idx = self.seer_market.outcome_as_enums[SeerOutcomeEnum.YES]
42
- price_yes = price_data[yes_idx] / sum(price_data.values())
43
- return Probability(price_yes)
44
33
 
45
- def current_market_p_yes(self) -> Probability:
46
- price_data = {}
47
- for idx in range(len(self.seer_market.outcomes)):
48
- wrapped_token = self.seer_market.wrapped_tokens[idx]
49
- price = self.get_price_for_token(
50
- token=Web3.to_checksum_address(wrapped_token)
51
- )
52
34
  price_data[idx] = price
53
35
 
54
36
  if sum(price_data.values()) == 0:
@@ -57,10 +39,8 @@ class PriceManager:
57
39
  )
58
40
  return Probability(0)
59
41
 
60
- yes_idx = self.seer_market.outcome_as_enums[SeerOutcomeEnum.YES]
61
- no_idx = self.seer_market.outcome_as_enums[SeerOutcomeEnum.NO]
62
- price_yes = price_data[yes_idx]
63
- price_no = price_data[no_idx]
42
+ price_yes = price_data[self.seer_market.outcome_as_enums[SeerOutcomeEnum.YES]]
43
+ price_no = price_data[self.seer_market.outcome_as_enums[SeerOutcomeEnum.NO]]
64
44
  if price_yes and not price_no:
65
45
  # We simply return p_yes since it's probably a bug that p_no wasn't found.
66
46
  return Probability(price_yes)
@@ -73,7 +53,10 @@ class PriceManager:
73
53
  return Probability(price_yes)
74
54
 
75
55
  @persistent_inmemory_cache
76
- def get_price_for_token(self, token: ChecksumAddress) -> float:
56
+ def get_price_for_token(
57
+ self,
58
+ token: ChecksumAddress,
59
+ ) -> float:
77
60
  collateral_exchange_amount = xdai_to_wei(xdai_type(1))
78
61
  try:
79
62
  quote = CowManager().get_quote(
@@ -94,8 +77,11 @@ class PriceManager:
94
77
  def _pool_token0_matches_token(token: ChecksumAddress, pool: SeerPool) -> bool:
95
78
  return pool.token0.id.hex().lower() == token.lower()
96
79
 
97
- def get_token_price_from_pools(self, token: ChecksumAddress) -> float:
98
- pool = self.subgraph_handler.get_pool_by_token(token_address=token)
80
+ def get_token_price_from_pools(
81
+ self,
82
+ token: ChecksumAddress,
83
+ ) -> float:
84
+ pool = SeerSubgraphHandler().get_pool_by_token(token_address=token)
99
85
 
100
86
  if not pool:
101
87
  logger.warning(f"Could not find a pool for {token=}, returning 0.")
@@ -109,16 +95,16 @@ class PriceManager:
109
95
  )
110
96
  if (
111
97
  collateral_address.hex().lower()
112
- != self.seer_market.collateral_token.lower()
98
+ != self.seer_market.collateral_token_contract_address_checksummed.lower()
113
99
  ):
114
100
  logger.warning(
115
- f"Pool {pool.id.hex()} has collateral mismatch with market. Collateral from pool {collateral_address.hex()}, collateral from market {self.seer_market.collateral_token}, returning 0."
101
+ f"Pool {pool.id.hex()} has collateral mismatch with market. Collateral from pool {collateral_address.hex()}, collateral from market {self.seer_market.collateral_token_contract_address_checksummed}, returning 0."
116
102
  )
117
103
  return 0
118
104
 
119
105
  price_in_collateral_units = (
120
106
  pool.token0Price
121
- if self._pool_token0_matches_token(pool)
107
+ if self._pool_token0_matches_token(token=token, pool=pool)
122
108
  else pool.token1Price
123
109
  )
124
110
  return price_in_collateral_units
@@ -33,16 +33,19 @@ from prediction_market_agent_tooling.markets.market_fees import MarketFees
33
33
  from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket
34
34
  from prediction_market_agent_tooling.markets.omen.omen_contracts import sDaiContract
35
35
  from prediction_market_agent_tooling.markets.seer.data_models import (
36
- NewMarketEvent,
37
36
  SeerMarket,
38
37
  SeerOutcomeEnum,
39
38
  )
39
+ from prediction_market_agent_tooling.markets.seer.price_manager import PriceManager
40
40
  from prediction_market_agent_tooling.markets.seer.seer_contracts import (
41
41
  SeerMarketFactory,
42
42
  )
43
43
  from prediction_market_agent_tooling.markets.seer.seer_subgraph_handler import (
44
44
  SeerSubgraphHandler,
45
45
  )
46
+ from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
47
+ NewMarketEvent,
48
+ )
46
49
  from prediction_market_agent_tooling.tools.balances import get_balances
47
50
  from prediction_market_agent_tooling.tools.contract import (
48
51
  ContractERC20OnGnosisChain,
@@ -166,6 +169,33 @@ class SeerAgentMarket(AgentMarket):
166
169
  def verify_operational_balance(api_keys: APIKeys) -> bool:
167
170
  return OmenAgentMarket.verify_operational_balance(api_keys=api_keys)
168
171
 
172
+ @staticmethod
173
+ def from_data_model_with_subgraph(
174
+ model: SeerMarket, seer_subgraph: SeerSubgraphHandler
175
+ ) -> "SeerAgentMarket":
176
+ p = PriceManager(seer_market=model, seer_subgraph=seer_subgraph)
177
+ current_p_yes = p.get_current_p_price()
178
+
179
+ return SeerAgentMarket(
180
+ id=model.id.hex(),
181
+ question=model.title,
182
+ creator=model.creator,
183
+ created_time=model.created_time,
184
+ outcomes=model.outcomes,
185
+ collateral_token_contract_address_checksummed=model.collateral_token_contract_address_checksummed,
186
+ condition_id=model.condition_id,
187
+ url=model.url,
188
+ close_time=model.close_time,
189
+ wrapped_tokens=[Web3.to_checksum_address(i) for i in model.wrapped_tokens],
190
+ fees=MarketFees.get_zero_fees(),
191
+ outcome_token_pool=None,
192
+ resolution=model.get_resolution_enum(),
193
+ volume=None,
194
+ # current_p_yes=model.current_p_yes,
195
+ current_p_yes=current_p_yes,
196
+ seer_outcomes=model.outcome_as_enums,
197
+ )
198
+
169
199
  @staticmethod
170
200
  def from_data_model(model: SeerMarket) -> "SeerAgentMarket":
171
201
  return SeerAgentMarket(
@@ -195,14 +225,11 @@ class SeerAgentMarket(AgentMarket):
195
225
  created_after: t.Optional[DatetimeUTC] = None,
196
226
  excluded_questions: set[str] | None = None,
197
227
  ) -> t.Sequence["SeerAgentMarket"]:
198
- return [
199
- SeerAgentMarket.from_data_model(m)
200
- for m in SeerSubgraphHandler().get_binary_markets(
201
- limit=limit,
202
- sort_by=sort_by,
203
- filter_by=filter_by,
204
- )
205
- ]
228
+ markets = SeerSubgraphHandler().get_binary_markets(
229
+ limit=limit, sort_by=sort_by, filter_by=filter_by
230
+ )
231
+
232
+ return [SeerAgentMarket.from_data_model(m) for m in markets]
206
233
 
207
234
  def has_liquidity_for_outcome(self, outcome: bool) -> bool:
208
235
  outcome_token = self.get_wrapped_token_for_outcome(outcome)
@@ -352,4 +379,4 @@ def extract_market_address_from_tx(
352
379
  .process_receipt(tx_receipt)
353
380
  )
354
381
  new_market_event = NewMarketEvent(**event_logs[0]["args"])
355
- return Web3.to_checksum_address(new_market_event.seer_market)
382
+ return Web3.to_checksum_address(new_market_event.market)
@@ -5,7 +5,7 @@ from web3.types import TxReceipt
5
5
 
6
6
  from prediction_market_agent_tooling.config import APIKeys
7
7
  from prediction_market_agent_tooling.gtypes import ABI, ChecksumAddress, xDai
8
- from prediction_market_agent_tooling.markets.seer.data_models import (
8
+ from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
9
9
  CreateCategoricalMarketsParams,
10
10
  )
11
11
  from prediction_market_agent_tooling.tools.contract import (
@@ -12,8 +12,8 @@ from prediction_market_agent_tooling.markets.base_subgraph_handler import (
12
12
  )
13
13
  from prediction_market_agent_tooling.markets.seer.data_models import (
14
14
  SeerMarket,
15
- SeerPool,
16
15
  )
16
+ from prediction_market_agent_tooling.markets.seer.subgraph_data_models import SeerPool
17
17
  from prediction_market_agent_tooling.tools.hexbytes_custom import HexBytes
18
18
  from prediction_market_agent_tooling.tools.utils import to_int_timestamp, utcnow
19
19
 
@@ -1,6 +1,7 @@
1
1
  from pydantic import BaseModel, ConfigDict, Field
2
+ from web3.constants import ADDRESS_ZERO
2
3
 
3
- from prediction_market_agent_tooling.gtypes import HexBytes, HexAddress
4
+ from prediction_market_agent_tooling.gtypes import HexBytes, HexAddress, Wei
4
5
 
5
6
 
6
7
  class SeerToken(BaseModel):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.61.1.dev483
3
+ Version: 0.61.1.dev485
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.13
@@ -61,12 +61,12 @@ prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=Fd5PI5y
61
61
  prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=VZhVccTApygSKMmy6Au2G02JCJOKJnR_oVeKlaesuSg,12548
62
62
  prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=NRoZK71PtH8kkangMqme7twcAXhRJSSabbmOir-UnAI,3418
63
63
  prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=8kTeVjXPcXC6DkDvWYsZQLY7x8DS6CEp_yznSEazsNU,2037
64
- prediction_market_agent_tooling/markets/seer/data_models.py,sha256=EDzVMgBvum400VQl4IUvdnchBszF6M_4LWxMWkeTIHY,5576
65
- prediction_market_agent_tooling/markets/seer/price_manager.py,sha256=tuozfXp2dwgUQXvD4G4UAOzs-rIm6vgevbi804vv8-0,5102
66
- prediction_market_agent_tooling/markets/seer/seer.py,sha256=Anxp66UUzIIKt5wgLoqtUjUM-5HQ0wC5f5rDiYwrRRg,12959
67
- prediction_market_agent_tooling/markets/seer/seer_contracts.py,sha256=E7CYAKZiK6cg3dyj1kJuIPKSYYUft98F64shF5S0g4s,2730
68
- prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py,sha256=2M6vmUxMKQU61VNCp4Ykican6XH1LOp257--GjCJZx8,8974
69
- prediction_market_agent_tooling/markets/seer/subgraph_data_models.py,sha256=uPTCYTg_lS91Pb7JCU-neVEgAQe3zSOtkttlhQGlcBI,1599
64
+ prediction_market_agent_tooling/markets/seer/data_models.py,sha256=ECuCDqRcs9vB9rKIec399HxsL915oT7VGSwztcMfGIw,5347
65
+ prediction_market_agent_tooling/markets/seer/price_manager.py,sha256=Anuz-O3ZsLXU7td830XuN5fWEDjm5-WwviTU19O_pDU,4406
66
+ prediction_market_agent_tooling/markets/seer/seer.py,sha256=0OQyvKQ_qGRMIKpVHveSUgKPIjhdjdti8ibNLqWClWE,14177
67
+ prediction_market_agent_tooling/markets/seer/seer_contracts.py,sha256=TXGDbv7CI08X8N5re1SAm-X_BaXj8m4ceyzkS_ktQok,2739
68
+ prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py,sha256=lcaKbFHxigMYwi4TCePyTb5HXJhGoCu5dJPFWTj5E28,9047
69
+ prediction_market_agent_tooling/markets/seer/subgraph_data_models.py,sha256=RIt2oO-PbykzbYN11Qltt8tjjYTty-PfjH3Q4D2VEoA,1644
70
70
  prediction_market_agent_tooling/monitor/financial_metrics/financial_metrics.py,sha256=fjIgjDIx5MhH5mwf7S0cspLOOSU3elYLhGYoIiM26mU,2746
71
71
  prediction_market_agent_tooling/monitor/markets/manifold.py,sha256=TS4ERwTfQnot8dhekNyVNhJYf5ysYsjF-9v5_kM3aVI,3334
72
72
  prediction_market_agent_tooling/monitor/markets/metaculus.py,sha256=LOnyWWBFdg10-cTWdb76nOsNjDloO8OfMT85GBzRCFI,1455
@@ -119,8 +119,8 @@ prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=7JPgVF4RbiFzLD
119
119
  prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
120
120
  prediction_market_agent_tooling/tools/utils.py,sha256=jLG4nbEoIzzJiZ4RgMx4Q969Zdl0p0s63p8uET_0Fuw,6440
121
121
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=3wfqNxvMn44ivweFRoeKNVb9QRtFd7kFtp7VUY5juEE,12862
122
- prediction_market_agent_tooling-0.61.1.dev483.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
123
- prediction_market_agent_tooling-0.61.1.dev483.dist-info/METADATA,sha256=078bYVh1iho-ehDfULc_ZXtRaQc71KnHdmJErDU_B5k,8636
124
- prediction_market_agent_tooling-0.61.1.dev483.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
125
- prediction_market_agent_tooling-0.61.1.dev483.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
126
- prediction_market_agent_tooling-0.61.1.dev483.dist-info/RECORD,,
122
+ prediction_market_agent_tooling-0.61.1.dev485.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
123
+ prediction_market_agent_tooling-0.61.1.dev485.dist-info/METADATA,sha256=1mVyJDn3LvVOE0LrV9q6nH4g9tGMab4ThJgdbTOCUw8,8636
124
+ prediction_market_agent_tooling-0.61.1.dev485.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
125
+ prediction_market_agent_tooling-0.61.1.dev485.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
126
+ prediction_market_agent_tooling-0.61.1.dev485.dist-info/RECORD,,