prediction-market-agent-tooling 0.51.1__py3-none-any.whl → 0.52.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.
@@ -73,6 +73,10 @@ class Question(BaseModel):
73
73
  answerFinalizedTimestamp: t.Optional[DatetimeUTC] = None
74
74
  currentAnswer: t.Optional[str] = None
75
75
 
76
+ @property
77
+ def question_id(self) -> HexBytes:
78
+ return self.id
79
+
76
80
  @property
77
81
  def question_raw(self) -> str:
78
82
  # Based on https://github.com/protofire/omen-exchange/blob/2cfdf6bfe37afa8b169731d51fea69d42321d66c/app/src/hooks/graph/useGraphMarketMakerData.tsx#L217.
@@ -583,7 +587,7 @@ class RealityQuestion(BaseModel):
583
587
  historyHash: HexBytes | None
584
588
  updatedTimestamp: int
585
589
  contentHash: HexBytes
586
- questionId: HexBytes
590
+ questionId: HexBytes # This is the `id` on question from omen subgraph.
587
591
  answerFinalizedTimestamp: int
588
592
  currentScheduledFinalizationTimestamp: int
589
593
 
@@ -660,6 +664,10 @@ def format_realitio_question(
660
664
  template_id: int,
661
665
  ) -> str:
662
666
  """If you add a new template id here, also add to the parsing function below."""
667
+
668
+ # Escape characters for JSON troubles on Reality.eth.
669
+ question = question.replace('"', '\\"')
670
+
663
671
  if template_id == 2:
664
672
  return "␟".join(
665
673
  [
@@ -218,30 +218,45 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
218
218
 
219
219
  def _build_where_statements(
220
220
  self,
221
- creator: t.Optional[HexAddress] = None,
222
- creator_in: t.Optional[t.Sequence[HexAddress]] = None,
223
- outcomes: list[str] = OMEN_BINARY_MARKET_OUTCOMES,
224
- created_after: t.Optional[DatetimeUTC] = None,
225
- opened_before: t.Optional[DatetimeUTC] = None,
226
- opened_after: t.Optional[DatetimeUTC] = None,
227
- finalized_before: t.Optional[DatetimeUTC] = None,
228
- finalized_after: t.Optional[DatetimeUTC] = None,
229
- resolved: bool | None = None,
230
- liquidity_bigger_than: Wei | None = None,
231
- condition_id_in: list[HexBytes] | None = None,
232
- id_in: list[str] | None = None,
233
- excluded_questions: set[str] | None = None,
234
- collateral_token_address_in: tuple[ChecksumAddress, ...] | None = None,
235
- category: str | None = None,
221
+ creator: HexAddress | None,
222
+ creator_in: t.Sequence[HexAddress] | None,
223
+ outcomes: list[str],
224
+ created_after: DatetimeUTC | None,
225
+ question_opened_before: DatetimeUTC | None,
226
+ question_opened_after: DatetimeUTC | None,
227
+ question_finalized_before: DatetimeUTC | None,
228
+ question_finalized_after: DatetimeUTC | None,
229
+ question_with_answers: bool | None,
230
+ question_id: HexBytes | None,
231
+ question_id_in: list[HexBytes] | None,
232
+ question_current_answer_before: DatetimeUTC | None,
233
+ question_excluded_titles: set[str] | None,
234
+ resolved: bool | None,
235
+ liquidity_bigger_than: Wei | None,
236
+ condition_id_in: list[HexBytes] | None,
237
+ id_in: list[str] | None,
238
+ collateral_token_address_in: tuple[ChecksumAddress, ...] | None,
239
+ category: str | None,
236
240
  ) -> dict[str, t.Any]:
237
241
  where_stms: dict[str, t.Any] = {
238
242
  "isPendingArbitration": False,
239
243
  "outcomes": outcomes,
240
244
  "title_not": None,
241
- "question_": {},
242
245
  "condition_": {},
243
246
  }
244
247
 
248
+ where_stms["question_"] = self.get_omen_question_filters(
249
+ question_id=question_id,
250
+ opened_before=question_opened_before,
251
+ opened_after=question_opened_after,
252
+ finalized_before=question_finalized_before,
253
+ finalized_after=question_finalized_after,
254
+ with_answers=question_with_answers,
255
+ current_answer_before=question_current_answer_before,
256
+ question_id_in=question_id_in,
257
+ excluded_titles=question_excluded_titles,
258
+ )
259
+
245
260
  if collateral_token_address_in:
246
261
  where_stms["collateralToken_in"] = [
247
262
  x.lower() for x in collateral_token_address_in
@@ -256,11 +271,6 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
256
271
  if created_after:
257
272
  where_stms["creationTimestamp_gt"] = to_int_timestamp(created_after)
258
273
 
259
- if opened_before:
260
- where_stms["question_"]["openingTimestamp_lt"] = to_int_timestamp(
261
- opened_before
262
- )
263
-
264
274
  if liquidity_bigger_than is not None:
265
275
  where_stms["liquidityParameter_gt"] = liquidity_bigger_than
266
276
 
@@ -277,30 +287,9 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
277
287
  else:
278
288
  where_stms["resolutionTimestamp"] = None
279
289
 
280
- if opened_after:
281
- where_stms["question_"]["openingTimestamp_gt"] = to_int_timestamp(
282
- opened_after
283
- )
284
-
285
- if finalized_before:
286
- where_stms["answerFinalizedTimestamp_lt"] = to_int_timestamp(
287
- finalized_before
288
- )
289
-
290
- if finalized_after:
291
- where_stms["answerFinalizedTimestamp_gt"] = to_int_timestamp(
292
- finalized_after
293
- )
294
-
295
290
  if category:
296
291
  where_stms["category"] = category
297
292
 
298
- # `excluded_question_titles` can not be an empty list, otherwise the API bugs out and returns nothing.
299
- excluded_question_titles = [""]
300
- if excluded_questions:
301
- excluded_question_titles = [i for i in excluded_questions]
302
-
303
- where_stms["question_"]["title_not_in"] = excluded_question_titles
304
293
  return where_stms
305
294
 
306
295
  def _build_sort_params(
@@ -378,12 +367,12 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
378
367
  return self.get_omen_binary_markets(
379
368
  limit=limit,
380
369
  resolved=resolved,
381
- opened_after=opened_after,
370
+ question_opened_after=opened_after,
382
371
  liquidity_bigger_than=liquidity_bigger_than,
383
372
  sort_direction=sort_direction,
384
373
  sort_by_field=sort_by_field,
385
374
  created_after=created_after,
386
- excluded_questions=excluded_questions,
375
+ question_excluded_titles=excluded_questions,
387
376
  collateral_token_address_in=collateral_token_address_in,
388
377
  category=category,
389
378
  )
@@ -391,18 +380,22 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
391
380
  def get_omen_binary_markets(
392
381
  self,
393
382
  limit: t.Optional[int],
394
- created_after: t.Optional[DatetimeUTC] = None,
395
- opened_before: t.Optional[DatetimeUTC] = None,
396
- opened_after: t.Optional[DatetimeUTC] = None,
397
- finalized_before: t.Optional[DatetimeUTC] = None,
398
- finalized_after: t.Optional[DatetimeUTC] = None,
383
+ creator: HexAddress | None = None,
384
+ creator_in: t.Sequence[HexAddress] | None = None,
385
+ created_after: DatetimeUTC | None = None,
386
+ question_opened_before: DatetimeUTC | None = None,
387
+ question_opened_after: DatetimeUTC | None = None,
388
+ question_finalized_before: DatetimeUTC | None = None,
389
+ question_finalized_after: DatetimeUTC | None = None,
390
+ question_with_answers: bool | None = None,
391
+ question_id: HexBytes | None = None,
392
+ question_id_in: list[HexBytes] | None = None,
393
+ question_current_answer_before: DatetimeUTC | None = None,
394
+ question_excluded_titles: set[str] | None = None,
399
395
  resolved: bool | None = None,
400
- creator: t.Optional[HexAddress] = None,
401
- creator_in: t.Optional[t.Sequence[HexAddress]] = None,
402
396
  liquidity_bigger_than: Wei | None = None,
403
397
  condition_id_in: list[HexBytes] | None = None,
404
398
  id_in: list[str] | None = None,
405
- excluded_questions: set[str] | None = None, # question titles
406
399
  sort_by_field: FieldPath | None = None,
407
400
  sort_direction: str | None = None,
408
401
  outcomes: list[str] = OMEN_BINARY_MARKET_OUTCOMES,
@@ -419,14 +412,18 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
419
412
  creator_in=creator_in,
420
413
  outcomes=outcomes,
421
414
  created_after=created_after,
422
- opened_before=opened_before,
423
- opened_after=opened_after,
424
- finalized_before=finalized_before,
425
- finalized_after=finalized_after,
415
+ question_opened_before=question_opened_before,
416
+ question_opened_after=question_opened_after,
417
+ question_finalized_before=question_finalized_before,
418
+ question_finalized_after=question_finalized_after,
419
+ question_with_answers=question_with_answers,
420
+ question_id=question_id,
421
+ question_id_in=question_id_in,
422
+ question_current_answer_before=question_current_answer_before,
423
+ question_excluded_titles=question_excluded_titles,
426
424
  resolved=resolved,
427
425
  condition_id_in=condition_id_in,
428
426
  id_in=id_in,
429
- excluded_questions=excluded_questions,
430
427
  liquidity_bigger_than=liquidity_bigger_than,
431
428
  collateral_token_address_in=collateral_token_address_in,
432
429
  category=category,
@@ -644,15 +641,21 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
644
641
 
645
642
  @staticmethod
646
643
  def get_reality_question_filters(
647
- user: HexAddress | None = None,
648
- claimed: bool | None = None,
649
- current_answer_before: DatetimeUTC | None = None,
650
- finalized_before: DatetimeUTC | None = None,
651
- finalized_after: DatetimeUTC | None = None,
652
- id_in: list[str] | None = None,
653
- question_id: HexBytes | None = None,
654
- question_id_in: list[HexBytes] | None = None,
644
+ user: HexAddress | None,
645
+ claimed: bool | None,
646
+ current_answer_before: DatetimeUTC | None,
647
+ finalized_before: DatetimeUTC | None,
648
+ finalized_after: DatetimeUTC | None,
649
+ with_answers: bool | None,
650
+ question_id: HexBytes | None,
651
+ question_id_in: list[HexBytes] | None,
652
+ opened_before: t.Optional[DatetimeUTC],
653
+ opened_after: t.Optional[DatetimeUTC],
654
+ excluded_titles: set[str] | None,
655
655
  ) -> dict[str, t.Any]:
656
+ """
657
+ Be aware, both Omen subgraph and Reality subgraph are indexing questions, but their fields are a bit different.
658
+ """
656
659
  where_stms: dict[str, t.Any] = {}
657
660
 
658
661
  if user is not None:
@@ -672,6 +675,12 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
672
675
  current_answer_before
673
676
  )
674
677
 
678
+ if opened_before:
679
+ where_stms["openingTimestamp_lt"] = to_int_timestamp(opened_before)
680
+
681
+ if opened_after:
682
+ where_stms["openingTimestamp_gt"] = to_int_timestamp(opened_after)
683
+
675
684
  if finalized_before is not None:
676
685
  where_stms["answerFinalizedTimestamp_lt"] = to_int_timestamp(
677
686
  finalized_before
@@ -682,12 +691,77 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
682
691
  finalized_after
683
692
  )
684
693
 
685
- if id_in is not None:
686
- where_stms["id_in"] = id_in
694
+ if with_answers is not None:
695
+ if with_answers:
696
+ where_stms["answerFinalizedTimestamp_not"] = None
697
+ else:
698
+ where_stms["answerFinalizedTimestamp"] = None
687
699
 
688
700
  if question_id_in is not None:
701
+ # Be aware: On Omen subgraph, question's `id` represents `questionId` on reality subgraph. And `id` on reality subraph is just a weird concat of multiple things from the question.
689
702
  where_stms["questionId_in"] = [x.hex() for x in question_id_in]
690
703
 
704
+ if excluded_titles:
705
+ # Be aware: This is called `title_not_in` on Omen subgraph.
706
+ where_stms["qTitle_not_in"] = [i for i in excluded_titles]
707
+
708
+ return where_stms
709
+
710
+ @staticmethod
711
+ def get_omen_question_filters(
712
+ current_answer_before: DatetimeUTC | None,
713
+ finalized_before: DatetimeUTC | None,
714
+ finalized_after: DatetimeUTC | None,
715
+ with_answers: bool | None,
716
+ question_id: HexBytes | None,
717
+ question_id_in: list[HexBytes] | None,
718
+ opened_before: t.Optional[DatetimeUTC],
719
+ opened_after: t.Optional[DatetimeUTC],
720
+ excluded_titles: set[str] | None,
721
+ ) -> dict[str, t.Any]:
722
+ """
723
+ Be aware, both Omen subgraph and Reality subgraph are indexing questions, but their fields are a bit different.
724
+ """
725
+ where_stms: dict[str, t.Any] = {}
726
+
727
+ if question_id is not None:
728
+ where_stms["questionId"] = question_id.hex()
729
+
730
+ if current_answer_before is not None:
731
+ where_stms["currentAnswerTimestamp_lt"] = to_int_timestamp(
732
+ current_answer_before
733
+ )
734
+
735
+ if opened_before:
736
+ where_stms["openingTimestamp_lt"] = to_int_timestamp(opened_before)
737
+
738
+ if opened_after:
739
+ where_stms["openingTimestamp_gt"] = to_int_timestamp(opened_after)
740
+
741
+ if finalized_before is not None:
742
+ where_stms["answerFinalizedTimestamp_lt"] = to_int_timestamp(
743
+ finalized_before
744
+ )
745
+
746
+ if finalized_after is not None:
747
+ where_stms["answerFinalizedTimestamp_gt"] = to_int_timestamp(
748
+ finalized_after
749
+ )
750
+
751
+ if with_answers is not None:
752
+ if with_answers:
753
+ where_stms["answerFinalizedTimestamp_not"] = None
754
+ else:
755
+ where_stms["answerFinalizedTimestamp"] = None
756
+
757
+ if question_id_in is not None:
758
+ # Be aware: On Omen subgraph, question's `id` represents `questionId` on reality subgraph. And `id` on reality subraph is just a weird concat of multiple things from the question.
759
+ where_stms["id_in"] = [x.hex() for x in question_id_in]
760
+
761
+ if excluded_titles:
762
+ # Be aware: This is called `qTitle_not_in` on Omen subgraph.
763
+ where_stms["title_not_in"] = [i for i in excluded_titles]
764
+
691
765
  return where_stms
692
766
 
693
767
  def get_questions(
@@ -698,17 +772,25 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
698
772
  current_answer_before: DatetimeUTC | None = None,
699
773
  finalized_before: DatetimeUTC | None = None,
700
774
  finalized_after: DatetimeUTC | None = None,
701
- id_in: list[str] | None = None,
775
+ with_answers: bool | None = None,
702
776
  question_id_in: list[HexBytes] | None = None,
777
+ question_id: HexBytes | None = None,
778
+ opened_before: DatetimeUTC | None = None,
779
+ opened_after: DatetimeUTC | None = None,
780
+ excluded_titles: set[str] | None = None,
703
781
  ) -> list[RealityQuestion]:
704
782
  where_stms: dict[str, t.Any] = self.get_reality_question_filters(
705
783
  user=user,
706
784
  claimed=claimed,
707
785
  finalized_before=finalized_before,
708
786
  finalized_after=finalized_after,
787
+ with_answers=with_answers,
709
788
  current_answer_before=current_answer_before,
710
- id_in=id_in,
711
789
  question_id_in=question_id_in,
790
+ question_id=question_id,
791
+ opened_before=opened_before,
792
+ opened_after=opened_after,
793
+ excluded_titles=excluded_titles,
712
794
  )
713
795
  questions = self.realityeth_subgraph.Query.questions(
714
796
  first=(
@@ -738,12 +820,17 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
738
820
  self,
739
821
  limit: int | None,
740
822
  user: HexAddress | None = None,
741
- question_id: HexBytes | None = None,
823
+ question_user: HexAddress | None = None,
742
824
  question_claimed: bool | None = None,
743
- question_finalized_before: DatetimeUTC | None = None,
744
- question_finalized_after: DatetimeUTC | None = None,
745
- question_current_answer_before: DatetimeUTC | None = None,
825
+ question_opened_before: t.Optional[DatetimeUTC] = None,
826
+ question_opened_after: t.Optional[DatetimeUTC] = None,
827
+ question_finalized_before: t.Optional[DatetimeUTC] = None,
828
+ question_finalized_after: t.Optional[DatetimeUTC] = None,
829
+ question_with_answers: bool | None = None,
830
+ question_id: HexBytes | None = None,
746
831
  question_id_in: list[HexBytes] | None = None,
832
+ question_current_answer_before: DatetimeUTC | None = None,
833
+ question_excluded_titles: set[str] | None = None,
747
834
  ) -> list[RealityResponse]:
748
835
  where_stms: dict[str, t.Any] = {}
749
836
 
@@ -751,12 +838,17 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
751
838
  where_stms["user"] = user.lower()
752
839
 
753
840
  where_stms["question_"] = self.get_reality_question_filters(
841
+ user=question_user,
754
842
  question_id=question_id,
755
843
  claimed=question_claimed,
844
+ opened_before=question_opened_before,
845
+ opened_after=question_opened_after,
756
846
  finalized_before=question_finalized_before,
757
847
  finalized_after=question_finalized_after,
848
+ with_answers=question_with_answers,
758
849
  current_answer_before=question_current_answer_before,
759
850
  question_id_in=question_id_in,
851
+ excluded_titles=question_excluded_titles,
760
852
  )
761
853
 
762
854
  responses = self.realityeth_subgraph.Query.responses(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.51.1
3
+ Version: 0.52.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
@@ -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=2wDZ0BmK9O5Lud-q-FCzgW0tsK9GxMU0rUMlcPxSS04,3184
44
44
  prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=ctRcGm1G8qmUB5RMPoQ_C_GN3Ct24BWDB1gJyOhH_vE,3604
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=yYPHpZM4fthC1EhyXkXC8iyDQ1ITNBBY9nOHeKD6XSw,27283
46
+ prediction_market_agent_tooling/markets/omen/data_models.py,sha256=nCjsc-ylIzQOCK_1BW-5NoYrS-NIXz2Hg9N1-IqhhC8,27516
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
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
50
+ prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=-vsSPrkPONDhBwq5TMDM2p3_nKTRpaW0J-wOnEGJABs,36746
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
@@ -91,8 +91,8 @@ prediction_market_agent_tooling/tools/tavily_storage/tavily_models.py,sha256=99S
91
91
  prediction_market_agent_tooling/tools/tavily_storage/tavily_storage.py,sha256=xrtQH9v5pXycBRyc5j45pWqkSffkoc9efNIU1_G633Q,3706
92
92
  prediction_market_agent_tooling/tools/utils.py,sha256=PGmh-9aeEJe_YcHVIiHMLybx31ppng7tVBlMaIfnWy8,7135
93
93
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=dkcjG-LtuaWRh7WEMzRGmZ5B5rsxZTlliFOI6fj-EJ8,11842
94
- prediction_market_agent_tooling-0.51.1.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
95
- prediction_market_agent_tooling-0.51.1.dist-info/METADATA,sha256=rGMwRfY6ulZ8GTMKjPP7EWN1nrwTxxazh4aj4vf7Qoc,8056
96
- prediction_market_agent_tooling-0.51.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
97
- prediction_market_agent_tooling-0.51.1.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
98
- prediction_market_agent_tooling-0.51.1.dist-info/RECORD,,
94
+ prediction_market_agent_tooling-0.52.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
95
+ prediction_market_agent_tooling-0.52.0.dist-info/METADATA,sha256=rjXGpbKmQHBjIE_0GbiO8uOMNebm1FqwLqWYXHTK3F4,8056
96
+ prediction_market_agent_tooling-0.52.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
97
+ prediction_market_agent_tooling-0.52.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
98
+ prediction_market_agent_tooling-0.52.0.dist-info/RECORD,,