prediction-market-agent-tooling 0.48.8__py3-none-any.whl → 0.48.9__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.
@@ -100,6 +100,10 @@ def initialize_langfuse(enable_langfuse: bool) -> None:
100
100
  Decision = Annotated[bool, BeforeValidator(to_boolean_outcome)]
101
101
 
102
102
 
103
+ class CantPayForGasError(ValueError):
104
+ pass
105
+
106
+
103
107
  class OutOfFundsError(ValueError):
104
108
  pass
105
109
 
@@ -337,17 +341,38 @@ class DeployableTraderAgent(DeployableAgent):
337
341
  ]
338
342
  )
339
343
 
340
- def check_min_required_balance_to_operate(self, market_type: MarketType) -> None:
344
+ def check_min_required_balance_to_operate(
345
+ self,
346
+ market_type: MarketType,
347
+ check_for_gas: bool = True,
348
+ check_for_trades: bool = True,
349
+ ) -> None:
341
350
  api_keys = APIKeys()
351
+ if (
352
+ market_type == MarketType.OMEN
353
+ and check_for_gas
354
+ and not is_minimum_required_balance(
355
+ api_keys.public_key,
356
+ min_required_balance=xdai_type(0.001),
357
+ sum_wxdai=False,
358
+ )
359
+ ):
360
+ raise CantPayForGasError(
361
+ f"{api_keys.public_key=} doesn't have enough xDai to pay for gas."
362
+ )
342
363
  if self.min_required_balance_to_operate is None:
343
364
  return
344
- if market_type == MarketType.OMEN and not is_minimum_required_balance(
345
- api_keys.public_key,
346
- min_required_balance=self.min_required_balance_to_operate,
365
+ if (
366
+ market_type == MarketType.OMEN
367
+ and check_for_trades
368
+ and not is_minimum_required_balance(
369
+ api_keys.bet_from_address,
370
+ min_required_balance=self.min_required_balance_to_operate,
371
+ )
347
372
  ):
348
373
  raise OutOfFundsError(
349
374
  f"Minimum required balance {self.min_required_balance_to_operate} "
350
- f"for agent with address {api_keys.public_key} is not met."
375
+ f"for agent with address {api_keys.bet_from_address=} is not met."
351
376
  )
352
377
 
353
378
  def have_bet_on_market_since(self, market: AgentMarket, since: timedelta) -> bool:
@@ -448,8 +473,13 @@ class DeployableTraderAgent(DeployableAgent):
448
473
  """
449
474
  api_keys = APIKeys()
450
475
  if market_type == MarketType.OMEN:
476
+ # First, check if we have enough xDai to pay for gas, there is no way of doing anything without it.
477
+ self.check_min_required_balance_to_operate(
478
+ market_type, check_for_trades=False
479
+ )
451
480
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
452
481
  redeem_from_all_user_positions(api_keys)
482
+ # After redeeming, check if we have enough xDai to pay for gas and place bets.
453
483
  self.check_min_required_balance_to_operate(market_type)
454
484
  # Exchange wxdai back to xdai if the balance is getting low, so we can keep paying for fees.
455
485
  if self.min_balance_to_keep_in_native_currency is not None:
@@ -1047,13 +1047,19 @@ def is_minimum_required_balance(
1047
1047
  address: ChecksumAddress,
1048
1048
  min_required_balance: xDai,
1049
1049
  web3: Web3 | None = None,
1050
+ sum_xdai: bool = True,
1051
+ sum_wxdai: bool = True,
1050
1052
  ) -> bool:
1051
1053
  """
1052
1054
  Checks if the total balance of xDai and wxDai in the wallet is above the minimum required balance.
1053
1055
  """
1054
1056
  current_balances = get_balances(address, web3)
1055
1057
  # xDai and wxDai have equal value and can be exchanged for almost no cost, so we can sum them up.
1056
- total_balance = current_balances.xdai + current_balances.wxdai
1058
+ total_balance = 0.0
1059
+ if sum_xdai:
1060
+ total_balance += current_balances.xdai
1061
+ if sum_wxdai:
1062
+ total_balance += current_balances.wxdai
1057
1063
  return total_balance >= min_required_balance
1058
1064
 
1059
1065
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.48.8
3
+ Version: 0.48.9
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -15,7 +15,7 @@ prediction_market_agent_tooling/benchmark/agents.py,sha256=BwE3U11tQq0rfOJBn-Xn5
15
15
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=xiHKzZx5GHSsDerFHMZ9j_LXAXnSaITSvv67iPe3MEU,21095
16
16
  prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
17
17
  prediction_market_agent_tooling/config.py,sha256=9h68Nb9O1YZabZqtOBrH1S-4U5aIdLKfVYLSKspfUeA,6008
18
- prediction_market_agent_tooling/deploy/agent.py,sha256=MdNiUG2y-E6S_Hc7d31ISIPF7e18-2bmO8SULg7RDd4,17760
18
+ prediction_market_agent_tooling/deploy/agent.py,sha256=KsAFknAbMPVSqBSSahuZuu2cX08azZ8EZ481XwWgR_8,18746
19
19
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
20
20
  prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=nJizN4d_jsw5WA8uukaKModVezAgVwoLrCOXsaBOwXo,2223
21
21
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
@@ -38,7 +38,7 @@ prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=6TBy17xn
38
38
  prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=uNF7LP4evvubk818g2zbX1VlnFxeUQOkNgx_e_LwaJA,3416
39
39
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  prediction_market_agent_tooling/markets/omen/data_models.py,sha256=7KXT8a_WYyXMFR8OtcPlaazeigc8eE_AvBkx2q-CNi8,16764
41
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=fL8Lk1H0guwNBcgvT8Ymy3jRewbWLbJ9m8br4HN7vPg,40014
41
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=0odOGRtuDjB12sXnRglUyW8IdOsuha7X6ALc2OryF3c,40156
42
42
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=MfaWfDDfEzHYVAbeT3Dgtl8KG7XsqEpdY3m3-rsOPwo,23588
43
43
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=Awaw1r32IBAClCktrXbYJ24RNyLDWcLb8RqAx6FGSkI,9529
44
44
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=XMCXEZi5TWpxxw5hDJ3QU-19VpD77otw3qhNLT_OhRE,28452
@@ -78,8 +78,8 @@ prediction_market_agent_tooling/tools/tavily_storage/tavily_models.py,sha256=dr-
78
78
  prediction_market_agent_tooling/tools/tavily_storage/tavily_storage.py,sha256=eln3BygdfsDf8WOlSQPL7qH946QnGnThRkazRZKBA8o,3194
79
79
  prediction_market_agent_tooling/tools/utils.py,sha256=JE9YWtPPhnTgLiOyGAZDNG5K8nCwUY9IZEuAlm9UcxA,6611
80
80
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=euq_MH-LhTowACq42colks2IXxZQjqjuisYl91EYZtU,10440
81
- prediction_market_agent_tooling-0.48.8.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
82
- prediction_market_agent_tooling-0.48.8.dist-info/METADATA,sha256=-l7BCizaFtD0scKftcebwoel16w9o2nggRSRjMJ_EEc,7810
83
- prediction_market_agent_tooling-0.48.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
84
- prediction_market_agent_tooling-0.48.8.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
85
- prediction_market_agent_tooling-0.48.8.dist-info/RECORD,,
81
+ prediction_market_agent_tooling-0.48.9.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
82
+ prediction_market_agent_tooling-0.48.9.dist-info/METADATA,sha256=fSQ6RbbxANUKOYmb4fZKIBA9aQpCPt4kNfgf8StohTA,7810
83
+ prediction_market_agent_tooling-0.48.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
84
+ prediction_market_agent_tooling-0.48.9.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
85
+ prediction_market_agent_tooling-0.48.9.dist-info/RECORD,,