prediction-market-agent-tooling 0.59.2__py3-none-any.whl → 0.60.0.dev408__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/markets/omen/data_models.py +15 -0
- prediction_market_agent_tooling/markets/omen/omen.py +50 -10
- prediction_market_agent_tooling/tools/omen/sell_positions.py +1 -1
- prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +20 -1
- {prediction_market_agent_tooling-0.59.2.dist-info → prediction_market_agent_tooling-0.60.0.dev408.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.59.2.dist-info → prediction_market_agent_tooling-0.60.0.dev408.dist-info}/RECORD +9 -9
- {prediction_market_agent_tooling-0.59.2.dist-info → prediction_market_agent_tooling-0.60.0.dev408.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.59.2.dist-info → prediction_market_agent_tooling-0.60.0.dev408.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.59.2.dist-info → prediction_market_agent_tooling-0.60.0.dev408.dist-info}/entry_points.txt +0 -0
@@ -23,6 +23,11 @@ from prediction_market_agent_tooling.markets.data_models import (
|
|
23
23
|
Resolution,
|
24
24
|
ResolvedBet,
|
25
25
|
)
|
26
|
+
from prediction_market_agent_tooling.tools.contract import (
|
27
|
+
ContractERC20OnGnosisChain,
|
28
|
+
init_collateral_token_contract,
|
29
|
+
to_gnosis_chain_contract,
|
30
|
+
)
|
26
31
|
from prediction_market_agent_tooling.tools.utils import (
|
27
32
|
BPS_CONSTANT,
|
28
33
|
DatetimeUTC,
|
@@ -168,6 +173,16 @@ class OmenPosition(BaseModel):
|
|
168
173
|
def collateral_token_contract_address_checksummed(self) -> ChecksumAddress:
|
169
174
|
return Web3.to_checksum_address(self.collateralTokenAddress)
|
170
175
|
|
176
|
+
def get_collateral_token_contract(
|
177
|
+
self, web3: Web3 | None
|
178
|
+
) -> ContractERC20OnGnosisChain:
|
179
|
+
web3 = web3 or ContractERC20OnGnosisChain.get_web3()
|
180
|
+
return to_gnosis_chain_contract(
|
181
|
+
init_collateral_token_contract(
|
182
|
+
self.collateral_token_contract_address_checksummed, web3
|
183
|
+
)
|
184
|
+
)
|
185
|
+
|
171
186
|
|
172
187
|
class OmenUserPosition(BaseModel):
|
173
188
|
id: HexBytes
|
@@ -80,6 +80,7 @@ from prediction_market_agent_tooling.tools.tokens.auto_deposit import (
|
|
80
80
|
from prediction_market_agent_tooling.tools.tokens.auto_withdraw import (
|
81
81
|
auto_withdraw_collateral_token,
|
82
82
|
)
|
83
|
+
from prediction_market_agent_tooling.tools.tokens.main_token import KEEPING_ERC20_TOKEN
|
83
84
|
from prediction_market_agent_tooling.tools.utils import (
|
84
85
|
DatetimeUTC,
|
85
86
|
calculate_sell_amount_in_collateral,
|
@@ -190,11 +191,10 @@ class OmenAgentMarket(AgentMarket):
|
|
190
191
|
for position_outcome, token_amount in prev_position.amounts.items():
|
191
192
|
position_outcome_bool = get_boolean_outcome(position_outcome)
|
192
193
|
if position_outcome_bool != bet_outcome:
|
193
|
-
# We keep it as collateral since we want to place a bet immediately after this function.
|
194
194
|
self.sell_tokens(
|
195
195
|
outcome=position_outcome_bool,
|
196
196
|
amount=token_amount,
|
197
|
-
auto_withdraw=
|
197
|
+
auto_withdraw=True,
|
198
198
|
web3=web3,
|
199
199
|
api_keys=api_keys,
|
200
200
|
)
|
@@ -259,7 +259,7 @@ class OmenAgentMarket(AgentMarket):
|
|
259
259
|
self,
|
260
260
|
outcome: bool,
|
261
261
|
amount: TokenAmount,
|
262
|
-
auto_withdraw: bool =
|
262
|
+
auto_withdraw: bool = True,
|
263
263
|
api_keys: APIKeys | None = None,
|
264
264
|
web3: Web3 | None = None,
|
265
265
|
) -> str:
|
@@ -408,8 +408,8 @@ class OmenAgentMarket(AgentMarket):
|
|
408
408
|
|
409
409
|
@staticmethod
|
410
410
|
def get_trade_balance(api_keys: APIKeys, web3: Web3 | None = None) -> xDai:
|
411
|
-
return
|
412
|
-
|
411
|
+
return wei_to_xdai(
|
412
|
+
KEEPING_ERC20_TOKEN.balanceOf(api_keys.bet_from_address, web3=web3)
|
413
413
|
)
|
414
414
|
|
415
415
|
@staticmethod
|
@@ -1060,6 +1060,7 @@ def omen_fund_market_tx(
|
|
1060
1060
|
def omen_redeem_full_position_tx(
|
1061
1061
|
api_keys: APIKeys,
|
1062
1062
|
market: OmenAgentMarket,
|
1063
|
+
auto_withdraw: bool = True,
|
1063
1064
|
web3: Web3 | None = None,
|
1064
1065
|
) -> None:
|
1065
1066
|
"""
|
@@ -1071,6 +1072,7 @@ def omen_redeem_full_position_tx(
|
|
1071
1072
|
|
1072
1073
|
market_contract: OmenFixedProductMarketMakerContract = market.get_contract()
|
1073
1074
|
conditional_token_contract = OmenConditionalTokenContract()
|
1075
|
+
collateral_token_contract = market_contract.get_collateral_token_contract(web3)
|
1074
1076
|
|
1075
1077
|
# Verify, that markets uses conditional tokens that we expect.
|
1076
1078
|
if market_contract.conditionalTokens() != conditional_token_contract.address:
|
@@ -1094,6 +1096,7 @@ def omen_redeem_full_position_tx(
|
|
1094
1096
|
logger.debug("Market not yet resolved, not possible to claim")
|
1095
1097
|
return
|
1096
1098
|
|
1099
|
+
original_balance = collateral_token_contract.balanceOf(from_address, web3=web3)
|
1097
1100
|
conditional_token_contract.redeemPositions(
|
1098
1101
|
api_keys=api_keys,
|
1099
1102
|
collateral_token_address=market.collateral_token_contract_address_checksummed,
|
@@ -1101,6 +1104,20 @@ def omen_redeem_full_position_tx(
|
|
1101
1104
|
index_sets=market.condition.index_sets,
|
1102
1105
|
web3=web3,
|
1103
1106
|
)
|
1107
|
+
new_balance = collateral_token_contract.balanceOf(from_address, web3=web3)
|
1108
|
+
balance_diff = wei_type(new_balance - original_balance)
|
1109
|
+
|
1110
|
+
logger.info(
|
1111
|
+
f"Redeemed {wei_to_xdai(balance_diff)} {collateral_token_contract.symbol_cached(web3=web3)} from market {market.question=} ({market.url})."
|
1112
|
+
)
|
1113
|
+
|
1114
|
+
if auto_withdraw:
|
1115
|
+
auto_withdraw_collateral_token(
|
1116
|
+
collateral_token_contract=collateral_token_contract,
|
1117
|
+
amount_wei=balance_diff,
|
1118
|
+
api_keys=api_keys,
|
1119
|
+
web3=web3,
|
1120
|
+
)
|
1104
1121
|
|
1105
1122
|
|
1106
1123
|
def get_conditional_tokens_balance_for_market(
|
@@ -1139,13 +1156,14 @@ def omen_remove_fund_market_tx(
|
|
1139
1156
|
market: OmenAgentMarket,
|
1140
1157
|
shares: Wei | None,
|
1141
1158
|
web3: Web3 | None = None,
|
1159
|
+
auto_withdraw: bool = True,
|
1142
1160
|
) -> None:
|
1143
1161
|
"""
|
1144
1162
|
Removes funding from a given OmenMarket (moving the funds from the OmenMarket to the
|
1145
1163
|
ConditionalTokens contract), and finally calls the `mergePositions` method which transfers collateralToken from the ConditionalTokens contract to the address corresponding to `from_private_key`.
|
1146
1164
|
|
1147
1165
|
Warning: Liquidity removal works on the principle of getting market's shares, not the collateral token itself.
|
1148
|
-
After we remove funding, using the `mergePositions` we get `min(shares per index)` of
|
1166
|
+
After we remove funding, using the `mergePositions` we get `min(shares per index)` of collateral token back, but the remaining shares can be converted back only after the market is resolved.
|
1149
1167
|
That can be done using the `redeem_from_all_user_positions` function below.
|
1150
1168
|
"""
|
1151
1169
|
from_address = api_keys.bet_from_address
|
@@ -1189,16 +1207,26 @@ def omen_remove_fund_market_tx(
|
|
1189
1207
|
)
|
1190
1208
|
|
1191
1209
|
new_balance = market_collateral_token_contract.balanceOf(from_address, web3=web3)
|
1210
|
+
balance_diff = wei_type(new_balance - original_balance)
|
1192
1211
|
|
1193
1212
|
logger.debug(f"Result from merge positions {result}")
|
1194
1213
|
logger.info(
|
1195
|
-
f"Withdrawn {
|
1214
|
+
f"Withdrawn {wei_to_xdai(balance_diff)} {market_collateral_token_contract.symbol_cached(web3=web3)} from liquidity at {market.url=}."
|
1196
1215
|
)
|
1197
1216
|
|
1217
|
+
if auto_withdraw:
|
1218
|
+
auto_withdraw_collateral_token(
|
1219
|
+
collateral_token_contract=market_collateral_token_contract,
|
1220
|
+
amount_wei=balance_diff,
|
1221
|
+
api_keys=api_keys,
|
1222
|
+
web3=web3,
|
1223
|
+
)
|
1224
|
+
|
1198
1225
|
|
1199
1226
|
def redeem_from_all_user_positions(
|
1200
1227
|
api_keys: APIKeys,
|
1201
1228
|
web3: Web3 | None = None,
|
1229
|
+
auto_withdraw: bool = True,
|
1202
1230
|
) -> None:
|
1203
1231
|
"""
|
1204
1232
|
Redeems from all user positions where the user didn't redeem yet.
|
@@ -1224,8 +1252,11 @@ def redeem_from_all_user_positions(
|
|
1224
1252
|
logger.info(
|
1225
1253
|
f"[{index + 1} / {len(user_positions)}] Processing redeem from {user_position.id=}."
|
1226
1254
|
)
|
1255
|
+
collateral_token_contract = (
|
1256
|
+
user_position.position.get_collateral_token_contract(web3=web3)
|
1257
|
+
)
|
1227
1258
|
|
1228
|
-
|
1259
|
+
original_balance = collateral_token_contract.balanceOf(public_key, web3=web3)
|
1229
1260
|
conditional_token_contract.redeemPositions(
|
1230
1261
|
api_keys=api_keys,
|
1231
1262
|
collateral_token_address=user_position.position.collateral_token_contract_address_checksummed,
|
@@ -1233,12 +1264,21 @@ def redeem_from_all_user_positions(
|
|
1233
1264
|
index_sets=user_position.position.indexSets,
|
1234
1265
|
web3=web3,
|
1235
1266
|
)
|
1236
|
-
|
1267
|
+
new_balance = collateral_token_contract.balanceOf(public_key, web3=web3)
|
1268
|
+
balance_diff = wei_type(new_balance - original_balance)
|
1237
1269
|
|
1238
1270
|
logger.info(
|
1239
|
-
f"Redeemed {
|
1271
|
+
f"Redeemed {wei_to_xdai(balance_diff)} {collateral_token_contract.symbol_cached(web3=web3)} from position {user_position.id=}."
|
1240
1272
|
)
|
1241
1273
|
|
1274
|
+
if auto_withdraw:
|
1275
|
+
auto_withdraw_collateral_token(
|
1276
|
+
collateral_token_contract=collateral_token_contract,
|
1277
|
+
amount_wei=balance_diff,
|
1278
|
+
api_keys=api_keys,
|
1279
|
+
web3=web3,
|
1280
|
+
)
|
1281
|
+
|
1242
1282
|
|
1243
1283
|
def get_binary_market_p_yes_history(market: OmenAgentMarket) -> list[Probability]:
|
1244
1284
|
history: list[Probability] = []
|
@@ -13,7 +13,7 @@ from prediction_market_agent_tooling.tools.utils import utcnow
|
|
13
13
|
def sell_all(
|
14
14
|
api_keys: APIKeys,
|
15
15
|
closing_later_than_days: int,
|
16
|
-
auto_withdraw: bool =
|
16
|
+
auto_withdraw: bool = True,
|
17
17
|
) -> None:
|
18
18
|
"""
|
19
19
|
Helper function to sell all existing outcomes on Omen that would resolve later than in X days.
|
@@ -2,6 +2,7 @@ from web3 import Web3
|
|
2
2
|
|
3
3
|
from prediction_market_agent_tooling.config import APIKeys
|
4
4
|
from prediction_market_agent_tooling.gtypes import Wei
|
5
|
+
from prediction_market_agent_tooling.loggers import logger
|
5
6
|
from prediction_market_agent_tooling.tools.contract import (
|
6
7
|
ContractERC20BaseClass,
|
7
8
|
ContractERC4626BaseClass,
|
@@ -12,7 +13,10 @@ from prediction_market_agent_tooling.tools.cow.cow_order import (
|
|
12
13
|
)
|
13
14
|
from prediction_market_agent_tooling.tools.tokens.main_token import KEEPING_ERC20_TOKEN
|
14
15
|
from prediction_market_agent_tooling.tools.utils import should_not_happen
|
15
|
-
from prediction_market_agent_tooling.tools.web3_utils import
|
16
|
+
from prediction_market_agent_tooling.tools.web3_utils import (
|
17
|
+
remove_fraction,
|
18
|
+
wei_to_xdai,
|
19
|
+
)
|
16
20
|
|
17
21
|
|
18
22
|
def auto_withdraw_collateral_token(
|
@@ -28,8 +32,17 @@ def auto_withdraw_collateral_token(
|
|
28
32
|
slippage,
|
29
33
|
)
|
30
34
|
|
35
|
+
if not amount_wei:
|
36
|
+
logger.warning(
|
37
|
+
f"Amount to withdraw is zero, skipping withdrawal of {collateral_token_contract.symbol_cached(web3)}."
|
38
|
+
)
|
39
|
+
return
|
40
|
+
|
31
41
|
if collateral_token_contract.address == KEEPING_ERC20_TOKEN.address:
|
32
42
|
# Do nothing, as this is the token we want to keep.
|
43
|
+
logger.info(
|
44
|
+
f"Collateral token {collateral_token_contract.symbol_cached(web3)} is the same as KEEPING_ERC20_TOKEN. Not withdrawing."
|
45
|
+
)
|
33
46
|
return
|
34
47
|
elif (
|
35
48
|
isinstance(collateral_token_contract, ContractERC4626BaseClass)
|
@@ -37,12 +50,18 @@ def auto_withdraw_collateral_token(
|
|
37
50
|
== KEEPING_ERC20_TOKEN.address
|
38
51
|
):
|
39
52
|
# If the ERC4626 is backed by KEEPING_ERC20_TOKEN, we can withdraw it directly, no need to go through DEX.
|
53
|
+
logger.info(
|
54
|
+
f"Withdrawing {wei_to_xdai(amount_wei)} from {collateral_token_contract.symbol_cached(web3)} into {KEEPING_ERC20_TOKEN.symbol_cached(web3)}"
|
55
|
+
)
|
40
56
|
collateral_token_contract.withdraw(
|
41
57
|
api_keys,
|
42
58
|
amount_wei,
|
43
59
|
web3=web3,
|
44
60
|
)
|
45
61
|
elif isinstance(collateral_token_contract, ContractERC20BaseClass):
|
62
|
+
logger.info(
|
63
|
+
f"Swapping {wei_to_xdai(amount_wei)} {collateral_token_contract.symbol_cached(web3)} into {KEEPING_ERC20_TOKEN.symbol_cached(web3)}"
|
64
|
+
)
|
46
65
|
# Otherwise, DEX will handle the rest of token swaps.
|
47
66
|
# First, convert `amount_wei` from xDai-based value into the collateral token-based value.
|
48
67
|
collateral_amount_wei = get_buy_token_amount(
|
@@ -50,8 +50,8 @@ prediction_market_agent_tooling/markets/metaculus/api.py,sha256=4TRPGytQQbSdf42D
|
|
50
50
|
prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=FaBCTPPezXbBwZ9p791CiVgQ4vB696xnMbz9XVXmiVI,3267
|
51
51
|
prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavEWc8Cv4KpZxSvwiSw9oFybXE3YB49pg-CA,4377
|
52
52
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
53
|
-
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=
|
54
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
53
|
+
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=sfaOpNk6oFIzxYQzs9EehqAT_19IxYJy9pns-UTepOc,28934
|
54
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=7XOcjzuzX4vJUVr-M2yp1Diq8MaURFsC_8syhdpZbGg,51460
|
55
55
|
prediction_market_agent_tooling/markets/omen/omen_constants.py,sha256=D9oflYKafLQiHYtB5sScMHqmXyzM8JP8J0yATmc4SQQ,233
|
56
56
|
prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=EXqBlVivbmW8aBQ65O09X2xkyesHAop49GUl1tUffWA,28648
|
57
57
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=E1BVDvQd1qYtCxmfC94kJtGkmQqpGPHL3zTkcs5wW6M,9697
|
@@ -101,7 +101,7 @@ prediction_market_agent_tooling/tools/is_predictable.py,sha256=qVd6zqay2Dg2fyeAu
|
|
101
101
|
prediction_market_agent_tooling/tools/langfuse_.py,sha256=jI_4ROxqo41CCnWGS1vN_AeDVhRzLMaQLxH3kxDu3L8,1153
|
102
102
|
prediction_market_agent_tooling/tools/langfuse_client_utils.py,sha256=83T31s-YbsnNBLyYCjmBI2BBKUEqJUuYFa0uCdkoqy8,5901
|
103
103
|
prediction_market_agent_tooling/tools/omen/reality_accuracy.py,sha256=M1SF7iSW1gVlQSTskdVFTn09uPLST23YeipVIWj54io,2236
|
104
|
-
prediction_market_agent_tooling/tools/omen/sell_positions.py,sha256=
|
104
|
+
prediction_market_agent_tooling/tools/omen/sell_positions.py,sha256=hZCxXpcACO95DyiZ5oLFp982N0erZg4wccdSUKTgRlA,2307
|
105
105
|
prediction_market_agent_tooling/tools/parallelism.py,sha256=6Gou0hbjtMZrYvxjTDFUDZuxmE2nqZVbb6hkg1hF82A,1022
|
106
106
|
prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py,sha256=95l84aztFaxcRLLcRQ46yKJbIlOEuDAbIGLouyliDzA,1316
|
107
107
|
prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py,sha256=CddJem7tk15NAudJDwmuL8znTycbR-YI8kTNtd3LzG8,5474
|
@@ -112,13 +112,13 @@ prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9
|
|
112
112
|
prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=5ldQs1pZe6uJ5eDAuP4OLpzmcqYShlIV67kttNFvGS0,342
|
113
113
|
prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=Kw2mXNkMTYTEe1MBSTqhQmLoeXtgb6CkmHlcAJvhtqE,3809
|
114
114
|
prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=o8_ERfPL-ps9FLvH5vgdiSRJQ4dZONJw9KK9sHgeP2I,6390
|
115
|
-
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=
|
115
|
+
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=gOvfZlrw6hdpYquGKLjMw-YpjAvWHnyGa-ke0Z6GIzU,3150
|
116
116
|
prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=5iHO7-iehSlXuue6ocVrr4IsklVjm7QHIwln4BsebJA,573
|
117
117
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
118
118
|
prediction_market_agent_tooling/tools/utils.py,sha256=jLG4nbEoIzzJiZ4RgMx4Q969Zdl0p0s63p8uET_0Fuw,6440
|
119
119
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=2PXZfGRrDVZD60agVpBN4JkOF0YsNBXgTEH1y-V71uQ,12723
|
120
|
-
prediction_market_agent_tooling-0.
|
121
|
-
prediction_market_agent_tooling-0.
|
122
|
-
prediction_market_agent_tooling-0.
|
123
|
-
prediction_market_agent_tooling-0.
|
124
|
-
prediction_market_agent_tooling-0.
|
120
|
+
prediction_market_agent_tooling-0.60.0.dev408.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
121
|
+
prediction_market_agent_tooling-0.60.0.dev408.dist-info/METADATA,sha256=_g5AhhMSsCOT5zVXMNwOPIVxIZGpPhP8jTsd1CaTPpY,8636
|
122
|
+
prediction_market_agent_tooling-0.60.0.dev408.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
123
|
+
prediction_market_agent_tooling-0.60.0.dev408.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
124
|
+
prediction_market_agent_tooling-0.60.0.dev408.dist-info/RECORD,,
|
File without changes
|
File without changes
|