prediction-market-agent-tooling 0.63.0.dev516__py3-none-any.whl → 0.63.2__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.
@@ -1,3 +1,4 @@
1
+ from cachetools import TTLCache, cached
1
2
  from web3 import Web3
2
3
 
3
4
  from prediction_market_agent_tooling.gtypes import (
@@ -14,7 +15,9 @@ from prediction_market_agent_tooling.markets.seer.seer_subgraph_handler import (
14
15
  SeerSubgraphHandler,
15
16
  )
16
17
  from prediction_market_agent_tooling.markets.seer.subgraph_data_models import SeerPool
17
- from prediction_market_agent_tooling.tools.cow.cow_order import get_quote
18
+ from prediction_market_agent_tooling.tools.cow.cow_order import (
19
+ get_buy_token_amount_else_raise,
20
+ )
18
21
  from prediction_market_agent_tooling.tools.hexbytes_custom import HexBytes
19
22
 
20
23
 
@@ -32,7 +35,8 @@ class PriceManager:
32
35
  def _log_track_price_normalization_diff(
33
36
  self, old_price: float, normalized_price: float, max_price_diff: float = 0.05
34
37
  ) -> None:
35
- price_diff_pct = abs(old_price - normalized_price) / old_price
38
+ # We add max(price,0.01) to avoid division by 0
39
+ price_diff_pct = abs(old_price - normalized_price) / max(old_price, 0.01)
36
40
  if price_diff_pct > max_price_diff:
37
41
  logger.info(
38
42
  f"{price_diff_pct=} larger than {max_price_diff=} for seer market {self.seer_market.id.hex()} "
@@ -62,6 +66,7 @@ class PriceManager:
62
66
  else:
63
67
  return None
64
68
 
69
+ @cached(TTLCache(maxsize=100, ttl=5 * 60))
65
70
  def get_price_for_token(
66
71
  self,
67
72
  token: ChecksumAddress,
@@ -74,11 +79,13 @@ class PriceManager:
74
79
  )
75
80
 
76
81
  try:
77
- quote = get_quote(
78
- amount_wei=collateral_exchange_amount.as_wei,
82
+ buy_token_amount = get_buy_token_amount_else_raise(
83
+ sell_amount=collateral_exchange_amount.as_wei,
79
84
  sell_token=self.seer_market.collateral_token_contract_address_checksummed,
80
85
  buy_token=token,
81
86
  )
87
+ price = collateral_exchange_amount.as_wei / buy_token_amount
88
+ return CollateralToken(price)
82
89
 
83
90
  except Exception as e:
84
91
  logger.warning(
@@ -86,9 +93,6 @@ class PriceManager:
86
93
  )
87
94
  return self.get_token_price_from_pools(token=token)
88
95
 
89
- price = collateral_exchange_amount / float(quote.quote.buyAmount.root)
90
- return price
91
-
92
96
  @staticmethod
93
97
  def _pool_token0_matches_token(token: ChecksumAddress, pool: SeerPool) -> bool:
94
98
  return pool.token0.id.hex().lower() == token.lower()
@@ -46,7 +46,10 @@ from prediction_market_agent_tooling.tools.contract import (
46
46
  init_collateral_token_contract,
47
47
  to_gnosis_chain_contract,
48
48
  )
49
- from prediction_market_agent_tooling.tools.cow.cow_order import swap_tokens_waiting
49
+ from prediction_market_agent_tooling.tools.cow.cow_order import (
50
+ get_buy_token_amount_else_raise,
51
+ swap_tokens_waiting,
52
+ )
50
53
  from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
51
54
  from prediction_market_agent_tooling.tools.tokens.auto_deposit import (
52
55
  auto_deposit_collateral_token,
@@ -122,6 +125,23 @@ class SeerAgentMarket(AgentMarket):
122
125
  amount_outcome_tokens = bet_amount_in_tokens / price
123
126
  return OutcomeToken(amount_outcome_tokens)
124
127
 
128
+ def get_sell_value_of_outcome_token(
129
+ self, outcome: str, amount: OutcomeToken
130
+ ) -> CollateralToken:
131
+ if amount == amount.zero():
132
+ return CollateralToken.zero()
133
+
134
+ outcome_index = self.get_outcome_index(outcome=outcome)
135
+ wrapped_outcome_token = self.wrapped_tokens[outcome_index]
136
+
137
+ # We calculate how much collateral we would get back if we sold `amount` of outcome token.
138
+ value_outcome_token_in_collateral = get_buy_token_amount_else_raise(
139
+ sell_amount=amount.as_outcome_wei.as_wei,
140
+ sell_token=wrapped_outcome_token,
141
+ buy_token=self.collateral_token_contract_address_checksummed,
142
+ )
143
+ return value_outcome_token_in_collateral.as_token
144
+
125
145
  def get_outcome_str_from_bool(self, outcome: bool) -> OutcomeStr:
126
146
  outcome_translated = SeerOutcomeEnum.from_bool(outcome)
127
147
  idx = self.seer_outcomes[outcome_translated]
@@ -134,9 +154,9 @@ class SeerAgentMarket(AgentMarket):
134
154
  def get_tiny_bet_amount(self) -> CollateralToken:
135
155
  return self.get_in_token(SEER_TINY_BET_AMOUNT)
136
156
 
137
- def get_position(
157
+ def get_position_else_raise(
138
158
  self, user_id: str, web3: Web3 | None = None
139
- ) -> ExistingPosition | None:
159
+ ) -> ExistingPosition:
140
160
  """
141
161
  Fetches position from the user in a given market.
142
162
  We ignore the INVALID balances since we are only interested in binary outcomes.
@@ -169,6 +189,15 @@ class SeerAgentMarket(AgentMarket):
169
189
  amounts_ot=amounts_ot,
170
190
  )
171
191
 
192
+ def get_position(
193
+ self, user_id: str, web3: Web3 | None = None
194
+ ) -> ExistingPosition | None:
195
+ try:
196
+ return self.get_position_else_raise(user_id=user_id, web3=web3)
197
+ except Exception as e:
198
+ logger.warning(f"Could not get position for user {user_id}, exception {e}")
199
+ return None
200
+
172
201
  @staticmethod
173
202
  def get_user_id(api_keys: APIKeys) -> str:
174
203
  return OmenAgentMarket.get_user_id(api_keys)
@@ -127,14 +127,14 @@ def get_quote(
127
127
 
128
128
 
129
129
  def get_buy_token_amount_else_raise(
130
- amount_wei: Wei,
130
+ sell_amount: Wei,
131
131
  sell_token: ChecksumAddress,
132
132
  buy_token: ChecksumAddress,
133
133
  chain: Chain = Chain.GNOSIS,
134
134
  env: Envs = "prod",
135
135
  ) -> Wei:
136
136
  order_quote = get_quote(
137
- amount_wei=amount_wei,
137
+ amount_wei=sell_amount,
138
138
  sell_token=sell_token,
139
139
  buy_token=buy_token,
140
140
  chain=chain,
@@ -50,7 +50,7 @@ def get_single_token_to_usd_rate(token_address: ChecksumAddress) -> USD:
50
50
  .as_token.value
51
51
  )
52
52
  in_wei = get_buy_token_amount_else_raise(
53
- amount_wei=CollateralToken(1).as_wei,
53
+ sell_amount=CollateralToken(1).as_wei,
54
54
  sell_token=token_address,
55
55
  buy_token=WRAPPED_XDAI_CONTRACT_ADDRESS,
56
56
  )
@@ -72,7 +72,7 @@ def get_single_usd_to_token_rate(token_address: ChecksumAddress) -> CollateralTo
72
72
  .as_token.value
73
73
  )
74
74
  in_wei = get_buy_token_amount_else_raise(
75
- amount_wei=CollateralToken(1).as_wei,
75
+ sell_amount=CollateralToken(1).as_wei,
76
76
  sell_token=WRAPPED_XDAI_CONTRACT_ADDRESS,
77
77
  buy_token=token_address,
78
78
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.63.0.dev516
3
+ Version: 0.63.2
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.13
@@ -62,8 +62,8 @@ prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=LVE
62
62
  prediction_market_agent_tooling/markets/polymarket/polymarket.py,sha256=6rc9qulPl90MxXKB55XiiWKLhjfAyG_eUzAlqpq1UIE,3339
63
63
  prediction_market_agent_tooling/markets/polymarket/utils.py,sha256=8kTeVjXPcXC6DkDvWYsZQLY7x8DS6CEp_yznSEazsNU,2037
64
64
  prediction_market_agent_tooling/markets/seer/data_models.py,sha256=FwTOq9X2iJ7r3ijtE0evl8pMSbFPm4lUwuc9m7YsMVA,6373
65
- prediction_market_agent_tooling/markets/seer/price_manager.py,sha256=GaDaFIz1jMgUUg4TpR-FdIF-_-C6pX4sjp3xTLi8KyI,4691
66
- prediction_market_agent_tooling/markets/seer/seer.py,sha256=PQ685AE9BjH4QZC_zcTCGt7RNBRI6wKkXoCUvQeMDO0,14897
65
+ prediction_market_agent_tooling/markets/seer/price_manager.py,sha256=PtGD9cm8JlxVTkSD-QgZuh_gWfG7WATakh8-t0szomk,4924
66
+ prediction_market_agent_tooling/markets/seer/seer.py,sha256=_FzFGTkaOHQ2WTkUa_ba-Tc9zqw4KTmbCTrH4EmvOsU,16035
67
67
  prediction_market_agent_tooling/markets/seer/seer_contracts.py,sha256=yufEojZxLa_SQv9xhsG23wLGsyHOWD8Azm7-7E5Zn_8,2714
68
68
  prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py,sha256=KKRI493VNNAY9tR1AjzNraeH76MvDsBV6GsiLZas0_Y,9859
69
69
  prediction_market_agent_tooling/markets/seer/subgraph_data_models.py,sha256=0izxS8Mtzonfdl9UqvFVXrdj0hVzieroekXhogfZKCw,1817
@@ -88,7 +88,7 @@ prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=ZW5iI5rmjq
88
88
  prediction_market_agent_tooling/tools/caches/serializers.py,sha256=vFDx4fsPxclXp2q0sv27j4al_M_Tj9aR2JJP-xNHQXA,2151
89
89
  prediction_market_agent_tooling/tools/contract.py,sha256=1ZFp_VoqTjM8cqOfAhco2Ht0DTqakjhZpuZUrAXr28Q,21332
90
90
  prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
91
- prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=jWBRF5UdXjlWNn3X8BxcMXSuU3fegoZzz-NXB7sSIt8,6959
91
+ prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=Kk-J3N3wTbmgdYs_XGp3nXbSi3-A17lQ61j60D_lPGg,6961
92
92
  prediction_market_agent_tooling/tools/custom_exceptions.py,sha256=Fh8z1fbwONvP4-j7AmV_PuEcoqb6-QXa9PJ9m7guMcM,93
93
93
  prediction_market_agent_tooling/tools/datetime_utc.py,sha256=8_WackjtjC8zHXrhQFTGQ6e6Fz_6llWoKR4CSFvIv9I,2766
94
94
  prediction_market_agent_tooling/tools/db/db_manager.py,sha256=GtzHH1NLl8HwqC8Z7s6eTlIQXuV0blxfaV2PeQrBnfQ,3013
@@ -117,12 +117,12 @@ prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=MWIRHYCN-7o2
117
117
  prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=22g0SIVmLlgITpdt3kPhJOw0sU4OPeBuYk_7xCrQr9U,2491
118
118
  prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=1rbwpdCusPgQIVFuo3m00nBZ_b2lCAoFVm67i-YDcEw,812
119
119
  prediction_market_agent_tooling/tools/tokens/token_utils.py,sha256=fhs-FH9m9IbzGa-30R3ZleSKLeKfLEDoJ7F5Om285Vk,1369
120
- prediction_market_agent_tooling/tools/tokens/usd.py,sha256=Qq8ofVCCMX-eo8mDlHv4gL9DV_bqHFpd63Wv5yE7cjY,3113
120
+ prediction_market_agent_tooling/tools/tokens/usd.py,sha256=yuW8iPPtcpP4eLH2nORMDAfztcq0Nv2ascSrCquF1f8,3115
121
121
  prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
122
122
  prediction_market_agent_tooling/tools/utils.py,sha256=1xsyBBJfiEdSoMlceB2F8o2sCb6Z8-qNz11pEJFrdyE,6566
123
123
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=eYCc1iWAVtqDKUPTwnMUHuYolPdwh_OTiM3-AdRgDp4,12198
124
- prediction_market_agent_tooling-0.63.0.dev516.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
125
- prediction_market_agent_tooling-0.63.0.dev516.dist-info/METADATA,sha256=UVtNAGPdvX4qJDZA-TN6kAp1U6Z68j-ls2yQl7GpTEo,8696
126
- prediction_market_agent_tooling-0.63.0.dev516.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
127
- prediction_market_agent_tooling-0.63.0.dev516.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
128
- prediction_market_agent_tooling-0.63.0.dev516.dist-info/RECORD,,
124
+ prediction_market_agent_tooling-0.63.2.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
125
+ prediction_market_agent_tooling-0.63.2.dist-info/METADATA,sha256=8842h65SdEztkGfvqLpAOdd1DdOrrJ7eFtSQtBcQYcA,8689
126
+ prediction_market_agent_tooling-0.63.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
127
+ prediction_market_agent_tooling-0.63.2.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
128
+ prediction_market_agent_tooling-0.63.2.dist-info/RECORD,,