prediction-market-agent-tooling 0.26.0__py3-none-any.whl → 0.28.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.
@@ -2,7 +2,6 @@ import typing as t
2
2
 
3
3
  from gnosis.eth import EthereumClient
4
4
  from gnosis.safe import Safe
5
- from pydantic import BaseModel
6
5
  from pydantic.types import SecretStr
7
6
  from pydantic_settings import BaseSettings, SettingsConfigDict
8
7
 
@@ -58,6 +57,15 @@ class APIKeys(BaseSettings):
58
57
  "BET_FROM_PRIVATE_KEY missing in the environment.",
59
58
  )
60
59
 
60
+ @property
61
+ def bet_from_address(self) -> ChecksumAddress:
62
+ """If the SAFE is available, we always route transactions via SAFE. Otherwise we use the EOA."""
63
+ return (
64
+ self.SAFE_ADDRESS
65
+ if self.SAFE_ADDRESS
66
+ else private_key_to_public_key(self.bet_from_private_key)
67
+ )
68
+
61
69
  @property
62
70
  def openai_api_key(self) -> SecretStr:
63
71
  return check_not_none(
@@ -110,35 +118,10 @@ class APIKeys(BaseSettings):
110
118
  if APIKeys.model_fields[k].annotation in SECRET_TYPES and v is not None
111
119
  }
112
120
 
113
-
114
- class PrivateCredentials(BaseModel):
115
- private_key: PrivateKey
116
- safe_address: ChecksumAddress | None
117
-
118
- @property
119
- def public_key(self) -> ChecksumAddress:
120
- """If the SAFE is available, we always route transactions via SAFE. Otherwise we use the EOA."""
121
- return (
122
- self.safe_address
123
- if self.safe_address is not None
124
- else private_key_to_public_key(self.private_key)
125
- )
126
-
127
- @property
128
- def has_safe_address(self) -> bool:
129
- return self.safe_address is not None
130
-
131
- @staticmethod
132
- def from_api_keys(api_keys: APIKeys) -> "PrivateCredentials":
133
- return PrivateCredentials(
134
- private_key=api_keys.bet_from_private_key,
135
- safe_address=api_keys.SAFE_ADDRESS,
136
- )
137
-
138
121
  def check_if_is_safe_owner(self, ethereum_client: EthereumClient) -> bool:
139
- if not self.safe_address:
122
+ if not self.SAFE_ADDRESS:
140
123
  raise ValueError("Cannot check ownership if safe_address is not defined.")
141
124
 
142
- s = Safe(self.safe_address, ethereum_client) # type: ignore[abstract]
143
- public_key_from_signer = private_key_to_public_key(self.private_key)
125
+ s = Safe(self.SAFE_ADDRESS, ethereum_client) # type: ignore[abstract]
126
+ public_key_from_signer = private_key_to_public_key(self.bet_from_private_key)
144
127
  return s.retrieve_is_owner(public_key_from_signer)
@@ -8,7 +8,7 @@ from datetime import datetime, timedelta
8
8
  from pydantic import BaseModel, BeforeValidator
9
9
  from typing_extensions import Annotated
10
10
 
11
- from prediction_market_agent_tooling.config import APIKeys, PrivateCredentials
11
+ from prediction_market_agent_tooling.config import APIKeys
12
12
  from prediction_market_agent_tooling.deploy.constants import (
13
13
  MARKET_TYPE_KEY,
14
14
  REPOSITORY_KEY,
@@ -260,11 +260,9 @@ class DeployableTraderAgent(DeployableAgent):
260
260
  """
261
261
  Executes actions that occur before bets are placed.
262
262
  """
263
- private_credentials = PrivateCredentials.from_api_keys(APIKeys())
264
-
265
263
  if market_type == MarketType.OMEN:
266
264
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
267
- redeem_from_all_user_positions(private_credentials)
265
+ redeem_from_all_user_positions(APIKeys())
268
266
 
269
267
  def process_bets(self, market_type: MarketType) -> None:
270
268
  """
@@ -1,5 +1,7 @@
1
+ import builtins
1
2
  import logging
2
3
  import sys
4
+ import typing as t
3
5
  import warnings
4
6
  from enum import Enum
5
7
 
@@ -35,9 +37,11 @@ def patch_logger() -> None:
35
37
  format_loguru = GCP_LOG_LOGURU_FORMAT
36
38
  format_logging = GCP_LOG_LOGGING_FORMAT
37
39
  datefmt_logging = GCP_LOG_FORMAT_LOGGING_DATEFMT
40
+ print_logging = print_using_loguru_info
38
41
 
39
42
  elif config.LOG_FORMAT == LogFormat.DEFAULT:
40
43
  format_loguru, format_logging, datefmt_logging = None, None, None
44
+ print_logging = None
41
45
 
42
46
  else:
43
47
  raise ValueError(f"Unknown log format: {config.LOG_FORMAT}")
@@ -63,9 +67,26 @@ def patch_logger() -> None:
63
67
  # Use logging module for warnings.
64
68
  logging.captureWarnings(True)
65
69
 
70
+ # Use loguru for prints.
71
+ if print_logging is not None:
72
+ builtins.print = print_logging # type: ignore[assignment] # Monkey patching, it's messy but it works.
73
+
66
74
  logger.info(f"Patched logger for {config.LOG_FORMAT.value} format.")
67
75
 
68
76
 
77
+ def print_using_loguru_info(
78
+ *values: object,
79
+ sep: str = " ",
80
+ end: str = "\n",
81
+ **kwargs: t.Any,
82
+ ) -> None:
83
+ message = sep.join(map(str, values)) + end
84
+ message = message.strip().replace(
85
+ "\n", "\\n"
86
+ ) # Escape new lines, because otherwise logs will be broken.
87
+ logger.info(message)
88
+
89
+
69
90
  def simple_warning_format(message, category, filename, lineno, line=None): # type: ignore[no-untyped-def] # Not typed in the standard library neither.
70
91
  return f"{category.__name__}: {message}"
71
92
 
@@ -18,6 +18,7 @@ from prediction_market_agent_tooling.tools.utils import (
18
18
  add_utc_timezone_validator,
19
19
  check_not_none,
20
20
  should_not_happen,
21
+ utcnow,
21
22
  )
22
23
 
23
24
 
@@ -147,9 +148,18 @@ class AgentMarket(BaseModel):
147
148
  ) -> list[Bet]:
148
149
  raise NotImplementedError("Subclasses must implement this method")
149
150
 
151
+ def is_closed(self) -> bool:
152
+ return self.close_time is not None and self.close_time <= utcnow()
153
+
150
154
  def is_resolved(self) -> bool:
151
155
  return self.resolution is not None
152
156
 
157
+ def get_liquidity(self) -> TokenAmount:
158
+ raise NotImplementedError("Subclasses must implement this method")
159
+
160
+ def has_liquidity(self) -> bool:
161
+ return self.get_liquidity().amount > 0
162
+
153
163
  def has_successful_resolution(self) -> bool:
154
164
  return self.resolution in [Resolution.YES, Resolution.NO]
155
165
 
@@ -174,8 +184,15 @@ class AgentMarket(BaseModel):
174
184
  raise NotImplementedError("Subclasses must implement this method")
175
185
 
176
186
  @classmethod
177
- def get_positions(cls, user_id: str) -> list[Position]:
187
+ def get_positions(cls, user_id: str, liquid_only: bool = False) -> list[Position]:
178
188
  """
179
189
  Get all non-zero positions a user has in any market.
190
+
191
+ If `liquid_only` is True, only return positions that can be sold.
180
192
  """
181
193
  raise NotImplementedError("Subclasses must implement this method")
194
+
195
+ def can_be_traded(self) -> bool:
196
+ if self.is_closed() or not self.has_liquidity():
197
+ return False
198
+ return True
@@ -2,7 +2,7 @@ import typing as t
2
2
  from datetime import datetime, timedelta
3
3
  from enum import Enum
4
4
 
5
- from prediction_market_agent_tooling.config import APIKeys, PrivateCredentials
5
+ from prediction_market_agent_tooling.config import APIKeys
6
6
  from prediction_market_agent_tooling.markets.agent_market import (
7
7
  AgentMarket,
8
8
  FilterBy,
@@ -68,7 +68,6 @@ def have_bet_on_market_since(
68
68
  keys: APIKeys, market: AgentMarket, since: timedelta
69
69
  ) -> bool:
70
70
  start_time = utcnow() - since
71
- credentials = PrivateCredentials.from_api_keys(keys)
72
71
  recently_betted_questions = (
73
72
  set(
74
73
  get_manifold_market(b.contractId).question
@@ -85,7 +84,7 @@ def have_bet_on_market_since(
85
84
  set(
86
85
  b.title
87
86
  for b in OmenSubgraphHandler().get_bets(
88
- better_address=credentials.public_key,
87
+ better_address=keys.bet_from_address,
89
88
  start_time=start_time,
90
89
  )
91
90
  )
@@ -5,7 +5,7 @@ from datetime import datetime
5
5
  from web3 import Web3
6
6
  from web3.constants import HASH_ZERO
7
7
 
8
- from prediction_market_agent_tooling.config import APIKeys, PrivateCredentials
8
+ from prediction_market_agent_tooling.config import APIKeys
9
9
  from prediction_market_agent_tooling.gtypes import (
10
10
  ChecksumAddress,
11
11
  HexAddress,
@@ -117,11 +117,17 @@ class OmenAgentMarket(AgentMarket):
117
117
  else None
118
118
  )
119
119
 
120
- def get_liquidity(self) -> Wei:
120
+ def get_liquidity_in_wei(self) -> Wei:
121
121
  return self.get_contract().totalSupply()
122
122
 
123
123
  def get_liquidity_in_xdai(self) -> xDai:
124
- return wei_to_xdai(self.get_liquidity())
124
+ return wei_to_xdai(self.get_liquidity_in_wei())
125
+
126
+ def get_liquidity(self) -> TokenAmount:
127
+ return TokenAmount(
128
+ amount=self.get_liquidity_in_xdai(),
129
+ currency=Currency.xDai,
130
+ )
125
131
 
126
132
  def get_tiny_bet_amount(self) -> BetAmount:
127
133
  return BetAmount(amount=0.00001, currency=self.currency)
@@ -133,13 +139,15 @@ class OmenAgentMarket(AgentMarket):
133
139
  omen_auto_deposit: bool = True,
134
140
  web3: Web3 | None = None,
135
141
  ) -> None:
142
+ if not self.can_be_traded():
143
+ raise ValueError(
144
+ f"Market {self.id} is not open for trading. Cannot place bet."
145
+ )
136
146
  if amount.currency != self.currency:
137
147
  raise ValueError(f"Omen bets are made in xDai. Got {amount.currency}.")
138
148
  amount_xdai = xDai(amount.amount)
139
- keys = APIKeys()
140
- private_credentials = PrivateCredentials.from_api_keys(keys)
141
149
  binary_omen_buy_outcome_tx(
142
- private_credentials=private_credentials,
150
+ api_keys=APIKeys(),
143
151
  amount=amount_xdai,
144
152
  market=self,
145
153
  binary_outcome=outcome,
@@ -150,10 +158,12 @@ class OmenAgentMarket(AgentMarket):
150
158
  def sell_tokens(
151
159
  self, outcome: bool, amount: TokenAmount, auto_withdraw: bool = True
152
160
  ) -> None:
153
- keys = APIKeys()
154
- private_credentials = PrivateCredentials.from_api_keys(keys)
161
+ if not self.can_be_traded():
162
+ raise ValueError(
163
+ f"Market {self.id} is not open for trading. Cannot sell tokens."
164
+ )
155
165
  binary_omen_sell_outcome_tx(
156
- private_credentials=private_credentials,
166
+ api_keys=APIKeys(),
157
167
  amount=xDai(amount.amount),
158
168
  market=self,
159
169
  binary_outcome=outcome,
@@ -206,9 +216,9 @@ class OmenAgentMarket(AgentMarket):
206
216
 
207
217
  def redeem_positions(
208
218
  self,
209
- private_credentials: PrivateCredentials,
219
+ api_keys: APIKeys,
210
220
  ) -> None:
211
- for_public_key = private_credentials.public_key
221
+ for_public_key = api_keys.bet_from_address
212
222
  market_is_redeemable = self.market_redeemable_by(user=for_public_key)
213
223
  if not market_is_redeemable:
214
224
  logger.debug(
@@ -216,9 +226,7 @@ class OmenAgentMarket(AgentMarket):
216
226
  )
217
227
  return None
218
228
 
219
- omen_redeem_full_position_tx(
220
- private_credentials=private_credentials, market=self
221
- )
229
+ omen_redeem_full_position_tx(api_keys=api_keys, market=self)
222
230
 
223
231
  @staticmethod
224
232
  def from_data_model(model: OmenMarket) -> "OmenAgentMarket":
@@ -273,9 +281,6 @@ class OmenAgentMarket(AgentMarket):
273
281
  bets = OmenSubgraphHandler().get_bets(
274
282
  better_address=better_address, start_time=start_time
275
283
  )
276
- # get unique titles
277
- seen_titles = {bet.title: bet for bet in bets}
278
- bets = list(seen_titles.values())
279
284
  bets.sort(key=lambda x: x.creation_datetime)
280
285
  return [b.to_bet() for b in bets]
281
286
 
@@ -310,7 +315,7 @@ class OmenAgentMarket(AgentMarket):
310
315
  )
311
316
 
312
317
  @classmethod
313
- def get_positions(cls, user_id: str) -> list[Position]:
318
+ def get_positions(cls, user_id: str, liquid_only: bool = False) -> list[Position]:
314
319
  sgh = OmenSubgraphHandler()
315
320
  omen_positions = sgh.get_user_positions(
316
321
  better_address=Web3.to_checksum_address(user_id),
@@ -338,6 +343,11 @@ class OmenAgentMarket(AgentMarket):
338
343
  positions = []
339
344
  for condition_id, omen_positions in omen_positions_dict.items():
340
345
  market = cls.from_data_model(omen_markets[condition_id])
346
+
347
+ # Skip markets that cannot be traded if `liquid_only`` is True.
348
+ if liquid_only and not market.can_be_traded():
349
+ continue
350
+
341
351
  amounts: dict[OutcomeStr, TokenAmount] = {}
342
352
  for omen_position in omen_positions:
343
353
  outecome_str = market.index_set_to_outcome_str(
@@ -370,7 +380,7 @@ def pick_binary_market(
370
380
 
371
381
 
372
382
  def omen_buy_outcome_tx(
373
- private_credentials: PrivateCredentials,
383
+ api_keys: APIKeys,
374
384
  amount: xDai,
375
385
  market: OmenAgentMarket,
376
386
  outcome: str,
@@ -381,7 +391,7 @@ def omen_buy_outcome_tx(
381
391
  Bets the given amount of xDai for the given outcome in the given market.
382
392
  """
383
393
  amount_wei = xdai_to_wei(amount)
384
- from_address_checksummed = private_credentials.public_key
394
+ from_address_checksummed = api_keys.bet_from_address
385
395
 
386
396
  market_contract: OmenFixedProductMarketMakerContract = market.get_contract()
387
397
 
@@ -398,7 +408,7 @@ def omen_buy_outcome_tx(
398
408
  expected_shares = remove_fraction(expected_shares, 0.01)
399
409
  # Approve the market maker to withdraw our collateral token.
400
410
  collateral_token_contract.approve(
401
- private_credentials=private_credentials,
411
+ api_keys=api_keys,
402
412
  for_address=market_contract.address,
403
413
  amount_wei=amount_wei,
404
414
  web3=web3,
@@ -410,11 +420,11 @@ def omen_buy_outcome_tx(
410
420
  )
411
421
  if auto_deposit and collateral_token_balance < amount_wei:
412
422
  collateral_token_contract.deposit(
413
- private_credentials=private_credentials, amount_wei=amount_wei, web3=web3
423
+ api_keys=api_keys, amount_wei=amount_wei, web3=web3
414
424
  )
415
425
  # Buy shares using the deposited xDai in the collateral token.
416
426
  market_contract.buy(
417
- private_credentials=private_credentials,
427
+ api_keys=api_keys,
418
428
  amount_wei=amount_wei,
419
429
  outcome_index=outcome_index,
420
430
  min_outcome_tokens_to_buy=expected_shares,
@@ -423,7 +433,7 @@ def omen_buy_outcome_tx(
423
433
 
424
434
 
425
435
  def binary_omen_buy_outcome_tx(
426
- private_credentials: PrivateCredentials,
436
+ api_keys: APIKeys,
427
437
  amount: xDai,
428
438
  market: OmenAgentMarket,
429
439
  binary_outcome: bool,
@@ -431,7 +441,7 @@ def binary_omen_buy_outcome_tx(
431
441
  web3: Web3 | None = None,
432
442
  ) -> None:
433
443
  omen_buy_outcome_tx(
434
- private_credentials=private_credentials,
444
+ api_keys=api_keys,
435
445
  amount=amount,
436
446
  market=market,
437
447
  outcome=OMEN_TRUE_OUTCOME if binary_outcome else OMEN_FALSE_OUTCOME,
@@ -441,7 +451,7 @@ def binary_omen_buy_outcome_tx(
441
451
 
442
452
 
443
453
  def omen_sell_outcome_tx(
444
- private_credentials: PrivateCredentials,
454
+ api_keys: APIKeys,
445
455
  amount: xDai, # The xDai value of shares to sell.
446
456
  market: OmenAgentMarket,
447
457
  outcome: str,
@@ -482,14 +492,14 @@ def omen_sell_outcome_tx(
482
492
 
483
493
  # Approve the market maker to move our (all) conditional tokens.
484
494
  conditional_token_contract.setApprovalForAll(
485
- private_credentials=private_credentials,
495
+ api_keys=api_keys,
486
496
  for_address=market_contract.address,
487
497
  approve=True,
488
498
  web3=web3,
489
499
  )
490
500
  # Sell the shares.
491
501
  market_contract.sell(
492
- private_credentials,
502
+ api_keys,
493
503
  amount_wei,
494
504
  outcome_index,
495
505
  max_outcome_tokens_to_sell,
@@ -497,13 +507,11 @@ def omen_sell_outcome_tx(
497
507
  )
498
508
  if auto_withdraw:
499
509
  # Optionally, withdraw from the collateral token back to the `from_address` wallet.
500
- collateral_token.withdraw(
501
- private_credentials=private_credentials, amount_wei=amount_wei, web3=web3
502
- )
510
+ collateral_token.withdraw(api_keys=api_keys, amount_wei=amount_wei, web3=web3)
503
511
 
504
512
 
505
513
  def binary_omen_sell_outcome_tx(
506
- private_credentials: PrivateCredentials,
514
+ api_keys: APIKeys,
507
515
  amount: xDai,
508
516
  market: OmenAgentMarket,
509
517
  binary_outcome: bool,
@@ -511,7 +519,7 @@ def binary_omen_sell_outcome_tx(
511
519
  web3: Web3 | None = None,
512
520
  ) -> None:
513
521
  omen_sell_outcome_tx(
514
- private_credentials=private_credentials,
522
+ api_keys=api_keys,
515
523
  amount=amount,
516
524
  market=market,
517
525
  outcome=OMEN_TRUE_OUTCOME if binary_outcome else OMEN_FALSE_OUTCOME,
@@ -521,7 +529,7 @@ def binary_omen_sell_outcome_tx(
521
529
 
522
530
 
523
531
  def omen_create_market_tx(
524
- private_credentials: PrivateCredentials,
532
+ api_keys: APIKeys,
525
533
  initial_funds: xDai,
526
534
  question: str,
527
535
  closing_time: datetime,
@@ -535,7 +543,7 @@ def omen_create_market_tx(
535
543
  """
536
544
  Based on omen-exchange TypeScript code: https://github.com/protofire/omen-exchange/blob/b0b9a3e71b415d6becf21fe428e1c4fc0dad2e80/app/src/services/cpk/cpk.ts#L308
537
545
  """
538
- from_address = private_credentials.public_key
546
+ from_address = api_keys.bet_from_address
539
547
  initial_funds_wei = xdai_to_wei(initial_funds)
540
548
 
541
549
  realitio_contract = OmenRealitioContract()
@@ -558,7 +566,7 @@ def omen_create_market_tx(
558
566
 
559
567
  # Approve the market maker to withdraw our collateral token.
560
568
  collateral_token_contract.approve(
561
- private_credentials=private_credentials,
569
+ api_keys=api_keys,
562
570
  for_address=factory_contract.address,
563
571
  amount_wei=initial_funds_wei,
564
572
  web3=web3,
@@ -574,13 +582,11 @@ def omen_create_market_tx(
574
582
  and initial_funds_wei > 0
575
583
  and collateral_token_balance < initial_funds_wei
576
584
  ):
577
- collateral_token_contract.deposit(
578
- private_credentials, initial_funds_wei, web3=web3
579
- )
585
+ collateral_token_contract.deposit(api_keys, initial_funds_wei, web3=web3)
580
586
 
581
587
  # Create the question on Realitio.
582
588
  question_id = realitio_contract.askQuestion(
583
- private_credentials=private_credentials,
589
+ api_keys=api_keys,
584
590
  question=question,
585
591
  category=category,
586
592
  outcomes=outcomes,
@@ -599,7 +605,7 @@ def omen_create_market_tx(
599
605
  )
600
606
  if not conditional_token_contract.does_condition_exists(condition_id, web3=web3):
601
607
  conditional_token_contract.prepareCondition(
602
- private_credentials=private_credentials,
608
+ api_keys=api_keys,
603
609
  question_id=question_id,
604
610
  oracle_address=oracle_contract.address,
605
611
  outcomes_slot_count=len(outcomes),
@@ -608,7 +614,7 @@ def omen_create_market_tx(
608
614
 
609
615
  # Create the market.
610
616
  create_market_receipt_tx = factory_contract.create2FixedProductMarketMaker(
611
- private_credentials=private_credentials,
617
+ api_keys=api_keys,
612
618
  condition_id=condition_id,
613
619
  fee=fee,
614
620
  initial_funds_wei=initial_funds_wei,
@@ -627,13 +633,13 @@ def omen_create_market_tx(
627
633
 
628
634
 
629
635
  def omen_fund_market_tx(
630
- private_credentials: PrivateCredentials,
636
+ api_keys: APIKeys,
631
637
  market: OmenAgentMarket,
632
638
  funds: Wei,
633
639
  auto_deposit: bool,
634
640
  web3: Web3 | None = None,
635
641
  ) -> None:
636
- from_address = private_credentials.public_key
642
+ from_address = api_keys.bet_from_address
637
643
  market_contract = market.get_contract()
638
644
  collateral_token_contract = OmenCollateralTokenContract()
639
645
 
@@ -644,16 +650,16 @@ def omen_fund_market_tx(
644
650
  and collateral_token_contract.balanceOf(for_address=from_address, web3=web3)
645
651
  < funds
646
652
  ):
647
- collateral_token_contract.deposit(private_credentials, funds, web3=web3)
653
+ collateral_token_contract.deposit(api_keys, funds, web3=web3)
648
654
 
649
655
  collateral_token_contract.approve(
650
- private_credentials=private_credentials,
656
+ api_keys=api_keys,
651
657
  for_address=market_contract.address,
652
658
  amount_wei=funds,
653
659
  web3=web3,
654
660
  )
655
661
 
656
- market_contract.addFunding(private_credentials, funds, web3=web3)
662
+ market_contract.addFunding(api_keys, funds, web3=web3)
657
663
 
658
664
 
659
665
  def build_parent_collection_id() -> HexStr:
@@ -661,7 +667,7 @@ def build_parent_collection_id() -> HexStr:
661
667
 
662
668
 
663
669
  def omen_redeem_full_position_tx(
664
- private_credentials: PrivateCredentials,
670
+ api_keys: APIKeys,
665
671
  market: OmenAgentMarket,
666
672
  web3: Web3 | None = None,
667
673
  ) -> None:
@@ -670,7 +676,7 @@ def omen_redeem_full_position_tx(
670
676
  to be redeemed before sending the transaction.
671
677
  """
672
678
 
673
- from_address = private_credentials.public_key
679
+ from_address = api_keys.bet_from_address
674
680
 
675
681
  market_contract: OmenFixedProductMarketMakerContract = market.get_contract()
676
682
  conditional_token_contract = OmenConditionalTokenContract()
@@ -700,7 +706,7 @@ def omen_redeem_full_position_tx(
700
706
  return
701
707
 
702
708
  conditional_token_contract.redeemPositions(
703
- private_credentials=private_credentials,
709
+ api_keys=api_keys,
704
710
  collateral_token_address=market.collateral_token_contract_address_checksummed,
705
711
  condition_id=market.condition.id,
706
712
  parent_collection_id=parent_collection_id,
@@ -741,7 +747,7 @@ def get_conditional_tokens_balance_for_market(
741
747
 
742
748
 
743
749
  def omen_remove_fund_market_tx(
744
- private_credentials: PrivateCredentials,
750
+ api_keys: APIKeys,
745
751
  market: OmenAgentMarket,
746
752
  shares: Wei | None,
747
753
  web3: Web3 | None = None,
@@ -754,7 +760,7 @@ def omen_remove_fund_market_tx(
754
760
  After we remove funding, using the `mergePositions` we get `min(shares per index)` of wxDai back, but the remaining shares can be converted back only after the market is resolved.
755
761
  That can be done using the `redeem_from_all_user_positions` function below.
756
762
  """
757
- from_address = private_credentials.public_key
763
+ from_address = api_keys.bet_from_address
758
764
  market_contract = market.get_contract()
759
765
  original_balances = get_balances(from_address, web3=web3)
760
766
 
@@ -769,9 +775,7 @@ def omen_remove_fund_market_tx(
769
775
  )
770
776
  shares = total_shares
771
777
 
772
- market_contract.removeFunding(
773
- private_credentials=private_credentials, remove_funding=shares, web3=web3
774
- )
778
+ market_contract.removeFunding(api_keys=api_keys, remove_funding=shares, web3=web3)
775
779
 
776
780
  conditional_tokens = OmenConditionalTokenContract()
777
781
  parent_collection_id = build_parent_collection_id()
@@ -784,7 +788,7 @@ def omen_remove_fund_market_tx(
784
788
  amount_to_merge = min(amount_per_index_set.values())
785
789
 
786
790
  result = conditional_tokens.mergePositions(
787
- private_credentials=private_credentials,
791
+ api_keys=api_keys,
788
792
  collateral_token_address=market.collateral_token_contract_address_checksummed,
789
793
  parent_collection_id=parent_collection_id,
790
794
  conditionId=market.condition.id,
@@ -802,13 +806,13 @@ def omen_remove_fund_market_tx(
802
806
 
803
807
 
804
808
  def redeem_from_all_user_positions(
805
- private_credentials: PrivateCredentials,
809
+ api_keys: APIKeys,
806
810
  web3: Web3 | None = None,
807
811
  ) -> None:
808
812
  """
809
813
  Redeems from all user positions where the user didn't redeem yet.
810
814
  """
811
- public_key = private_credentials.public_key
815
+ public_key = api_keys.bet_from_address
812
816
 
813
817
  conditional_token_contract = OmenConditionalTokenContract()
814
818
  user_positions = OmenSubgraphHandler().get_user_positions(
@@ -832,7 +836,7 @@ def redeem_from_all_user_positions(
832
836
 
833
837
  original_balances = get_balances(public_key, web3)
834
838
  conditional_token_contract.redeemPositions(
835
- private_credentials=private_credentials,
839
+ api_keys=api_keys,
836
840
  collateral_token_address=user_position.position.collateral_token_contract_address_checksummed,
837
841
  condition_id=condition_id,
838
842
  parent_collection_id=build_parent_collection_id(),
@@ -6,7 +6,7 @@ from enum import Enum
6
6
 
7
7
  from web3 import Web3
8
8
 
9
- from prediction_market_agent_tooling.config import PrivateCredentials
9
+ from prediction_market_agent_tooling.config import APIKeys
10
10
  from prediction_market_agent_tooling.gtypes import (
11
11
  ABI,
12
12
  ChecksumAddress,
@@ -51,7 +51,7 @@ class OmenOracleContract(ContractOnGnosisChain):
51
51
 
52
52
  def resolve(
53
53
  self,
54
- private_credentials: PrivateCredentials,
54
+ api_keys: APIKeys,
55
55
  question_id: HexBytes,
56
56
  template_id: int,
57
57
  question_raw: str,
@@ -59,7 +59,7 @@ class OmenOracleContract(ContractOnGnosisChain):
59
59
  web3: Web3 | None = None,
60
60
  ) -> TxReceipt:
61
61
  return self.send(
62
- private_credentials=private_credentials,
62
+ api_keys=api_keys,
63
63
  function_name="resolve",
64
64
  function_params=dict(
65
65
  questionId=question_id,
@@ -138,7 +138,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
138
138
 
139
139
  def mergePositions(
140
140
  self,
141
- private_credentials: PrivateCredentials,
141
+ api_keys: APIKeys,
142
142
  collateral_token_address: ChecksumAddress,
143
143
  parent_collection_id: HexStr,
144
144
  conditionId: HexBytes,
@@ -147,7 +147,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
147
147
  web3: Web3 | None = None,
148
148
  ) -> TxReceipt:
149
149
  return self.send(
150
- private_credentials=private_credentials,
150
+ api_keys=api_keys,
151
151
  function_name="mergePositions",
152
152
  function_params=[
153
153
  collateral_token_address,
@@ -161,7 +161,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
161
161
 
162
162
  def redeemPositions(
163
163
  self,
164
- private_credentials: PrivateCredentials,
164
+ api_keys: APIKeys,
165
165
  collateral_token_address: HexAddress,
166
166
  condition_id: HexBytes,
167
167
  parent_collection_id: HexStr,
@@ -169,7 +169,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
169
169
  web3: Web3 | None = None,
170
170
  ) -> TxReceipt:
171
171
  return self.send(
172
- private_credentials=private_credentials,
172
+ api_keys=api_keys,
173
173
  function_name="redeemPositions",
174
174
  function_params=[
175
175
  collateral_token_address,
@@ -209,14 +209,14 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
209
209
 
210
210
  def setApprovalForAll(
211
211
  self,
212
- private_credentials: PrivateCredentials,
212
+ api_keys: APIKeys,
213
213
  for_address: ChecksumAddress,
214
214
  approve: bool,
215
215
  tx_params: t.Optional[TxParams] = None,
216
216
  web3: Web3 | None = None,
217
217
  ) -> TxReceipt:
218
218
  return self.send(
219
- private_credentials=private_credentials,
219
+ api_keys=api_keys,
220
220
  function_name="setApprovalForAll",
221
221
  function_params=[
222
222
  for_address,
@@ -228,7 +228,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
228
228
 
229
229
  def prepareCondition(
230
230
  self,
231
- private_credentials: PrivateCredentials,
231
+ api_keys: APIKeys,
232
232
  oracle_address: ChecksumAddress,
233
233
  question_id: HexBytes,
234
234
  outcomes_slot_count: int,
@@ -236,7 +236,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
236
236
  web3: Web3 | None = None,
237
237
  ) -> TxReceipt:
238
238
  return self.send(
239
- private_credentials=private_credentials,
239
+ api_keys=api_keys,
240
240
  function_name="prepareCondition",
241
241
  function_params=[
242
242
  oracle_address,
@@ -291,7 +291,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
291
291
 
292
292
  def buy(
293
293
  self,
294
- private_credentials: PrivateCredentials,
294
+ api_keys: APIKeys,
295
295
  amount_wei: Wei,
296
296
  outcome_index: int,
297
297
  min_outcome_tokens_to_buy: OmenOutcomeToken,
@@ -299,7 +299,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
299
299
  web3: Web3 | None = None,
300
300
  ) -> TxReceipt:
301
301
  return self.send(
302
- private_credentials=private_credentials,
302
+ api_keys=api_keys,
303
303
  function_name="buy",
304
304
  function_params=[
305
305
  amount_wei,
@@ -312,7 +312,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
312
312
 
313
313
  def sell(
314
314
  self,
315
- private_credentials: PrivateCredentials,
315
+ api_keys: APIKeys,
316
316
  amount_wei: Wei,
317
317
  outcome_index: int,
318
318
  max_outcome_tokens_to_sell: OmenOutcomeToken,
@@ -320,7 +320,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
320
320
  web3: Web3 | None = None,
321
321
  ) -> TxReceipt:
322
322
  return self.send(
323
- private_credentials=private_credentials,
323
+ api_keys=api_keys,
324
324
  function_name="sell",
325
325
  function_params=[
326
326
  amount_wei,
@@ -333,7 +333,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
333
333
 
334
334
  def addFunding(
335
335
  self,
336
- private_credentials: PrivateCredentials,
336
+ api_keys: APIKeys,
337
337
  add_funding: Wei,
338
338
  tx_params: t.Optional[TxParams] = None,
339
339
  web3: Web3 | None = None,
@@ -344,7 +344,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
344
344
  # `addFunding` with `distribution_hint` can be used only during the market creation, so forcing empty here.
345
345
  distribution_hint: list[int] = []
346
346
  return self.send(
347
- private_credentials=private_credentials,
347
+ api_keys=api_keys,
348
348
  function_name="addFunding",
349
349
  function_params=[add_funding, distribution_hint],
350
350
  tx_params=tx_params,
@@ -353,7 +353,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
353
353
 
354
354
  def removeFunding(
355
355
  self,
356
- private_credentials: PrivateCredentials,
356
+ api_keys: APIKeys,
357
357
  remove_funding: Wei,
358
358
  tx_params: t.Optional[TxParams] = None,
359
359
  web3: Web3 | None = None,
@@ -362,7 +362,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
362
362
  Remove funding is done in shares.
363
363
  """
364
364
  return self.send(
365
- private_credentials=private_credentials,
365
+ api_keys=api_keys,
366
366
  function_name="removeFunding",
367
367
  function_params=[remove_funding],
368
368
  tx_params=tx_params,
@@ -407,7 +407,7 @@ class OmenFixedProductMarketMakerFactoryContract(ContractOnGnosisChain):
407
407
 
408
408
  def create2FixedProductMarketMaker(
409
409
  self,
410
- private_credentials: PrivateCredentials,
410
+ api_keys: APIKeys,
411
411
  condition_id: HexBytes,
412
412
  initial_funds_wei: Wei,
413
413
  fee: float = OMEN_DEFAULT_MARKET_FEE,
@@ -418,7 +418,7 @@ class OmenFixedProductMarketMakerFactoryContract(ContractOnGnosisChain):
418
418
  xdai_type(fee)
419
419
  ) # We need to convert this to the wei units, but in reality it's % fee as stated in the `OMEN_DEFAULT_MARKET_FEE` variable.
420
420
  return self.send(
421
- private_credentials=private_credentials,
421
+ api_keys=api_keys,
422
422
  function_name="create2FixedProductMarketMaker",
423
423
  function_params=dict(
424
424
  saltNonce=random.randint(
@@ -491,7 +491,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
491
491
 
492
492
  def askQuestion(
493
493
  self,
494
- private_credentials: PrivateCredentials,
494
+ api_keys: APIKeys,
495
495
  question: str,
496
496
  category: str,
497
497
  outcomes: list[str],
@@ -518,7 +518,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
518
518
  ]
519
519
  )
520
520
  receipt_tx = self.send(
521
- private_credentials=private_credentials,
521
+ api_keys=api_keys,
522
522
  function_name="askQuestion",
523
523
  function_params=dict(
524
524
  template_id=template_id,
@@ -540,7 +540,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
540
540
 
541
541
  def submitAnswer(
542
542
  self,
543
- private_credentials: PrivateCredentials,
543
+ api_keys: APIKeys,
544
544
  question_id: HexBytes,
545
545
  answer: str,
546
546
  outcomes: list[str],
@@ -558,7 +558,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
558
558
  outcomes = [o.lower() for o in outcomes]
559
559
 
560
560
  return self.send_with_value(
561
- private_credentials=private_credentials,
561
+ api_keys=api_keys,
562
562
  function_name="submitAnswer",
563
563
  function_params=dict(
564
564
  question_id=question_id,
@@ -573,7 +573,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
573
573
 
574
574
  def claimWinnings(
575
575
  self,
576
- private_credentials: PrivateCredentials,
576
+ api_keys: APIKeys,
577
577
  question_id: HexBytes,
578
578
  history_hashes: list[HexBytes],
579
579
  addresses: list[ChecksumAddress],
@@ -583,7 +583,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
583
583
  web3: Web3 | None = None,
584
584
  ) -> TxReceipt:
585
585
  return self.send(
586
- private_credentials=private_credentials,
586
+ api_keys=api_keys,
587
587
  function_name="claimWinnings",
588
588
  function_params=dict(
589
589
  question_id=question_id,
@@ -606,9 +606,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
606
606
 
607
607
  def withdraw(
608
608
  self,
609
- private_credentials: PrivateCredentials,
609
+ api_keys: APIKeys,
610
610
  web3: Web3 | None = None,
611
611
  ) -> TxReceipt:
612
- return self.send(
613
- private_credentials=private_credentials, function_name="withdraw", web3=web3
614
- )
612
+ return self.send(api_keys=api_keys, function_name="withdraw", web3=web3)
@@ -1,6 +1,6 @@
1
1
  from web3 import Web3
2
2
 
3
- from prediction_market_agent_tooling.config import PrivateCredentials
3
+ from prediction_market_agent_tooling.config import APIKeys
4
4
  from prediction_market_agent_tooling.gtypes import (
5
5
  ChecksumAddress,
6
6
  HexAddress,
@@ -35,7 +35,7 @@ from prediction_market_agent_tooling.tools.web3_utils import ZERO_BYTES, xdai_to
35
35
 
36
36
 
37
37
  def claim_bonds_on_realitio_questions(
38
- private_credentials: PrivateCredentials,
38
+ api_keys: APIKeys,
39
39
  questions: list[RealityQuestion],
40
40
  auto_withdraw: bool,
41
41
  web3: Web3 | None = None,
@@ -47,7 +47,7 @@ def claim_bonds_on_realitio_questions(
47
47
  f"[{idx+1} / {len(questions)}] Claiming bond for {question.questionId=} {question.url=}"
48
48
  )
49
49
  claim_bonds_on_realitio_question(
50
- private_credentials, question, auto_withdraw=auto_withdraw, web3=web3
50
+ api_keys, question, auto_withdraw=auto_withdraw, web3=web3
51
51
  )
52
52
  claimed_questions.append(question.questionId)
53
53
 
@@ -55,12 +55,12 @@ def claim_bonds_on_realitio_questions(
55
55
 
56
56
 
57
57
  def claim_bonds_on_realitio_question(
58
- private_credentials: PrivateCredentials,
58
+ api_keys: APIKeys,
59
59
  question: RealityQuestion,
60
60
  auto_withdraw: bool,
61
61
  web3: Web3 | None = None,
62
62
  ) -> None:
63
- public_key = private_credentials.public_key
63
+ public_key = api_keys.bet_from_address
64
64
  realitio_contract = OmenRealitioContract()
65
65
 
66
66
  # Get all answers for the question.
@@ -105,7 +105,7 @@ def claim_bonds_on_realitio_question(
105
105
  answers.append(answer.answer)
106
106
 
107
107
  realitio_contract.claimWinnings(
108
- private_credentials=private_credentials,
108
+ api_keys=api_keys,
109
109
  question_id=question.questionId,
110
110
  history_hashes=history_hashes,
111
111
  addresses=addresses,
@@ -118,11 +118,11 @@ def claim_bonds_on_realitio_question(
118
118
  # Keeping balance on Realitio is not useful, so it's recommended to just withdraw it.
119
119
  if current_balance > 0 and auto_withdraw:
120
120
  logger.info(f"Withdrawing remaining balance {current_balance=}")
121
- realitio_contract.withdraw(private_credentials, web3=web3)
121
+ realitio_contract.withdraw(api_keys, web3=web3)
122
122
 
123
123
 
124
124
  def finalize_markets(
125
- private_credentials: PrivateCredentials,
125
+ api_keys: APIKeys,
126
126
  markets_with_resolutions: list[tuple[OmenMarket, Resolution | None]],
127
127
  web3: Web3 | None = None,
128
128
  ) -> list[HexAddress]:
@@ -139,7 +139,7 @@ def finalize_markets(
139
139
  elif resolution in (Resolution.YES, Resolution.NO):
140
140
  logger.info(f"Found resolution {resolution.value=} for {market.url=}")
141
141
  omen_submit_answer_market_tx(
142
- private_credentials,
142
+ api_keys,
143
143
  market,
144
144
  resolution,
145
145
  OMEN_DEFAULT_REALITIO_BOND_VALUE,
@@ -155,7 +155,7 @@ def finalize_markets(
155
155
 
156
156
 
157
157
  def resolve_markets(
158
- private_credentials: PrivateCredentials,
158
+ api_keys: APIKeys,
159
159
  markets: list[OmenMarket],
160
160
  web3: Web3 | None = None,
161
161
  ) -> list[HexAddress]:
@@ -165,14 +165,14 @@ def resolve_markets(
165
165
  logger.info(
166
166
  f"[{idx+1} / {len(markets)}] Resolving {market.url=} {market.question_title=}"
167
167
  )
168
- omen_resolve_market_tx(private_credentials, market, web3=web3)
168
+ omen_resolve_market_tx(api_keys, market, web3=web3)
169
169
  resolved_markets.append(market.id)
170
170
 
171
171
  return resolved_markets
172
172
 
173
173
 
174
174
  def omen_submit_answer_market_tx(
175
- private_credentials: PrivateCredentials,
175
+ api_keys: APIKeys,
176
176
  market: OmenMarket,
177
177
  resolution: Resolution,
178
178
  bond: xDai,
@@ -184,7 +184,7 @@ def omen_submit_answer_market_tx(
184
184
  """
185
185
  realitio_contract = OmenRealitioContract()
186
186
  realitio_contract.submitAnswer(
187
- private_credentials=private_credentials,
187
+ api_keys=api_keys,
188
188
  question_id=market.question.id,
189
189
  answer=resolution.value,
190
190
  outcomes=market.question.outcomes,
@@ -194,7 +194,7 @@ def omen_submit_answer_market_tx(
194
194
 
195
195
 
196
196
  def omen_resolve_market_tx(
197
- private_credentials: PrivateCredentials,
197
+ api_keys: APIKeys,
198
198
  market: OmenMarket,
199
199
  web3: Web3 | None = None,
200
200
  ) -> None:
@@ -203,7 +203,7 @@ def omen_resolve_market_tx(
203
203
  """
204
204
  oracle_contract = OmenOracleContract()
205
205
  oracle_contract.resolve(
206
- private_credentials=private_credentials,
206
+ api_keys=api_keys,
207
207
  question_id=market.question.id,
208
208
  template_id=market.question.templateId,
209
209
  question_raw=market.question.question_raw,
@@ -83,7 +83,7 @@ class Market(BaseModel):
83
83
  category: t.Any | None
84
84
  ammType: t.Any | None
85
85
  description: str
86
- liquidity: str
86
+ liquidity: str | None
87
87
  startDate: datetime
88
88
  createdAt: datetime
89
89
  xAxisValue: t.Any | None
@@ -128,7 +128,7 @@ class Market(BaseModel):
128
128
  umaResolutionStatus: t.Any | None
129
129
  curationOrder: t.Any | None
130
130
  volumeNum: USDC | None
131
- liquidityNum: float
131
+ liquidityNum: float | None
132
132
  endDateIso: datetime | None
133
133
  startDateIso: datetime | None
134
134
  umaEndDateIso: datetime | None
@@ -137,8 +137,8 @@ class Market(BaseModel):
137
137
  gameStartTime: datetime | None
138
138
  secondsDelay: int | None
139
139
  clobTokenIds: list[str]
140
- liquidityAmm: float
141
- liquidityClob: float
140
+ liquidityAmm: float | None
141
+ liquidityClob: float | None
142
142
  makerBaseFee: int | None
143
143
  takerBaseFee: int | None
144
144
  negRisk: t.Any | None
@@ -163,7 +163,7 @@ class Market(BaseModel):
163
163
  closed_time: t.Any | None
164
164
  wide_format: bool | None
165
165
  volume_num: USDC | None
166
- liquidity_num: USDC
166
+ liquidity_num: USDC | None
167
167
  image_raw: str
168
168
  resolutionData: ResolutionData
169
169
 
@@ -228,7 +228,7 @@ class PolymarketFullMarket(BaseModel):
228
228
  new: bool
229
229
  featured: bool
230
230
  restricted: bool
231
- liquidity: USDC
231
+ liquidity: USDC | None
232
232
  volume: USDC | None
233
233
  volume24hr: USDC | None
234
234
  competitive: float
@@ -239,8 +239,8 @@ class PolymarketFullMarket(BaseModel):
239
239
  disqusThread: t.Any | None
240
240
  updatedAt: datetime
241
241
  enableOrderBook: bool
242
- liquidityAmm: float
243
- liquidityClob: float
242
+ liquidityAmm: float | None
243
+ liquidityClob: float | None
244
244
  imageOptimized: ImageOptimized | None
245
245
  iconOptimized: IconOptimized | None
246
246
  featuredImageOptimized: str | None
@@ -248,7 +248,7 @@ class PolymarketFullMarket(BaseModel):
248
248
  negRiskMarketID: t.Any | None
249
249
  negRiskFeeBips: t.Any | None
250
250
  markets: list[Market]
251
- categories: list[Category] | None
251
+ categories: list[Category] | None = None
252
252
  series: t.Any | None
253
253
  image_raw: str
254
254
 
@@ -2,7 +2,7 @@ import typing as t
2
2
 
3
3
  from google.cloud.functions_v2.types.functions import Function
4
4
 
5
- from prediction_market_agent_tooling.config import APIKeys, PrivateCredentials
5
+ from prediction_market_agent_tooling.config import APIKeys
6
6
  from prediction_market_agent_tooling.deploy.constants import MARKET_TYPE_KEY
7
7
  from prediction_market_agent_tooling.gtypes import ChecksumAddress, DatetimeWithTimezone
8
8
  from prediction_market_agent_tooling.markets.data_models import ResolvedBet
@@ -49,8 +49,7 @@ class DeployedOmenAgent(DeployedAgent):
49
49
  and api_keys.BET_FROM_PRIVATE_KEY
50
50
  != APIKeys().BET_FROM_PRIVATE_KEY # Check that it didn't get if from the default env.
51
51
  ):
52
- private_credentials = PrivateCredentials.from_api_keys(api_keys)
53
- env_vars["omen_public_key"] = private_credentials.public_key
52
+ env_vars["omen_public_key"] = api_keys.bet_from_address
54
53
  return super().from_env_vars_without_prefix(
55
54
  env_vars=env_vars, extra_vars=extra_vars
56
55
  )
@@ -61,11 +60,10 @@ class DeployedOmenAgent(DeployedAgent):
61
60
  start_time: DatetimeWithTimezone,
62
61
  api_keys: APIKeys,
63
62
  ) -> "DeployedOmenAgent":
64
- private_credentials = PrivateCredentials.from_api_keys(api_keys)
65
63
  return DeployedOmenAgent(
66
64
  name=name,
67
65
  start_time=start_time,
68
- omen_public_key=private_credentials.public_key,
66
+ omen_public_key=api_keys.bet_from_address,
69
67
  )
70
68
 
71
69
  @classmethod
@@ -2,7 +2,7 @@ import typing as t
2
2
 
3
3
  from google.cloud.functions_v2.types.functions import Function
4
4
 
5
- from prediction_market_agent_tooling.config import APIKeys, PrivateCredentials
5
+ from prediction_market_agent_tooling.config import APIKeys
6
6
  from prediction_market_agent_tooling.deploy.constants import MARKET_TYPE_KEY
7
7
  from prediction_market_agent_tooling.gtypes import ChecksumAddress, DatetimeWithTimezone
8
8
  from prediction_market_agent_tooling.markets.data_models import ResolvedBet
@@ -28,11 +28,10 @@ class DeployedPolymarketAgent(DeployedAgent):
28
28
  start_time: DatetimeWithTimezone,
29
29
  api_keys: APIKeys,
30
30
  ) -> "DeployedPolymarketAgent":
31
- private_credentials = PrivateCredentials.from_api_keys(api_keys)
32
31
  return DeployedPolymarketAgent(
33
32
  name=name,
34
33
  start_time=start_time,
35
- polymarket_public_key=private_credentials.public_key,
34
+ polymarket_public_key=api_keys.bet_from_address,
36
35
  )
37
36
 
38
37
  @classmethod
@@ -6,7 +6,7 @@ from contextlib import contextmanager
6
6
  from pydantic import BaseModel, field_validator
7
7
  from web3 import Web3
8
8
 
9
- from prediction_market_agent_tooling.config import PrivateCredentials
9
+ from prediction_market_agent_tooling.config import APIKeys
10
10
  from prediction_market_agent_tooling.gtypes import (
11
11
  ABI,
12
12
  ChainID,
@@ -86,7 +86,7 @@ class ContractBaseClass(BaseModel):
86
86
 
87
87
  def send(
88
88
  self,
89
- private_credentials: PrivateCredentials,
89
+ api_keys: APIKeys,
90
90
  function_name: str,
91
91
  function_params: t.Optional[list[t.Any] | dict[str, t.Any]] = None,
92
92
  tx_params: t.Optional[TxParams] = None,
@@ -97,13 +97,13 @@ class ContractBaseClass(BaseModel):
97
97
  Used for changing a state (writing) to the contract.
98
98
  """
99
99
 
100
- if private_credentials.safe_address is not None:
100
+ if api_keys.SAFE_ADDRESS:
101
101
  return send_function_on_contract_tx_using_safe(
102
102
  web3=web3 or self.get_web3(),
103
103
  contract_address=self.address,
104
104
  contract_abi=self.abi,
105
- from_private_key=private_credentials.private_key,
106
- safe_address=private_credentials.safe_address,
105
+ from_private_key=api_keys.bet_from_private_key,
106
+ safe_address=api_keys.SAFE_ADDRESS,
107
107
  function_name=function_name,
108
108
  function_params=function_params,
109
109
  tx_params=tx_params,
@@ -113,7 +113,7 @@ class ContractBaseClass(BaseModel):
113
113
  web3=web3 or self.get_web3(),
114
114
  contract_address=self.address,
115
115
  contract_abi=self.abi,
116
- from_private_key=private_credentials.private_key,
116
+ from_private_key=api_keys.bet_from_private_key,
117
117
  function_name=function_name,
118
118
  function_params=function_params,
119
119
  tx_params=tx_params,
@@ -122,7 +122,7 @@ class ContractBaseClass(BaseModel):
122
122
 
123
123
  def send_with_value(
124
124
  self,
125
- private_credentials: PrivateCredentials,
125
+ api_keys: APIKeys,
126
126
  function_name: str,
127
127
  amount_wei: Wei,
128
128
  function_params: t.Optional[list[t.Any] | dict[str, t.Any]] = None,
@@ -134,7 +134,7 @@ class ContractBaseClass(BaseModel):
134
134
  Used for changing a state (writing) to the contract, including sending chain's native currency.
135
135
  """
136
136
  return self.send(
137
- private_credentials=private_credentials,
137
+ api_keys=api_keys,
138
138
  function_name=function_name,
139
139
  function_params=function_params,
140
140
  tx_params={"value": amount_wei, **(tx_params or {})},
@@ -158,14 +158,14 @@ class ContractERC20BaseClass(ContractBaseClass):
158
158
 
159
159
  def approve(
160
160
  self,
161
- private_credentials: PrivateCredentials,
161
+ api_keys: APIKeys,
162
162
  for_address: ChecksumAddress,
163
163
  amount_wei: Wei,
164
164
  tx_params: t.Optional[TxParams] = None,
165
165
  web3: Web3 | None = None,
166
166
  ) -> TxReceipt:
167
167
  return self.send(
168
- private_credentials=private_credentials,
168
+ api_keys=api_keys,
169
169
  function_name="approve",
170
170
  function_params=[
171
171
  for_address,
@@ -177,13 +177,13 @@ class ContractERC20BaseClass(ContractBaseClass):
177
177
 
178
178
  def deposit(
179
179
  self,
180
- private_credentials: PrivateCredentials,
180
+ api_keys: APIKeys,
181
181
  amount_wei: Wei,
182
182
  tx_params: t.Optional[TxParams] = None,
183
183
  web3: Web3 | None = None,
184
184
  ) -> TxReceipt:
185
185
  return self.send_with_value(
186
- private_credentials=private_credentials,
186
+ api_keys=api_keys,
187
187
  function_name="deposit",
188
188
  amount_wei=amount_wei,
189
189
  tx_params=tx_params,
@@ -192,7 +192,7 @@ class ContractERC20BaseClass(ContractBaseClass):
192
192
 
193
193
  def transferFrom(
194
194
  self,
195
- private_credentials: PrivateCredentials,
195
+ api_keys: APIKeys,
196
196
  sender: ChecksumAddress,
197
197
  recipient: ChecksumAddress,
198
198
  amount_wei: Wei,
@@ -200,7 +200,7 @@ class ContractERC20BaseClass(ContractBaseClass):
200
200
  web3: Web3 | None = None,
201
201
  ) -> TxReceipt:
202
202
  return self.send(
203
- private_credentials=private_credentials,
203
+ api_keys=api_keys,
204
204
  function_name="transferFrom",
205
205
  function_params=[sender, recipient, amount_wei],
206
206
  tx_params=tx_params,
@@ -209,13 +209,13 @@ class ContractERC20BaseClass(ContractBaseClass):
209
209
 
210
210
  def withdraw(
211
211
  self,
212
- private_credentials: PrivateCredentials,
212
+ api_keys: APIKeys,
213
213
  amount_wei: Wei,
214
214
  tx_params: t.Optional[TxParams] = None,
215
215
  web3: Web3 | None = None,
216
216
  ) -> TxReceipt:
217
217
  return self.send(
218
- private_credentials=private_credentials,
218
+ api_keys=api_keys,
219
219
  function_name="withdraw",
220
220
  function_params=[amount_wei],
221
221
  tx_params=tx_params,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.26.0
3
+ Version: 0.28.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
@@ -11,16 +11,16 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
11
11
  prediction_market_agent_tooling/benchmark/agents.py,sha256=HPIFJvackW110ch3UkktbxhU48gMRVo4gQse84Klhdc,4000
12
12
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=xiHKzZx5GHSsDerFHMZ9j_LXAXnSaITSvv67iPe3MEU,21095
13
13
  prediction_market_agent_tooling/benchmark/utils.py,sha256=iS1BzyXcCMfMm1Rx--1QCH0pHvBTblTndcDQFbTUJ2s,2897
14
- prediction_market_agent_tooling/config.py,sha256=FI8feNLmA0QYmN-llvyDh3c6tN2ZGl7Eerw1e27v51A,4757
15
- prediction_market_agent_tooling/deploy/agent.py,sha256=M6qSZ1mN0AEwyix3WJal7ulifI0o-v89S2K_s_zTBbs,10292
14
+ prediction_market_agent_tooling/config.py,sha256=yELIlzAm2yBwZzGRvHtHBZZV3NZy5CllJfo3chMQMo0,4297
15
+ prediction_market_agent_tooling/deploy/agent.py,sha256=P4MaueaXpNakAWXhB0EYsWLNRXSeRisaN55IVDb8AR8,10187
16
16
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=tqXVA2HSFK3pdZ49tMmta8aKdJFT8JN8WeJ1akjrpBk,909
17
17
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
18
18
  prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
19
19
  prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py,sha256=qYIHRxQLac3yxtZ8ChikiPG9O1aUQucHW0muTSm1nto,2627
20
20
  prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=oyW0jgrUT2Tr49c7GlpcMsYNQjoCSOcWis3q-MmVAhU,6089
21
21
  prediction_market_agent_tooling/gtypes.py,sha256=xGSJXw12hzp8LwvQ956l01GiZMWd07MZTYqo8CXVeLY,2417
22
- prediction_market_agent_tooling/loggers.py,sha256=0znHrzxSbeBaDiB920EZC6a2TiF0tw80Sa_yoLwvo_w,2289
23
- prediction_market_agent_tooling/markets/agent_market.py,sha256=b2gsqEXADJir_LxcNUmzEfxGCcJ_V5mWPGM2SZfIA6M,6250
22
+ prediction_market_agent_tooling/loggers.py,sha256=gG92EeLAxqFqAm9E_Uz5dFXL_FC-8x9zszI9a-4A1Os,2898
23
+ prediction_market_agent_tooling/markets/agent_market.py,sha256=I1r83EU5yMJ1dJhCqZjJ523XOElhBkb96oGDxbr4mlU,6818
24
24
  prediction_market_agent_tooling/markets/categorize.py,sha256=yTd-lDMPW4ESDSzmxeLLBuzLX0FggOF7Vbswh7295o0,941
25
25
  prediction_market_agent_tooling/markets/data_models.py,sha256=uODY3aoFp8YYeLAUcrzMk1yU8pIKsTLobB9xIEGTmKs,1170
26
26
  prediction_market_agent_tooling/markets/manifold/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -28,22 +28,22 @@ prediction_market_agent_tooling/markets/manifold/api.py,sha256=m6qOzDiyQfxj62Eo_
28
28
  prediction_market_agent_tooling/markets/manifold/data_models.py,sha256=2DZIxwtDp-PH0UWTGiktMFIGAAQoVutI07UsxjNyTyE,5296
29
29
  prediction_market_agent_tooling/markets/manifold/manifold.py,sha256=DJZ88r5BGtAugUw5SIyDfzK1S70titba_fwT7OYXuAY,3896
30
30
  prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy7_ctJZuQH9ZDaPL4_AgAYzGWkoow,513
31
- prediction_market_agent_tooling/markets/markets.py,sha256=TXo2qNmjUXhbTK0d-V7hW_aaJDpqP9RWHxm7mayhI0o,3042
31
+ prediction_market_agent_tooling/markets/markets.py,sha256=w05Oo7yCA2axpCw69Q9y4i9Gcdpht0u5bZGbWqld3rU,2964
32
32
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  prediction_market_agent_tooling/markets/omen/data_models.py,sha256=f7RO1Zvytii-M2koGuLQiPERjTq_DsDjrT01mar_sX4,14398
34
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=iNL8m5qzkkxr_ohDfQaYIGiFg92h70WOMxq8-udToIE,32337
35
- prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=cHL-VYQDzLWLtqS_4l91HGaKAOKoFjXHN76OYfIU2T0,20537
36
- prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=WbVAQyhFlwFCk1wncs3Uf2PM6YZ9hV7pUbkFIGGu8iw,9067
34
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=UeBKfiEzTVZMRJ-r6YHXdlrMniwz3V1Te2yZgNX64rA,31902
35
+ prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=eDS8vN4Klv_-Y1wwfIeLDt3twhl9U_AJjPQov0JScb0,19888
36
+ prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=-qssaOJweI_QktR7bQiYjn-V6T_bBTQOH9qQjG35D48,8809
37
37
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=QZWwkqvOqQ-b15jidwTNsn1K64x3FY_Un-l6A6g3Twg,22299
38
38
  prediction_market_agent_tooling/markets/polymarket/api.py,sha256=p1JkqL9kF8C04qbmqFzF0hgtzD5kN3yup2hYOjxazQ4,4188
39
39
  prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=srTl8-0FM76AGLRDWzjLpf46ikWloaBCgkn0XqZoKCI,4248
40
- prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=qop9lK4-3VfEJ9SuSCJdYPhjMqP4g6F5FpHziJv8HDY,10887
40
+ prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=_GCa3P60W8kNeg_8kF20CZF0hvaM2RR4FhTcDfXwF2o,10950
41
41
  prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=zqGfiUOH9f7jmDcQAt30wrHyfmqLMNwCYtotsxFoJmA,2678
42
42
  prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=Gwd2kOK_DrsjtyqgO6ob8oK7tjsB1Yo-Hf7IS5UGnio,1960
43
43
  prediction_market_agent_tooling/monitor/langfuse/langfuse_wrapper.py,sha256=b6T69YB1x8kSUvW9uRFuSWPLOrXzapZG7m5O5SU0QTQ,895
44
44
  prediction_market_agent_tooling/monitor/markets/manifold.py,sha256=GdYpgRX1GahDi-75Mr53jgtEg6nWcs_rHDUkg4o_7dQ,3352
45
- prediction_market_agent_tooling/monitor/markets/omen.py,sha256=cYyKdX4qhGo-VqsboOyWHmMyFsdcX899RrHH5oMEwRI,3503
46
- prediction_market_agent_tooling/monitor/markets/polymarket.py,sha256=j_CHY03LAhg84p-TpwbkuzzIdd5YUWapW3hk7U79Phs,1879
45
+ prediction_market_agent_tooling/monitor/markets/omen.py,sha256=jOLPnIbDU9syjnYtHfOb2xa6-Ize3vbplgh-8WWkuT4,3323
46
+ prediction_market_agent_tooling/monitor/markets/polymarket.py,sha256=I9z9aO1wncyGI3a09ihrw17JkeBKjAuMmC0I9pl_9o4,1781
47
47
  prediction_market_agent_tooling/monitor/monitor.py,sha256=elvCqCASCd3fOnM7f2kajb_Oy3RMUmGh88jzpworrEU,13387
48
48
  prediction_market_agent_tooling/monitor/monitor_app.py,sha256=rDxgdDJqSK0ARx0TJFMkS76npkHZJz0__Rp0xTpiRok,4611
49
49
  prediction_market_agent_tooling/monitor/monitor_settings.py,sha256=Xiozs3AsufuJ04JOe1vjUri-IAMWHjjmc2ugGGiHNH4,947
@@ -54,7 +54,7 @@ prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256
54
54
  prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
55
55
  prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
56
56
  prediction_market_agent_tooling/tools/cache.py,sha256=tGHHd9HCiE_hCCtPtloHZQdDfBuiow9YsqJNYi2Tx_0,499
57
- prediction_market_agent_tooling/tools/contract.py,sha256=FTC5povNDOyTWJNKieCmoMkUK25_sHcTQkBuCVWh5Ck,7290
57
+ prediction_market_agent_tooling/tools/contract.py,sha256=fWYQAJhLLBasEJCiJqZEiXOgJ3dO9Mknppdsd1gHchc,6999
58
58
  prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
59
59
  prediction_market_agent_tooling/tools/gnosis_rpc.py,sha256=_MYSoyOR2MgAJkop1ERf8RhLum-M8S6OjaAsaqUW41w,203
60
60
  prediction_market_agent_tooling/tools/google.py,sha256=SfVDxb3oEOUK8mpd0l3mTX9ybrdrTPNM6HjfJ7kfNjA,1794
@@ -65,8 +65,8 @@ prediction_market_agent_tooling/tools/safe.py,sha256=h0xOO0eNtitClf0fPkn-0oTc6A_
65
65
  prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0rnVhtQGzwoUdAgn_7u_GBM,729
66
66
  prediction_market_agent_tooling/tools/utils.py,sha256=zkmwPi3YisgZDPCeNwaRbL8sInOYOkvFgFY4Q8PbEo4,5077
67
67
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=cboATXNmEdn5RmPbVblHOwOdUMKBYrUK3GiI6i6Vzxo,9855
68
- prediction_market_agent_tooling-0.26.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
- prediction_market_agent_tooling-0.26.0.dist-info/METADATA,sha256=WS8GWqlx4050Kncw9dK8RBO2RTWVkWOaeINf-O94paM,5465
70
- prediction_market_agent_tooling-0.26.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
- prediction_market_agent_tooling-0.26.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
- prediction_market_agent_tooling-0.26.0.dist-info/RECORD,,
68
+ prediction_market_agent_tooling-0.28.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
69
+ prediction_market_agent_tooling-0.28.0.dist-info/METADATA,sha256=NtheDRRimzmgtWXNLObDx0rKM3ZvZT3toRmpCNV04oY,5465
70
+ prediction_market_agent_tooling-0.28.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
71
+ prediction_market_agent_tooling-0.28.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
72
+ prediction_market_agent_tooling-0.28.0.dist-info/RECORD,,