prediction-market-agent-tooling 0.63.9__py3-none-any.whl → 0.63.10.dev566__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/gvp2_settlement.abi.json +89 -0
- prediction_market_agent_tooling/config.py +3 -2
- prediction_market_agent_tooling/markets/omen/cow_contracts.py +34 -0
- prediction_market_agent_tooling/tools/cow/cow_order.py +44 -9
- {prediction_market_agent_tooling-0.63.9.dist-info → prediction_market_agent_tooling-0.63.10.dev566.dist-info}/METADATA +2 -2
- {prediction_market_agent_tooling-0.63.9.dist-info → prediction_market_agent_tooling-0.63.10.dev566.dist-info}/RECORD +9 -7
- {prediction_market_agent_tooling-0.63.9.dist-info → prediction_market_agent_tooling-0.63.10.dev566.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.63.9.dist-info → prediction_market_agent_tooling-0.63.10.dev566.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.63.9.dist-info → prediction_market_agent_tooling-0.63.10.dev566.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"anonymous": false,
|
4
|
+
"inputs": [
|
5
|
+
{
|
6
|
+
"indexed": true,
|
7
|
+
"internalType": "address",
|
8
|
+
"name": "owner",
|
9
|
+
"type": "address"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"indexed": false,
|
13
|
+
"internalType": "contract IERC20",
|
14
|
+
"name": "sellToken",
|
15
|
+
"type": "address"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"indexed": false,
|
19
|
+
"internalType": "contract IERC20",
|
20
|
+
"name": "buyToken",
|
21
|
+
"type": "address"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"indexed": false,
|
25
|
+
"internalType": "uint256",
|
26
|
+
"name": "sellAmount",
|
27
|
+
"type": "uint256"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"indexed": false,
|
31
|
+
"internalType": "uint256",
|
32
|
+
"name": "buyAmount",
|
33
|
+
"type": "uint256"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"indexed": false,
|
37
|
+
"internalType": "uint256",
|
38
|
+
"name": "feeAmount",
|
39
|
+
"type": "uint256"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"indexed": false,
|
43
|
+
"internalType": "bytes",
|
44
|
+
"name": "orderUid",
|
45
|
+
"type": "bytes"
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"name": "Trade",
|
49
|
+
"type": "event"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"inputs": [
|
53
|
+
{
|
54
|
+
"internalType": "bytes",
|
55
|
+
"name": "orderUid",
|
56
|
+
"type": "bytes"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"internalType": "bool",
|
60
|
+
"name": "signed",
|
61
|
+
"type": "bool"
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"name": "setPreSignature",
|
65
|
+
"outputs": [],
|
66
|
+
"stateMutability": "nonpayable",
|
67
|
+
"type": "function"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"inputs": [
|
71
|
+
{
|
72
|
+
"internalType": "bytes",
|
73
|
+
"name": "orderUid",
|
74
|
+
"type": "bytes"
|
75
|
+
}
|
76
|
+
],
|
77
|
+
"name": "invalidateOrder",
|
78
|
+
"outputs": [],
|
79
|
+
"stateMutability": "nonpayable",
|
80
|
+
"type": "function"
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"inputs": [],
|
84
|
+
"name": "domainSeparator",
|
85
|
+
"outputs": [{ "name": "", "type": "bytes32" }],
|
86
|
+
"stateMutability": "nonpayable",
|
87
|
+
"type": "function"
|
88
|
+
}
|
89
|
+
]
|
@@ -3,6 +3,7 @@ import typing as t
|
|
3
3
|
from copy import deepcopy
|
4
4
|
|
5
5
|
from eth_account.signers.local import LocalAccount
|
6
|
+
from eth_typing import URI
|
6
7
|
from pydantic import Field, model_validator
|
7
8
|
from pydantic.types import SecretStr
|
8
9
|
from pydantic.v1.types import SecretStr as SecretStrV1
|
@@ -277,11 +278,11 @@ class RPCConfig(BaseSettings):
|
|
277
278
|
env_file=".env", env_file_encoding="utf-8", extra="ignore"
|
278
279
|
)
|
279
280
|
|
280
|
-
GNOSIS_RPC_URL:
|
281
|
+
GNOSIS_RPC_URL: URI = Field(default=URI("https://rpc.gnosischain.com"))
|
281
282
|
CHAIN_ID: ChainID = Field(default=ChainID(100))
|
282
283
|
|
283
284
|
@property
|
284
|
-
def gnosis_rpc_url(self) ->
|
285
|
+
def gnosis_rpc_url(self) -> URI:
|
285
286
|
return check_not_none(
|
286
287
|
self.GNOSIS_RPC_URL, "GNOSIS_RPC_URL missing in the environment."
|
287
288
|
)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from web3 import Web3
|
4
|
+
|
5
|
+
from prediction_market_agent_tooling.config import APIKeys
|
6
|
+
from prediction_market_agent_tooling.gtypes import ABI, HexBytes
|
7
|
+
from prediction_market_agent_tooling.tools.contract import (
|
8
|
+
ContractOnGnosisChain,
|
9
|
+
abi_field_validator,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
class CowGPv2SettlementContract(ContractOnGnosisChain):
|
14
|
+
# Contract ABI taken from https://github.com/cowprotocol/cow-sdk/blob/main/abi/GPv2Settlement.json.
|
15
|
+
abi: ABI = abi_field_validator(
|
16
|
+
os.path.join(
|
17
|
+
os.path.dirname(os.path.realpath(__file__)),
|
18
|
+
"../../abis/gvp2_settlement.abi.json",
|
19
|
+
)
|
20
|
+
)
|
21
|
+
|
22
|
+
def setPreSignature(
|
23
|
+
self,
|
24
|
+
api_keys: APIKeys,
|
25
|
+
orderId: HexBytes,
|
26
|
+
signed: bool,
|
27
|
+
web3: Web3 | None = None,
|
28
|
+
) -> None:
|
29
|
+
self.send(
|
30
|
+
api_keys=api_keys,
|
31
|
+
function_name="setPreSignature",
|
32
|
+
function_params=[orderId, signed],
|
33
|
+
web3=web3,
|
34
|
+
)
|
@@ -8,7 +8,7 @@ from cowdao_cowpy.common.api.errors import UnexpectedResponseError
|
|
8
8
|
from cowdao_cowpy.common.chains import Chain
|
9
9
|
from cowdao_cowpy.common.config import SupportedChainId
|
10
10
|
from cowdao_cowpy.common.constants import CowContractAddress
|
11
|
-
from cowdao_cowpy.cow.swap import get_order_quote
|
11
|
+
from cowdao_cowpy.cow.swap import CompletedOrder, get_order_quote, swap_tokens
|
12
12
|
from cowdao_cowpy.order_book.api import OrderBookApi
|
13
13
|
from cowdao_cowpy.order_book.config import Envs, OrderBookAPIConfigFactory
|
14
14
|
from cowdao_cowpy.order_book.generated.model import (
|
@@ -24,15 +24,17 @@ from cowdao_cowpy.order_book.generated.model import (
|
|
24
24
|
TokenAmount,
|
25
25
|
)
|
26
26
|
from cowdao_cowpy.subgraph.client import BaseModel
|
27
|
-
from eth_account.signers.local import LocalAccount
|
28
27
|
from tenacity import retry_if_not_exception_type, stop_after_attempt, wait_fixed
|
29
28
|
from web3 import Web3
|
30
29
|
|
31
30
|
from prediction_market_agent_tooling.config import APIKeys
|
32
|
-
from prediction_market_agent_tooling.gtypes import ChecksumAddress, Wei
|
31
|
+
from prediction_market_agent_tooling.gtypes import ChecksumAddress, HexBytes, Wei
|
33
32
|
from prediction_market_agent_tooling.loggers import logger
|
33
|
+
from prediction_market_agent_tooling.markets.omen.cow_contracts import (
|
34
|
+
CowGPv2SettlementContract,
|
35
|
+
)
|
34
36
|
from prediction_market_agent_tooling.tools.contract import ContractERC20OnGnosisChain
|
35
|
-
from prediction_market_agent_tooling.tools.utils import utcnow
|
37
|
+
from prediction_market_agent_tooling.tools.utils import check_not_none, utcnow
|
36
38
|
|
37
39
|
|
38
40
|
class MinimalisticToken(BaseModel):
|
@@ -164,8 +166,6 @@ def swap_tokens_waiting(
|
|
164
166
|
env: Envs = "prod",
|
165
167
|
web3: Web3 | None = None,
|
166
168
|
) -> OrderMetaData:
|
167
|
-
account = api_keys.get_account()
|
168
|
-
|
169
169
|
# Approve the CoW Swap Vault Relayer to get the sell token.
|
170
170
|
ContractERC20OnGnosisChain(address=sell_token).approve(
|
171
171
|
api_keys,
|
@@ -177,7 +177,7 @@ def swap_tokens_waiting(
|
|
177
177
|
# CoW library uses async, so we need to wrap the call in asyncio.run for us to use it.
|
178
178
|
return asyncio.run(
|
179
179
|
swap_tokens_waiting_async(
|
180
|
-
amount_wei, sell_token, buy_token,
|
180
|
+
amount_wei, sell_token, buy_token, api_keys, chain, env
|
181
181
|
)
|
182
182
|
)
|
183
183
|
|
@@ -186,20 +186,31 @@ async def swap_tokens_waiting_async(
|
|
186
186
|
amount_wei: Wei,
|
187
187
|
sell_token: ChecksumAddress,
|
188
188
|
buy_token: ChecksumAddress,
|
189
|
-
|
189
|
+
api_keys: APIKeys,
|
190
190
|
chain: Chain,
|
191
191
|
env: Envs,
|
192
|
-
timeout: timedelta = timedelta(seconds=
|
192
|
+
timeout: timedelta = timedelta(seconds=120),
|
193
|
+
slippage_tolerance: float = 0.01,
|
193
194
|
) -> OrderMetaData:
|
195
|
+
account = api_keys.get_account()
|
196
|
+
safe_address = api_keys.safe_address_checksum
|
197
|
+
|
194
198
|
order = await swap_tokens(
|
195
199
|
amount=amount_wei.value,
|
196
200
|
sell_token=sell_token,
|
197
201
|
buy_token=buy_token,
|
198
202
|
account=account,
|
203
|
+
safe_address=safe_address,
|
199
204
|
chain=chain,
|
200
205
|
env=env,
|
206
|
+
slippage_tolerance=slippage_tolerance,
|
201
207
|
)
|
202
208
|
logger.info(f"Order created: {order}")
|
209
|
+
|
210
|
+
if safe_address is not None:
|
211
|
+
logger.info(f"Safe is used. Signing the order after its creation.")
|
212
|
+
await sign_safe_cow_swap(api_keys, order, chain, env)
|
213
|
+
|
203
214
|
start_time = utcnow()
|
204
215
|
|
205
216
|
while True:
|
@@ -229,6 +240,30 @@ async def swap_tokens_waiting_async(
|
|
229
240
|
await asyncio.sleep(3.14)
|
230
241
|
|
231
242
|
|
243
|
+
@tenacity.retry(
|
244
|
+
stop=tenacity.stop_after_attempt(3),
|
245
|
+
wait=tenacity.wait_fixed(1),
|
246
|
+
after=lambda x: logger.debug(f"sign_safe_cow_swap failed, {x.attempt_number=}."),
|
247
|
+
)
|
248
|
+
async def sign_safe_cow_swap(
|
249
|
+
api_keys: APIKeys,
|
250
|
+
order: CompletedOrder,
|
251
|
+
chain: Chain,
|
252
|
+
env: Envs,
|
253
|
+
) -> None:
|
254
|
+
order_book_api = get_order_book_api(env, chain)
|
255
|
+
posted_order = await order_book_api.get_order_by_uid(order.uid)
|
256
|
+
CowGPv2SettlementContract(
|
257
|
+
address=Web3.to_checksum_address(
|
258
|
+
check_not_none(posted_order.settlementContract).root
|
259
|
+
)
|
260
|
+
).setPreSignature(
|
261
|
+
api_keys,
|
262
|
+
HexBytes(posted_order.uid.root),
|
263
|
+
True,
|
264
|
+
)
|
265
|
+
|
266
|
+
|
232
267
|
@tenacity.retry(
|
233
268
|
stop=stop_after_attempt(3),
|
234
269
|
wait=wait_fixed(1),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: prediction-market-agent-tooling
|
3
|
-
Version: 0.63.
|
3
|
+
Version: 0.63.10.dev566
|
4
4
|
Summary: Tools to benchmark, deploy and monitor prediction market agents.
|
5
5
|
Author: Gnosis
|
6
6
|
Requires-Python: >=3.10,<3.13
|
@@ -14,7 +14,7 @@ Provides-Extra: openai
|
|
14
14
|
Provides-Extra: optuna
|
15
15
|
Requires-Dist: autoflake (>=2.2.1,<3.0.0)
|
16
16
|
Requires-Dist: base58 (>=1.0.2,<2.0)
|
17
|
-
Requires-Dist: cowdao-cowpy (
|
17
|
+
Requires-Dist: cowdao-cowpy-kongzii (==1.0.0rc2)
|
18
18
|
Requires-Dist: cron-validator (>=1.0.8,<2.0.0)
|
19
19
|
Requires-Dist: eth-account (>=0.8.0,<0.12.0)
|
20
20
|
Requires-Dist: eth-keys (>=0.6.1,<0.7.0)
|
@@ -3,6 +3,7 @@ prediction_market_agent_tooling/abis/depositablewrapper_erc20.abi.json,sha256=m0
|
|
3
3
|
prediction_market_agent_tooling/abis/erc20.abi.json,sha256=b8t6tPUhjBo5dHFq8ipsK-ih_g29dOTbWI0GBZiEWL8,3685
|
4
4
|
prediction_market_agent_tooling/abis/erc4626.abi.json,sha256=qvmonhj3tJU5flR4pJjXCSSwB8tgEiJcx4Sc5ilQ5VY,17801
|
5
5
|
prediction_market_agent_tooling/abis/erc721.abi.json,sha256=sslrlTfLAkHA7cAJAaAHmGBSsY8_3K6jNK-2OoPUTPs,5396
|
6
|
+
prediction_market_agent_tooling/abis/gvp2_settlement.abi.json,sha256=J-OqsRqeqIo81RaT4btCGmwqBv6s7mYuTI9vWLr6Eu4,1790
|
6
7
|
prediction_market_agent_tooling/abis/omen_agentresultmapping.abi.json,sha256=TVWP5J6RO8mb1YpI-RA2iCgeCqGfrIw0OfbHngekTSs,5769
|
7
8
|
prediction_market_agent_tooling/abis/omen_dxdao.abi.json,sha256=Z1kD1QfgYfGwsZEI2UFDNEGZ4hMOix3HGICk8xlO4Ds,9578
|
8
9
|
prediction_market_agent_tooling/abis/omen_fpmm.abi.json,sha256=CDib_b5PVj4m0JBVCB20cTshiVx8st1Be-7E460qFoY,11406
|
@@ -21,7 +22,7 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
|
|
21
22
|
prediction_market_agent_tooling/benchmark/agents.py,sha256=B1-uWdyeN4GGKMWGK_-CcAFJg1m9Y_XuaeIHPB29QR8,3971
|
22
23
|
prediction_market_agent_tooling/benchmark/benchmark.py,sha256=MqTiaaJ3cYiOLUVR7OyImLWxcEya3Rl5JyFYW-K0lwM,17097
|
23
24
|
prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
|
24
|
-
prediction_market_agent_tooling/config.py,sha256=
|
25
|
+
prediction_market_agent_tooling/config.py,sha256=QWybGq-DfjlRKG2G4l_4kJEyH3pmUvmcw4n2d2-z3eQ,10183
|
25
26
|
prediction_market_agent_tooling/deploy/agent.py,sha256=tEYX133rSsZ6b9kx-RtZSHxkdN8LZvn0P6CVz6KOJlc,26531
|
26
27
|
prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
|
27
28
|
prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=p25t7VU7I4hSkSl6SpzI_W55kLbYEySQdBqeschmARY,12918
|
@@ -51,6 +52,7 @@ prediction_market_agent_tooling/markets/metaculus/api.py,sha256=4TRPGytQQbSdf42D
|
|
51
52
|
prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=FaBCTPPezXbBwZ9p791CiVgQ4vB696xnMbz9XVXmiVI,3267
|
52
53
|
prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavEWc8Cv4KpZxSvwiSw9oFybXE3YB49pg-CA,4377
|
53
54
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
|
+
prediction_market_agent_tooling/markets/omen/cow_contracts.py,sha256=sl1L4cK5nAJwZ2wdhLzqh8p7h_IEValNvLwKUlInKxw,957
|
54
56
|
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=dtWbRy9tpasssQP80ZFYxAc_9pnVD-zUpVjenBqurnA,30221
|
55
57
|
prediction_market_agent_tooling/markets/omen/omen.py,sha256=Jf2qSJJn0UUISpi24xYRwoVycGuYE42kZ2z1HRGl43w,51927
|
56
58
|
prediction_market_agent_tooling/markets/omen/omen_constants.py,sha256=D9oflYKafLQiHYtB5sScMHqmXyzM8JP8J0yATmc4SQQ,233
|
@@ -89,7 +91,7 @@ prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=ZW5iI5rmjq
|
|
89
91
|
prediction_market_agent_tooling/tools/caches/serializers.py,sha256=vFDx4fsPxclXp2q0sv27j4al_M_Tj9aR2JJP-xNHQXA,2151
|
90
92
|
prediction_market_agent_tooling/tools/contract.py,sha256=1ZFp_VoqTjM8cqOfAhco2Ht0DTqakjhZpuZUrAXr28Q,21332
|
91
93
|
prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
|
92
|
-
prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=
|
94
|
+
prediction_market_agent_tooling/tools/cow/cow_order.py,sha256=gakwBMVD287v4FrgJC-qwpc5zZHu9yLfTzcmhht-BXA,8797
|
93
95
|
prediction_market_agent_tooling/tools/custom_exceptions.py,sha256=Fh8z1fbwONvP4-j7AmV_PuEcoqb6-QXa9PJ9m7guMcM,93
|
94
96
|
prediction_market_agent_tooling/tools/datetime_utc.py,sha256=8_WackjtjC8zHXrhQFTGQ6e6Fz_6llWoKR4CSFvIv9I,2766
|
95
97
|
prediction_market_agent_tooling/tools/db/db_manager.py,sha256=GtzHH1NLl8HwqC8Z7s6eTlIQXuV0blxfaV2PeQrBnfQ,3013
|
@@ -122,8 +124,8 @@ prediction_market_agent_tooling/tools/tokens/usd.py,sha256=yuW8iPPtcpP4eLH2nORMD
|
|
122
124
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
123
125
|
prediction_market_agent_tooling/tools/utils.py,sha256=AC2a68jwASMWuQi-w8twl8b_M52YwrEJ81abmuEaqMY,6661
|
124
126
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=zRq-eeBGWt8uUGN9G_WfjmJ0eVvO8aWE9S0Pz_Y6AOA,12342
|
125
|
-
prediction_market_agent_tooling-0.63.
|
126
|
-
prediction_market_agent_tooling-0.63.
|
127
|
-
prediction_market_agent_tooling-0.63.
|
128
|
-
prediction_market_agent_tooling-0.63.
|
129
|
-
prediction_market_agent_tooling-0.63.
|
127
|
+
prediction_market_agent_tooling-0.63.10.dev566.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
128
|
+
prediction_market_agent_tooling-0.63.10.dev566.dist-info/METADATA,sha256=g4ONjybn7fFmipE1kk65OoW16MeIhsy8l3GmKOubu5U,8698
|
129
|
+
prediction_market_agent_tooling-0.63.10.dev566.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
130
|
+
prediction_market_agent_tooling-0.63.10.dev566.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
131
|
+
prediction_market_agent_tooling-0.63.10.dev566.dist-info/RECORD,,
|
File without changes
|
File without changes
|