prediction-market-agent-tooling 0.62.1__tar.gz → 0.63.0.dev499__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.
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/PKG-INFO +1 -1
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/betting_strategy.py +21 -5
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/agent_market.py +3 -1
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/blockchain_utils.py +6 -2
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/omen.py +1 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/seer/data_models.py +4 -65
- prediction_market_agent_tooling-0.63.0.dev499/prediction_market_agent_tooling/markets/seer/price_manager.py +122 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/seer/seer.py +103 -45
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/seer/seer_contracts.py +4 -4
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py +47 -18
- prediction_market_agent_tooling-0.63.0.dev499/prediction_market_agent_tooling/markets/seer/subgraph_data_models.py +57 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/contract.py +11 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/cow/cow_order.py +53 -19
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tokens/auto_deposit.py +1 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tokens/token_utils.py +4 -3
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tokens/usd.py +7 -6
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/pyproject.toml +1 -1
- prediction_market_agent_tooling-0.62.1/prediction_market_agent_tooling/tools/cow/cow_manager.py +0 -112
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/README.md +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/debuggingcontract.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/depositablewrapper_erc20.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/erc20.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/erc4626.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/erc721.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_agentresultmapping.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_dxdao.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_fpmm.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_fpmm_conditionaltokens.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_fpmm_factory.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_kleros.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_oracle.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_realitio.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/omen_thumbnailmapping.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/ownable.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/ownable_erc721.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/proxy.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/abis/seer_market_factory.abi.json +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/benchmark/__init__.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/benchmark/agents.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/benchmark/benchmark.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/benchmark/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/config.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/agent.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/agent_example.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/constants.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/gcp/deploy.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/gcp/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/deploy/trade_interval.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/gtypes.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/jobs/__init__.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/jobs/jobs_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/jobs/omen/omen_jobs.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/loggers.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/base_subgraph_handler.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/categorize.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/manifold/__init__.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/manifold/api.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/manifold/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/manifold/manifold.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/manifold/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/market_fees.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/markets.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/metaculus/api.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/metaculus/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/metaculus/metaculus.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/__init__.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/omen_constants.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/omen_contracts.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/omen_resolving.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/polymarket/api.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/polymarket/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/polymarket/data_models_web.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/polymarket/polymarket.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/markets/polymarket/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/financial_metrics/financial_metrics.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/markets/manifold.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/markets/metaculus.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/markets/omen.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/markets/polymarket.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/monitor.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/monitor_app.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/monitor/monitor_settings.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/py.typed +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/_generic_value.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/balances.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/betting_strategies/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/caches/db_cache.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/caches/inmemory_cache.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/caches/serializers.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/costs.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/custom_exceptions.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/datetime_utc.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/db/db_manager.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/google_utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/hexbytes_custom.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/httpx_cached_client.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/image_gen/image_gen.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/is_invalid.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/is_predictable.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/langfuse_.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/langfuse_client_utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/omen/reality_accuracy.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/omen/sell_positions.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/parallelism.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/safe.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/singleton.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/streamlit_user_login.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tavily/tavily_models.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tavily/tavily_search.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/tokens/main_token.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/transaction_cache.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/utils.py +0 -0
- {prediction_market_agent_tooling-0.62.1 → prediction_market_agent_tooling-0.63.0.dev499}/prediction_market_agent_tooling/tools/web3_utils.py +0 -0
@@ -47,23 +47,39 @@ class BettingStrategy(ABC):
|
|
47
47
|
@staticmethod
|
48
48
|
def assert_buy_trade_wont_be_guaranteed_loss(
|
49
49
|
market: AgentMarket, trades: list[Trade]
|
50
|
-
) ->
|
50
|
+
) -> list[Trade]:
|
51
|
+
clean_trades = []
|
51
52
|
for trade in trades:
|
52
53
|
if trade.trade_type == TradeType.BUY:
|
53
54
|
outcome_tokens_to_get = market.get_buy_token_amount(
|
54
55
|
trade.amount, trade.outcome
|
55
56
|
)
|
57
|
+
|
58
|
+
if not outcome_tokens_to_get:
|
59
|
+
logger.info(
|
60
|
+
f"Could not determine buy_token_amount for trade {trade}. Skipping trade."
|
61
|
+
)
|
62
|
+
continue
|
63
|
+
|
56
64
|
outcome_tokens_to_get_in_usd = market.get_token_in_usd(
|
57
65
|
outcome_tokens_to_get.as_token
|
58
66
|
)
|
67
|
+
|
59
68
|
if outcome_tokens_to_get_in_usd <= trade.amount:
|
60
69
|
raise GuaranteedLossError(
|
61
|
-
f"Trade {trade=} would result in guaranteed loss by getting only {outcome_tokens_to_get=}."
|
70
|
+
f"Trade {trade=} would result in guaranteed loss by getting only {outcome_tokens_to_get=}. Halting execution."
|
62
71
|
)
|
63
72
|
|
73
|
+
clean_trades.append(trade)
|
74
|
+
|
75
|
+
return clean_trades
|
76
|
+
|
64
77
|
@staticmethod
|
65
|
-
def
|
66
|
-
BettingStrategy.assert_buy_trade_wont_be_guaranteed_loss(
|
78
|
+
def filter_trades(market: AgentMarket, trades: list[Trade]) -> list[Trade]:
|
79
|
+
trades = BettingStrategy.assert_buy_trade_wont_be_guaranteed_loss(
|
80
|
+
market, trades
|
81
|
+
)
|
82
|
+
return trades
|
67
83
|
|
68
84
|
def _build_rebalance_trades_from_positions(
|
69
85
|
self,
|
@@ -109,7 +125,7 @@ class BettingStrategy(ABC):
|
|
109
125
|
trades.sort(key=lambda t: t.trade_type == TradeType.SELL)
|
110
126
|
|
111
127
|
# Run some sanity checks to not place unreasonable bets.
|
112
|
-
BettingStrategy.
|
128
|
+
trades = BettingStrategy.filter_trades(market, trades)
|
113
129
|
|
114
130
|
return trades
|
115
131
|
|
@@ -4,6 +4,7 @@ from enum import Enum
|
|
4
4
|
from eth_typing import ChecksumAddress
|
5
5
|
from pydantic import BaseModel, field_validator, model_validator
|
6
6
|
from pydantic_core.core_schema import FieldValidationInfo
|
7
|
+
from web3 import Web3
|
7
8
|
|
8
9
|
from prediction_market_agent_tooling.config import APIKeys
|
9
10
|
from prediction_market_agent_tooling.gtypes import (
|
@@ -235,7 +236,7 @@ class AgentMarket(BaseModel):
|
|
235
236
|
|
236
237
|
def get_buy_token_amount(
|
237
238
|
self, bet_amount: USD | CollateralToken, direction: bool
|
238
|
-
) -> OutcomeToken:
|
239
|
+
) -> OutcomeToken | None:
|
239
240
|
raise NotImplementedError("Subclasses must implement this method")
|
240
241
|
|
241
242
|
def sell_tokens(self, outcome: bool, amount: USD | OutcomeToken) -> str:
|
@@ -293,6 +294,7 @@ class AgentMarket(BaseModel):
|
|
293
294
|
traded_market: ProcessedTradedMarket | None,
|
294
295
|
keys: APIKeys,
|
295
296
|
agent_name: str,
|
297
|
+
web3: Web3 | None = None,
|
296
298
|
) -> None:
|
297
299
|
"""
|
298
300
|
If market allows to upload trades somewhere, implement it in this method.
|
@@ -22,10 +22,11 @@ def store_trades(
|
|
22
22
|
traded_market: ProcessedTradedMarket | None,
|
23
23
|
keys: APIKeys,
|
24
24
|
agent_name: str,
|
25
|
+
web3: Web3 | None = None,
|
25
26
|
) -> None:
|
26
27
|
if traded_market is None:
|
27
28
|
logger.warning(f"No prediction for market {market_id}, not storing anything.")
|
28
|
-
return
|
29
|
+
return None
|
29
30
|
|
30
31
|
reasoning = traded_market.answer.reasoning if traded_market.answer.reasoning else ""
|
31
32
|
|
@@ -37,8 +38,10 @@ def store_trades(
|
|
37
38
|
)
|
38
39
|
ipfs_hash_decoded = ipfscidv0_to_byte32(ipfs_hash)
|
39
40
|
|
41
|
+
# tx_hashes must be list of bytes32 (see Solidity contract).
|
42
|
+
# For regular tx hashes that's fine, but for other types of IDs we take the first 32 bytes (orderDigest).
|
40
43
|
tx_hashes = [
|
41
|
-
HexBytes(HexStr(i.id)) for i in traded_market.trades if i.id is not None
|
44
|
+
HexBytes(HexStr(i.id[:32])) for i in traded_market.trades if i.id is not None
|
42
45
|
]
|
43
46
|
prediction = ContractPrediction(
|
44
47
|
publisher=keys.bet_from_address,
|
@@ -50,6 +53,7 @@ def store_trades(
|
|
50
53
|
api_keys=keys,
|
51
54
|
market_address=Web3.to_checksum_address(market_id),
|
52
55
|
prediction=prediction,
|
56
|
+
web3=web3,
|
53
57
|
)
|
54
58
|
logger.info(
|
55
59
|
f"Added prediction to market {market_id}. - receipt {tx_receipt['transactionHash'].hex()}."
|
@@ -10,16 +10,15 @@ from web3.constants import ADDRESS_ZERO
|
|
10
10
|
from prediction_market_agent_tooling.config import RPCConfig
|
11
11
|
from prediction_market_agent_tooling.gtypes import (
|
12
12
|
ChecksumAddress,
|
13
|
-
CollateralToken,
|
14
13
|
HexAddress,
|
15
14
|
HexBytes,
|
16
15
|
OutcomeStr,
|
17
|
-
Probability,
|
18
16
|
Web3Wei,
|
19
17
|
)
|
20
|
-
from prediction_market_agent_tooling.loggers import logger
|
21
18
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
22
|
-
from prediction_market_agent_tooling.
|
19
|
+
from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
|
20
|
+
SeerParentMarket,
|
21
|
+
)
|
23
22
|
from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
|
24
23
|
|
25
24
|
|
@@ -84,10 +83,6 @@ class SeerOutcomeEnum(str, Enum):
|
|
84
83
|
raise ValueError(f"Unknown outcome: {self}")
|
85
84
|
|
86
85
|
|
87
|
-
class SeerParentMarket(BaseModel):
|
88
|
-
id: HexBytes
|
89
|
-
|
90
|
-
|
91
86
|
SEER_BASE_URL = "https://app.seer.pm"
|
92
87
|
|
93
88
|
|
@@ -110,6 +105,7 @@ class SeerMarket(BaseModel):
|
|
110
105
|
has_answers: bool | None = Field(alias="hasAnswers")
|
111
106
|
payout_reported: bool = Field(alias="payoutReported")
|
112
107
|
payout_numerators: list[int] = Field(alias="payoutNumerators")
|
108
|
+
outcomes_supply: int = Field(alias="outcomesSupply")
|
113
109
|
|
114
110
|
@property
|
115
111
|
def has_valid_answer(self) -> bool:
|
@@ -186,64 +182,7 @@ class SeerMarket(BaseModel):
|
|
186
182
|
def created_time(self) -> DatetimeUTC:
|
187
183
|
return DatetimeUTC.to_datetime_utc(self.block_timestamp)
|
188
184
|
|
189
|
-
@property
|
190
|
-
def current_p_yes(self) -> Probability:
|
191
|
-
price_data = {}
|
192
|
-
for idx in range(len(self.outcomes)):
|
193
|
-
wrapped_token = self.wrapped_tokens[idx]
|
194
|
-
price = self._get_price_for_token(
|
195
|
-
token=Web3.to_checksum_address(wrapped_token)
|
196
|
-
)
|
197
|
-
price_data[idx] = price
|
198
|
-
|
199
|
-
if sum(price_data.values()) == 0:
|
200
|
-
logger.warning(
|
201
|
-
f"Could not get p_yes for market {self.id.hex()}, all price quotes are 0."
|
202
|
-
)
|
203
|
-
return Probability(0)
|
204
|
-
|
205
|
-
yes_idx = self.outcome_as_enums[SeerOutcomeEnum.YES]
|
206
|
-
price_yes = price_data[yes_idx] / sum(price_data.values())
|
207
|
-
return Probability(price_yes)
|
208
|
-
|
209
|
-
def _get_price_for_token(self, token: ChecksumAddress) -> float:
|
210
|
-
collateral_exchange_amount = CollateralToken(1).as_wei
|
211
|
-
try:
|
212
|
-
quote = CowManager().get_quote(
|
213
|
-
collateral_token=self.collateral_token_contract_address_checksummed,
|
214
|
-
buy_token=token,
|
215
|
-
sell_amount=collateral_exchange_amount,
|
216
|
-
)
|
217
|
-
except Exception as e:
|
218
|
-
logger.warning(f"Could not get quote for {token=}, returning price 0. {e=}")
|
219
|
-
return 0
|
220
|
-
|
221
|
-
return collateral_exchange_amount.value / float(quote.quote.buyAmount.root)
|
222
|
-
|
223
185
|
@property
|
224
186
|
def url(self) -> str:
|
225
187
|
chain_id = RPCConfig().chain_id
|
226
188
|
return urljoin(SEER_BASE_URL, f"markets/{chain_id}/{self.id.hex()}")
|
227
|
-
|
228
|
-
|
229
|
-
class SeerToken(BaseModel):
|
230
|
-
id: HexBytes
|
231
|
-
name: str
|
232
|
-
symbol: str
|
233
|
-
|
234
|
-
|
235
|
-
class SeerPool(BaseModel):
|
236
|
-
model_config = ConfigDict(populate_by_name=True)
|
237
|
-
id: HexBytes
|
238
|
-
liquidity: int
|
239
|
-
token0: SeerToken
|
240
|
-
token1: SeerToken
|
241
|
-
|
242
|
-
|
243
|
-
class NewMarketEvent(BaseModel):
|
244
|
-
market: HexAddress
|
245
|
-
marketName: str
|
246
|
-
parentMarket: HexAddress
|
247
|
-
conditionId: HexBytes
|
248
|
-
questionId: HexBytes
|
249
|
-
questionsIds: list[HexBytes]
|
@@ -0,0 +1,122 @@
|
|
1
|
+
from web3 import Web3
|
2
|
+
|
3
|
+
from prediction_market_agent_tooling.gtypes import (
|
4
|
+
ChecksumAddress,
|
5
|
+
Probability,
|
6
|
+
Wei,
|
7
|
+
CollateralToken,
|
8
|
+
)
|
9
|
+
from prediction_market_agent_tooling.loggers import logger
|
10
|
+
from prediction_market_agent_tooling.markets.seer.data_models import (
|
11
|
+
SeerMarket,
|
12
|
+
SeerOutcomeEnum,
|
13
|
+
)
|
14
|
+
from prediction_market_agent_tooling.markets.seer.seer_subgraph_handler import (
|
15
|
+
SeerSubgraphHandler,
|
16
|
+
)
|
17
|
+
from prediction_market_agent_tooling.markets.seer.subgraph_data_models import SeerPool
|
18
|
+
from prediction_market_agent_tooling.tools.cow.cow_order import get_quote
|
19
|
+
from prediction_market_agent_tooling.tools.hexbytes_custom import HexBytes
|
20
|
+
from prediction_market_agent_tooling.tools.utils import check_not_none
|
21
|
+
|
22
|
+
|
23
|
+
class PriceManager:
|
24
|
+
def __init__(self, seer_market: SeerMarket, seer_subgraph: SeerSubgraphHandler):
|
25
|
+
self.seer_market = seer_market
|
26
|
+
self.seer_subgraph = seer_subgraph
|
27
|
+
|
28
|
+
@staticmethod
|
29
|
+
def build(market_id: HexBytes) -> "PriceManager":
|
30
|
+
s = SeerSubgraphHandler()
|
31
|
+
market = s.get_market_by_id(market_id=market_id)
|
32
|
+
return PriceManager(seer_market=market, seer_subgraph=s)
|
33
|
+
|
34
|
+
def _log_track_price_normalization_diff(
|
35
|
+
self, old_price: float, normalized_price: float, max_price_diff: float = 0.05
|
36
|
+
) -> None:
|
37
|
+
price_diff_pct = abs(old_price - normalized_price) / old_price
|
38
|
+
if price_diff_pct > max_price_diff:
|
39
|
+
logger.info(
|
40
|
+
f"{price_diff_pct=} larger than {max_price_diff=} for seer market {self.seer_market.id.hex()} "
|
41
|
+
)
|
42
|
+
|
43
|
+
def current_p_yes(self) -> Probability | None:
|
44
|
+
# Inspired by https://github.com/seer-pm/demo/blob/ca682153a6b4d4dd3dcc4ad8bdcbe32202fc8fe7/web/src/hooks/useMarketOdds.ts#L15
|
45
|
+
price_data = {}
|
46
|
+
for idx, wrapped_token in enumerate(self.seer_market.wrapped_tokens):
|
47
|
+
price = self.get_price_for_token(
|
48
|
+
token=Web3.to_checksum_address(wrapped_token),
|
49
|
+
)
|
50
|
+
|
51
|
+
price_data[idx] = price
|
52
|
+
|
53
|
+
price_yes = price_data[self.seer_market.outcome_as_enums[SeerOutcomeEnum.YES]]
|
54
|
+
price_no = price_data[self.seer_market.outcome_as_enums[SeerOutcomeEnum.NO]]
|
55
|
+
|
56
|
+
# We only return a probability if we have both price_yes and price_no, since we could place bets
|
57
|
+
# in both sides hence we need current probabilities for both outcomes.
|
58
|
+
if price_yes and price_no:
|
59
|
+
# If other outcome`s price is None, we set it to 0.
|
60
|
+
total_price = sum(
|
61
|
+
price if price is not None else 0.0 for price in price_data.values()
|
62
|
+
)
|
63
|
+
normalized_price_yes = price_yes / total_price
|
64
|
+
self._log_track_price_normalization_diff(
|
65
|
+
old_price=price_yes, normalized_price=normalized_price_yes
|
66
|
+
)
|
67
|
+
return Probability(normalized_price_yes)
|
68
|
+
else:
|
69
|
+
return None
|
70
|
+
|
71
|
+
def get_price_for_token(
|
72
|
+
self, token: ChecksumAddress, collateral_exchange_amount: Wei | None = None
|
73
|
+
) -> float | None:
|
74
|
+
collateral_exchange_amount = (
|
75
|
+
collateral_exchange_amount
|
76
|
+
if collateral_exchange_amount is not None
|
77
|
+
else CollateralToken(1).as_wei
|
78
|
+
)
|
79
|
+
|
80
|
+
try:
|
81
|
+
quote = get_quote(
|
82
|
+
amount_wei=collateral_exchange_amount,
|
83
|
+
sell_token=self.seer_market.collateral_token_contract_address_checksummed,
|
84
|
+
buy_token=token,
|
85
|
+
)
|
86
|
+
|
87
|
+
except Exception as e:
|
88
|
+
logger.warning(
|
89
|
+
f"Could not get quote for {token=} from Cow, exception {e=}. Falling back to pools. "
|
90
|
+
)
|
91
|
+
return self.get_token_price_from_pools(token=token)
|
92
|
+
|
93
|
+
collateral_exchange_amount = check_not_none(collateral_exchange_amount)
|
94
|
+
price = collateral_exchange_amount / float(quote.quote.buyAmount.root)
|
95
|
+
return Wei(str(price)).value
|
96
|
+
|
97
|
+
@staticmethod
|
98
|
+
def _pool_token0_matches_token(token: ChecksumAddress, pool: SeerPool) -> bool:
|
99
|
+
return pool.token0.id.hex().lower() == token.lower()
|
100
|
+
|
101
|
+
def get_token_price_from_pools(
|
102
|
+
self,
|
103
|
+
token: ChecksumAddress,
|
104
|
+
) -> float | None:
|
105
|
+
pool = SeerSubgraphHandler().get_pool_by_token(
|
106
|
+
token_address=token,
|
107
|
+
collateral_address=self.seer_market.collateral_token_contract_address_checksummed,
|
108
|
+
)
|
109
|
+
|
110
|
+
if not pool:
|
111
|
+
logger.warning(f"Could not find a pool for {token=}")
|
112
|
+
return None
|
113
|
+
|
114
|
+
# The mapping below is odd but surprisingly the Algebra subgraph delivers the token1Price
|
115
|
+
# for the token0 and the token0Price for the token1 pool.
|
116
|
+
# For example, in a outcomeYES (token0)/sDAI pool (token1), token1Price is the price of outcomeYES in units of sDAI.
|
117
|
+
price_in_collateral_units = (
|
118
|
+
pool.token1Price
|
119
|
+
if self._pool_token0_matches_token(token=token, pool=pool)
|
120
|
+
else pool.token0Price
|
121
|
+
)
|
122
|
+
return price_in_collateral_units
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import typing as t
|
2
2
|
|
3
|
+
import tenacity
|
4
|
+
from eth_pydantic_types import HexStr
|
3
5
|
from eth_typing import ChecksumAddress
|
4
6
|
from web3 import Web3
|
5
7
|
from web3.types import TxReceipt
|
@@ -20,33 +22,32 @@ from prediction_market_agent_tooling.markets.agent_market import (
|
|
20
22
|
AgentMarket,
|
21
23
|
FilterBy,
|
22
24
|
ProcessedMarket,
|
23
|
-
ProcessedTradedMarket,
|
24
25
|
SortBy,
|
26
|
+
ProcessedTradedMarket,
|
25
27
|
)
|
26
|
-
from prediction_market_agent_tooling.markets.blockchain_utils import store_trades
|
27
28
|
from prediction_market_agent_tooling.markets.data_models import ExistingPosition
|
28
29
|
from prediction_market_agent_tooling.markets.market_fees import MarketFees
|
29
30
|
from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket
|
30
31
|
from prediction_market_agent_tooling.markets.seer.data_models import (
|
31
|
-
NewMarketEvent,
|
32
32
|
SeerMarket,
|
33
33
|
SeerOutcomeEnum,
|
34
34
|
)
|
35
|
+
from prediction_market_agent_tooling.markets.seer.price_manager import PriceManager
|
35
36
|
from prediction_market_agent_tooling.markets.seer.seer_contracts import (
|
36
37
|
SeerMarketFactory,
|
37
38
|
)
|
38
39
|
from prediction_market_agent_tooling.markets.seer.seer_subgraph_handler import (
|
39
40
|
SeerSubgraphHandler,
|
40
41
|
)
|
42
|
+
from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
|
43
|
+
NewMarketEvent,
|
44
|
+
)
|
41
45
|
from prediction_market_agent_tooling.tools.contract import (
|
42
46
|
ContractERC20OnGnosisChain,
|
43
47
|
init_collateral_token_contract,
|
44
48
|
to_gnosis_chain_contract,
|
45
49
|
)
|
46
|
-
from prediction_market_agent_tooling.tools.cow.
|
47
|
-
CowManager,
|
48
|
-
NoLiquidityAvailableOnCowException,
|
49
|
-
)
|
50
|
+
from prediction_market_agent_tooling.tools.cow.cow_order import swap_tokens_waiting
|
50
51
|
from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
|
51
52
|
from prediction_market_agent_tooling.tools.tokens.auto_deposit import (
|
52
53
|
auto_deposit_collateral_token,
|
@@ -87,19 +88,16 @@ class SeerAgentMarket(AgentMarket):
|
|
87
88
|
agent_name: str,
|
88
89
|
) -> None:
|
89
90
|
"""On Seer, we have to store predictions along with trades, see `store_trades`."""
|
91
|
+
pass
|
90
92
|
|
91
93
|
def store_trades(
|
92
94
|
self,
|
93
95
|
traded_market: ProcessedTradedMarket | None,
|
94
96
|
keys: APIKeys,
|
95
97
|
agent_name: str,
|
98
|
+
web3: Web3 | None = None,
|
96
99
|
) -> None:
|
97
|
-
|
98
|
-
market_id=self.id,
|
99
|
-
traded_market=traded_market,
|
100
|
-
keys=keys,
|
101
|
-
agent_name=agent_name,
|
102
|
-
)
|
100
|
+
pass
|
103
101
|
|
104
102
|
def get_token_in_usd(self, x: CollateralToken) -> USD:
|
105
103
|
return get_token_in_usd(x, self.collateral_token_contract_address_checksummed)
|
@@ -109,20 +107,22 @@ class SeerAgentMarket(AgentMarket):
|
|
109
107
|
|
110
108
|
def get_buy_token_amount(
|
111
109
|
self, bet_amount: USD | CollateralToken, direction: bool
|
112
|
-
) -> OutcomeToken:
|
110
|
+
) -> OutcomeToken | None:
|
113
111
|
"""Returns number of outcome tokens returned for a given bet expressed in collateral units."""
|
114
112
|
|
115
113
|
outcome_token = self.get_wrapped_token_for_outcome(direction)
|
116
114
|
bet_amount_in_tokens = self.get_in_token(bet_amount)
|
117
|
-
bet_amount_in_wei = bet_amount_in_tokens.as_wei
|
118
115
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
collateral_token=self.collateral_token_contract_address_checksummed,
|
116
|
+
p = PriceManager.build(market_id=HexBytes(HexStr(self.id)))
|
117
|
+
price_in_collateral_units = p.get_price_for_token(
|
118
|
+
token=outcome_token, collateral_exchange_amount=bet_amount_in_tokens.as_wei
|
123
119
|
)
|
124
|
-
|
125
|
-
|
120
|
+
if not price_in_collateral_units:
|
121
|
+
logger.info(f"Could not get price for token {outcome_token}")
|
122
|
+
return None
|
123
|
+
|
124
|
+
amount_outcome_tokens = bet_amount_in_tokens.value / price_in_collateral_units
|
125
|
+
return OutcomeToken(amount_outcome_tokens)
|
126
126
|
|
127
127
|
def get_outcome_str_from_bool(self, outcome: bool) -> OutcomeStr:
|
128
128
|
outcome_translated = SeerOutcomeEnum.from_bool(outcome)
|
@@ -185,7 +185,17 @@ class SeerAgentMarket(AgentMarket):
|
|
185
185
|
return OmenAgentMarket.verify_operational_balance(api_keys=api_keys)
|
186
186
|
|
187
187
|
@staticmethod
|
188
|
-
def
|
188
|
+
def from_data_model_with_subgraph(
|
189
|
+
model: SeerMarket, seer_subgraph: SeerSubgraphHandler
|
190
|
+
) -> t.Optional["SeerAgentMarket"]:
|
191
|
+
p = PriceManager(seer_market=model, seer_subgraph=seer_subgraph)
|
192
|
+
current_p_yes = p.current_p_yes()
|
193
|
+
if not current_p_yes:
|
194
|
+
logger.info(
|
195
|
+
f"p_yes for market {model.id.hex()} could not be calculated. Skipping."
|
196
|
+
)
|
197
|
+
return None
|
198
|
+
|
189
199
|
return SeerAgentMarket(
|
190
200
|
id=model.id.hex(),
|
191
201
|
question=model.title,
|
@@ -201,7 +211,7 @@ class SeerAgentMarket(AgentMarket):
|
|
201
211
|
outcome_token_pool=None,
|
202
212
|
resolution=model.get_resolution_enum(),
|
203
213
|
volume=None,
|
204
|
-
current_p_yes=
|
214
|
+
current_p_yes=current_p_yes,
|
205
215
|
seer_outcomes=model.outcome_as_enums,
|
206
216
|
)
|
207
217
|
|
@@ -213,31 +223,31 @@ class SeerAgentMarket(AgentMarket):
|
|
213
223
|
created_after: t.Optional[DatetimeUTC] = None,
|
214
224
|
excluded_questions: set[str] | None = None,
|
215
225
|
) -> t.Sequence["SeerAgentMarket"]:
|
226
|
+
seer_subgraph = SeerSubgraphHandler()
|
227
|
+
markets = seer_subgraph.get_binary_markets(
|
228
|
+
limit=limit, sort_by=sort_by, filter_by=filter_by
|
229
|
+
)
|
230
|
+
|
231
|
+
# We exclude the None values below because `from_data_model_with_subgraph` can return None, which
|
232
|
+
# represents an invalid market.
|
216
233
|
return [
|
217
|
-
|
218
|
-
for m in
|
219
|
-
|
220
|
-
|
221
|
-
|
234
|
+
market
|
235
|
+
for m in markets
|
236
|
+
if (
|
237
|
+
market := SeerAgentMarket.from_data_model_with_subgraph(
|
238
|
+
model=m, seer_subgraph=seer_subgraph
|
239
|
+
)
|
222
240
|
)
|
241
|
+
is not None
|
223
242
|
]
|
224
243
|
|
225
244
|
def has_liquidity_for_outcome(self, outcome: bool) -> bool:
|
226
245
|
outcome_token = self.get_wrapped_token_for_outcome(outcome)
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
1
|
233
|
-
).as_wei, # we take 1 as a baseline value for common trades the agents take.
|
234
|
-
)
|
235
|
-
return True
|
236
|
-
except NoLiquidityAvailableOnCowException:
|
237
|
-
logger.info(
|
238
|
-
f"Could not get a quote for {outcome_token=} {outcome=}, returning no liquidity"
|
239
|
-
)
|
240
|
-
return False
|
246
|
+
pool = SeerSubgraphHandler().get_pool_by_token(
|
247
|
+
token_address=outcome_token,
|
248
|
+
collateral_address=self.collateral_token_contract_address_checksummed,
|
249
|
+
)
|
250
|
+
return pool is not None and pool.liquidity > 0
|
241
251
|
|
242
252
|
def has_liquidity(self) -> bool:
|
243
253
|
# We conservatively define a market as having liquidity if it has liquidity for the `True` outcome token AND the `False` outcome token.
|
@@ -281,14 +291,62 @@ class SeerAgentMarket(AgentMarket):
|
|
281
291
|
)
|
282
292
|
|
283
293
|
outcome_token = self.get_wrapped_token_for_outcome(outcome)
|
284
|
-
|
285
|
-
|
286
|
-
|
294
|
+
|
295
|
+
# Sell sDAI using token address
|
296
|
+
order_metadata = swap_tokens_waiting(
|
297
|
+
amount_wei=amount_wei,
|
287
298
|
sell_token=collateral_contract.address,
|
288
299
|
buy_token=outcome_token,
|
289
300
|
api_keys=api_keys,
|
290
301
|
web3=web3,
|
291
302
|
)
|
303
|
+
logger.debug(
|
304
|
+
f"Purchased {outcome_token} in exchange for {collateral_contract.address}. Order details {order_metadata}"
|
305
|
+
)
|
306
|
+
|
307
|
+
return order_metadata.uid.root
|
308
|
+
|
309
|
+
@tenacity.retry(
|
310
|
+
stop=tenacity.stop_after_attempt(3),
|
311
|
+
wait=tenacity.wait_fixed(1),
|
312
|
+
after=lambda x: logger.debug(
|
313
|
+
f"seer_sell_outcome_tx failed, {x.attempt_number=}."
|
314
|
+
),
|
315
|
+
)
|
316
|
+
def sell_tokens(
|
317
|
+
self,
|
318
|
+
outcome: bool,
|
319
|
+
amount: USD | OutcomeToken,
|
320
|
+
auto_withdraw: bool = True,
|
321
|
+
api_keys: APIKeys | None = None,
|
322
|
+
web3: Web3 | None = None,
|
323
|
+
) -> str:
|
324
|
+
"""
|
325
|
+
Sells the given number of shares for the given outcome in the given market.
|
326
|
+
"""
|
327
|
+
outcome_token = self.get_wrapped_token_for_outcome(outcome)
|
328
|
+
api_keys = api_keys if api_keys is not None else APIKeys()
|
329
|
+
|
330
|
+
########
|
331
|
+
token_amount = (
|
332
|
+
amount.as_outcome_wei.as_wei
|
333
|
+
if isinstance(amount, OutcomeToken)
|
334
|
+
else self.get_in_token(amount).as_wei
|
335
|
+
)
|
336
|
+
|
337
|
+
order_metadata = swap_tokens_waiting(
|
338
|
+
amount_wei=token_amount,
|
339
|
+
sell_token=outcome_token,
|
340
|
+
buy_token=Web3.to_checksum_address(
|
341
|
+
self.collateral_token_contract_address_checksummed
|
342
|
+
),
|
343
|
+
api_keys=api_keys,
|
344
|
+
web3=web3,
|
345
|
+
)
|
346
|
+
|
347
|
+
logger.debug(
|
348
|
+
f"Sold {outcome_token} in exchange for {self.collateral_token_contract_address_checksummed}. Order details {order_metadata}"
|
349
|
+
)
|
292
350
|
|
293
351
|
return order_metadata.uid.root
|
294
352
|
|
@@ -2,7 +2,6 @@ import os
|
|
2
2
|
import typing as t
|
3
3
|
|
4
4
|
from web3 import Web3
|
5
|
-
from web3.types import TxReceipt
|
6
5
|
|
7
6
|
from prediction_market_agent_tooling.config import APIKeys
|
8
7
|
from prediction_market_agent_tooling.gtypes import (
|
@@ -10,8 +9,9 @@ from prediction_market_agent_tooling.gtypes import (
|
|
10
9
|
ChecksumAddress,
|
11
10
|
OutcomeStr,
|
12
11
|
xDai,
|
12
|
+
TxReceipt,
|
13
13
|
)
|
14
|
-
from prediction_market_agent_tooling.markets.seer.
|
14
|
+
from prediction_market_agent_tooling.markets.seer.subgraph_data_models import (
|
15
15
|
CreateCategoricalMarketsParams,
|
16
16
|
)
|
17
17
|
from prediction_market_agent_tooling.tools.contract import (
|
@@ -47,9 +47,9 @@ class SeerMarketFactory(ContractOnGnosisChain):
|
|
47
47
|
token_names=[
|
48
48
|
o.upper() for o in outcomes
|
49
49
|
], # Following usual token names on Seer (YES,NO).
|
50
|
-
min_bond=min_bond.as_xdai_wei.
|
50
|
+
min_bond=min_bond.as_xdai_wei.as_wei,
|
51
51
|
opening_time=int(opening_time.timestamp()),
|
52
|
-
outcomes=outcomes,
|
52
|
+
outcomes=list(outcomes),
|
53
53
|
lang=language,
|
54
54
|
category=category,
|
55
55
|
)
|