prediction-market-agent-tooling 0.14.0__py3-none-any.whl → 0.15.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.
Files changed (28) hide show
  1. prediction_market_agent_tooling/abis/erc20.abi.json +315 -0
  2. prediction_market_agent_tooling/benchmark/agents.py +7 -1
  3. prediction_market_agent_tooling/benchmark/benchmark.py +22 -24
  4. prediction_market_agent_tooling/config.py +27 -4
  5. prediction_market_agent_tooling/deploy/agent.py +3 -3
  6. prediction_market_agent_tooling/markets/agent_market.py +22 -10
  7. prediction_market_agent_tooling/markets/manifold/manifold.py +9 -1
  8. prediction_market_agent_tooling/markets/omen/data_models.py +42 -11
  9. prediction_market_agent_tooling/markets/omen/omen.py +135 -52
  10. prediction_market_agent_tooling/markets/omen/omen_contracts.py +36 -34
  11. prediction_market_agent_tooling/markets/omen/omen_replicate.py +11 -16
  12. prediction_market_agent_tooling/markets/omen/omen_resolve_replicated.py +32 -25
  13. prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +46 -13
  14. prediction_market_agent_tooling/markets/polymarket/polymarket.py +1 -1
  15. prediction_market_agent_tooling/monitor/markets/omen.py +5 -3
  16. prediction_market_agent_tooling/monitor/markets/polymarket.py +3 -2
  17. prediction_market_agent_tooling/monitor/monitor.py +26 -20
  18. prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py +1 -1
  19. prediction_market_agent_tooling/tools/contract.py +32 -17
  20. prediction_market_agent_tooling/tools/costs.py +31 -0
  21. prediction_market_agent_tooling/tools/parallelism.py +16 -1
  22. prediction_market_agent_tooling/tools/safe.py +130 -0
  23. prediction_market_agent_tooling/tools/web3_utils.py +100 -15
  24. {prediction_market_agent_tooling-0.14.0.dist-info → prediction_market_agent_tooling-0.15.0.dist-info}/METADATA +13 -1
  25. {prediction_market_agent_tooling-0.14.0.dist-info → prediction_market_agent_tooling-0.15.0.dist-info}/RECORD +28 -25
  26. {prediction_market_agent_tooling-0.14.0.dist-info → prediction_market_agent_tooling-0.15.0.dist-info}/LICENSE +0 -0
  27. {prediction_market_agent_tooling-0.14.0.dist-info → prediction_market_agent_tooling-0.15.0.dist-info}/WHEEL +0 -0
  28. {prediction_market_agent_tooling-0.14.0.dist-info → prediction_market_agent_tooling-0.15.0.dist-info}/entry_points.txt +0 -0
@@ -6,6 +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
10
  from prediction_market_agent_tooling.gtypes import (
10
11
  ABI,
11
12
  ChecksumAddress,
@@ -13,7 +14,6 @@ from prediction_market_agent_tooling.gtypes import (
13
14
  HexBytes,
14
15
  HexStr,
15
16
  OmenOutcomeToken,
16
- PrivateKey,
17
17
  TxParams,
18
18
  TxReceipt,
19
19
  Wei,
@@ -51,14 +51,14 @@ class OmenOracleContract(ContractOnGnosisChain):
51
51
 
52
52
  def resolve(
53
53
  self,
54
+ private_credentials: PrivateCredentials,
54
55
  question_id: HexBytes,
55
56
  template_id: int,
56
57
  question_raw: str,
57
58
  n_outcomes: int,
58
- from_private_key: PrivateKey,
59
59
  ) -> TxReceipt:
60
60
  return self.send(
61
- from_private_key=from_private_key,
61
+ private_credentials=private_credentials,
62
62
  function_name="resolve",
63
63
  function_params=dict(
64
64
  questionId=question_id,
@@ -134,7 +134,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
134
134
 
135
135
  def mergePositions(
136
136
  self,
137
- from_private_key: PrivateKey,
137
+ private_credentials: PrivateCredentials,
138
138
  collateral_token_address: ChecksumAddress,
139
139
  parent_collection_id: HexStr,
140
140
  conditionId: HexBytes,
@@ -143,7 +143,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
143
143
  web3: Web3 | None = None,
144
144
  ) -> TxReceipt:
145
145
  return self.send(
146
- from_private_key=from_private_key,
146
+ private_credentials=private_credentials,
147
147
  function_name="mergePositions",
148
148
  function_params=[
149
149
  collateral_token_address,
@@ -157,7 +157,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
157
157
 
158
158
  def redeemPositions(
159
159
  self,
160
- from_private_key: PrivateKey,
160
+ private_credentials: PrivateCredentials,
161
161
  collateral_token_address: HexAddress,
162
162
  condition_id: HexBytes,
163
163
  parent_collection_id: HexStr,
@@ -165,7 +165,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
165
165
  web3: Web3 | None = None,
166
166
  ) -> TxReceipt:
167
167
  return self.send(
168
- from_private_key=from_private_key,
168
+ private_credentials=private_credentials,
169
169
  function_name="redeemPositions",
170
170
  function_params=[
171
171
  collateral_token_address,
@@ -210,13 +210,13 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
210
210
 
211
211
  def setApprovalForAll(
212
212
  self,
213
+ private_credentials: PrivateCredentials,
213
214
  for_address: ChecksumAddress,
214
215
  approve: bool,
215
- from_private_key: PrivateKey,
216
216
  tx_params: t.Optional[TxParams] = None,
217
217
  ) -> TxReceipt:
218
218
  return self.send(
219
- from_private_key=from_private_key,
219
+ private_credentials=private_credentials,
220
220
  function_name="setApprovalForAll",
221
221
  function_params=[
222
222
  for_address,
@@ -227,14 +227,14 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
227
227
 
228
228
  def prepareCondition(
229
229
  self,
230
+ private_credentials: PrivateCredentials,
230
231
  oracle_address: ChecksumAddress,
231
232
  question_id: HexBytes,
232
233
  outcomes_slot_count: int,
233
- from_private_key: PrivateKey,
234
234
  tx_params: t.Optional[TxParams] = None,
235
235
  ) -> TxReceipt:
236
236
  return self.send(
237
- from_private_key=from_private_key,
237
+ private_credentials=private_credentials,
238
238
  function_name="prepareCondition",
239
239
  function_params=[
240
240
  oracle_address,
@@ -261,16 +261,13 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
261
261
  return balance
262
262
 
263
263
  def calcBuyAmount(
264
- self,
265
- investment_amount: Wei,
266
- outcome_index: int,
264
+ self, investment_amount: Wei, outcome_index: int, web3: Web3 | None = None
267
265
  ) -> OmenOutcomeToken:
268
266
  """
269
267
  Returns amount of shares we will get for the given outcome_index for the given investment amount.
270
268
  """
271
269
  calculated_shares: OmenOutcomeToken = self.call(
272
- "calcBuyAmount",
273
- [investment_amount, outcome_index],
270
+ "calcBuyAmount", [investment_amount, outcome_index], web3=web3
274
271
  )
275
272
  return calculated_shares
276
273
 
@@ -298,14 +295,15 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
298
295
 
299
296
  def buy(
300
297
  self,
298
+ private_credentials: PrivateCredentials,
301
299
  amount_wei: Wei,
302
300
  outcome_index: int,
303
301
  min_outcome_tokens_to_buy: OmenOutcomeToken,
304
- from_private_key: PrivateKey,
305
302
  tx_params: t.Optional[TxParams] = None,
303
+ web3: Web3 | None = None,
306
304
  ) -> TxReceipt:
307
305
  return self.send(
308
- from_private_key=from_private_key,
306
+ private_credentials=private_credentials,
309
307
  function_name="buy",
310
308
  function_params=[
311
309
  amount_wei,
@@ -313,18 +311,19 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
313
311
  min_outcome_tokens_to_buy,
314
312
  ],
315
313
  tx_params=tx_params,
314
+ web3=web3,
316
315
  )
317
316
 
318
317
  def sell(
319
318
  self,
319
+ private_credentials: PrivateCredentials,
320
320
  amount_wei: Wei,
321
321
  outcome_index: int,
322
322
  max_outcome_tokens_to_sell: OmenOutcomeToken,
323
- from_private_key: PrivateKey,
324
323
  tx_params: t.Optional[TxParams] = None,
325
324
  ) -> TxReceipt:
326
325
  return self.send(
327
- from_private_key=from_private_key,
326
+ private_credentials=private_credentials,
328
327
  function_name="sell",
329
328
  function_params=[
330
329
  amount_wei,
@@ -336,8 +335,8 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
336
335
 
337
336
  def addFunding(
338
337
  self,
338
+ private_credentials: PrivateCredentials,
339
339
  add_funding: Wei,
340
- from_private_key: PrivateKey,
341
340
  tx_params: t.Optional[TxParams] = None,
342
341
  ) -> TxReceipt:
343
342
  """
@@ -346,7 +345,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
346
345
  # `addFunding` with `distribution_hint` can be used only during the market creation, so forcing empty here.
347
346
  distribution_hint: list[int] = []
348
347
  return self.send(
349
- from_private_key=from_private_key,
348
+ private_credentials=private_credentials,
350
349
  function_name="addFunding",
351
350
  function_params=[add_funding, distribution_hint],
352
351
  tx_params=tx_params,
@@ -354,8 +353,8 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
354
353
 
355
354
  def removeFunding(
356
355
  self,
356
+ private_credentials: PrivateCredentials,
357
357
  remove_funding: Wei,
358
- from_private_key: PrivateKey,
359
358
  tx_params: t.Optional[TxParams] = None,
360
359
  web3: Web3 | None = None,
361
360
  ) -> TxReceipt:
@@ -363,7 +362,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
363
362
  Remove funding is done in shares.
364
363
  """
365
364
  return self.send(
366
- from_private_key=from_private_key,
365
+ private_credentials=private_credentials,
367
366
  function_name="removeFunding",
368
367
  function_params=[remove_funding],
369
368
  tx_params=tx_params,
@@ -408,9 +407,9 @@ class OmenFixedProductMarketMakerFactoryContract(ContractOnGnosisChain):
408
407
 
409
408
  def create2FixedProductMarketMaker(
410
409
  self,
410
+ private_credentials: PrivateCredentials,
411
411
  condition_id: HexBytes,
412
412
  initial_funds_wei: Wei,
413
- from_private_key: PrivateKey,
414
413
  fee: float = OMEN_DEFAULT_MARKET_FEE,
415
414
  tx_params: t.Optional[TxParams] = None,
416
415
  ) -> TxReceipt:
@@ -418,7 +417,7 @@ class OmenFixedProductMarketMakerFactoryContract(ContractOnGnosisChain):
418
417
  xdai_type(fee)
419
418
  ) # 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
419
  return self.send(
421
- from_private_key=from_private_key,
420
+ private_credentials=private_credentials,
422
421
  function_name="create2FixedProductMarketMaker",
423
422
  function_params=dict(
424
423
  saltNonce=random.randint(
@@ -490,13 +489,13 @@ class OmenRealitioContract(ContractOnGnosisChain):
490
489
 
491
490
  def askQuestion(
492
491
  self,
492
+ private_credentials: PrivateCredentials,
493
493
  question: str,
494
494
  category: str,
495
495
  outcomes: list[str],
496
496
  language: str,
497
497
  arbitrator: Arbitrator,
498
498
  opening: datetime,
499
- from_private_key: PrivateKey,
500
499
  nonce: int | None = None,
501
500
  tx_params: t.Optional[TxParams] = None,
502
501
  ) -> HexBytes:
@@ -516,7 +515,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
516
515
  ]
517
516
  )
518
517
  receipt_tx = self.send(
519
- from_private_key=from_private_key,
518
+ private_credentials=private_credentials,
520
519
  function_name="askQuestion",
521
520
  function_params=dict(
522
521
  template_id=template_id,
@@ -537,11 +536,11 @@ class OmenRealitioContract(ContractOnGnosisChain):
537
536
 
538
537
  def submitAnswer(
539
538
  self,
539
+ private_credentials: PrivateCredentials,
540
540
  question_id: HexBytes,
541
541
  answer: str,
542
542
  outcomes: list[str],
543
543
  bond: Wei,
544
- from_private_key: PrivateKey,
545
544
  max_previous: Wei | None = None,
546
545
  ) -> TxReceipt:
547
546
  if max_previous is None:
@@ -554,7 +553,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
554
553
  outcomes = [o.lower() for o in outcomes]
555
554
 
556
555
  return self.send_with_value(
557
- from_private_key=from_private_key,
556
+ private_credentials=private_credentials,
558
557
  function_name="submitAnswer",
559
558
  function_params=dict(
560
559
  question_id=question_id,
@@ -568,15 +567,16 @@ class OmenRealitioContract(ContractOnGnosisChain):
568
567
 
569
568
  def claimWinnings(
570
569
  self,
570
+ private_credentials: PrivateCredentials,
571
571
  question_id: HexBytes,
572
572
  history_hashes: list[HexBytes],
573
573
  addresses: list[ChecksumAddress],
574
574
  bonds: list[Wei],
575
575
  answers: list[HexBytes],
576
- from_private_key: PrivateKey,
577
576
  tx_params: t.Optional[TxParams] = None,
578
577
  ) -> TxReceipt:
579
578
  return self.send(
579
+ private_credentials=private_credentials,
580
580
  function_name="claimWinnings",
581
581
  function_params=dict(
582
582
  question_id=question_id,
@@ -585,7 +585,6 @@ class OmenRealitioContract(ContractOnGnosisChain):
585
585
  bonds=bonds,
586
586
  answers=answers,
587
587
  ),
588
- from_private_key=from_private_key,
589
588
  tx_params=tx_params,
590
589
  )
591
590
 
@@ -593,8 +592,11 @@ class OmenRealitioContract(ContractOnGnosisChain):
593
592
  balance = wei_type(self.call("balanceOf", [from_address]))
594
593
  return balance
595
594
 
596
- def withdraw(self, from_private_key: PrivateKey) -> TxReceipt:
595
+ def withdraw(
596
+ self,
597
+ private_credentials: PrivateCredentials,
598
+ ) -> TxReceipt:
597
599
  return self.send(
600
+ private_credentials=private_credentials,
598
601
  function_name="withdraw",
599
- from_private_key=from_private_key,
600
602
  )
@@ -2,12 +2,8 @@ from datetime import datetime, timedelta
2
2
 
3
3
  from loguru import logger
4
4
 
5
- from prediction_market_agent_tooling.gtypes import (
6
- ChecksumAddress,
7
- PrivateKey,
8
- wei_type,
9
- xDai,
10
- )
5
+ from prediction_market_agent_tooling.config import PrivateCredentials
6
+ from prediction_market_agent_tooling.gtypes import ChecksumAddress, wei_type, xDai
11
7
  from prediction_market_agent_tooling.markets.agent_market import FilterBy, SortBy
12
8
  from prediction_market_agent_tooling.markets.categorize import infer_category
13
9
  from prediction_market_agent_tooling.markets.markets import (
@@ -29,7 +25,6 @@ from prediction_market_agent_tooling.markets.omen.omen_subgraph_handler import (
29
25
  )
30
26
  from prediction_market_agent_tooling.tools.is_predictable import is_predictable_binary
31
27
  from prediction_market_agent_tooling.tools.utils import utcnow
32
- from prediction_market_agent_tooling.tools.web3_utils import private_key_to_public_key
33
28
 
34
29
  # According to Omen's recommendation, closing time of the market should be at least 6 days after the outcome is known.
35
30
  # That is because at the closing time, the question will open on Realitio, and we don't want it to be resolved as unknown/invalid.
@@ -38,14 +33,14 @@ EXTEND_CLOSING_TIME_DELTA = timedelta(days=6)
38
33
 
39
34
 
40
35
  def omen_replicate_from_tx(
36
+ private_credentials: PrivateCredentials,
41
37
  market_type: MarketType,
42
38
  n_to_replicate: int,
43
39
  initial_funds: xDai,
44
- from_private_key: PrivateKey,
45
40
  close_time_before: datetime | None = None,
46
41
  auto_deposit: bool = False,
47
42
  ) -> list[ChecksumAddress]:
48
- from_address = private_key_to_public_key(from_private_key)
43
+ from_address = private_credentials.public_key
49
44
  already_created_markets = OmenSubgraphHandler().get_omen_binary_markets(
50
45
  limit=None,
51
46
  creator=from_address,
@@ -120,13 +115,13 @@ def omen_replicate_from_tx(
120
115
  continue
121
116
 
122
117
  market_address = omen_create_market_tx(
118
+ private_credentials=private_credentials,
123
119
  initial_funds=initial_funds,
124
120
  fee=OMEN_DEFAULT_MARKET_FEE,
125
121
  question=market.question,
126
122
  closing_time=safe_closing_time,
127
123
  category=category,
128
124
  language="en",
129
- from_private_key=from_private_key,
130
125
  outcomes=[OMEN_TRUE_OUTCOME, OMEN_FALSE_OUTCOME],
131
126
  auto_deposit=auto_deposit,
132
127
  )
@@ -145,10 +140,10 @@ def omen_replicate_from_tx(
145
140
 
146
141
 
147
142
  def omen_unfund_replicated_known_markets_tx(
148
- from_private_key: PrivateKey,
143
+ private_credentials: PrivateCredentials,
149
144
  saturation_above_threshold: float | None = None,
150
145
  ) -> None:
151
- from_address = private_key_to_public_key(from_private_key)
146
+ from_address = private_credentials.public_key
152
147
 
153
148
  now = utcnow()
154
149
  # We want to unfund markets ~1 day before the resolution should be known.
@@ -171,19 +166,19 @@ def omen_unfund_replicated_known_markets_tx(
171
166
  saturation_above_threshold is not None
172
167
  and not market.is_resolved
173
168
  and not (
174
- market.p_yes > saturation_above_threshold
175
- or market.p_no > saturation_above_threshold
169
+ market.current_p_yes > saturation_above_threshold
170
+ or market.current_p_no > saturation_above_threshold
176
171
  )
177
172
  ):
178
173
  logger.info(
179
- f"[{idx+1}/{len(markets)}] Skipping unfunding of `{market.liquidityParameter=} {market.question=} {market.url=}`, because it's not saturated yet, `{market.p_yes=}`."
174
+ f"[{idx+1}/{len(markets)}] Skipping unfunding of `{market.liquidityParameter=} {market.question=} {market.url=}`, because it's not saturated yet, `{market.current_p_yes=}`."
180
175
  )
181
176
  continue
182
177
  logger.info(
183
178
  f"[{idx+1}/{len(markets)}] Unfunding market `{market.liquidityParameter=} {market.question=} {market.url=}`."
184
179
  )
185
180
  omen_remove_fund_market_tx(
181
+ private_credentials=private_credentials,
186
182
  market=OmenAgentMarket.from_data_model(market),
187
183
  shares=None,
188
- from_private_key=from_private_key,
189
184
  )
@@ -4,11 +4,11 @@ from loguru import logger
4
4
  from pydantic import BaseModel
5
5
  from web3 import Web3
6
6
 
7
+ from prediction_market_agent_tooling.config import PrivateCredentials
7
8
  from prediction_market_agent_tooling.gtypes import (
8
9
  ChecksumAddress,
9
10
  HexAddress,
10
11
  HexBytes,
11
- PrivateKey,
12
12
  Wei,
13
13
  xDai,
14
14
  )
@@ -36,11 +36,7 @@ from prediction_market_agent_tooling.markets.polymarket.utils import (
36
36
  )
37
37
  from prediction_market_agent_tooling.tools.balances import get_balances
38
38
  from prediction_market_agent_tooling.tools.utils import utcnow
39
- from prediction_market_agent_tooling.tools.web3_utils import (
40
- ZERO_BYTES,
41
- private_key_to_public_key,
42
- xdai_to_wei,
43
- )
39
+ from prediction_market_agent_tooling.tools.web3_utils import ZERO_BYTES, xdai_to_wei
44
40
 
45
41
 
46
42
  class FinalizeAndResolveResult(BaseModel):
@@ -50,9 +46,9 @@ class FinalizeAndResolveResult(BaseModel):
50
46
 
51
47
 
52
48
  def omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx(
53
- from_private_key: PrivateKey,
49
+ private_credentials: PrivateCredentials,
54
50
  ) -> FinalizeAndResolveResult:
55
- public_key = private_key_to_public_key(from_private_key)
51
+ public_key = private_credentials.public_key
56
52
  balances_start = get_balances(public_key)
57
53
  logger.info(f"{balances_start=}")
58
54
 
@@ -68,7 +64,8 @@ def omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx(
68
64
  )
69
65
  # Finalize them (set answer on Realitio).
70
66
  finalized_markets = finalize_markets(
71
- created_opened_markets, from_private_key=from_private_key
67
+ private_credentials,
68
+ created_opened_markets,
72
69
  )
73
70
  balances_after_finalization = get_balances(public_key)
74
71
  logger.info(f"{balances_after_finalization=}")
@@ -82,7 +79,8 @@ def omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx(
82
79
  )
83
80
  # Resolve them (resolve them on Oracle).
84
81
  resolved_markets = resolve_markets(
85
- created_finalized_markets, from_private_key=from_private_key
82
+ private_credentials,
83
+ created_finalized_markets,
86
84
  )
87
85
  balances_after_resolution = get_balances(public_key)
88
86
  logger.info(f"{balances_after_resolution=}")
@@ -96,7 +94,9 @@ def omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx(
96
94
  current_answer_before=before - timedelta(hours=24),
97
95
  )
98
96
  claimed_question_ids = claim_bonds_on_realitio_quetions(
99
- created_not_claimed_questions, from_private_key, auto_withdraw=True
97
+ private_credentials,
98
+ created_not_claimed_questions,
99
+ auto_withdraw=True,
100
100
  )
101
101
  balances_after_claiming = get_balances(public_key)
102
102
  logger.info(f"{balances_after_claiming=}")
@@ -109,7 +109,9 @@ def omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx(
109
109
 
110
110
 
111
111
  def claim_bonds_on_realitio_quetions(
112
- questions: list[RealityQuestion], from_private_key: PrivateKey, auto_withdraw: bool
112
+ private_credentials: PrivateCredentials,
113
+ questions: list[RealityQuestion],
114
+ auto_withdraw: bool,
113
115
  ) -> list[HexBytes]:
114
116
  claimed_questions: list[HexBytes] = []
115
117
 
@@ -118,7 +120,7 @@ def claim_bonds_on_realitio_quetions(
118
120
  f"[{idx+1} / {len(questions)}] Claiming bond for {question.questionId=} {question.url=}"
119
121
  )
120
122
  claim_bonds_on_realitio_question(
121
- question, from_private_key, auto_withdraw=auto_withdraw
123
+ private_credentials, question, auto_withdraw=auto_withdraw
122
124
  )
123
125
  claimed_questions.append(question.questionId)
124
126
 
@@ -126,11 +128,11 @@ def claim_bonds_on_realitio_quetions(
126
128
 
127
129
 
128
130
  def claim_bonds_on_realitio_question(
131
+ private_credentials: PrivateCredentials,
129
132
  question: RealityQuestion,
130
- from_private_key: PrivateKey,
131
133
  auto_withdraw: bool,
132
134
  ) -> None:
133
- public_key = private_key_to_public_key(from_private_key)
135
+ public_key = private_credentials.public_key
134
136
  realitio_contract = OmenRealitioContract()
135
137
 
136
138
  # Get all answers for the question.
@@ -175,23 +177,24 @@ def claim_bonds_on_realitio_question(
175
177
  answers.append(answer.answer)
176
178
 
177
179
  realitio_contract.claimWinnings(
180
+ private_credentials=private_credentials,
178
181
  question_id=question.questionId,
179
182
  history_hashes=history_hashes,
180
183
  addresses=addresses,
181
184
  bonds=bonds,
182
185
  answers=answers,
183
- from_private_key=from_private_key,
184
186
  )
185
187
 
186
188
  current_balance = realitio_contract.balanceOf(public_key)
187
189
  # Keeping balance on Realitio is not useful, so it's recommended to just withdraw it.
188
190
  if current_balance > 0 and auto_withdraw:
189
191
  logger.info(f"Withdrawing remaining balance {current_balance=}")
190
- realitio_contract.withdraw(from_private_key)
192
+ realitio_contract.withdraw(private_credentials)
191
193
 
192
194
 
193
195
  def finalize_markets(
194
- markets: list[OmenMarket], from_private_key: PrivateKey
196
+ private_credentials: PrivateCredentials,
197
+ markets: list[OmenMarket],
195
198
  ) -> list[HexAddress]:
196
199
  finalized_markets: list[HexAddress] = []
197
200
 
@@ -207,7 +210,10 @@ def finalize_markets(
207
210
  elif resolution in (Resolution.YES, Resolution.NO):
208
211
  logger.info(f"Found resolution {resolution.value=} for {market.url=}")
209
212
  omen_submit_answer_market_tx(
210
- market, resolution, OMEN_DEFAULT_REALITIO_BOND_VALUE, from_private_key
213
+ private_credentials,
214
+ market,
215
+ resolution,
216
+ OMEN_DEFAULT_REALITIO_BOND_VALUE,
211
217
  )
212
218
  finalized_markets.append(market.id)
213
219
  logger.info(f"Finalized {market.url=}")
@@ -219,7 +225,8 @@ def finalize_markets(
219
225
 
220
226
 
221
227
  def resolve_markets(
222
- markets: list[OmenMarket], from_private_key: PrivateKey
228
+ private_credentials: PrivateCredentials,
229
+ markets: list[OmenMarket],
223
230
  ) -> list[HexAddress]:
224
231
  resolved_markets: list[HexAddress] = []
225
232
 
@@ -227,17 +234,17 @@ def resolve_markets(
227
234
  logger.info(
228
235
  f"[{idx+1} / {len(markets)}] Resolving {market.url=} {market.question_title=}"
229
236
  )
230
- omen_resolve_market_tx(market, from_private_key)
237
+ omen_resolve_market_tx(private_credentials, market)
231
238
  resolved_markets.append(market.id)
232
239
 
233
240
  return resolved_markets
234
241
 
235
242
 
236
243
  def omen_submit_answer_market_tx(
244
+ private_credentials: PrivateCredentials,
237
245
  market: OmenMarket,
238
246
  resolution: Resolution,
239
247
  bond: xDai,
240
- from_private_key: PrivateKey,
241
248
  ) -> None:
242
249
  """
243
250
  After the answer is submitted, there is 24h waiting period where the answer can be challenged by others.
@@ -245,28 +252,28 @@ def omen_submit_answer_market_tx(
245
252
  """
246
253
  realitio_contract = OmenRealitioContract()
247
254
  realitio_contract.submitAnswer(
255
+ private_credentials=private_credentials,
248
256
  question_id=market.question.id,
249
257
  answer=resolution.value,
250
258
  outcomes=market.question.outcomes,
251
259
  bond=xdai_to_wei(bond),
252
- from_private_key=from_private_key,
253
260
  )
254
261
 
255
262
 
256
263
  def omen_resolve_market_tx(
264
+ private_credentials: PrivateCredentials,
257
265
  market: OmenMarket,
258
- from_private_key: PrivateKey,
259
266
  ) -> None:
260
267
  """
261
268
  Market can be resolved 24h after last answer was submitted via `omen_submit_answer_market_tx`.
262
269
  """
263
270
  oracle_contract = OmenOracleContract()
264
271
  oracle_contract.resolve(
272
+ private_credentials=private_credentials,
265
273
  question_id=market.question.id,
266
274
  template_id=market.question.templateId,
267
275
  question_raw=market.question.question_raw,
268
276
  n_outcomes=market.question.n_outcomes,
269
- from_private_key=from_private_key,
270
277
  )
271
278
 
272
279