prediction-market-agent-tooling 0.62.0.dev474__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.
@@ -725,6 +725,10 @@ def omen_buy_outcome_tx(
725
725
  amount_token = market.get_in_token(amount)
726
726
  amount_wei = amount_token.as_wei
727
727
 
728
+ logger.info(
729
+ f"Buying asked {amount.value=} {amount.symbol}, converted to {amount_token.value=} {amount_token.symbol} for {outcome=} in market {market.url=}."
730
+ )
731
+
728
732
  # Get the index of the outcome we want to buy.
729
733
  outcome_index: int = market.get_outcome_index(outcome)
730
734
 
@@ -806,7 +810,7 @@ def omen_sell_outcome_tx(
806
810
  amount_wei = amount_wei.without_fraction(slippage)
807
811
 
808
812
  logger.info(
809
- f"Selling asked {amount.value=} {amount.symbol}, converted to {amount_wei.as_token.value=} (collateral token worth) for {outcome=} in market {market.url=}."
813
+ 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=}."
810
814
  )
811
815
 
812
816
  # Verify, that markets uses conditional tokens that we expect.
@@ -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 = get_single_token_unit_to_usd_rate(token_address)
31
- return CollateralToken(amount.value / rate.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
- amount: CollateralToken | OutcomeToken, token_address: ChecksumAddress
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
- RATE_CACHE: TTLCache[ChecksumAddress, USD] = TTLCache(maxsize=100, ttl=5 * 60)
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.62.0.dev474
3
+ Version: 0.62.0.dev490
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.13
@@ -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=TNODbUHsQ8VSXH95OPOGkmZhNulWUIEWQwc7wmtb-m8,51767
54
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=L1NaKGkdCVtGVz7RbkBuHaYRyYfuYRthTxmnYWNwgeU,51949
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
@@ -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=FmQUfrkLvN8cI_6vw9QNhOXdaqYlw-DxevP39VA8hmQ,2240
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.dev474.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
124
- prediction_market_agent_tooling-0.62.0.dev474.dist-info/METADATA,sha256=10VgtMIyKALMPagmYlJ0LKO5htx9XmltcIC8tVLt6Bo,8696
125
- prediction_market_agent_tooling-0.62.0.dev474.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
126
- prediction_market_agent_tooling-0.62.0.dev474.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
127
- prediction_market_agent_tooling-0.62.0.dev474.dist-info/RECORD,,
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,,