prediction-market-agent-tooling 0.39.5__py3-none-any.whl → 0.40.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.
@@ -58,14 +58,14 @@ class APIKeys(BaseSettings):
58
58
  "BET_FROM_PRIVATE_KEY missing in the environment.",
59
59
  )
60
60
 
61
+ @property
62
+ def public_key(self) -> ChecksumAddress:
63
+ return private_key_to_public_key(self.bet_from_private_key)
64
+
61
65
  @property
62
66
  def bet_from_address(self) -> ChecksumAddress:
63
67
  """If the SAFE is available, we always route transactions via SAFE. Otherwise we use the EOA."""
64
- return (
65
- self.SAFE_ADDRESS
66
- if self.SAFE_ADDRESS
67
- else private_key_to_public_key(self.bet_from_private_key)
68
- )
68
+ return self.SAFE_ADDRESS if self.SAFE_ADDRESS else self.public_key
69
69
 
70
70
  @property
71
71
  def openai_api_key(self) -> SecretStr:
@@ -22,7 +22,7 @@ from prediction_market_agent_tooling.deploy.gcp.utils import (
22
22
  gcp_function_is_active,
23
23
  gcp_resolve_api_keys_secrets,
24
24
  )
25
- from prediction_market_agent_tooling.gtypes import Probability
25
+ from prediction_market_agent_tooling.gtypes import Probability, xdai_type
26
26
  from prediction_market_agent_tooling.loggers import logger
27
27
  from prediction_market_agent_tooling.markets.agent_market import (
28
28
  AgentMarket,
@@ -36,6 +36,7 @@ from prediction_market_agent_tooling.markets.markets import (
36
36
  )
37
37
  from prediction_market_agent_tooling.markets.omen.omen import (
38
38
  redeem_from_all_user_positions,
39
+ withdraw_wxdai_to_xdai_to_keep_balance,
39
40
  )
40
41
  from prediction_market_agent_tooling.monitor.langfuse.langfuse_wrapper import (
41
42
  LangfuseWrapper,
@@ -260,9 +261,14 @@ class DeployableTraderAgent(DeployableAgent):
260
261
  """
261
262
  Executes actions that occur before bets are placed.
262
263
  """
264
+ api_keys = APIKeys()
263
265
  if market_type == MarketType.OMEN:
264
266
  # Omen is specific, because the user (agent) needs to manually withdraw winnings from the market.
265
- redeem_from_all_user_positions(APIKeys())
267
+ redeem_from_all_user_positions(api_keys)
268
+ # Exchange wxdai back to xdai if the balance is getting low, so we can keep paying for fees.
269
+ withdraw_wxdai_to_xdai_to_keep_balance(
270
+ api_keys, min_required_balance=xdai_type(1), withdraw_multiplier=2
271
+ )
266
272
 
267
273
  def process_bets(self, market_type: MarketType) -> None:
268
274
  """
@@ -1000,3 +1000,40 @@ def get_binary_market_p_yes_history(market: OmenAgentMarket) -> list[Probability
1000
1000
  )
1001
1001
 
1002
1002
  return history
1003
+
1004
+
1005
+ def withdraw_wxdai_to_xdai_to_keep_balance(
1006
+ api_keys: APIKeys,
1007
+ min_required_balance: xDai,
1008
+ withdraw_multiplier: float = 1.0,
1009
+ web3: Web3 | None = None,
1010
+ ) -> None:
1011
+ """
1012
+ Keeps xDai balance above the minimum required balance by withdrawing wxDai to xDai.
1013
+ Optionally, the amount to withdraw can be multiplied by the `withdraw_multiplier`, which can be useful to keep a buffer.
1014
+ """
1015
+ # xDai needs to be in our wallet where we pay transaction fees, so do not check for Safe's balance.
1016
+ current_balances = get_balances(api_keys.public_key, web3)
1017
+
1018
+ if current_balances.xdai >= min_required_balance:
1019
+ logger.info(
1020
+ f"Current xDai balance {current_balances.xdai} is more or equal than the required minimum balance {min_required_balance}."
1021
+ )
1022
+ return
1023
+
1024
+ need_to_withdraw = xDai(
1025
+ (min_required_balance - current_balances.xdai) * withdraw_multiplier
1026
+ )
1027
+
1028
+ if current_balances.wxdai < need_to_withdraw:
1029
+ raise ValueError(
1030
+ f"Current wxDai balance {current_balances.wxdai} is less than the required minimum wxDai to withdraw {need_to_withdraw}."
1031
+ )
1032
+
1033
+ collateral_token_contract = OmenCollateralTokenContract()
1034
+ collateral_token_contract.withdraw(
1035
+ api_keys=api_keys, amount_wei=xdai_to_wei(need_to_withdraw), web3=web3
1036
+ )
1037
+ logger.info(
1038
+ f"Withdrew {need_to_withdraw} wxDai to keep the balance above the minimum required balance {min_required_balance}."
1039
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.39.5
3
+ Version: 0.40.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
@@ -12,8 +12,8 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
12
12
  prediction_market_agent_tooling/benchmark/agents.py,sha256=HPIFJvackW110ch3UkktbxhU48gMRVo4gQse84Klhdc,4000
13
13
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=xiHKzZx5GHSsDerFHMZ9j_LXAXnSaITSvv67iPe3MEU,21095
14
14
  prediction_market_agent_tooling/benchmark/utils.py,sha256=iS1BzyXcCMfMm1Rx--1QCH0pHvBTblTndcDQFbTUJ2s,2897
15
- prediction_market_agent_tooling/config.py,sha256=pTeV4mbvPmrS_MzmiBklg05_gtsR3pa9Id5HCS-AzKQ,4519
16
- prediction_market_agent_tooling/deploy/agent.py,sha256=h33uU97x3DjBy8INONtS1Hc5B-NnNDV6MENeeCp0qoA,10185
15
+ prediction_market_agent_tooling/config.py,sha256=kIluGnzhBWIs6DIEoBXbRcIEKaEDU39kVAa3lbIOWlY,4562
16
+ prediction_market_agent_tooling/deploy/agent.py,sha256=TXuQ0L2-dG0tIrJ7srxD3Hbabe_2gILfdBQI-tkl9Og,10522
17
17
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=tqXVA2HSFK3pdZ49tMmta8aKdJFT8JN8WeJ1akjrpBk,909
18
18
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
19
19
  prediction_market_agent_tooling/deploy/gcp/deploy.py,sha256=CYUgnfy-9XVk04kkxA_5yp0GE9Mw5caYqlFUZQ2j3ks,3739
@@ -32,7 +32,7 @@ prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy
32
32
  prediction_market_agent_tooling/markets/markets.py,sha256=w05Oo7yCA2axpCw69Q9y4i9Gcdpht0u5bZGbWqld3rU,2964
33
33
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  prediction_market_agent_tooling/markets/omen/data_models.py,sha256=EXtjmcujx68Xu50BVkYXvLuf_Asx5o65RvFS3ZS6HGs,14405
35
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=dMun3MvkvEVrBmN2NwCCb1Uq3kd9nePe1FhFBgHHcj0,36868
35
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=NtbfiaUQsN0zi7CYbBcQbasc32Dx7OmtIVMv-aXZtbk,38349
36
36
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=JGXCO9MIVr-DGyoH2sxReAw7ZDTC_ev0UxDpq1QBv5Q,21854
37
37
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=g77QsQ5WnSI2rzBlX87L_EhWMwobkyXyfRhHQmpAdzo,9012
38
38
  prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=cwimJjzWw7GNXYj_79ztgJawlwJQzf4Q9BPAtqByRFY,25248
@@ -69,8 +69,8 @@ prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0r
69
69
  prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
70
70
  prediction_market_agent_tooling/tools/utils.py,sha256=-G22UEbCRm59bm1RWFdeF55hRsaxgwZVAHvK32-Ye1g,6190
71
71
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=nKRHmdLnWSKd3wpo-cysXGvhhrJ2Yf69sN2FFQfSt6s,10578
72
- prediction_market_agent_tooling-0.39.5.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
73
- prediction_market_agent_tooling-0.39.5.dist-info/METADATA,sha256=pJlbhUhEMtWTxji9oFxWVINfG5NQlwypKHU0ZYg7G5s,7634
74
- prediction_market_agent_tooling-0.39.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
75
- prediction_market_agent_tooling-0.39.5.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
76
- prediction_market_agent_tooling-0.39.5.dist-info/RECORD,,
72
+ prediction_market_agent_tooling-0.40.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
73
+ prediction_market_agent_tooling-0.40.0.dist-info/METADATA,sha256=Jok34BfwM81xbX25ug6pvRUb1a0ch8-vXpHJyNTGQs0,7634
74
+ prediction_market_agent_tooling-0.40.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
75
+ prediction_market_agent_tooling-0.40.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
76
+ prediction_market_agent_tooling-0.40.0.dist-info/RECORD,,