prediction-market-agent-tooling 0.61.1.dev462__py3-none-any.whl → 0.61.1.dev477__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.
- prediction_market_agent_tooling/deploy/agent.py +5 -4
- prediction_market_agent_tooling/deploy/betting_strategy.py +69 -53
- prediction_market_agent_tooling/gtypes.py +27 -105
- prediction_market_agent_tooling/jobs/jobs_models.py +7 -5
- prediction_market_agent_tooling/jobs/omen/omen_jobs.py +17 -13
- prediction_market_agent_tooling/markets/agent_market.py +52 -96
- prediction_market_agent_tooling/markets/blockchain_utils.py +27 -1
- prediction_market_agent_tooling/markets/data_models.py +44 -40
- prediction_market_agent_tooling/markets/manifold/api.py +6 -2
- prediction_market_agent_tooling/markets/manifold/data_models.py +25 -33
- prediction_market_agent_tooling/markets/manifold/manifold.py +11 -8
- prediction_market_agent_tooling/markets/market_fees.py +2 -4
- prediction_market_agent_tooling/markets/omen/data_models.py +57 -66
- prediction_market_agent_tooling/markets/omen/omen.py +249 -214
- prediction_market_agent_tooling/markets/omen/omen_contracts.py +29 -31
- prediction_market_agent_tooling/markets/omen/omen_resolving.py +14 -7
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +14 -20
- prediction_market_agent_tooling/markets/polymarket/data_models.py +3 -3
- prediction_market_agent_tooling/markets/polymarket/data_models_web.py +4 -4
- prediction_market_agent_tooling/markets/polymarket/polymarket.py +5 -3
- prediction_market_agent_tooling/markets/seer/data_models.py +11 -8
- prediction_market_agent_tooling/markets/seer/seer.py +71 -85
- prediction_market_agent_tooling/markets/seer/seer_contracts.py +5 -10
- prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py +7 -7
- prediction_market_agent_tooling/monitor/monitor.py +2 -2
- prediction_market_agent_tooling/tools/balances.py +11 -9
- prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +10 -12
- prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +24 -27
- prediction_market_agent_tooling/tools/betting_strategies/utils.py +1 -3
- prediction_market_agent_tooling/tools/contract.py +10 -14
- prediction_market_agent_tooling/tools/cow/cow_manager.py +4 -3
- prediction_market_agent_tooling/tools/cow/cow_order.py +4 -3
- prediction_market_agent_tooling/tools/langfuse_client_utils.py +1 -13
- prediction_market_agent_tooling/tools/omen/sell_positions.py +3 -6
- prediction_market_agent_tooling/tools/safe.py +6 -5
- prediction_market_agent_tooling/tools/tokens/auto_deposit.py +30 -32
- prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +22 -5
- prediction_market_agent_tooling/tools/tokens/main_token.py +2 -2
- prediction_market_agent_tooling/tools/utils.py +8 -14
- prediction_market_agent_tooling/tools/web3_utils.py +41 -24
- {prediction_market_agent_tooling-0.61.1.dev462.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/METADATA +1 -2
- {prediction_market_agent_tooling-0.61.1.dev462.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/RECORD +45 -48
- prediction_market_agent_tooling/tools/_generic_value.py +0 -248
- prediction_market_agent_tooling/tools/tokens/token_utils.py +0 -46
- prediction_market_agent_tooling/tools/tokens/usd.py +0 -63
- {prediction_market_agent_tooling-0.61.1.dev462.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.61.1.dev462.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.61.1.dev462.dist-info → prediction_market_agent_tooling-0.61.1.dev477.dist-info}/entry_points.txt +0 -0
@@ -15,12 +15,12 @@ from prediction_market_agent_tooling.gtypes import (
|
|
15
15
|
HexBytes,
|
16
16
|
HexStr,
|
17
17
|
IPFSCIDVersion0,
|
18
|
-
|
18
|
+
OmenOutcomeToken,
|
19
19
|
TxParams,
|
20
20
|
TxReceipt,
|
21
21
|
Wei,
|
22
22
|
int_to_hexbytes,
|
23
|
-
|
23
|
+
wei_type,
|
24
24
|
)
|
25
25
|
from prediction_market_agent_tooling.markets.omen.data_models import (
|
26
26
|
INVALID_ANSWER_HEX_BYTES,
|
@@ -128,8 +128,8 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
|
|
128
128
|
|
129
129
|
def balanceOf(
|
130
130
|
self, from_address: ChecksumAddress, position_id: int, web3: Web3 | None = None
|
131
|
-
) ->
|
132
|
-
balance =
|
131
|
+
) -> Wei:
|
132
|
+
balance = wei_type(
|
133
133
|
self.call("balanceOf", [from_address, position_id], web3=web3)
|
134
134
|
)
|
135
135
|
return balance
|
@@ -169,7 +169,7 @@ class OmenConditionalTokenContract(ContractOnGnosisChain):
|
|
169
169
|
collateral_token_address: ChecksumAddress,
|
170
170
|
conditionId: HexBytes,
|
171
171
|
index_sets: t.List[int],
|
172
|
-
amount:
|
172
|
+
amount: Wei,
|
173
173
|
parent_collection_id: HexStr = build_parent_collection_id(),
|
174
174
|
web3: Web3 | None = None,
|
175
175
|
) -> TxReceipt:
|
@@ -296,28 +296,28 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
296
296
|
# Factory contract at https://gnosisscan.io/address/0x9083a2b699c0a4ad06f63580bde2635d26a3eef0.
|
297
297
|
|
298
298
|
def balanceOf(self, for_address: ChecksumAddress, web3: Web3 | None = None) -> Wei:
|
299
|
-
balance =
|
299
|
+
balance: Wei = self.call("balanceOf", [for_address], web3=web3)
|
300
300
|
return balance
|
301
301
|
|
302
302
|
def calcBuyAmount(
|
303
303
|
self, investment_amount: Wei, outcome_index: int, web3: Web3 | None = None
|
304
|
-
) ->
|
304
|
+
) -> OmenOutcomeToken:
|
305
305
|
"""
|
306
306
|
Returns amount of shares we will get for the given outcome_index for the given investment amount.
|
307
307
|
"""
|
308
|
-
calculated_shares =
|
309
|
-
|
308
|
+
calculated_shares: OmenOutcomeToken = self.call(
|
309
|
+
"calcBuyAmount", [investment_amount, outcome_index], web3=web3
|
310
310
|
)
|
311
311
|
return calculated_shares
|
312
312
|
|
313
313
|
def calcSellAmount(
|
314
314
|
self, return_amount: Wei, outcome_index: int, web3: Web3 | None = None
|
315
|
-
) ->
|
315
|
+
) -> OmenOutcomeToken:
|
316
316
|
"""
|
317
317
|
Returns amount of shares we will sell for the requested wei.
|
318
318
|
"""
|
319
|
-
calculated_shares =
|
320
|
-
|
319
|
+
calculated_shares: OmenOutcomeToken = self.call(
|
320
|
+
"calcSellAmount", [return_amount, outcome_index], web3=web3
|
321
321
|
)
|
322
322
|
return calculated_shares
|
323
323
|
|
@@ -334,7 +334,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
334
334
|
api_keys: APIKeys,
|
335
335
|
amount_wei: Wei,
|
336
336
|
outcome_index: int,
|
337
|
-
min_outcome_tokens_to_buy:
|
337
|
+
min_outcome_tokens_to_buy: OmenOutcomeToken,
|
338
338
|
tx_params: t.Optional[TxParams] = None,
|
339
339
|
web3: Web3 | None = None,
|
340
340
|
) -> TxReceipt:
|
@@ -355,7 +355,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
355
355
|
api_keys: APIKeys,
|
356
356
|
amount_wei: Wei,
|
357
357
|
outcome_index: int,
|
358
|
-
max_outcome_tokens_to_sell:
|
358
|
+
max_outcome_tokens_to_sell: OmenOutcomeToken,
|
359
359
|
tx_params: t.Optional[TxParams] = None,
|
360
360
|
web3: Web3 | None = None,
|
361
361
|
) -> TxReceipt:
|
@@ -411,7 +411,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
411
411
|
|
412
412
|
def totalSupply(self, web3: Web3 | None = None) -> Wei:
|
413
413
|
# This is the liquidity you seen on the Omen website (but in Wei).
|
414
|
-
total_supply =
|
414
|
+
total_supply: Wei = self.call("totalSupply", web3=web3)
|
415
415
|
return total_supply
|
416
416
|
|
417
417
|
def get_collateral_token_contract(
|
@@ -466,7 +466,7 @@ class OmenFixedProductMarketMakerFactoryContract(ContractOnGnosisChain):
|
|
466
466
|
initial_funds_wei: Wei,
|
467
467
|
collateral_token_address: ChecksumAddress,
|
468
468
|
fee: Wei, # This is actually fee in %, 'where 100% == 1 xDai'.
|
469
|
-
distribution_hint: list[
|
469
|
+
distribution_hint: list[OmenOutcomeToken] | None = None,
|
470
470
|
tx_params: t.Optional[TxParams] = None,
|
471
471
|
web3: Web3 | None = None,
|
472
472
|
) -> tuple[
|
@@ -585,7 +585,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
585
585
|
api_keys: APIKeys,
|
586
586
|
question: str,
|
587
587
|
category: str,
|
588
|
-
outcomes:
|
588
|
+
outcomes: list[str],
|
589
589
|
language: str,
|
590
590
|
arbitrator: Arbitrator,
|
591
591
|
opening: DatetimeUTC,
|
@@ -640,14 +640,14 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
640
640
|
api_keys: APIKeys,
|
641
641
|
question_id: HexBytes,
|
642
642
|
answer: HexBytes,
|
643
|
-
bond:
|
644
|
-
max_previous:
|
643
|
+
bond: Wei,
|
644
|
+
max_previous: Wei | None = None,
|
645
645
|
web3: Web3 | None = None,
|
646
646
|
) -> TxReceipt:
|
647
647
|
if max_previous is None:
|
648
648
|
# If not provided, defaults to 0, which means no checking,
|
649
649
|
# same as on Omen website: https://github.com/protofire/omen-exchange/blob/763d9c9d05ebf9edacbc1dbaa561aa5d08813c0f/app/src/services/realitio.ts#L363.
|
650
|
-
max_previous =
|
650
|
+
max_previous = Wei(0)
|
651
651
|
|
652
652
|
return self.send_with_value(
|
653
653
|
api_keys=api_keys,
|
@@ -657,7 +657,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
657
657
|
answer=answer,
|
658
658
|
max_previous=max_previous,
|
659
659
|
),
|
660
|
-
amount_wei=bond
|
660
|
+
amount_wei=bond,
|
661
661
|
web3=web3,
|
662
662
|
)
|
663
663
|
|
@@ -666,9 +666,9 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
666
666
|
api_keys: APIKeys,
|
667
667
|
question_id: HexBytes,
|
668
668
|
answer: str,
|
669
|
-
outcomes:
|
670
|
-
bond:
|
671
|
-
max_previous:
|
669
|
+
outcomes: list[str],
|
670
|
+
bond: Wei,
|
671
|
+
max_previous: Wei | None = None,
|
672
672
|
web3: Web3 | None = None,
|
673
673
|
) -> TxReceipt:
|
674
674
|
# Normalise the answer to lowercase, to match Enum values as [YES, NO] against outcomes as ["Yes", "No"].
|
@@ -690,8 +690,8 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
690
690
|
self,
|
691
691
|
api_keys: APIKeys,
|
692
692
|
question_id: HexBytes,
|
693
|
-
bond:
|
694
|
-
max_previous:
|
693
|
+
bond: Wei,
|
694
|
+
max_previous: Wei | None = None,
|
695
695
|
web3: Web3 | None = None,
|
696
696
|
) -> TxReceipt:
|
697
697
|
return self.submitAnswer(
|
@@ -709,7 +709,7 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
709
709
|
question_id: HexBytes,
|
710
710
|
history_hashes: list[HexBytes],
|
711
711
|
addresses: list[ChecksumAddress],
|
712
|
-
bonds: list[
|
712
|
+
bonds: list[Wei],
|
713
713
|
answers: list[HexBytes],
|
714
714
|
tx_params: t.Optional[TxParams] = None,
|
715
715
|
web3: Web3 | None = None,
|
@@ -732,8 +732,8 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
732
732
|
self,
|
733
733
|
from_address: ChecksumAddress,
|
734
734
|
web3: Web3 | None = None,
|
735
|
-
) ->
|
736
|
-
balance =
|
735
|
+
) -> Wei:
|
736
|
+
balance = wei_type(self.call("balanceOf", [from_address], web3=web3))
|
737
737
|
return balance
|
738
738
|
|
739
739
|
def withdraw(
|
@@ -896,11 +896,9 @@ class OmenThumbnailMapping(ContractOnGnosisChain):
|
|
896
896
|
class CollateralTokenChoice(str, Enum):
|
897
897
|
wxdai = "wxdai"
|
898
898
|
sdai = "sdai"
|
899
|
-
gno = "gno"
|
900
899
|
|
901
900
|
|
902
901
|
COLLATERAL_TOKEN_CHOICE_TO_ADDRESS = {
|
903
902
|
CollateralTokenChoice.wxdai: WrappedxDaiContract().address,
|
904
903
|
CollateralTokenChoice.sdai: sDaiContract().address,
|
905
|
-
CollateralTokenChoice.gno: GNOContract().address,
|
906
904
|
}
|
@@ -5,8 +5,8 @@ from prediction_market_agent_tooling.gtypes import (
|
|
5
5
|
ChecksumAddress,
|
6
6
|
HexAddress,
|
7
7
|
HexBytes,
|
8
|
+
Wei,
|
8
9
|
xDai,
|
9
|
-
xDaiWei,
|
10
10
|
)
|
11
11
|
from prediction_market_agent_tooling.loggers import logger
|
12
12
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
@@ -32,7 +32,12 @@ from prediction_market_agent_tooling.tools.tokens.main_token import (
|
|
32
32
|
MINIMUM_NATIVE_TOKEN_IN_EOA_FOR_FEES,
|
33
33
|
)
|
34
34
|
from prediction_market_agent_tooling.tools.utils import utcnow
|
35
|
-
from prediction_market_agent_tooling.tools.web3_utils import
|
35
|
+
from prediction_market_agent_tooling.tools.web3_utils import (
|
36
|
+
ZERO_BYTES,
|
37
|
+
wei_to_xdai,
|
38
|
+
xdai_to_wei,
|
39
|
+
xdai_type,
|
40
|
+
)
|
36
41
|
|
37
42
|
|
38
43
|
def claim_bonds_on_realitio_questions(
|
@@ -88,7 +93,7 @@ def claim_bonds_on_realitio_question(
|
|
88
93
|
|
89
94
|
history_hashes: list[HexBytes] = []
|
90
95
|
addresses: list[ChecksumAddress] = []
|
91
|
-
bonds: list[
|
96
|
+
bonds: list[Wei] = []
|
92
97
|
answers: list[HexBytes] = []
|
93
98
|
|
94
99
|
# Caller must provide the answer history, in reverse order.
|
@@ -123,7 +128,7 @@ def claim_bonds_on_realitio_question(
|
|
123
128
|
# Keeping balance on Realitio is not useful, so it's recommended to just withdraw it.
|
124
129
|
if current_balance > 0 and auto_withdraw:
|
125
130
|
logger.info(
|
126
|
-
f"Withdrawing remaining balance {current_balance
|
131
|
+
f"Withdrawing remaining balance {wei_to_xdai(current_balance)} xDai from Realitio."
|
127
132
|
)
|
128
133
|
realitio_contract.withdraw(api_keys, web3=web3)
|
129
134
|
|
@@ -145,7 +150,9 @@ def finalize_markets(
|
|
145
150
|
# If we don't have enough of xDai for bond, try to get it from the keeping token.
|
146
151
|
send_keeping_token_to_eoa_xdai(
|
147
152
|
api_keys=api_keys,
|
148
|
-
min_required_balance=
|
153
|
+
min_required_balance=xdai_type(
|
154
|
+
realitio_bond + MINIMUM_NATIVE_TOKEN_IN_EOA_FOR_FEES
|
155
|
+
),
|
149
156
|
web3=web3,
|
150
157
|
)
|
151
158
|
|
@@ -228,7 +235,7 @@ def omen_submit_answer_market_tx(
|
|
228
235
|
question_id=market.question.id,
|
229
236
|
answer=resolution.value,
|
230
237
|
outcomes=market.question.outcomes,
|
231
|
-
bond=bond
|
238
|
+
bond=xdai_to_wei(bond),
|
232
239
|
web3=web3,
|
233
240
|
)
|
234
241
|
|
@@ -247,7 +254,7 @@ def omen_submit_invalid_answer_market_tx(
|
|
247
254
|
realitio_contract.submit_answer_invalid(
|
248
255
|
api_keys=api_keys,
|
249
256
|
question_id=market.question.id,
|
250
|
-
bond=bond
|
257
|
+
bond=xdai_to_wei(bond),
|
251
258
|
web3=web3,
|
252
259
|
)
|
253
260
|
|
@@ -11,6 +11,7 @@ from prediction_market_agent_tooling.gtypes import (
|
|
11
11
|
HexAddress,
|
12
12
|
HexBytes,
|
13
13
|
Wei,
|
14
|
+
wei_type,
|
14
15
|
)
|
15
16
|
from prediction_market_agent_tooling.markets.agent_market import FilterBy, SortBy
|
16
17
|
from prediction_market_agent_tooling.markets.base_subgraph_handler import (
|
@@ -23,8 +24,6 @@ from prediction_market_agent_tooling.markets.omen.data_models import (
|
|
23
24
|
OmenMarket,
|
24
25
|
OmenPosition,
|
25
26
|
OmenUserPosition,
|
26
|
-
OutcomeStr,
|
27
|
-
OutcomeWei,
|
28
27
|
RealityAnswer,
|
29
28
|
RealityQuestion,
|
30
29
|
RealityResponse,
|
@@ -45,7 +44,6 @@ from prediction_market_agent_tooling.tools.utils import (
|
|
45
44
|
from prediction_market_agent_tooling.tools.web3_utils import (
|
46
45
|
ZERO_BYTES,
|
47
46
|
byte32_to_ipfscidv0,
|
48
|
-
unwrap_generic_value,
|
49
47
|
)
|
50
48
|
|
51
49
|
SAFE_COLLATERAL_TOKENS = (
|
@@ -211,7 +209,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
211
209
|
self,
|
212
210
|
creator: HexAddress | None,
|
213
211
|
creator_in: t.Sequence[HexAddress] | None,
|
214
|
-
outcomes:
|
212
|
+
outcomes: list[str],
|
215
213
|
created_after: DatetimeUTC | None,
|
216
214
|
question_opened_before: DatetimeUTC | None,
|
217
215
|
question_opened_after: DatetimeUTC | None,
|
@@ -349,7 +347,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
349
347
|
# because even closed markets don't need to be resolved yet (e.g. if someone forgot to finalize the question on reality).
|
350
348
|
opened_after = utcnow()
|
351
349
|
# Even if the market isn't closed yet, liquidity can be withdrawn to 0, which essentially closes the market.
|
352
|
-
liquidity_bigger_than =
|
350
|
+
liquidity_bigger_than = wei_type(0)
|
353
351
|
elif filter_by == FilterBy.NONE:
|
354
352
|
pass
|
355
353
|
else:
|
@@ -393,7 +391,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
393
391
|
id_in: list[str] | None = None,
|
394
392
|
sort_by_field: FieldPath | None = None,
|
395
393
|
sort_direction: str | None = None,
|
396
|
-
outcomes:
|
394
|
+
outcomes: list[str] = OMEN_BINARY_MARKET_OUTCOMES,
|
397
395
|
collateral_token_address_in: (
|
398
396
|
tuple[ChecksumAddress, ...] | None
|
399
397
|
) = SAFE_COLLATERAL_TOKENS_ADDRESSES,
|
@@ -436,7 +434,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
436
434
|
first=(
|
437
435
|
limit if limit else sys.maxsize
|
438
436
|
), # if not limit, we fetch all possible markets
|
439
|
-
where=
|
437
|
+
where=where_stms,
|
440
438
|
**optional_params,
|
441
439
|
)
|
442
440
|
|
@@ -491,7 +489,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
491
489
|
where_stms["conditionIds_contains"] = [condition_id.hex()]
|
492
490
|
|
493
491
|
positions = self.conditional_tokens_subgraph.Query.positions(
|
494
|
-
first=sys.maxsize, where=
|
492
|
+
first=sys.maxsize, where=where_stms
|
495
493
|
)
|
496
494
|
fields = self._get_fields_for_positions(positions)
|
497
495
|
result = self.sg.query_json(fields)
|
@@ -502,7 +500,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
502
500
|
self,
|
503
501
|
better_address: ChecksumAddress,
|
504
502
|
position_id_in: list[HexBytes] | None = None,
|
505
|
-
total_balance_bigger_than:
|
503
|
+
total_balance_bigger_than: Wei | None = None,
|
506
504
|
) -> list[OmenUserPosition]:
|
507
505
|
where_stms: dict[str, t.Any] = {
|
508
506
|
"user": better_address.lower(),
|
@@ -516,7 +514,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
516
514
|
where_stms["position_"]["positionId_in"] = [x.hex() for x in position_id_in]
|
517
515
|
|
518
516
|
positions = self.conditional_tokens_subgraph.Query.userPositions(
|
519
|
-
first=sys.maxsize, where=
|
517
|
+
first=sys.maxsize, where=where_stms
|
520
518
|
)
|
521
519
|
fields = self._get_fields_for_user_positions(positions)
|
522
520
|
result = self.sg.query_json(fields)
|
@@ -570,9 +568,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
570
568
|
< to_int_timestamp(market_resolved_before)
|
571
569
|
)
|
572
570
|
if collateral_amount_more_than is not None:
|
573
|
-
where_stms.append(
|
574
|
-
trade.collateralAmount > collateral_amount_more_than.value
|
575
|
-
)
|
571
|
+
where_stms.append(trade.collateralAmount > collateral_amount_more_than)
|
576
572
|
|
577
573
|
# These values can not be set to `None`, but they can be omitted.
|
578
574
|
optional_params = {}
|
@@ -583,7 +579,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
583
579
|
|
584
580
|
trades = self.trades_subgraph.Query.fpmmTrades(
|
585
581
|
first=limit if limit else sys.maxsize,
|
586
|
-
where=
|
582
|
+
where=where_stms,
|
587
583
|
**optional_params,
|
588
584
|
)
|
589
585
|
fields = self._get_fields_for_bets(trades)
|
@@ -822,7 +818,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
822
818
|
first=(
|
823
819
|
limit if limit else sys.maxsize
|
824
820
|
), # if not limit, we fetch all possible
|
825
|
-
where=
|
821
|
+
where=where_stms,
|
826
822
|
)
|
827
823
|
fields = self._get_fields_for_reality_questions(questions)
|
828
824
|
result = self.sg.query_json(fields)
|
@@ -836,9 +832,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
836
832
|
answer.question.questionId == question_id.hex(),
|
837
833
|
]
|
838
834
|
|
839
|
-
answers = self.realityeth_subgraph.Query.answers(
|
840
|
-
where=unwrap_generic_value(where_stms)
|
841
|
-
)
|
835
|
+
answers = self.realityeth_subgraph.Query.answers(where=where_stms)
|
842
836
|
fields = self._get_fields_for_answers(answers)
|
843
837
|
result = self.sg.query_json(fields)
|
844
838
|
items = self._parse_items_from_json(result)
|
@@ -885,7 +879,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
885
879
|
first=(
|
886
880
|
limit if limit else sys.maxsize
|
887
881
|
), # if not limit, we fetch all possible
|
888
|
-
where=
|
882
|
+
where=where_stms,
|
889
883
|
)
|
890
884
|
fields = self._get_fields_for_responses(responses)
|
891
885
|
result = self.sg.query_json(fields)
|
@@ -944,7 +938,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
944
938
|
|
945
939
|
prediction_added = (
|
946
940
|
self.omen_agent_result_mapping_subgraph.Query.predictionAddeds(
|
947
|
-
where=
|
941
|
+
where=where_stms,
|
948
942
|
orderBy="blockNumber",
|
949
943
|
orderDirection="asc",
|
950
944
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from pydantic import BaseModel
|
2
2
|
|
3
|
-
from prediction_market_agent_tooling.gtypes import USDC,
|
3
|
+
from prediction_market_agent_tooling.gtypes import USDC, Probability, usdc_type
|
4
4
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
5
5
|
from prediction_market_agent_tooling.markets.polymarket.data_models_web import (
|
6
6
|
POLYMARKET_FALSE_OUTCOME,
|
@@ -22,7 +22,7 @@ class PolymarketRewards(BaseModel):
|
|
22
22
|
|
23
23
|
class PolymarketToken(BaseModel):
|
24
24
|
token_id: str
|
25
|
-
outcome:
|
25
|
+
outcome: str
|
26
26
|
winner: bool
|
27
27
|
|
28
28
|
|
@@ -111,7 +111,7 @@ class PolymarketPriceResponse(BaseModel):
|
|
111
111
|
|
112
112
|
@property
|
113
113
|
def price_dec(self) -> USDC:
|
114
|
-
return
|
114
|
+
return usdc_type(self.price)
|
115
115
|
|
116
116
|
|
117
117
|
class Prices(BaseModel):
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"""
|
2
|
-
Autogenerated using `datamodel-codegen` from a single Polymarket response. Then adjusted, fixed.
|
2
|
+
Autogenerated using `datamodel-codegen` from a single Polymarket response. Then adjusted, fixed.
|
3
3
|
Keep in mind that not all fields were used so far, so there might be some bugs.
|
4
4
|
|
5
5
|
These models are based on what Polymarket's website returns in the response, and `prediction_market_agent_tooling/markets/polymarket/data_models.py` are based on what their API returns.
|
@@ -11,7 +11,7 @@ import typing as t
|
|
11
11
|
import requests
|
12
12
|
from pydantic import BaseModel, field_validator
|
13
13
|
|
14
|
-
from prediction_market_agent_tooling.gtypes import USDC, HexAddress
|
14
|
+
from prediction_market_agent_tooling.gtypes import USDC, HexAddress
|
15
15
|
from prediction_market_agent_tooling.loggers import logger
|
16
16
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
17
17
|
from prediction_market_agent_tooling.tools.utils import DatetimeUTC
|
@@ -47,7 +47,7 @@ class Market1(BaseModel):
|
|
47
47
|
question: str
|
48
48
|
image: str
|
49
49
|
volume: USDC | None = None
|
50
|
-
outcomes:
|
50
|
+
outcomes: list[str]
|
51
51
|
outcomePrices: list[USDC]
|
52
52
|
active: bool
|
53
53
|
archived: bool
|
@@ -92,7 +92,7 @@ class Market(BaseModel):
|
|
92
92
|
fee: str | None = None
|
93
93
|
lowerBound: t.Any | None = None
|
94
94
|
upperBound: t.Any | None = None
|
95
|
-
outcomes:
|
95
|
+
outcomes: list[str]
|
96
96
|
image: str | None = None
|
97
97
|
icon: str | None = None
|
98
98
|
imageOptimized: t.Any | None = None
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import typing as t
|
2
2
|
|
3
|
-
from prediction_market_agent_tooling.gtypes import USD, Token
|
4
3
|
from prediction_market_agent_tooling.markets.agent_market import (
|
5
4
|
AgentMarket,
|
6
5
|
FilterBy,
|
7
6
|
MarketFees,
|
8
7
|
SortBy,
|
9
8
|
)
|
9
|
+
from prediction_market_agent_tooling.markets.data_models import BetAmount, Currency
|
10
10
|
from prediction_market_agent_tooling.markets.polymarket.api import (
|
11
11
|
get_polymarket_binary_markets,
|
12
12
|
)
|
@@ -24,6 +24,7 @@ class PolymarketAgentMarket(AgentMarket):
|
|
24
24
|
Polymarket's market class that can be used by agents to make predictions.
|
25
25
|
"""
|
26
26
|
|
27
|
+
currency: t.ClassVar[Currency] = Currency.USDC
|
27
28
|
base_url: t.ClassVar[str] = POLYMARKET_BASE_URL
|
28
29
|
|
29
30
|
# Based on https://docs.polymarket.com/#fees, there are currently no fees, except for transactions fees.
|
@@ -48,10 +49,11 @@ class PolymarketAgentMarket(AgentMarket):
|
|
48
49
|
outcome_token_pool=None,
|
49
50
|
)
|
50
51
|
|
51
|
-
|
52
|
+
@classmethod
|
53
|
+
def get_tiny_bet_amount(cls) -> BetAmount:
|
52
54
|
raise NotImplementedError("TODO: Implement to allow betting on Polymarket.")
|
53
55
|
|
54
|
-
def place_bet(self, outcome: bool, amount:
|
56
|
+
def place_bet(self, outcome: bool, amount: BetAmount) -> str:
|
55
57
|
raise NotImplementedError("TODO: Implement to allow betting on Polymarket.")
|
56
58
|
|
57
59
|
@staticmethod
|
@@ -12,22 +12,22 @@ from prediction_market_agent_tooling.gtypes import (
|
|
12
12
|
ChecksumAddress,
|
13
13
|
HexAddress,
|
14
14
|
HexBytes,
|
15
|
-
OutcomeStr,
|
16
15
|
Probability,
|
17
|
-
|
18
|
-
|
16
|
+
Wei,
|
17
|
+
xdai_type,
|
19
18
|
)
|
20
19
|
from prediction_market_agent_tooling.loggers import logger
|
21
20
|
from prediction_market_agent_tooling.markets.data_models import Resolution
|
22
21
|
from prediction_market_agent_tooling.tools.cow.cow_manager import CowManager
|
23
22
|
from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
|
23
|
+
from prediction_market_agent_tooling.tools.web3_utils import xdai_to_wei
|
24
24
|
|
25
25
|
|
26
26
|
class CreateCategoricalMarketsParams(BaseModel):
|
27
27
|
model_config = ConfigDict(populate_by_name=True)
|
28
28
|
|
29
29
|
market_name: str = Field(..., alias="marketName")
|
30
|
-
outcomes:
|
30
|
+
outcomes: list[str]
|
31
31
|
# Only relevant for scalar markets
|
32
32
|
question_start: str = Field(alias="questionStart", default="")
|
33
33
|
question_end: str = Field(alias="questionEnd", default="")
|
@@ -41,7 +41,7 @@ class CreateCategoricalMarketsParams(BaseModel):
|
|
41
41
|
lang: str
|
42
42
|
lower_bound: int = Field(alias="lowerBound", default=0)
|
43
43
|
upper_bound: int = Field(alias="upperBound", default=0)
|
44
|
-
min_bond:
|
44
|
+
min_bond: Wei = Field(..., alias="minBond")
|
45
45
|
opening_time: int = Field(..., alias="openingTime")
|
46
46
|
token_names: list[str] = Field(..., alias="tokenNames")
|
47
47
|
|
@@ -97,7 +97,7 @@ class SeerMarket(BaseModel):
|
|
97
97
|
id: HexBytes
|
98
98
|
creator: HexAddress
|
99
99
|
title: str = Field(alias="marketName")
|
100
|
-
outcomes:
|
100
|
+
outcomes: list[str]
|
101
101
|
wrapped_tokens: list[HexAddress] = Field(alias="wrappedTokens")
|
102
102
|
parent_outcome: int = Field(alias="parentOutcome")
|
103
103
|
parent_market: t.Optional[SeerParentMarket] = Field(
|
@@ -207,7 +207,7 @@ class SeerMarket(BaseModel):
|
|
207
207
|
return Probability(price_yes)
|
208
208
|
|
209
209
|
def _get_price_for_token(self, token: ChecksumAddress) -> float:
|
210
|
-
collateral_exchange_amount =
|
210
|
+
collateral_exchange_amount = xdai_to_wei(xdai_type(1))
|
211
211
|
try:
|
212
212
|
quote = CowManager().get_quote(
|
213
213
|
collateral_token=self.collateral_token_contract_address_checksummed,
|
@@ -218,7 +218,7 @@ class SeerMarket(BaseModel):
|
|
218
218
|
logger.warning(f"Could not get quote for {token=}, returning price 0. {e=}")
|
219
219
|
return 0
|
220
220
|
|
221
|
-
return collateral_exchange_amount
|
221
|
+
return collateral_exchange_amount / float(quote.quote.buyAmount.root)
|
222
222
|
|
223
223
|
@property
|
224
224
|
def url(self) -> str:
|
@@ -238,6 +238,9 @@ class SeerPool(BaseModel):
|
|
238
238
|
liquidity: int
|
239
239
|
token0: SeerToken
|
240
240
|
token1: SeerToken
|
241
|
+
token0Price: float
|
242
|
+
token1Price: float
|
243
|
+
sqrtPrice: int
|
241
244
|
|
242
245
|
|
243
246
|
class NewMarketEvent(BaseModel):
|