prediction-market-agent-tooling 0.62.0.dev475__py3-none-any.whl → 0.62.0.dev490__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/tools/tokens/usd.py +28 -12
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev490.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev490.dist-info}/RECORD +6 -6
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev490.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev490.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.62.0.dev475.dist-info → prediction_market_agent_tooling-0.62.0.dev490.dist-info}/entry_points.txt +0 -0
@@ -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)
|
@@ -116,12 +116,12 @@ prediction_market_agent_tooling/tools/tokens/auto_deposit.py,sha256=ZKGJPoRhch7Q
|
|
116
116
|
prediction_market_agent_tooling/tools/tokens/auto_withdraw.py,sha256=nV9jSUt1ydceDj03cTwdyrJs8kFGqz9z6YcvTVUaNg4,2682
|
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.dev490.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
124
|
+
prediction_market_agent_tooling-0.62.0.dev490.dist-info/METADATA,sha256=QXEPne_UD36t4P1ZD9N0bTdv8U0DceB4xBtDnrwjmz4,8696
|
125
|
+
prediction_market_agent_tooling-0.62.0.dev490.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
126
|
+
prediction_market_agent_tooling-0.62.0.dev490.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
127
|
+
prediction_market_agent_tooling-0.62.0.dev490.dist-info/RECORD,,
|
File without changes
|
File without changes
|