prediction-market-agent-tooling 0.11.0__tar.gz → 0.13.1__tar.gz

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 (65) hide show
  1. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/PKG-INFO +2 -2
  2. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/agent_market.py +10 -0
  3. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/categorize.py +1 -2
  4. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/data_models.py +4 -4
  5. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/omen.py +28 -11
  6. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/contract.py +13 -11
  7. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/is_predictable.py +1 -1
  8. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/pyproject.toml +2 -2
  9. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/LICENSE +0 -0
  10. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/README.md +0 -0
  11. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_dxdao.abi.json +0 -0
  12. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_fpmm.abi.json +0 -0
  13. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_fpmm_conditionaltokens.abi.json +0 -0
  14. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_fpmm_factory.abi.json +0 -0
  15. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_kleros.abi.json +0 -0
  16. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_oracle.abi.json +0 -0
  17. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/omen_realitio.abi.json +0 -0
  18. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/abis/wxdai.abi.json +0 -0
  19. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/benchmark/__init__.py +0 -0
  20. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/benchmark/agents.py +0 -0
  21. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/benchmark/benchmark.py +0 -0
  22. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/benchmark/utils.py +0 -0
  23. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/config.py +0 -0
  24. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/deploy/agent.py +0 -0
  25. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/deploy/agent_example.py +0 -0
  26. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/deploy/constants.py +0 -0
  27. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/deploy/gcp/deploy.py +0 -0
  28. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/deploy/gcp/utils.py +0 -0
  29. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/gtypes.py +0 -0
  30. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/manifold/__init__.py +0 -0
  31. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/manifold/api.py +0 -0
  32. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/manifold/data_models.py +0 -0
  33. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/manifold/manifold.py +0 -0
  34. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/manifold/utils.py +0 -0
  35. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/markets.py +0 -0
  36. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/__init__.py +0 -0
  37. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/data_models.py +0 -0
  38. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/omen_contracts.py +0 -0
  39. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/omen_replicate.py +0 -0
  40. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/omen_resolve_replicated.py +0 -0
  41. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +0 -0
  42. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/polymarket/api.py +0 -0
  43. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/polymarket/data_models.py +0 -0
  44. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/polymarket/data_models_web.py +0 -0
  45. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/polymarket/polymarket.py +0 -0
  46. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/markets/polymarket/utils.py +0 -0
  47. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/monitor/markets/manifold.py +0 -0
  48. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/monitor/markets/omen.py +0 -0
  49. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/monitor/markets/polymarket.py +0 -0
  50. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/monitor/monitor.py +0 -0
  51. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/monitor/monitor_app.py +0 -0
  52. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/py.typed +0 -0
  53. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/balances.py +0 -0
  54. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +0 -0
  55. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +0 -0
  56. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py +0 -0
  57. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py +0 -0
  58. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/cache.py +0 -0
  59. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/gnosis_rpc.py +0 -0
  60. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/google.py +0 -0
  61. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/hexbytes_custom.py +0 -0
  62. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/parallelism.py +0 -0
  63. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/singleton.py +0 -0
  64. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/utils.py +0 -0
  65. {prediction_market_agent_tooling-0.11.0 → prediction_market_agent_tooling-0.13.1}/prediction_market_agent_tooling/tools/web3_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.11.0
3
+ Version: 0.13.1
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -20,7 +20,7 @@ Requires-Dist: google-cloud-secret-manager (>=2.18.2,<3.0.0)
20
20
  Requires-Dist: isort (>=5.13.2,<6.0.0)
21
21
  Requires-Dist: langchain (>=0.1.9,<0.2.0) ; extra == "langchain"
22
22
  Requires-Dist: langchain-community (>=0.0.19)
23
- Requires-Dist: langchain-openai (>=0.0.8,<0.0.9) ; extra == "langchain"
23
+ Requires-Dist: langchain-openai (>=0.0.5,<0.0.6) ; extra == "langchain"
24
24
  Requires-Dist: loguru (>=0.7.2,<0.8.0)
25
25
  Requires-Dist: numpy (>=1.26.4,<2.0.0)
26
26
  Requires-Dist: pydantic (>=2.6.1,<3.0.0)
@@ -10,6 +10,7 @@ from prediction_market_agent_tooling.markets.data_models import (
10
10
  BetAmount,
11
11
  Currency,
12
12
  Resolution,
13
+ TokenAmount,
13
14
  )
14
15
  from prediction_market_agent_tooling.tools.utils import (
15
16
  add_utc_timezone_validator,
@@ -104,6 +105,12 @@ class AgentMarket(BaseModel):
104
105
  def place_bet(self, outcome: bool, amount: BetAmount) -> None:
105
106
  raise NotImplementedError("Subclasses must implement this method")
106
107
 
108
+ def buy_tokens(self, outcome: bool, amount: TokenAmount) -> None:
109
+ return self.place_bet(outcome=outcome, amount=amount)
110
+
111
+ def sell_tokens(self, outcome: bool, amount: TokenAmount) -> None:
112
+ raise NotImplementedError("Subclasses must implement this method")
113
+
107
114
  @staticmethod
108
115
  def get_binary_markets(
109
116
  limit: int,
@@ -143,3 +150,6 @@ class AgentMarket(BaseModel):
143
150
 
144
151
  def get_squared_error(self) -> float:
145
152
  return (self.p_yes - self.boolean_outcome) ** 2
153
+
154
+ def get_token_balance(self, user_id: str, outcome: str) -> TokenAmount:
155
+ raise NotImplementedError("Subclasses must implement this method")
@@ -3,7 +3,6 @@ from langchain.schema.output_parser import StrOutputParser
3
3
  from langchain_openai import ChatOpenAI
4
4
 
5
5
  from prediction_market_agent_tooling.config import APIKeys
6
- from prediction_market_agent_tooling.gtypes import secretstr_to_v1_secretstr
7
6
 
8
7
 
9
8
  def infer_category(
@@ -22,7 +21,7 @@ Write only the category itself, nothing else.
22
21
  prompt
23
22
  | ChatOpenAI(
24
23
  model=model,
25
- api_key=secretstr_to_v1_secretstr(APIKeys().openai_api_key),
24
+ api_key=APIKeys().openai_api_key.get_secret_value(),
26
25
  )
27
26
  | StrOutputParser()
28
27
  )
@@ -1,6 +1,7 @@
1
1
  from datetime import datetime
2
2
  from decimal import Decimal
3
3
  from enum import Enum
4
+ from typing import TypeAlias
4
5
 
5
6
  from pydantic import BaseModel
6
7
 
@@ -18,14 +19,13 @@ class Resolution(str, Enum):
18
19
  MKT = "MKT"
19
20
 
20
21
 
21
- class BetAmount(BaseModel):
22
+ class TokenAmount(BaseModel):
22
23
  amount: Decimal
23
24
  currency: Currency
24
25
 
25
26
 
26
- class ProfitAmount(BaseModel):
27
- amount: Decimal
28
- currency: Currency
27
+ BetAmount: TypeAlias = TokenAmount
28
+ ProfitAmount: TypeAlias = TokenAmount
29
29
 
30
30
 
31
31
  class Bet(BaseModel):
@@ -22,7 +22,11 @@ from prediction_market_agent_tooling.markets.agent_market import (
22
22
  FilterBy,
23
23
  SortBy,
24
24
  )
25
- from prediction_market_agent_tooling.markets.data_models import BetAmount, Currency
25
+ from prediction_market_agent_tooling.markets.data_models import (
26
+ BetAmount,
27
+ Currency,
28
+ TokenAmount,
29
+ )
26
30
  from prediction_market_agent_tooling.markets.omen.data_models import (
27
31
  OMEN_BASE_URL,
28
32
  OMEN_FALSE_OUTCOME,
@@ -100,6 +104,18 @@ class OmenAgentMarket(AgentMarket):
100
104
  auto_deposit=omen_auto_deposit,
101
105
  )
102
106
 
107
+ def sell_tokens(
108
+ self, outcome: bool, amount: TokenAmount, auto_withdraw: bool = True
109
+ ) -> None:
110
+ keys = APIKeys()
111
+ binary_omen_sell_outcome_tx(
112
+ amount=xDai(amount.amount),
113
+ from_private_key=keys.bet_from_private_key,
114
+ market=self,
115
+ binary_outcome=outcome,
116
+ auto_withdraw=auto_withdraw,
117
+ )
118
+
103
119
  def was_any_bet_outcome_correct(
104
120
  self, resolved_omen_bets: t.List[OmenBet]
105
121
  ) -> bool | None:
@@ -206,17 +222,18 @@ class OmenAgentMarket(AgentMarket):
206
222
  address=self.market_maker_contract_address_checksummed
207
223
  )
208
224
 
225
+ def get_index_set(self, outcome: str) -> int:
226
+ return self.get_outcome_index(outcome) + 1
209
227
 
210
- def ordering_from_sort_by(sort_by: SortBy) -> tuple[str, str]:
211
- """
212
- Returns 'orderBy' and 'orderDirection' strings for the given SortBy.
213
- """
214
- if sort_by == SortBy.CLOSING_SOONEST:
215
- return "creationTimestamp", "desc" # TODO make more accurate
216
- elif sort_by == SortBy.NEWEST:
217
- return "creationTimestamp", "desc"
218
- else:
219
- raise ValueError(f"Unknown sort_by: {sort_by}")
228
+ def get_token_balance(self, user_id: str, outcome: str) -> TokenAmount:
229
+ index_set = self.get_index_set(outcome)
230
+ balances = get_conditional_tokens_balance_for_market(
231
+ self, Web3.to_checksum_address(user_id)
232
+ )
233
+ return TokenAmount(
234
+ amount=Decimal(wei_to_xdai(balances[index_set])),
235
+ currency=Currency.xDai,
236
+ )
220
237
 
221
238
 
222
239
  def pick_binary_market(
@@ -22,6 +22,7 @@ from prediction_market_agent_tooling.tools.gnosis_rpc import (
22
22
  )
23
23
  from prediction_market_agent_tooling.tools.web3_utils import (
24
24
  call_function_on_contract,
25
+ private_key_to_public_key,
25
26
  send_function_on_contract_tx,
26
27
  )
27
28
 
@@ -95,17 +96,18 @@ class ContractBaseClass(BaseModel):
95
96
  """
96
97
  Used for changing a state (writing) to the contract.
97
98
  """
98
- web3 = web3 or self.get_web3()
99
- return send_function_on_contract_tx(
100
- web3=web3,
101
- contract_address=self.address,
102
- contract_abi=self.abi,
103
- from_private_key=from_private_key,
104
- function_name=function_name,
105
- function_params=function_params,
106
- tx_params=tx_params,
107
- timeout=timeout,
108
- )
99
+ with wait_until_nonce_changed(private_key_to_public_key(from_private_key)):
100
+ receipt = send_function_on_contract_tx(
101
+ web3=web3 or self.get_web3(),
102
+ contract_address=self.address,
103
+ contract_abi=self.abi,
104
+ from_private_key=from_private_key,
105
+ function_name=function_name,
106
+ function_params=function_params,
107
+ tx_params=tx_params,
108
+ timeout=timeout,
109
+ )
110
+ return receipt
109
111
 
110
112
  def send_with_value(
111
113
  self,
@@ -42,7 +42,7 @@ def is_predictable_binary(
42
42
 
43
43
  prompt = ChatPromptTemplate.from_template(template=prompt_template)
44
44
  messages = prompt.format_messages(question=question)
45
- completion = llm(messages, max_tokens=512).content
45
+ completion = str(llm(messages, max_tokens=512).content)
46
46
 
47
47
  try:
48
48
  decision = completion.lower().rsplit("decision", 1)[1]
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "prediction-market-agent-tooling"
3
- version = "0.11.0"
3
+ version = "0.13.1"
4
4
  description = "Tools to benchmark, deploy and monitor prediction market agents."
5
5
  authors = ["Gnosis"]
6
6
  readme = "README.md"
@@ -32,7 +32,7 @@ tabulate = "^0.9.0"
32
32
  types-pytz = "^2024.1.0.20240203"
33
33
  google-cloud-secret-manager = "^2.18.2"
34
34
  langchain = { version = "^0.1.9", optional = true}
35
- langchain-openai = { version = "^0.0.8", optional = true}
35
+ langchain-openai = { version = "^0.0.5", optional = true}
36
36
  google-api-python-client = { version = "2.95.0", optional = true}
37
37
  subgrounds = "^1.8.1"
38
38
  loguru = "^0.7.2"