prediction-market-agent-tooling 0.62.0.dev475__py3-none-any.whl → 0.62.0.dev491__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/omen.py +1 -2
- prediction_market_agent_tooling/tools/tokens/auto_deposit.py +8 -11
- prediction_market_agent_tooling/tools/tokens/auto_withdraw.py +0 -4
- prediction_market_agent_tooling/tools/tokens/usd.py +28 -12
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev491.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev491.dist-info}/RECORD +9 -9
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev491.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev491.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev491.dist-info}/entry_points.txt +0 -0
@@ -788,7 +788,7 @@ def omen_sell_outcome_tx(
|
|
788
788
|
outcome: str,
|
789
789
|
auto_withdraw: bool,
|
790
790
|
web3: Web3 | None = None,
|
791
|
-
slippage: float = 0.
|
791
|
+
slippage: float = 0.01,
|
792
792
|
) -> str:
|
793
793
|
"""
|
794
794
|
Sells the given xDai value of shares corresponding to the given outcome in
|
@@ -807,7 +807,6 @@ def omen_sell_outcome_tx(
|
|
807
807
|
else market.get_in_token(amount)
|
808
808
|
)
|
809
809
|
amount_wei = amount_token.as_wei
|
810
|
-
amount_wei = amount_wei.without_fraction(slippage)
|
811
810
|
|
812
811
|
logger.info(
|
813
812
|
f"Selling asked {amount.value=} {amount.symbol}, converted to {amount_wei.as_token.value=} {amount_wei.as_token.symbol} for {outcome=} in market {market.url=}."
|
@@ -23,7 +23,7 @@ def auto_deposit_collateral_token(
|
|
23
23
|
collateral_amount_wei_or_usd: Wei | USD,
|
24
24
|
api_keys: APIKeys,
|
25
25
|
web3: Web3 | None = None,
|
26
|
-
|
26
|
+
surplus: float = 0.01,
|
27
27
|
) -> None:
|
28
28
|
collateral_amount_wei = (
|
29
29
|
collateral_amount_wei_or_usd
|
@@ -32,8 +32,8 @@ def auto_deposit_collateral_token(
|
|
32
32
|
collateral_amount_wei_or_usd, collateral_token_contract.address
|
33
33
|
).as_wei
|
34
34
|
)
|
35
|
-
# Deposit a bit more
|
36
|
-
collateral_amount_wei = collateral_amount_wei.with_fraction(
|
35
|
+
# Deposit a bit more to cover any small changes in conversions.
|
36
|
+
collateral_amount_wei = collateral_amount_wei.with_fraction(surplus)
|
37
37
|
|
38
38
|
if isinstance(collateral_token_contract, ContractDepositableWrapperERC20BaseClass):
|
39
39
|
# In this case, we can use deposit function directly, no need to go through DEX.
|
@@ -137,14 +137,11 @@ def auto_deposit_erc20(
|
|
137
137
|
)
|
138
138
|
if not remaining_to_get_in_collateral_wei:
|
139
139
|
return
|
140
|
-
# Get of how much of the source token we need to sell in order to fill the remaining collateral amount
|
141
|
-
amount_to_sell_wei = (
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
buy_token=collateral_token_contract.address,
|
146
|
-
)
|
147
|
-
* 1.01
|
140
|
+
# Get of how much of the source token we need to sell in order to fill the remaining collateral amount.
|
141
|
+
amount_to_sell_wei = get_sell_token_amount(
|
142
|
+
remaining_to_get_in_collateral_wei,
|
143
|
+
sell_token=KEEPING_ERC20_TOKEN.address,
|
144
|
+
buy_token=collateral_token_contract.address,
|
148
145
|
)
|
149
146
|
# If we don't have enough of the source token.
|
150
147
|
if amount_to_sell_wei > ContractERC20OnGnosisChain(
|
@@ -17,11 +17,7 @@ def auto_withdraw_collateral_token(
|
|
17
17
|
amount_wei: Wei,
|
18
18
|
api_keys: APIKeys,
|
19
19
|
web3: Web3 | None = None,
|
20
|
-
slippage: float = 0.001,
|
21
20
|
) -> None:
|
22
|
-
# Small slippage as exact exchange rate constantly changes and we don't care about small differences.
|
23
|
-
amount_wei = amount_wei.without_fraction(slippage)
|
24
|
-
|
25
21
|
if not amount_wei:
|
26
22
|
logger.warning(
|
27
23
|
f"Amount to withdraw is zero, skipping withdrawal of {collateral_token_contract.symbol_cached(web3)}."
|
@@ -5,7 +5,6 @@ from prediction_market_agent_tooling.gtypes import (
|
|
5
5
|
USD,
|
6
6
|
ChecksumAddress,
|
7
7
|
CollateralToken,
|
8
|
-
OutcomeToken,
|
9
8
|
xDai,
|
10
9
|
)
|
11
10
|
from prediction_market_agent_tooling.markets.omen.omen_constants import (
|
@@ -27,23 +26,18 @@ def get_xdai_in_usd(amount: xDai) -> USD:
|
|
27
26
|
|
28
27
|
|
29
28
|
def get_usd_in_token(amount: USD, token_address: ChecksumAddress) -> CollateralToken:
|
30
|
-
rate =
|
31
|
-
return CollateralToken(amount.value
|
29
|
+
rate = get_single_usd_to_token_rate(token_address)
|
30
|
+
return CollateralToken(amount.value * rate.value)
|
32
31
|
|
33
32
|
|
34
|
-
def get_token_in_usd(
|
35
|
-
|
36
|
-
) -> USD:
|
37
|
-
rate = get_single_token_unit_to_usd_rate(token_address)
|
33
|
+
def get_token_in_usd(amount: CollateralToken, token_address: ChecksumAddress) -> USD:
|
34
|
+
rate = get_single_token_to_usd_rate(token_address)
|
38
35
|
return USD(amount.value * rate.value)
|
39
36
|
|
40
37
|
|
41
38
|
# A short cache to not spam CoW and prevent timeouts, but still have relatively fresh data.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@cached(RATE_CACHE)
|
46
|
-
def get_single_token_unit_to_usd_rate(token_address: ChecksumAddress) -> USD:
|
39
|
+
@cached(TTLCache(maxsize=100, ttl=5 * 60))
|
40
|
+
def get_single_token_to_usd_rate(token_address: ChecksumAddress) -> USD:
|
47
41
|
# (w)xDai is a stable coin against USD, so use it to estimate USD worth.
|
48
42
|
if WRAPPED_XDAI_CONTRACT_ADDRESS == token_address:
|
49
43
|
return USD(1.0)
|
@@ -61,3 +55,25 @@ def get_single_token_unit_to_usd_rate(token_address: ChecksumAddress) -> USD:
|
|
61
55
|
)
|
62
56
|
in_token = in_wei.as_token
|
63
57
|
return USD(in_token.value)
|
58
|
+
|
59
|
+
|
60
|
+
# A short cache to not spam CoW and prevent timeouts, but still have relatively fresh data.
|
61
|
+
@cached(TTLCache(maxsize=100, ttl=5 * 60))
|
62
|
+
def get_single_usd_to_token_rate(token_address: ChecksumAddress) -> CollateralToken:
|
63
|
+
# (w)xDai is a stable coin against USD, so use it to estimate USD worth.
|
64
|
+
if WRAPPED_XDAI_CONTRACT_ADDRESS == token_address:
|
65
|
+
return CollateralToken(1.0)
|
66
|
+
# sDai is ERC4626 with wxDai as asset, we can take the rate directly from there instead of calling CoW.
|
67
|
+
if SDAI_CONTRACT_ADDRESS == token_address:
|
68
|
+
return CollateralToken(
|
69
|
+
ContractERC4626OnGnosisChain(address=SDAI_CONTRACT_ADDRESS)
|
70
|
+
.convertToShares(CollateralToken(1).as_wei)
|
71
|
+
.as_token.value
|
72
|
+
)
|
73
|
+
in_wei = get_buy_token_amount(
|
74
|
+
sell_amount=CollateralToken(1).as_wei,
|
75
|
+
sell_token=WRAPPED_XDAI_CONTRACT_ADDRESS,
|
76
|
+
buy_token=token_address,
|
77
|
+
)
|
78
|
+
in_token = in_wei.as_token
|
79
|
+
return CollateralToken(in_token.value)
|
@@ -51,7 +51,7 @@ prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=FaBCTPPe
|
|
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
53
|
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=URvplDcTLeL6vfpkSgi8ln2iEKxt8w5qf6mTZkSyrCo,29189
|
54
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
54
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=_Vt1_w_A6-FHPVgNclwSh2qpABBXXTJ2wKPtcFfrDTQ,51893
|
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=bCC9A7ZTJxMDJcPbl3jof6HcAGGHv1BrFq3RRWbkQ_c,28739
|
57
57
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=Cyi9Ci-Z-K8WCZWVLs9oSuJC6qRobi_CpqDCno_5F-0,10238
|
@@ -112,16 +112,16 @@ prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0r
|
|
112
112
|
prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
|
113
113
|
prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=5ldQs1pZe6uJ5eDAuP4OLpzmcqYShlIV67kttNFvGS0,342
|
114
114
|
prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=pPs0qZNfJ7G-1ajfz0iaWOBQyiC0TbcShfrW8T39jtg,3859
|
115
|
-
prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=
|
116
|
-
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=
|
115
|
+
prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=MWIRHYCN-7o2uawEBwnBNhlzme1kLyX_5Q2zg7UIegQ,6700
|
116
|
+
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=22g0SIVmLlgITpdt3kPhJOw0sU4OPeBuYk_7xCrQr9U,2491
|
117
117
|
prediction_market_agent_tooling/tools/tokens/main_token.py,sha256=1rbwpdCusPgQIVFuo3m00nBZ_b2lCAoFVm67i-YDcEw,812
|
118
118
|
prediction_market_agent_tooling/tools/tokens/token_utils.py,sha256=zwV-jGFkPJu4-IslXOUqnsNQjzh_9CrfkruDQL0dq0c,1381
|
119
|
-
prediction_market_agent_tooling/tools/tokens/usd.py,sha256=
|
119
|
+
prediction_market_agent_tooling/tools/tokens/usd.py,sha256=l4vPemtF6Zcwh8HNXH3-L5k7OE_XolbklzBsTpFruW8,3116
|
120
120
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
121
121
|
prediction_market_agent_tooling/tools/utils.py,sha256=1xsyBBJfiEdSoMlceB2F8o2sCb6Z8-qNz11pEJFrdyE,6566
|
122
122
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=eYCc1iWAVtqDKUPTwnMUHuYolPdwh_OTiM3-AdRgDp4,12198
|
123
|
-
prediction_market_agent_tooling-0.62.0.
|
124
|
-
prediction_market_agent_tooling-0.62.0.
|
125
|
-
prediction_market_agent_tooling-0.62.0.
|
126
|
-
prediction_market_agent_tooling-0.62.0.
|
127
|
-
prediction_market_agent_tooling-0.62.0.
|
123
|
+
prediction_market_agent_tooling-0.62.0.dev491.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
124
|
+
prediction_market_agent_tooling-0.62.0.dev491.dist-info/METADATA,sha256=ke5Gwr94EoF5Ng4zCSmSZ82erv0TIiILRsXBE3IcyT8,8696
|
125
|
+
prediction_market_agent_tooling-0.62.0.dev491.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
126
|
+
prediction_market_agent_tooling-0.62.0.dev491.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
127
|
+
prediction_market_agent_tooling-0.62.0.dev491.dist-info/RECORD,,
|
File without changes
|
File without changes
|