prediction-market-agent-tooling 0.50.0__py3-none-any.whl → 0.51.0__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.
@@ -45,6 +45,7 @@ class APIKeys(BaseSettings):
45
45
  LANGFUSE_HOST: t.Optional[str] = None
46
46
  LANGFUSE_DEPLOYMENT_VERSION: t.Optional[str] = None
47
47
 
48
+ ENABLE_IPFS_UPLOAD: bool = False
48
49
  PINATA_API_KEY: t.Optional[SecretStr] = None
49
50
  PINATA_API_SECRET: t.Optional[SecretStr] = None
50
51
 
@@ -151,6 +152,12 @@ class APIKeys(BaseSettings):
151
152
  and self.LANGFUSE_HOST is not None
152
153
  )
153
154
 
155
+ @property
156
+ def enable_ipfs_upload(self) -> bool:
157
+ return check_not_none(
158
+ self.ENABLE_IPFS_UPLOAD, "ENABLE_IPFS_UPLOAD missing in the environment."
159
+ )
160
+
154
161
  @property
155
162
  def pinata_api_key(self) -> SecretStr:
156
163
  return check_not_none(
@@ -11,6 +11,7 @@ from functools import cached_property
11
11
  from pydantic import BaseModel, BeforeValidator, computed_field
12
12
  from typing_extensions import Annotated
13
13
  from web3 import Web3
14
+ from web3.constants import HASH_ZERO
14
15
 
15
16
  from prediction_market_agent_tooling.config import APIKeys
16
17
  from prediction_market_agent_tooling.deploy.betting_strategy import (
@@ -302,7 +303,6 @@ class DeployableTraderAgent(DeployableAgent):
302
303
  ) -> None:
303
304
  super().__init__(enable_langfuse=enable_langfuse)
304
305
  self.place_bet = place_bet
305
- self.ipfs_handler = IPFSHandler(APIKeys())
306
306
 
307
307
  def get_betting_strategy(self, market: AgentMarket) -> BettingStrategy:
308
308
  user_id = market.get_user_id(api_keys=APIKeys())
@@ -522,16 +522,21 @@ class DeployableTraderAgent(DeployableAgent):
522
522
  if processed_market.answer.reasoning
523
523
  else ""
524
524
  )
525
- ipfs_hash = self.ipfs_handler.store_agent_result(
526
- IPFSAgentResult(reasoning=reasoning)
527
- )
525
+
526
+ ipfs_hash_decoded = HexBytes(HASH_ZERO)
527
+ if keys.enable_ipfs_upload:
528
+ logger.info("Storing prediction on IPFS.")
529
+ ipfs_hash = IPFSHandler(keys).store_agent_result(
530
+ IPFSAgentResult(reasoning=reasoning)
531
+ )
532
+ ipfs_hash_decoded = ipfscidv0_to_byte32(ipfs_hash)
528
533
 
529
534
  tx_hashes = [
530
535
  HexBytes(HexStr(i.id)) for i in processed_market.trades if i.id is not None
531
536
  ]
532
537
  prediction = ContractPrediction(
533
538
  publisher=keys.public_key,
534
- ipfs_hash=ipfscidv0_to_byte32(ipfs_hash),
539
+ ipfs_hash=ipfs_hash_decoded,
535
540
  tx_hashes=tx_hashes,
536
541
  estimated_probability_bps=int(processed_market.answer.p_yes * 10000),
537
542
  )
@@ -352,25 +352,38 @@ class OmenMarket(BaseModel):
352
352
  def is_binary(self) -> bool:
353
353
  return len(self.outcomes) == 2
354
354
 
355
- @property
356
- def boolean_outcome(self) -> bool:
355
+ def boolean_outcome_from_answer(self, answer: HexBytes) -> bool:
357
356
  if not self.is_binary:
358
357
  raise ValueError(
359
358
  f"Market with title {self.title} is not binary, it has {len(self.outcomes)} outcomes."
360
359
  )
360
+ outcome: str = self.outcomes[answer.as_int()]
361
+ return get_boolean_outcome(outcome)
362
+
363
+ @property
364
+ def boolean_outcome(self) -> bool:
361
365
  if not self.is_resolved_with_valid_answer:
362
366
  raise ValueError(f"Bet with title {self.title} is not resolved.")
367
+ return self.boolean_outcome_from_answer(
368
+ check_not_none(
369
+ self.currentAnswer, "Can not be None if `is_resolved_with_valid_answer`"
370
+ )
371
+ )
363
372
 
364
- outcome: str = self.outcomes[check_not_none(self.answer_index)]
365
- return get_boolean_outcome(outcome)
373
+ def get_resolution_enum_from_answer(self, answer: HexBytes) -> Resolution:
374
+ if self.boolean_outcome_from_answer(answer):
375
+ return Resolution.YES
376
+ else:
377
+ return Resolution.NO
366
378
 
367
379
  def get_resolution_enum(self) -> t.Optional[Resolution]:
368
380
  if not self.is_resolved_with_valid_answer:
369
381
  return None
370
- if self.boolean_outcome:
371
- return Resolution.YES
372
- else:
373
- return Resolution.NO
382
+ return self.get_resolution_enum_from_answer(
383
+ check_not_none(
384
+ self.currentAnswer, "Can not be None if `is_resolved_with_valid_answer`"
385
+ )
386
+ )
374
387
 
375
388
  @property
376
389
  def url(self) -> str:
@@ -18,9 +18,6 @@ from prediction_market_agent_tooling.markets.omen.data_models import (
18
18
  OmenMarket,
19
19
  RealityQuestion,
20
20
  )
21
- from prediction_market_agent_tooling.markets.omen.omen import (
22
- OMEN_DEFAULT_REALITIO_BOND_VALUE,
23
- )
24
21
  from prediction_market_agent_tooling.markets.omen.omen_contracts import (
25
22
  OmenOracleContract,
26
23
  OmenRealitioContract,
@@ -121,6 +118,7 @@ def claim_bonds_on_realitio_question(
121
118
  def finalize_markets(
122
119
  api_keys: APIKeys,
123
120
  markets_with_resolutions: list[tuple[OmenMarket, Resolution | None]],
121
+ realitio_bond: xDai,
124
122
  wait_n_days_before_invalid: int = 30,
125
123
  web3: Web3 | None = None,
126
124
  ) -> list[HexAddress]:
@@ -140,7 +138,7 @@ def finalize_markets(
140
138
  omen_submit_invalid_answer_market_tx(
141
139
  api_keys,
142
140
  market,
143
- OMEN_DEFAULT_REALITIO_BOND_VALUE,
141
+ realitio_bond,
144
142
  web3=web3,
145
143
  )
146
144
 
@@ -155,7 +153,7 @@ def finalize_markets(
155
153
  api_keys,
156
154
  market,
157
155
  resolution,
158
- OMEN_DEFAULT_REALITIO_BOND_VALUE,
156
+ realitio_bond,
159
157
  web3=web3,
160
158
  )
161
159
  finalized_markets.append(market.id)
@@ -168,7 +166,7 @@ def finalize_markets(
168
166
  omen_submit_invalid_answer_market_tx(
169
167
  api_keys,
170
168
  market,
171
- OMEN_DEFAULT_REALITIO_BOND_VALUE,
169
+ realitio_bond,
172
170
  web3=web3,
173
171
  )
174
172
 
@@ -71,12 +71,17 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
71
71
  def __init__(self) -> None:
72
72
  self.sg = Subgrounds()
73
73
 
74
- # Patch the query_json method to retry on failure.
74
+ # Patch methods to retry on failure.
75
75
  self.sg.query_json = tenacity.retry(
76
76
  stop=tenacity.stop_after_attempt(3),
77
77
  wait=tenacity.wait_fixed(1),
78
78
  after=lambda x: logger.debug(f"query_json failed, {x.attempt_number=}."),
79
79
  )(self.sg.query_json)
80
+ self.sg.load_subgraph = tenacity.retry(
81
+ stop=tenacity.stop_after_attempt(3),
82
+ wait=tenacity.wait_fixed(1),
83
+ after=lambda x: logger.debug(f"load_subgraph failed, {x.attempt_number=}."),
84
+ )(self.sg.load_subgraph)
80
85
 
81
86
  keys = APIKeys()
82
87
 
@@ -221,7 +226,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
221
226
  opened_after: t.Optional[DatetimeUTC] = None,
222
227
  finalized_before: t.Optional[DatetimeUTC] = None,
223
228
  finalized_after: t.Optional[DatetimeUTC] = None,
224
- finalized: bool | None = None,
225
229
  resolved: bool | None = None,
226
230
  liquidity_bigger_than: Wei | None = None,
227
231
  condition_id_in: list[HexBytes] | None = None,
@@ -273,12 +277,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
273
277
  else:
274
278
  where_stms["resolutionTimestamp"] = None
275
279
 
276
- if finalized is not None:
277
- if finalized:
278
- where_stms["answerFinalizedTimestamp_not"] = None
279
- else:
280
- where_stms["answerFinalizedTimestamp"] = None
281
-
282
280
  if opened_after:
283
281
  where_stms["question_"]["openingTimestamp_gt"] = to_int_timestamp(
284
282
  opened_after
@@ -358,13 +356,11 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
358
356
  Simplified `get_omen_binary_markets` method, which allows to fetch markets based on the filter_by and sort_by values.
359
357
  """
360
358
  # These values need to be set according to the filter_by value, so they can not be passed as arguments.
361
- finalized: bool | None = None
362
359
  resolved: bool | None = None
363
360
  opened_after: DatetimeUTC | None = None
364
361
  liquidity_bigger_than: Wei | None = None
365
362
 
366
363
  if filter_by == FilterBy.RESOLVED:
367
- finalized = True
368
364
  resolved = True
369
365
  elif filter_by == FilterBy.OPEN:
370
366
  # We can not use `resolved=False` + `finalized=False` here,
@@ -381,7 +377,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
381
377
 
382
378
  return self.get_omen_binary_markets(
383
379
  limit=limit,
384
- finalized=finalized,
385
380
  resolved=resolved,
386
381
  opened_after=opened_after,
387
382
  liquidity_bigger_than=liquidity_bigger_than,
@@ -401,7 +396,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
401
396
  opened_after: t.Optional[DatetimeUTC] = None,
402
397
  finalized_before: t.Optional[DatetimeUTC] = None,
403
398
  finalized_after: t.Optional[DatetimeUTC] = None,
404
- finalized: bool | None = None,
405
399
  resolved: bool | None = None,
406
400
  creator: t.Optional[HexAddress] = None,
407
401
  creator_in: t.Optional[t.Sequence[HexAddress]] = None,
@@ -429,7 +423,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
429
423
  opened_after=opened_after,
430
424
  finalized_before=finalized_before,
431
425
  finalized_after=finalized_after,
432
- finalized=finalized,
433
426
  resolved=resolved,
434
427
  condition_id_in=condition_id_in,
435
428
  id_in=id_in,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.50.0
3
+ Version: 0.51.0
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -16,8 +16,8 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
16
16
  prediction_market_agent_tooling/benchmark/agents.py,sha256=B1-uWdyeN4GGKMWGK_-CcAFJg1m9Y_XuaeIHPB29QR8,3971
17
17
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=MqTiaaJ3cYiOLUVR7OyImLWxcEya3Rl5JyFYW-K0lwM,17097
18
18
  prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
19
- prediction_market_agent_tooling/config.py,sha256=LAOG22P7yi8zDBqMuhBD6FaoCG-w4_tE8rF14hqDffk,6519
20
- prediction_market_agent_tooling/deploy/agent.py,sha256=xCIisNL-WW96hlndI_Cfftv__Eb6X7-LghzNmovCbno,21817
19
+ prediction_market_agent_tooling/config.py,sha256=WC30Nr16RGueTafA9i67OIB-6KDHZRryhiLPzebg9_I,6740
20
+ prediction_market_agent_tooling/deploy/agent.py,sha256=c9ovjd5UUk1Qw64Si7q0OO7SvM6I6Wne1fySpu0oWco,22005
21
21
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
22
22
  prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=cOPznMX0jd380qHw06A-l1XUyoicV54AXBghirtPw0Q,12127
23
23
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
@@ -43,11 +43,11 @@ prediction_market_agent_tooling/markets/metaculus/api.py,sha256=4TRPGytQQbSdf42D
43
43
  prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=PIRN2FAQ32vNj78JRZPB1pXK61B0w2RBJvJSJ7dvvrg,2514
44
44
  prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=S-XpK6Ij5AZgGMFMdXXcHm7hH2o8BRU-a_XqaW4xC54,3674
45
45
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
- prediction_market_agent_tooling/markets/omen/data_models.py,sha256=YRsdASXBp5sMKmSTbwkZDWh0iwNnMnmJwLfgY-oj21s,26748
46
+ prediction_market_agent_tooling/markets/omen/data_models.py,sha256=yYPHpZM4fthC1EhyXkXC8iyDQ1ITNBBY9nOHeKD6XSw,27283
47
47
  prediction_market_agent_tooling/markets/omen/omen.py,sha256=6tBhn7qxtsdrk0xgDSqWy44f_m1qmhfXjvQUWXtW3TI,47974
48
48
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=w_ClGd8U4w2pKH3HLZqy2bAFkqZMSAhVgGFGlUqET6Y,28266
49
- prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=eBFzXYsSvGRrGjQ60_SDQr1ZiPTe6U2CcZkSuKt_Wxc,9551
50
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=_KlGEOoGCnZ33p_CxOXnYZ5pWqMmsIsBF4Yi6YaZcuQ,32735
49
+ prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=iDWdjICGkt968exwCjY-6nsnQyrrNAg3YjnDdP430GQ,9415
50
+ prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=EZN3K93WjMQ3FmKBtHmMlmorZ-9v7mWenHRWqMmV-RU,32563
51
51
  prediction_market_agent_tooling/markets/polymarket/api.py,sha256=UZ4_TG8ceb9Y-qgsOKs8Qiv8zDt957QkT8IX2c83yqo,4800
52
52
  prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=Fd5PI5y3mJM8VHExBhWFWEnuuIKxQmIAXgBuoPDvNjw,4341
53
53
  prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=VZhVccTApygSKMmy6Au2G02JCJOKJnR_oVeKlaesuSg,12548
@@ -90,8 +90,8 @@ prediction_market_agent_tooling/tools/tavily_storage/tavily_models.py,sha256=99S
90
90
  prediction_market_agent_tooling/tools/tavily_storage/tavily_storage.py,sha256=xrtQH9v5pXycBRyc5j45pWqkSffkoc9efNIU1_G633Q,3706
91
91
  prediction_market_agent_tooling/tools/utils.py,sha256=JZj_xM4VbsDSiDlbn2lZFZPEOBSYhqqxd1Y2NpCqnJ4,7117
92
92
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=dkcjG-LtuaWRh7WEMzRGmZ5B5rsxZTlliFOI6fj-EJ8,11842
93
- prediction_market_agent_tooling-0.50.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
94
- prediction_market_agent_tooling-0.50.0.dist-info/METADATA,sha256=WJM6adz0OH9KsvN-ZcCPV46AnEIEPNGio8ZXZFFeqbA,8056
95
- prediction_market_agent_tooling-0.50.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
96
- prediction_market_agent_tooling-0.50.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
97
- prediction_market_agent_tooling-0.50.0.dist-info/RECORD,,
93
+ prediction_market_agent_tooling-0.51.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
94
+ prediction_market_agent_tooling-0.51.0.dist-info/METADATA,sha256=G5RtTj92IHwgLBO6VKf6xCz4WWva0BNo77Xhbfl2lVs,8056
95
+ prediction_market_agent_tooling-0.51.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
96
+ prediction_market_agent_tooling-0.51.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
97
+ prediction_market_agent_tooling-0.51.0.dist-info/RECORD,,