prediction-market-agent-tooling 0.61.1.dev463__py3-none-any.whl → 0.61.1.dev477__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.
Files changed (48) hide show
  1. prediction_market_agent_tooling/deploy/agent.py +5 -4
  2. prediction_market_agent_tooling/deploy/betting_strategy.py +69 -53
  3. prediction_market_agent_tooling/gtypes.py +27 -105
  4. prediction_market_agent_tooling/jobs/jobs_models.py +7 -5
  5. prediction_market_agent_tooling/jobs/omen/omen_jobs.py +17 -13
  6. prediction_market_agent_tooling/markets/agent_market.py +52 -96
  7. prediction_market_agent_tooling/markets/blockchain_utils.py +27 -1
  8. prediction_market_agent_tooling/markets/data_models.py +44 -40
  9. prediction_market_agent_tooling/markets/manifold/api.py +6 -2
  10. prediction_market_agent_tooling/markets/manifold/data_models.py +25 -33
  11. prediction_market_agent_tooling/markets/manifold/manifold.py +11 -8
  12. prediction_market_agent_tooling/markets/market_fees.py +2 -4
  13. prediction_market_agent_tooling/markets/omen/data_models.py +57 -66
  14. prediction_market_agent_tooling/markets/omen/omen.py +249 -214
  15. prediction_market_agent_tooling/markets/omen/omen_contracts.py +29 -31
  16. prediction_market_agent_tooling/markets/omen/omen_resolving.py +14 -7
  17. prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +14 -20
  18. prediction_market_agent_tooling/markets/polymarket/data_models.py +3 -3
  19. prediction_market_agent_tooling/markets/polymarket/data_models_web.py +4 -4
  20. prediction_market_agent_tooling/markets/polymarket/polymarket.py +5 -3
  21. prediction_market_agent_tooling/markets/seer/data_models.py +11 -8
  22. prediction_market_agent_tooling/markets/seer/seer.py +71 -85
  23. prediction_market_agent_tooling/markets/seer/seer_contracts.py +5 -10
  24. prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py +7 -7
  25. prediction_market_agent_tooling/monitor/monitor.py +2 -2
  26. prediction_market_agent_tooling/tools/balances.py +11 -9
  27. prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +10 -12
  28. prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +24 -27
  29. prediction_market_agent_tooling/tools/betting_strategies/utils.py +1 -3
  30. prediction_market_agent_tooling/tools/contract.py +10 -14
  31. prediction_market_agent_tooling/tools/cow/cow_manager.py +4 -3
  32. prediction_market_agent_tooling/tools/cow/cow_order.py +4 -3
  33. prediction_market_agent_tooling/tools/langfuse_client_utils.py +1 -13
  34. prediction_market_agent_tooling/tools/omen/sell_positions.py +3 -6
  35. prediction_market_agent_tooling/tools/safe.py +6 -5
  36. prediction_market_agent_tooling/tools/tokens/auto_deposit.py +30 -32
  37. prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +22 -5
  38. prediction_market_agent_tooling/tools/tokens/main_token.py +2 -2
  39. prediction_market_agent_tooling/tools/utils.py +8 -14
  40. prediction_market_agent_tooling/tools/web3_utils.py +41 -24
  41. {prediction_market_agent_tooling-0.61.1.dev463.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/METADATA +1 -2
  42. {prediction_market_agent_tooling-0.61.1.dev463.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/RECORD +45 -48
  43. prediction_market_agent_tooling/tools/_generic_value.py +0 -255
  44. prediction_market_agent_tooling/tools/tokens/token_utils.py +0 -46
  45. prediction_market_agent_tooling/tools/tokens/usd.py +0 -63
  46. {prediction_market_agent_tooling-0.61.1.dev463.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/LICENSE +0 -0
  47. {prediction_market_agent_tooling-0.61.1.dev463.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/WHEEL +0 -0
  48. {prediction_market_agent_tooling-0.61.1.dev463.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/entry_points.txt +0 -0
@@ -1,7 +1,5 @@
1
1
  from pydantic import BaseModel, Field
2
2
 
3
- from prediction_market_agent_tooling.gtypes import Token
4
-
5
3
 
6
4
  class MarketFees(BaseModel):
7
5
  bet_proportion: float = Field(
@@ -34,5 +32,5 @@ class MarketFees(BaseModel):
34
32
  total_fee = self.total_fee_absolute_value(bet_amount)
35
33
  return total_fee / bet_amount
36
34
 
37
- def get_after_fees(self, bet_amount: Token) -> Token:
38
- return bet_amount - Token(self.total_fee_absolute_value(bet_amount.value))
35
+ def get_bet_size_after_fees(self, bet_amount: float) -> float:
36
+ return bet_amount - self.total_fee_absolute_value(bet_amount)
@@ -9,16 +9,17 @@ from prediction_market_agent_tooling.gtypes import (
9
9
  HexAddress,
10
10
  HexBytes,
11
11
  HexStr,
12
- OutcomeStr,
13
- OutcomeWei,
12
+ OmenOutcomeToken,
14
13
  Probability,
15
- Token,
16
14
  Wei,
15
+ wei_type,
17
16
  xDai,
18
- xDaiWei,
19
17
  )
20
18
  from prediction_market_agent_tooling.markets.data_models import (
21
19
  Bet,
20
+ BetAmount,
21
+ Currency,
22
+ ProfitAmount,
22
23
  Resolution,
23
24
  ResolvedBet,
24
25
  )
@@ -27,7 +28,6 @@ from prediction_market_agent_tooling.tools.contract import (
27
28
  init_collateral_token_contract,
28
29
  to_gnosis_chain_contract,
29
30
  )
30
- from prediction_market_agent_tooling.tools.tokens.usd import get_token_in_usd
31
31
  from prediction_market_agent_tooling.tools.utils import (
32
32
  BPS_CONSTANT,
33
33
  DatetimeUTC,
@@ -35,13 +35,11 @@ from prediction_market_agent_tooling.tools.utils import (
35
35
  should_not_happen,
36
36
  utcnow,
37
37
  )
38
+ from prediction_market_agent_tooling.tools.web3_utils import wei_to_xdai
38
39
 
39
- OMEN_TRUE_OUTCOME = OutcomeStr("Yes")
40
- OMEN_FALSE_OUTCOME = OutcomeStr("No")
41
- OMEN_BINARY_MARKET_OUTCOMES: t.Sequence[OutcomeStr] = [
42
- OMEN_TRUE_OUTCOME,
43
- OMEN_FALSE_OUTCOME,
44
- ]
40
+ OMEN_TRUE_OUTCOME = "Yes"
41
+ OMEN_FALSE_OUTCOME = "No"
42
+ OMEN_BINARY_MARKET_OUTCOMES = [OMEN_TRUE_OUTCOME, OMEN_FALSE_OUTCOME]
45
43
  INVALID_ANSWER = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
46
44
  INVALID_ANSWER_HEX_BYTES = HexBytes(INVALID_ANSWER)
47
45
  INVALID_ANSWER_STR = HexStr(INVALID_ANSWER_HEX_BYTES.hex())
@@ -80,7 +78,7 @@ class Question(BaseModel):
80
78
  title: str
81
79
  data: str
82
80
  templateId: int
83
- outcomes: t.Sequence[OutcomeStr]
81
+ outcomes: list[str]
84
82
  isPendingArbitration: bool
85
83
  openingTimestamp: int
86
84
  answerFinalizedTimestamp: t.Optional[DatetimeUTC] = None
@@ -189,9 +187,9 @@ class OmenPosition(BaseModel):
189
187
  class OmenUserPosition(BaseModel):
190
188
  id: HexBytes
191
189
  position: OmenPosition
192
- balance: OutcomeWei
193
- wrappedBalance: OutcomeWei
194
- totalBalance: OutcomeWei
190
+ balance: Wei
191
+ wrappedBalance: Wei
192
+ totalBalance: Wei
195
193
 
196
194
  @property
197
195
  def redeemable(self) -> bool:
@@ -211,6 +209,8 @@ class OmenMarket(BaseModel):
211
209
  5. redeeming - a user withdraws collateral tokens from the market
212
210
  """
213
211
 
212
+ BET_AMOUNT_CURRENCY: t.ClassVar[Currency] = Currency.xDai
213
+
214
214
  id: HexAddress
215
215
  title: str
216
216
  creator: HexAddress
@@ -224,9 +224,9 @@ class OmenMarket(BaseModel):
224
224
  liquidityParameter: Wei
225
225
  usdVolume: USD
226
226
  collateralToken: HexAddress
227
- outcomes: t.Sequence[OutcomeStr]
228
- outcomeTokenAmounts: list[OutcomeWei]
229
- outcomeTokenMarginalPrices: t.Optional[list[Token]]
227
+ outcomes: list[str]
228
+ outcomeTokenAmounts: list[OmenOutcomeToken]
229
+ outcomeTokenMarginalPrices: t.Optional[list[xDai]]
230
230
  fee: t.Optional[Wei]
231
231
  resolutionTimestamp: t.Optional[int] = None
232
232
  answerFinalizedTimestamp: t.Optional[int] = None
@@ -367,11 +367,7 @@ class OmenMarket(BaseModel):
367
367
  )
368
368
 
369
369
  return Probability(
370
- 1
371
- - (
372
- self.outcomeTokenAmounts[self.yes_index]
373
- / sum(self.outcomeTokenAmounts, start=OutcomeWei(0))
374
- )
370
+ 1 - self.outcomeTokenAmounts[self.yes_index] / sum(self.outcomeTokenAmounts)
375
371
  )
376
372
 
377
373
  def __repr__(self) -> str:
@@ -470,22 +466,22 @@ class OmenMarket(BaseModel):
470
466
 
471
467
 
472
468
  def calculate_liquidity_parameter(
473
- outcome_token_amounts: list[OutcomeWei],
469
+ outcome_token_amounts: list[OmenOutcomeToken],
474
470
  ) -> Wei:
475
471
  """
476
472
  Converted to Python from https://github.com/protofire/omen-subgraph/blob/f92bbfb6fa31ed9cd5985c416a26a2f640837d8b/src/utils/fpmm.ts#L171.
477
473
  """
478
- amounts_product = Wei(1)
474
+ amounts_product = 1.0
479
475
  for amount in outcome_token_amounts:
480
- amounts_product *= amount.as_wei
476
+ amounts_product *= amount
481
477
  n = len(outcome_token_amounts)
482
- liquidity_parameter = amounts_product.value ** (1.0 / n)
483
- return Wei(liquidity_parameter)
478
+ liquidity_parameter = amounts_product ** (1.0 / n)
479
+ return wei_type(liquidity_parameter)
484
480
 
485
481
 
486
482
  def calculate_marginal_prices(
487
- outcome_token_amounts: list[OutcomeWei],
488
- ) -> list[Token] | None:
483
+ outcome_token_amounts: list[OmenOutcomeToken],
484
+ ) -> list[xDai] | None:
489
485
  """
490
486
  Converted to Python from https://github.com/protofire/omen-subgraph/blob/f92bbfb6fa31ed9cd5985c416a26a2f640837d8b/src/utils/fpmm.ts#L197.
491
487
  """
@@ -494,19 +490,19 @@ def calculate_marginal_prices(
494
490
  return None
495
491
 
496
492
  n_outcomes = len(outcome_token_amounts)
497
- weights: list[Wei] = []
493
+ weights = []
498
494
 
499
495
  for i in range(n_outcomes):
500
- weight = Wei(1)
496
+ weight = 1.0
501
497
  for j in range(n_outcomes):
502
498
  if i != j:
503
- weight *= outcome_token_amounts[j].as_wei.value
499
+ weight *= outcome_token_amounts[j]
504
500
  weights.append(weight)
505
501
 
506
- sum_weights = sum(weights, start=Wei(0))
502
+ sum_weights = sum(weights)
507
503
 
508
- marginal_prices = [weights[i].value / sum_weights.value for i in range(n_outcomes)]
509
- return [Token(mp) for mp in marginal_prices]
504
+ marginal_prices = [weights[i] / sum_weights for i in range(n_outcomes)]
505
+ return [xDai(mp) for mp in marginal_prices]
510
506
 
511
507
 
512
508
  class OmenBetCreator(BaseModel):
@@ -517,25 +513,22 @@ class OmenBet(BaseModel):
517
513
  id: HexAddress # A concatenation of: FPMM contract ID, trader ID and nonce. See https://github.com/protofire/omen-subgraph/blob/f92bbfb6fa31ed9cd5985c416a26a2f640837d8b/src/FixedProductMarketMakerMapping.ts#L109
518
514
  title: str
519
515
  collateralToken: HexAddress
520
- outcomeTokenMarginalPrice: Token
521
- oldOutcomeTokenMarginalPrice: Token
516
+ outcomeTokenMarginalPrice: xDai
517
+ oldOutcomeTokenMarginalPrice: xDai
522
518
  type: str
523
519
  creator: OmenBetCreator
524
520
  creationTimestamp: int
525
521
  collateralAmount: Wei
526
522
  feeAmount: Wei
527
523
  outcomeIndex: int
528
- outcomeTokensTraded: OutcomeWei
524
+ outcomeTokensTraded: Wei
529
525
  transactionHash: HexBytes
530
526
  fpmm: OmenMarket
531
527
 
532
528
  @property
533
- def collateral_amount_token(self) -> Token:
534
- return self.collateralAmount.as_token
535
-
536
- @property
537
- def collateral_token_checksummed(self) -> ChecksumAddress:
538
- return Web3.to_checksum_address(self.collateralToken)
529
+ def collateral_amount_usd(self) -> USD:
530
+ # Convert manually instad of using the field `collateralAmountUSD` available on the graph, because it's bugged, it's 0 for non-xDai markets.
531
+ return USD(wei_to_xdai(self.collateralAmount))
539
532
 
540
533
  @property
541
534
  def creation_datetime(self) -> DatetimeUTC:
@@ -555,25 +548,23 @@ class OmenBet(BaseModel):
555
548
  # Marginal price is the probability of the outcome after placing this bet.
556
549
  return Probability(float(self.outcomeTokenMarginalPrice))
557
550
 
558
- def get_collateral_amount_usd(self) -> USD:
559
- return get_token_in_usd(
560
- self.collateral_amount_token, self.collateral_token_checksummed
561
- )
562
-
563
- def get_profit(self) -> Token:
564
- bet_amount = self.collateral_amount_token
551
+ def get_profit(self) -> ProfitAmount:
552
+ bet_amount_xdai = wei_to_xdai(self.collateralAmount)
565
553
  profit = (
566
- self.outcomeTokensTraded.as_outcome_token.as_token - bet_amount
554
+ wei_to_xdai(self.outcomeTokensTraded) - bet_amount_xdai
567
555
  if self.boolean_outcome == self.fpmm.boolean_outcome
568
- else -bet_amount
556
+ else -bet_amount_xdai
557
+ )
558
+ return ProfitAmount(
559
+ amount=profit,
560
+ currency=Currency.xDai,
569
561
  )
570
- return profit
571
562
 
572
563
  def to_bet(self) -> Bet:
573
564
  return Bet(
574
565
  id=str(self.transactionHash),
575
566
  # Use the transaction hash instead of the bet id - both are valid, but we return the transaction hash from the trade functions, so be consistent here.
576
- amount=self.collateral_amount_token,
567
+ amount=BetAmount(amount=self.collateral_amount_usd, currency=Currency.xDai),
577
568
  outcome=self.boolean_outcome,
578
569
  created_time=self.creation_datetime,
579
570
  market_question=self.title,
@@ -589,7 +580,7 @@ class OmenBet(BaseModel):
589
580
  return ResolvedBet(
590
581
  id=self.transactionHash.hex(),
591
582
  # Use the transaction hash instead of the bet id - both are valid, but we return the transaction hash from the trade functions, so be consistent here.
592
- amount=self.collateral_amount_token,
583
+ amount=BetAmount(amount=self.collateral_amount_usd, currency=Currency.xDai),
593
584
  outcome=self.boolean_outcome,
594
585
  created_time=self.creation_datetime,
595
586
  market_question=self.title,
@@ -667,7 +658,7 @@ class RealityResponse(BaseModel):
667
658
  answer: HexBytes
668
659
  isUnrevealed: bool
669
660
  isCommitment: bool
670
- bond: xDaiWei
661
+ bond: Wei
671
662
  user: HexAddress
672
663
  historyHash: HexBytes
673
664
  question: RealityQuestion
@@ -676,7 +667,7 @@ class RealityResponse(BaseModel):
676
667
 
677
668
  @property
678
669
  def bond_xdai(self) -> xDai:
679
- return self.bond.as_xdai
670
+ return wei_to_xdai(self.bond)
680
671
 
681
672
  @property
682
673
  def user_checksummed(self) -> ChecksumAddress:
@@ -693,7 +684,7 @@ class RealityAnswersResponse(BaseModel):
693
684
 
694
685
  def format_realitio_question(
695
686
  question: str,
696
- outcomes: t.Sequence[str],
687
+ outcomes: list[str],
697
688
  category: str,
698
689
  language: str,
699
690
  template_id: int,
@@ -720,7 +711,7 @@ def parse_realitio_question(question_raw: str, template_id: int) -> "ParsedQuest
720
711
  """If you add a new template id here, also add to the encoding function above."""
721
712
  if template_id == 2:
722
713
  question, outcomes_raw, category, language = question_raw.split("␟")
723
- outcomes = [OutcomeStr(o.strip('"')) for o in outcomes_raw.split(",")]
714
+ outcomes = [o.strip('"') for o in outcomes_raw.split(",")]
724
715
  return ParsedQuestion(
725
716
  question=question, outcomes=outcomes, category=category, language=language
726
717
  )
@@ -730,7 +721,7 @@ def parse_realitio_question(question_raw: str, template_id: int) -> "ParsedQuest
730
721
 
731
722
  class ParsedQuestion(BaseModel):
732
723
  question: str
733
- outcomes: t.Sequence[OutcomeStr]
724
+ outcomes: list[str]
734
725
  language: str
735
726
  category: str
736
727
 
@@ -792,13 +783,13 @@ class ConditionPreparationEvent(BaseModel):
792
783
 
793
784
  class FPMMFundingAddedEvent(BaseModel):
794
785
  funder: HexAddress
795
- amountsAdded: list[Wei]
786
+ amountsAdded: list[OmenOutcomeToken]
796
787
  sharesMinted: Wei
797
788
 
798
789
  @property
799
- def outcome_token_amounts(self) -> list[OutcomeWei]:
790
+ def outcome_token_amounts(self) -> list[OmenOutcomeToken]:
800
791
  # Just renaming so we remember what it is.
801
- return [OutcomeWei(x.value) for x in self.amountsAdded]
792
+ return self.amountsAdded
802
793
 
803
794
 
804
795
  class CreatedMarket(BaseModel):
@@ -810,7 +801,7 @@ class CreatedMarket(BaseModel):
810
801
  condition_event: ConditionPreparationEvent | None
811
802
  initial_funds: Wei
812
803
  fee: Wei
813
- distribution_hint: list[OutcomeWei] | None
804
+ distribution_hint: list[OmenOutcomeToken] | None
814
805
 
815
806
  @property
816
807
  def url(self) -> str: