prediction-market-agent-tooling 0.65.5__py3-none-any.whl → 0.69.17.dev1149__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/abis/agentresultmapping.abi.json +192 -0
- prediction_market_agent_tooling/abis/erc1155.abi.json +352 -0
- prediction_market_agent_tooling/abis/processor.abi.json +16 -0
- prediction_market_agent_tooling/abis/swapr_quoter.abi.json +221 -0
- prediction_market_agent_tooling/abis/swapr_router.abi.json +634 -0
- prediction_market_agent_tooling/benchmark/benchmark.py +1 -1
- prediction_market_agent_tooling/benchmark/utils.py +13 -0
- prediction_market_agent_tooling/chains.py +1 -0
- prediction_market_agent_tooling/config.py +61 -2
- prediction_market_agent_tooling/data_download/langfuse_data_downloader.py +405 -0
- prediction_market_agent_tooling/deploy/agent.py +199 -67
- prediction_market_agent_tooling/deploy/agent_example.py +1 -1
- prediction_market_agent_tooling/deploy/betting_strategy.py +412 -68
- prediction_market_agent_tooling/deploy/constants.py +6 -0
- prediction_market_agent_tooling/gtypes.py +11 -1
- prediction_market_agent_tooling/jobs/jobs_models.py +2 -2
- prediction_market_agent_tooling/jobs/omen/omen_jobs.py +19 -20
- prediction_market_agent_tooling/loggers.py +9 -1
- prediction_market_agent_tooling/logprobs_parser.py +2 -1
- prediction_market_agent_tooling/markets/agent_market.py +106 -18
- prediction_market_agent_tooling/markets/blockchain_utils.py +37 -19
- prediction_market_agent_tooling/markets/data_models.py +120 -7
- prediction_market_agent_tooling/markets/manifold/data_models.py +5 -3
- prediction_market_agent_tooling/markets/manifold/manifold.py +21 -2
- prediction_market_agent_tooling/markets/manifold/utils.py +8 -2
- prediction_market_agent_tooling/markets/market_type.py +74 -0
- prediction_market_agent_tooling/markets/markets.py +7 -99
- prediction_market_agent_tooling/markets/metaculus/data_models.py +3 -3
- prediction_market_agent_tooling/markets/metaculus/metaculus.py +5 -8
- prediction_market_agent_tooling/markets/omen/cow_contracts.py +5 -1
- prediction_market_agent_tooling/markets/omen/data_models.py +63 -32
- prediction_market_agent_tooling/markets/omen/omen.py +112 -23
- prediction_market_agent_tooling/markets/omen/omen_constants.py +8 -0
- prediction_market_agent_tooling/markets/omen/omen_contracts.py +18 -203
- prediction_market_agent_tooling/markets/omen/omen_resolving.py +33 -13
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +23 -18
- prediction_market_agent_tooling/markets/polymarket/api.py +123 -100
- prediction_market_agent_tooling/markets/polymarket/clob_manager.py +156 -0
- prediction_market_agent_tooling/markets/polymarket/constants.py +15 -0
- prediction_market_agent_tooling/markets/polymarket/data_models.py +95 -19
- prediction_market_agent_tooling/markets/polymarket/polymarket.py +373 -29
- prediction_market_agent_tooling/markets/polymarket/polymarket_contracts.py +35 -0
- prediction_market_agent_tooling/markets/polymarket/polymarket_subgraph_handler.py +91 -0
- prediction_market_agent_tooling/markets/polymarket/utils.py +1 -22
- prediction_market_agent_tooling/markets/seer/data_models.py +111 -17
- prediction_market_agent_tooling/markets/seer/exceptions.py +2 -0
- prediction_market_agent_tooling/markets/seer/price_manager.py +165 -50
- prediction_market_agent_tooling/markets/seer/seer.py +393 -106
- prediction_market_agent_tooling/markets/seer/seer_api.py +28 -0
- prediction_market_agent_tooling/markets/seer/seer_contracts.py +115 -5
- prediction_market_agent_tooling/markets/seer/seer_subgraph_handler.py +297 -66
- prediction_market_agent_tooling/markets/seer/subgraph_data_models.py +43 -8
- prediction_market_agent_tooling/markets/seer/swap_pool_handler.py +80 -0
- prediction_market_agent_tooling/tools/_generic_value.py +8 -2
- prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +271 -8
- prediction_market_agent_tooling/tools/betting_strategies/utils.py +6 -1
- prediction_market_agent_tooling/tools/caches/db_cache.py +219 -117
- prediction_market_agent_tooling/tools/caches/serializers.py +11 -2
- prediction_market_agent_tooling/tools/contract.py +480 -38
- prediction_market_agent_tooling/tools/contract_utils.py +61 -0
- prediction_market_agent_tooling/tools/cow/cow_order.py +218 -45
- prediction_market_agent_tooling/tools/cow/models.py +122 -0
- prediction_market_agent_tooling/tools/cow/semaphore.py +104 -0
- prediction_market_agent_tooling/tools/datetime_utc.py +14 -2
- prediction_market_agent_tooling/tools/db/db_manager.py +59 -0
- prediction_market_agent_tooling/tools/hexbytes_custom.py +4 -1
- prediction_market_agent_tooling/tools/httpx_cached_client.py +15 -6
- prediction_market_agent_tooling/tools/langfuse_client_utils.py +21 -8
- prediction_market_agent_tooling/tools/openai_utils.py +31 -0
- prediction_market_agent_tooling/tools/perplexity/perplexity_client.py +86 -0
- prediction_market_agent_tooling/tools/perplexity/perplexity_models.py +26 -0
- prediction_market_agent_tooling/tools/perplexity/perplexity_search.py +73 -0
- prediction_market_agent_tooling/tools/rephrase.py +71 -0
- prediction_market_agent_tooling/tools/singleton.py +11 -6
- prediction_market_agent_tooling/tools/streamlit_utils.py +188 -0
- prediction_market_agent_tooling/tools/tokens/auto_deposit.py +64 -0
- prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +8 -0
- prediction_market_agent_tooling/tools/tokens/slippage.py +21 -0
- prediction_market_agent_tooling/tools/tokens/usd.py +5 -2
- prediction_market_agent_tooling/tools/utils.py +61 -3
- prediction_market_agent_tooling/tools/web3_utils.py +63 -9
- {prediction_market_agent_tooling-0.65.5.dist-info → prediction_market_agent_tooling-0.69.17.dev1149.dist-info}/METADATA +13 -9
- {prediction_market_agent_tooling-0.65.5.dist-info → prediction_market_agent_tooling-0.69.17.dev1149.dist-info}/RECORD +86 -64
- {prediction_market_agent_tooling-0.65.5.dist-info → prediction_market_agent_tooling-0.69.17.dev1149.dist-info}/WHEEL +1 -1
- prediction_market_agent_tooling/abis/omen_agentresultmapping.abi.json +0 -171
- prediction_market_agent_tooling/markets/polymarket/data_models_web.py +0 -420
- {prediction_market_agent_tooling-0.65.5.dist-info → prediction_market_agent_tooling-0.69.17.dev1149.dist-info}/entry_points.txt +0 -0
- {prediction_market_agent_tooling-0.65.5.dist-info → prediction_market_agent_tooling-0.69.17.dev1149.dist-info/licenses}/LICENSE +0 -0
|
@@ -5,7 +5,6 @@ from datetime import timedelta
|
|
|
5
5
|
from enum import Enum
|
|
6
6
|
|
|
7
7
|
from web3 import Web3
|
|
8
|
-
from web3.constants import HASH_ZERO
|
|
9
8
|
|
|
10
9
|
from prediction_market_agent_tooling.config import APIKeys
|
|
11
10
|
from prediction_market_agent_tooling.gtypes import (
|
|
@@ -13,7 +12,6 @@ from prediction_market_agent_tooling.gtypes import (
|
|
|
13
12
|
ChecksumAddress,
|
|
14
13
|
HexAddress,
|
|
15
14
|
HexBytes,
|
|
16
|
-
HexStr,
|
|
17
15
|
IPFSCIDVersion0,
|
|
18
16
|
OutcomeWei,
|
|
19
17
|
TxParams,
|
|
@@ -24,19 +22,19 @@ from prediction_market_agent_tooling.gtypes import (
|
|
|
24
22
|
)
|
|
25
23
|
from prediction_market_agent_tooling.markets.omen.data_models import (
|
|
26
24
|
INVALID_ANSWER_HEX_BYTES,
|
|
27
|
-
ConditionPreparationEvent,
|
|
28
25
|
ContractPrediction,
|
|
29
26
|
FPMMFundingAddedEvent,
|
|
30
27
|
OmenFixedProductMarketMakerCreationEvent,
|
|
31
|
-
PayoutRedemptionEvent,
|
|
32
28
|
RealitioLogNewQuestionEvent,
|
|
33
29
|
format_realitio_question,
|
|
34
30
|
)
|
|
35
31
|
from prediction_market_agent_tooling.markets.omen.omen_constants import (
|
|
32
|
+
METRI_SUPER_GROUP_CONTRACT_ADDRESS,
|
|
36
33
|
SDAI_CONTRACT_ADDRESS,
|
|
37
34
|
WRAPPED_XDAI_CONTRACT_ADDRESS,
|
|
38
35
|
)
|
|
39
36
|
from prediction_market_agent_tooling.tools.contract import (
|
|
37
|
+
ConditionalTokenContract,
|
|
40
38
|
ContractDepositableWrapperERC20OnGnosisChain,
|
|
41
39
|
ContractERC20OnGnosisChain,
|
|
42
40
|
ContractERC4626OnGnosisChain,
|
|
@@ -95,202 +93,11 @@ class OmenOracleContract(ContractOnGnosisChain):
|
|
|
95
93
|
)
|
|
96
94
|
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
return HASH_ZERO # Taken from Olas
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
class OmenConditionalTokenContract(ContractOnGnosisChain):
|
|
103
|
-
# Contract ABI taken from https://gnosisscan.io/address/0xCeAfDD6bc0bEF976fdCd1112955828E00543c0Ce#code.
|
|
104
|
-
abi: ABI = abi_field_validator(
|
|
105
|
-
os.path.join(
|
|
106
|
-
os.path.dirname(os.path.realpath(__file__)),
|
|
107
|
-
"../../abis/omen_fpmm_conditionaltokens.abi.json",
|
|
108
|
-
)
|
|
109
|
-
)
|
|
96
|
+
class OmenConditionalTokenContract(ConditionalTokenContract, ContractOnGnosisChain):
|
|
110
97
|
address: ChecksumAddress = Web3.to_checksum_address(
|
|
111
98
|
"0xCeAfDD6bc0bEF976fdCd1112955828E00543c0Ce"
|
|
112
99
|
)
|
|
113
100
|
|
|
114
|
-
def getConditionId(
|
|
115
|
-
self,
|
|
116
|
-
question_id: HexBytes,
|
|
117
|
-
oracle_address: ChecksumAddress,
|
|
118
|
-
outcomes_slot_count: int,
|
|
119
|
-
web3: Web3 | None = None,
|
|
120
|
-
) -> HexBytes:
|
|
121
|
-
id_ = HexBytes(
|
|
122
|
-
self.call(
|
|
123
|
-
"getConditionId",
|
|
124
|
-
[oracle_address, question_id, outcomes_slot_count],
|
|
125
|
-
web3=web3,
|
|
126
|
-
)
|
|
127
|
-
)
|
|
128
|
-
return id_
|
|
129
|
-
|
|
130
|
-
def balanceOf(
|
|
131
|
-
self, from_address: ChecksumAddress, position_id: int, web3: Web3 | None = None
|
|
132
|
-
) -> OutcomeWei:
|
|
133
|
-
balance = OutcomeWei(
|
|
134
|
-
self.call("balanceOf", [from_address, position_id], web3=web3)
|
|
135
|
-
)
|
|
136
|
-
return balance
|
|
137
|
-
|
|
138
|
-
def getCollectionId(
|
|
139
|
-
self,
|
|
140
|
-
parent_collection_id: HexStr,
|
|
141
|
-
condition_id: HexBytes,
|
|
142
|
-
index_set: int,
|
|
143
|
-
web3: Web3 | None = None,
|
|
144
|
-
) -> HexBytes:
|
|
145
|
-
collection_id = HexBytes(
|
|
146
|
-
self.call(
|
|
147
|
-
"getCollectionId",
|
|
148
|
-
[parent_collection_id, condition_id, index_set],
|
|
149
|
-
web3=web3,
|
|
150
|
-
)
|
|
151
|
-
)
|
|
152
|
-
return collection_id
|
|
153
|
-
|
|
154
|
-
def getPositionId(
|
|
155
|
-
self,
|
|
156
|
-
collateral_token_address: ChecksumAddress,
|
|
157
|
-
collection_id: HexBytes,
|
|
158
|
-
web3: Web3 | None = None,
|
|
159
|
-
) -> int:
|
|
160
|
-
position_id: int = self.call(
|
|
161
|
-
"getPositionId",
|
|
162
|
-
[collateral_token_address, collection_id],
|
|
163
|
-
web3=web3,
|
|
164
|
-
)
|
|
165
|
-
return position_id
|
|
166
|
-
|
|
167
|
-
def mergePositions(
|
|
168
|
-
self,
|
|
169
|
-
api_keys: APIKeys,
|
|
170
|
-
collateral_token_address: ChecksumAddress,
|
|
171
|
-
conditionId: HexBytes,
|
|
172
|
-
index_sets: t.List[int],
|
|
173
|
-
amount: OutcomeWei,
|
|
174
|
-
parent_collection_id: HexStr = build_parent_collection_id(),
|
|
175
|
-
web3: Web3 | None = None,
|
|
176
|
-
) -> TxReceipt:
|
|
177
|
-
return self.send(
|
|
178
|
-
api_keys=api_keys,
|
|
179
|
-
function_name="mergePositions",
|
|
180
|
-
function_params=[
|
|
181
|
-
collateral_token_address,
|
|
182
|
-
parent_collection_id,
|
|
183
|
-
conditionId,
|
|
184
|
-
index_sets,
|
|
185
|
-
amount,
|
|
186
|
-
],
|
|
187
|
-
web3=web3,
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
def redeemPositions(
|
|
191
|
-
self,
|
|
192
|
-
api_keys: APIKeys,
|
|
193
|
-
collateral_token_address: HexAddress,
|
|
194
|
-
condition_id: HexBytes,
|
|
195
|
-
index_sets: t.List[int],
|
|
196
|
-
parent_collection_id: HexStr = build_parent_collection_id(),
|
|
197
|
-
web3: Web3 | None = None,
|
|
198
|
-
) -> PayoutRedemptionEvent:
|
|
199
|
-
receipt_tx = self.send(
|
|
200
|
-
api_keys=api_keys,
|
|
201
|
-
function_name="redeemPositions",
|
|
202
|
-
function_params=[
|
|
203
|
-
collateral_token_address,
|
|
204
|
-
parent_collection_id,
|
|
205
|
-
condition_id,
|
|
206
|
-
index_sets,
|
|
207
|
-
],
|
|
208
|
-
web3=web3,
|
|
209
|
-
)
|
|
210
|
-
redeem_event_logs = (
|
|
211
|
-
self.get_web3_contract(web3=web3)
|
|
212
|
-
.events.PayoutRedemption()
|
|
213
|
-
.process_receipt(receipt_tx)
|
|
214
|
-
)
|
|
215
|
-
redeem_event = PayoutRedemptionEvent(**redeem_event_logs[0]["args"])
|
|
216
|
-
return redeem_event
|
|
217
|
-
|
|
218
|
-
def getOutcomeSlotCount(
|
|
219
|
-
self, condition_id: HexBytes, web3: Web3 | None = None
|
|
220
|
-
) -> int:
|
|
221
|
-
count: int = self.call("getOutcomeSlotCount", [condition_id], web3=web3)
|
|
222
|
-
return count
|
|
223
|
-
|
|
224
|
-
def does_condition_exists(
|
|
225
|
-
self, condition_id: HexBytes, web3: Web3 | None = None
|
|
226
|
-
) -> bool:
|
|
227
|
-
return self.getOutcomeSlotCount(condition_id, web3=web3) > 0
|
|
228
|
-
|
|
229
|
-
def is_condition_resolved(
|
|
230
|
-
self, condition_id: HexBytes, web3: Web3 | None = None
|
|
231
|
-
) -> bool:
|
|
232
|
-
# from ConditionalTokens.redeemPositions:
|
|
233
|
-
# uint den = payoutDenominator[conditionId]; require(den > 0, "result for condition not received yet");
|
|
234
|
-
payout_for_condition = self.payoutDenominator(condition_id, web3=web3)
|
|
235
|
-
return payout_for_condition > 0
|
|
236
|
-
|
|
237
|
-
def payoutDenominator(
|
|
238
|
-
self, condition_id: HexBytes, web3: Web3 | None = None
|
|
239
|
-
) -> int:
|
|
240
|
-
payoutForCondition: int = self.call(
|
|
241
|
-
"payoutDenominator", [condition_id], web3=web3
|
|
242
|
-
)
|
|
243
|
-
return payoutForCondition
|
|
244
|
-
|
|
245
|
-
def setApprovalForAll(
|
|
246
|
-
self,
|
|
247
|
-
api_keys: APIKeys,
|
|
248
|
-
for_address: ChecksumAddress,
|
|
249
|
-
approve: bool,
|
|
250
|
-
tx_params: t.Optional[TxParams] = None,
|
|
251
|
-
web3: Web3 | None = None,
|
|
252
|
-
) -> TxReceipt:
|
|
253
|
-
return self.send(
|
|
254
|
-
api_keys=api_keys,
|
|
255
|
-
function_name="setApprovalForAll",
|
|
256
|
-
function_params=[
|
|
257
|
-
for_address,
|
|
258
|
-
approve,
|
|
259
|
-
],
|
|
260
|
-
tx_params=tx_params,
|
|
261
|
-
web3=web3,
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
def prepareCondition(
|
|
265
|
-
self,
|
|
266
|
-
api_keys: APIKeys,
|
|
267
|
-
oracle_address: ChecksumAddress,
|
|
268
|
-
question_id: HexBytes,
|
|
269
|
-
outcomes_slot_count: int,
|
|
270
|
-
tx_params: t.Optional[TxParams] = None,
|
|
271
|
-
web3: Web3 | None = None,
|
|
272
|
-
) -> ConditionPreparationEvent:
|
|
273
|
-
receipt_tx = self.send(
|
|
274
|
-
api_keys=api_keys,
|
|
275
|
-
function_name="prepareCondition",
|
|
276
|
-
function_params=[
|
|
277
|
-
oracle_address,
|
|
278
|
-
question_id,
|
|
279
|
-
outcomes_slot_count,
|
|
280
|
-
],
|
|
281
|
-
tx_params=tx_params,
|
|
282
|
-
web3=web3,
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
event_logs = (
|
|
286
|
-
self.get_web3_contract(web3=web3)
|
|
287
|
-
.events.ConditionPreparation()
|
|
288
|
-
.process_receipt(receipt_tx)
|
|
289
|
-
)
|
|
290
|
-
cond_event = ConditionPreparationEvent(**event_logs[0]["args"])
|
|
291
|
-
|
|
292
|
-
return cond_event
|
|
293
|
-
|
|
294
101
|
|
|
295
102
|
class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
296
103
|
# File content taken from https://github.com/protofire/omen-exchange/blob/master/app/src/abi/marketMaker.json.
|
|
@@ -433,7 +240,7 @@ class OmenFixedProductMarketMakerContract(ContractOnGnosisChain):
|
|
|
433
240
|
|
|
434
241
|
class MetriSuperGroup(ContractERC20OnGnosisChain):
|
|
435
242
|
address: ChecksumAddress = Web3.to_checksum_address(
|
|
436
|
-
|
|
243
|
+
METRI_SUPER_GROUP_CONTRACT_ADDRESS
|
|
437
244
|
)
|
|
438
245
|
|
|
439
246
|
|
|
@@ -821,20 +628,16 @@ class OmenRealitioContract(ContractOnGnosisChain):
|
|
|
821
628
|
return is_pending_arbitration
|
|
822
629
|
|
|
823
630
|
|
|
824
|
-
class
|
|
631
|
+
class _AgentResultMappingContract(ContractOnGnosisChain):
|
|
825
632
|
# Contract ABI taken from built https://github.com/gnosis/labs-contracts.
|
|
826
633
|
|
|
827
634
|
abi: ABI = abi_field_validator(
|
|
828
635
|
os.path.join(
|
|
829
636
|
os.path.dirname(os.path.realpath(__file__)),
|
|
830
|
-
"../../abis/
|
|
637
|
+
"../../abis/agentresultmapping.abi.json",
|
|
831
638
|
)
|
|
832
639
|
)
|
|
833
640
|
|
|
834
|
-
address: ChecksumAddress = Web3.to_checksum_address(
|
|
835
|
-
"0x260E1077dEA98e738324A6cEfB0EE9A272eD471a"
|
|
836
|
-
)
|
|
837
|
-
|
|
838
641
|
def get_predictions(
|
|
839
642
|
self,
|
|
840
643
|
market_address: ChecksumAddress,
|
|
@@ -860,6 +663,18 @@ class OmenAgentResultMappingContract(ContractOnGnosisChain):
|
|
|
860
663
|
)
|
|
861
664
|
|
|
862
665
|
|
|
666
|
+
class OmenAgentResultMappingContract(_AgentResultMappingContract):
|
|
667
|
+
address: ChecksumAddress = Web3.to_checksum_address(
|
|
668
|
+
"0x99c43743A2dbd406160CC43cf08113b17178789c"
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
class SeerAgentResultMappingContract(_AgentResultMappingContract):
|
|
673
|
+
address: ChecksumAddress = Web3.to_checksum_address(
|
|
674
|
+
"0x1aafdfBD38EE92A4a74A44A1614E00894205074e"
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
|
|
863
678
|
class OmenThumbnailMapping(ContractOnGnosisChain):
|
|
864
679
|
# Contract ABI taken from built https://github.com/gnosis/labs-contracts.
|
|
865
680
|
abi: ABI = abi_field_validator(
|
|
@@ -13,7 +13,7 @@ from prediction_market_agent_tooling.markets.data_models import Resolution
|
|
|
13
13
|
from prediction_market_agent_tooling.markets.manifold.api import (
|
|
14
14
|
find_resolution_on_manifold,
|
|
15
15
|
)
|
|
16
|
-
from prediction_market_agent_tooling.markets.
|
|
16
|
+
from prediction_market_agent_tooling.markets.market_type import MarketType
|
|
17
17
|
from prediction_market_agent_tooling.markets.omen.data_models import (
|
|
18
18
|
OmenMarket,
|
|
19
19
|
RealityQuestion,
|
|
@@ -31,7 +31,11 @@ from prediction_market_agent_tooling.markets.omen.omen_subgraph_handler import (
|
|
|
31
31
|
from prediction_market_agent_tooling.tools.tokens.main_token import (
|
|
32
32
|
MINIMUM_NATIVE_TOKEN_IN_EOA_FOR_FEES,
|
|
33
33
|
)
|
|
34
|
-
from prediction_market_agent_tooling.tools.utils import
|
|
34
|
+
from prediction_market_agent_tooling.tools.utils import (
|
|
35
|
+
check_not_none,
|
|
36
|
+
extract_error_from_retry_error,
|
|
37
|
+
utcnow,
|
|
38
|
+
)
|
|
35
39
|
from prediction_market_agent_tooling.tools.web3_utils import ZERO_BYTES
|
|
36
40
|
|
|
37
41
|
|
|
@@ -81,10 +85,10 @@ def claim_bonds_on_realitio_question(
|
|
|
81
85
|
responses = sorted(responses, key=lambda x: x.timestamp)
|
|
82
86
|
|
|
83
87
|
if not responses:
|
|
84
|
-
raise ValueError(f"No answers found for {question.questionId.
|
|
88
|
+
raise ValueError(f"No answers found for {question.questionId.to_0x_hex()=}")
|
|
85
89
|
|
|
86
90
|
if responses[-1].question.historyHash == ZERO_BYTES:
|
|
87
|
-
raise ValueError(f"Already claimed {question.questionId.
|
|
91
|
+
raise ValueError(f"Already claimed {question.questionId.to_0x_hex()=}.")
|
|
88
92
|
|
|
89
93
|
history_hashes: list[HexBytes] = []
|
|
90
94
|
addresses: list[ChecksumAddress] = []
|
|
@@ -223,7 +227,10 @@ def omen_submit_answer_market_tx(
|
|
|
223
227
|
And after the period is over, you need to resolve the market using `omen_resolve_market_tx`.
|
|
224
228
|
"""
|
|
225
229
|
realitio_contract = OmenRealitioContract()
|
|
226
|
-
|
|
230
|
+
outcome_matching_market = check_not_none(
|
|
231
|
+
resolution.find_outcome_matching_market(market.outcomes)
|
|
232
|
+
)
|
|
233
|
+
outcome_index = market.outcomes.index(outcome_matching_market)
|
|
227
234
|
realitio_contract.submit_answer(
|
|
228
235
|
api_keys=api_keys,
|
|
229
236
|
question_id=market.question.id,
|
|
@@ -261,14 +268,27 @@ def omen_resolve_market_tx(
|
|
|
261
268
|
Market can be resolved after the answer if finalized on Reality.
|
|
262
269
|
"""
|
|
263
270
|
oracle_contract = OmenOracleContract()
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
try:
|
|
272
|
+
oracle_contract.resolve(
|
|
273
|
+
api_keys=api_keys,
|
|
274
|
+
question_id=market.question.id,
|
|
275
|
+
template_id=market.question.templateId,
|
|
276
|
+
question_raw=market.question.question_raw,
|
|
277
|
+
n_outcomes=market.question.n_outcomes,
|
|
278
|
+
web3=web3,
|
|
279
|
+
)
|
|
280
|
+
except BaseException as e:
|
|
281
|
+
e = extract_error_from_retry_error(e)
|
|
282
|
+
if "condition not prepared or found" in str(e):
|
|
283
|
+
# We can't do anything about these, so just skip them with warning.
|
|
284
|
+
logger.warning(
|
|
285
|
+
f"Market {market.url=} not resolved, because `condition not prepared or found`, skipping."
|
|
286
|
+
)
|
|
287
|
+
elif "payout denominator already set" in str(e):
|
|
288
|
+
# We can just skip, it's been resolved already.
|
|
289
|
+
logger.info(f"Market {market.url=} is already resolved.")
|
|
290
|
+
else:
|
|
291
|
+
raise
|
|
272
292
|
|
|
273
293
|
|
|
274
294
|
def find_resolution_on_other_markets(market: OmenMarket) -> Resolution | None:
|
|
@@ -32,6 +32,7 @@ from prediction_market_agent_tooling.markets.omen.omen_contracts import (
|
|
|
32
32
|
COWContract,
|
|
33
33
|
EUReContract,
|
|
34
34
|
GNOContract,
|
|
35
|
+
MetriSuperGroup,
|
|
35
36
|
OmenThumbnailMapping,
|
|
36
37
|
SAFEContract,
|
|
37
38
|
WETHContract,
|
|
@@ -52,7 +53,7 @@ from prediction_market_agent_tooling.tools.web3_utils import (
|
|
|
52
53
|
unwrap_generic_value,
|
|
53
54
|
)
|
|
54
55
|
|
|
55
|
-
SAFE_COLLATERAL_TOKENS =
|
|
56
|
+
SAFE_COLLATERAL_TOKENS = [
|
|
56
57
|
WrappedxDaiContract(),
|
|
57
58
|
sDaiContract(),
|
|
58
59
|
GNOContract(),
|
|
@@ -60,10 +61,11 @@ SAFE_COLLATERAL_TOKENS = (
|
|
|
60
61
|
EUReContract(),
|
|
61
62
|
SAFEContract(),
|
|
62
63
|
COWContract(),
|
|
63
|
-
)
|
|
64
|
-
|
|
64
|
+
MetriSuperGroup(),
|
|
65
|
+
]
|
|
66
|
+
SAFE_COLLATERAL_TOKENS_ADDRESSES = [
|
|
65
67
|
contract.address for contract in SAFE_COLLATERAL_TOKENS
|
|
66
|
-
|
|
68
|
+
]
|
|
67
69
|
|
|
68
70
|
|
|
69
71
|
class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
@@ -188,6 +190,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
188
190
|
questions_field.templateId,
|
|
189
191
|
questions_field.isPendingArbitration,
|
|
190
192
|
questions_field.openingTimestamp,
|
|
193
|
+
questions_field.timeout,
|
|
191
194
|
]
|
|
192
195
|
|
|
193
196
|
def _get_fields_for_markets(self, markets_field: FieldPath) -> list[FieldPath]:
|
|
@@ -235,7 +238,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
235
238
|
liquidity_bigger_than: Wei | None,
|
|
236
239
|
condition_id_in: list[HexBytes] | None,
|
|
237
240
|
id_in: list[str] | None,
|
|
238
|
-
collateral_token_address_in:
|
|
241
|
+
collateral_token_address_in: t.Sequence[ChecksumAddress] | None,
|
|
239
242
|
category: str | None,
|
|
240
243
|
include_categorical_markets: bool = False,
|
|
241
244
|
include_scalar_markets: bool = False,
|
|
@@ -283,7 +286,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
283
286
|
where_stms["liquidityParameter_gt"] = liquidity_bigger_than
|
|
284
287
|
|
|
285
288
|
if condition_id_in is not None:
|
|
286
|
-
where_stms["condition_"]["id_in"] = [x.
|
|
289
|
+
where_stms["condition_"]["id_in"] = [x.to_0x_hex() for x in condition_id_in]
|
|
287
290
|
|
|
288
291
|
if id_in is not None:
|
|
289
292
|
where_stms["id_in"] = [i.lower() for i in id_in]
|
|
@@ -346,7 +349,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
346
349
|
created_after: DatetimeUTC | None = None,
|
|
347
350
|
excluded_questions: set[str] | None = None, # question titles
|
|
348
351
|
collateral_token_address_in: (
|
|
349
|
-
|
|
352
|
+
t.Sequence[ChecksumAddress] | None
|
|
350
353
|
) = SAFE_COLLATERAL_TOKENS_ADDRESSES,
|
|
351
354
|
category: str | None = None,
|
|
352
355
|
creator_in: t.Sequence[HexAddress] | None = None,
|
|
@@ -414,7 +417,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
414
417
|
sort_by_field: FieldPath | None = None,
|
|
415
418
|
sort_direction: str | None = None,
|
|
416
419
|
collateral_token_address_in: (
|
|
417
|
-
|
|
420
|
+
t.Sequence[ChecksumAddress] | None
|
|
418
421
|
) = SAFE_COLLATERAL_TOKENS_ADDRESSES,
|
|
419
422
|
category: str | None = None,
|
|
420
423
|
include_categorical_markets: bool = True,
|
|
@@ -511,7 +514,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
511
514
|
where_stms: dict[str, t.Any] = {}
|
|
512
515
|
|
|
513
516
|
if condition_id is not None:
|
|
514
|
-
where_stms["conditionIds_contains"] = [condition_id.
|
|
517
|
+
where_stms["conditionIds_contains"] = [condition_id.to_0x_hex()]
|
|
515
518
|
|
|
516
519
|
positions = self.conditional_tokens_subgraph.Query.positions(
|
|
517
520
|
first=sys.maxsize, where=unwrap_generic_value(where_stms)
|
|
@@ -539,10 +542,12 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
539
542
|
where_stms["totalBalance_gt"] = total_balance_bigger_than
|
|
540
543
|
|
|
541
544
|
if user_position_id_in is not None:
|
|
542
|
-
where_stms["id_in"] = [x.
|
|
545
|
+
where_stms["id_in"] = [x.to_0x_hex() for x in user_position_id_in]
|
|
543
546
|
|
|
544
547
|
if position_id_in is not None:
|
|
545
|
-
where_stms["position_"]["positionId_in"] = [
|
|
548
|
+
where_stms["position_"]["positionId_in"] = [
|
|
549
|
+
x.to_0x_hex() for x in position_id_in
|
|
550
|
+
]
|
|
546
551
|
|
|
547
552
|
positions = self.conditional_tokens_subgraph.Query.userPositions(
|
|
548
553
|
first=sys.maxsize, where=unwrap_generic_value(where_stms)
|
|
@@ -708,13 +713,13 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
708
713
|
where_stms["user"] = user.lower()
|
|
709
714
|
|
|
710
715
|
if question_id is not None:
|
|
711
|
-
where_stms["questionId"] = question_id.
|
|
716
|
+
where_stms["questionId"] = question_id.to_0x_hex()
|
|
712
717
|
|
|
713
718
|
if claimed is not None:
|
|
714
719
|
if claimed:
|
|
715
|
-
where_stms["historyHash"] = ZERO_BYTES.
|
|
720
|
+
where_stms["historyHash"] = ZERO_BYTES.to_0x_hex()
|
|
716
721
|
else:
|
|
717
|
-
where_stms["historyHash_not"] = ZERO_BYTES.
|
|
722
|
+
where_stms["historyHash_not"] = ZERO_BYTES.to_0x_hex()
|
|
718
723
|
|
|
719
724
|
if current_answer_before is not None:
|
|
720
725
|
where_stms["currentAnswerTimestamp_lt"] = to_int_timestamp(
|
|
@@ -748,7 +753,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
748
753
|
|
|
749
754
|
if question_id_in is not None:
|
|
750
755
|
# Be aware: On Omen subgraph, question's `id` represents `questionId` on reality subgraph. And `id` on reality subraph is just a weird concat of multiple things from the question.
|
|
751
|
-
where_stms["questionId_in"] = [x.
|
|
756
|
+
where_stms["questionId_in"] = [x.to_0x_hex() for x in question_id_in]
|
|
752
757
|
|
|
753
758
|
if excluded_titles:
|
|
754
759
|
# Be aware: This is called `title_not_in` on Omen subgraph.
|
|
@@ -775,7 +780,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
775
780
|
where_stms: dict[str, t.Any] = {}
|
|
776
781
|
|
|
777
782
|
if question_id is not None:
|
|
778
|
-
where_stms["id"] = question_id.
|
|
783
|
+
where_stms["id"] = question_id.to_0x_hex()
|
|
779
784
|
|
|
780
785
|
if current_answer_before is not None:
|
|
781
786
|
where_stms["currentAnswerTimestamp_lt"] = to_int_timestamp(
|
|
@@ -809,7 +814,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
809
814
|
|
|
810
815
|
if question_id_in is not None:
|
|
811
816
|
# Be aware: On Omen subgraph, question's `id` represents `questionId` on reality subgraph. And `id` on reality subraph is just a weird concat of multiple things from the question.
|
|
812
|
-
where_stms["id_in"] = [x.
|
|
817
|
+
where_stms["id_in"] = [x.to_0x_hex() for x in question_id_in]
|
|
813
818
|
|
|
814
819
|
if excluded_titles:
|
|
815
820
|
# Be aware: This is called `qTitle_not_in` on Omen subgraph.
|
|
@@ -862,7 +867,7 @@ class OmenSubgraphHandler(BaseSubgraphHandler):
|
|
|
862
867
|
answer = self.realityeth_subgraph.Answer
|
|
863
868
|
# subgrounds complains if bytes is passed, hence we convert it to HexStr
|
|
864
869
|
where_stms = [
|
|
865
|
-
answer.question.questionId == question_id.
|
|
870
|
+
answer.question.questionId == question_id.to_0x_hex(),
|
|
866
871
|
]
|
|
867
872
|
|
|
868
873
|
answers = self.realityeth_subgraph.Query.answers(
|