polymarket-apis 0.3.2__py3-none-any.whl → 0.3.3__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.
Potentially problematic release.
This version of polymarket-apis might be problematic. Click here for more details.
- polymarket_apis/__init__.py +3 -2
- polymarket_apis/clients/gamma_client.py +9 -3
- polymarket_apis/clients/web3_client.py +288 -86
- polymarket_apis/types/clob_types.py +3 -3
- polymarket_apis/types/gamma_types.py +9 -0
- polymarket_apis/utilities/constants.py +1 -1
- polymarket_apis/utilities/web3/abis/Safe.json +1138 -0
- polymarket_apis/utilities/web3/abis/SafeProxyFactory.json +224 -0
- polymarket_apis/utilities/web3/helpers.py +152 -0
- {polymarket_apis-0.3.2.dist-info → polymarket_apis-0.3.3.dist-info}/METADATA +2 -1
- {polymarket_apis-0.3.2.dist-info → polymarket_apis-0.3.3.dist-info}/RECORD +12 -10
- {polymarket_apis-0.3.2.dist-info → polymarket_apis-0.3.3.dist-info}/WHEEL +0 -0
polymarket_apis/__init__.py
CHANGED
|
@@ -10,7 +10,7 @@ This package provides a comprehensive interface to Polymarket's APIs including:
|
|
|
10
10
|
- GraphQL API for flexible data queries
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
|
-
__version__ = "0.3.
|
|
13
|
+
__version__ = "0.3.3"
|
|
14
14
|
__author__ = "Razvan Gheorghe"
|
|
15
15
|
__email__ = "razvan@gheorghe.me"
|
|
16
16
|
|
|
@@ -23,12 +23,13 @@ from .clients import (
|
|
|
23
23
|
PolymarketWeb3Client,
|
|
24
24
|
PolymarketWebsocketsClient,
|
|
25
25
|
)
|
|
26
|
-
from .types.clob_types import MarketOrderArgs, OrderArgs
|
|
26
|
+
from .types.clob_types import MarketOrderArgs, OrderArgs, OrderType
|
|
27
27
|
|
|
28
28
|
__all__ = [
|
|
29
29
|
"AsyncPolymarketGraphQLClient",
|
|
30
30
|
"MarketOrderArgs",
|
|
31
31
|
"OrderArgs",
|
|
32
|
+
"OrderType",
|
|
32
33
|
"PolymarketClobClient",
|
|
33
34
|
"PolymarketDataClient",
|
|
34
35
|
"PolymarketGammaClient",
|
|
@@ -551,7 +551,9 @@ class PolymarketGammaClient:
|
|
|
551
551
|
params["omit_empty"] = str(omit_empty).lower()
|
|
552
552
|
if status:
|
|
553
553
|
params["status"] = status
|
|
554
|
-
response = self.client.get(
|
|
554
|
+
response = self.client.get(
|
|
555
|
+
self._build_url(f"/tags/{tag_id}/related-tags"), params=params
|
|
556
|
+
)
|
|
555
557
|
response.raise_for_status()
|
|
556
558
|
return [TagRelation(**tag) for tag in response.json()]
|
|
557
559
|
|
|
@@ -566,7 +568,9 @@ class PolymarketGammaClient:
|
|
|
566
568
|
params["omit_empty"] = str(omit_empty).lower()
|
|
567
569
|
if status:
|
|
568
570
|
params["status"] = status
|
|
569
|
-
response = self.client.get(
|
|
571
|
+
response = self.client.get(
|
|
572
|
+
self._build_url(f"/tags/slug/{slug}/related-tags"), params=params
|
|
573
|
+
)
|
|
570
574
|
response.raise_for_status()
|
|
571
575
|
return [TagRelation(**tag) for tag in response.json()]
|
|
572
576
|
|
|
@@ -581,7 +585,9 @@ class PolymarketGammaClient:
|
|
|
581
585
|
params["omit_empty"] = str(omit_empty).lower()
|
|
582
586
|
if status:
|
|
583
587
|
params["status"] = status
|
|
584
|
-
response = self.client.get(
|
|
588
|
+
response = self.client.get(
|
|
589
|
+
self._build_url(f"/tags/{tag_id}/related-tags/tags"), params=params
|
|
590
|
+
)
|
|
585
591
|
response.raise_for_status()
|
|
586
592
|
return [Tag(**tag) for tag in response.json()]
|
|
587
593
|
|
|
@@ -8,9 +8,12 @@ from web3.middleware import ExtraDataToPOAMiddleware, SignAndSendRawMiddlewareBu
|
|
|
8
8
|
|
|
9
9
|
from ..types.common import EthAddress, Keccak256
|
|
10
10
|
from ..utilities.config import get_contract_config
|
|
11
|
-
from ..utilities.constants import HASH_ZERO, POLYGON
|
|
11
|
+
from ..utilities.constants import ADDRESS_ZERO, HASH_ZERO, POLYGON
|
|
12
12
|
from ..utilities.web3.abis.custom_contract_errors import CUSTOM_ERROR_DICT
|
|
13
|
-
from ..utilities.web3.helpers import
|
|
13
|
+
from ..utilities.web3.helpers import (
|
|
14
|
+
get_index_set,
|
|
15
|
+
sign_safe_transaction,
|
|
16
|
+
)
|
|
14
17
|
|
|
15
18
|
|
|
16
19
|
def _load_abi(contract_name: str) -> list:
|
|
@@ -26,7 +29,12 @@ def _load_abi(contract_name: str) -> list:
|
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
class PolymarketWeb3Client:
|
|
29
|
-
def __init__(
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
private_key: str,
|
|
35
|
+
signature_type: Literal[1, 2] = 1,
|
|
36
|
+
chain_id: Literal[137, 80002] = POLYGON,
|
|
37
|
+
):
|
|
30
38
|
self.w3 = Web3(Web3.HTTPProvider("https://polygon-rpc.com"))
|
|
31
39
|
self.w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
|
32
40
|
self.w3.middleware_onion.inject(
|
|
@@ -34,6 +42,7 @@ class PolymarketWeb3Client:
|
|
|
34
42
|
)
|
|
35
43
|
|
|
36
44
|
self.account = self.w3.eth.account.from_key(private_key)
|
|
45
|
+
self.signature_type = signature_type
|
|
37
46
|
|
|
38
47
|
self.config = get_contract_config(chain_id, neg_risk=False)
|
|
39
48
|
self.neg_risk_config = get_contract_config(chain_id, neg_risk=True)
|
|
@@ -74,6 +83,23 @@ class PolymarketWeb3Client:
|
|
|
74
83
|
self.proxy_factory_address, self.proxy_factory_abi
|
|
75
84
|
)
|
|
76
85
|
|
|
86
|
+
self.safe_proxy_factory_address = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b"
|
|
87
|
+
self.safe_proxy_factory_abi = _load_abi("SafeProxyFactory")
|
|
88
|
+
self.safe_proxy_factory = self.contract(
|
|
89
|
+
self.safe_proxy_factory_address, self.safe_proxy_factory_abi
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
match self.signature_type:
|
|
93
|
+
case 1:
|
|
94
|
+
self.proxy_address = self.get_poly_proxy_address()
|
|
95
|
+
case 2:
|
|
96
|
+
self.proxy_address = self.get_safe_proxy_address()
|
|
97
|
+
self.safe_abi = _load_abi("Safe")
|
|
98
|
+
self.safe = self.contract(self.proxy_address, self.safe_abi)
|
|
99
|
+
case _:
|
|
100
|
+
msg = "Invalid signature_type: choose 1 for Magic/Email wallet or 2 for Safe/Gnosis wallet"
|
|
101
|
+
raise ValueError(msg)
|
|
102
|
+
|
|
77
103
|
def _encode_split(self, condition_id: Keccak256, amount: int) -> str:
|
|
78
104
|
return self.conditional_tokens.encode_abi(
|
|
79
105
|
abi_element_identifier="splitPosition",
|
|
@@ -114,6 +140,16 @@ class PolymarketWeb3Client:
|
|
|
114
140
|
abi=abi,
|
|
115
141
|
)
|
|
116
142
|
|
|
143
|
+
def get_poly_proxy_address(self, address: EthAddress | None = None) -> EthAddress:
|
|
144
|
+
"""Get the polymarket proxy address for the current account."""
|
|
145
|
+
address = address if address else self.account.address
|
|
146
|
+
return self.exchange.functions.getPolyProxyWalletAddress(address).call()
|
|
147
|
+
|
|
148
|
+
def get_safe_proxy_address(self, address: EthAddress | None = None) -> EthAddress:
|
|
149
|
+
"""Get the safe proxy address for the current account."""
|
|
150
|
+
address = address if address else self.account.address
|
|
151
|
+
return self.safe_proxy_factory.functions.computeProxyAddress(address).call()
|
|
152
|
+
|
|
117
153
|
def get_usdc_balance(self, address: EthAddress | None = None) -> float:
|
|
118
154
|
"""
|
|
119
155
|
Get the usdc balance of the given address.
|
|
@@ -123,9 +159,7 @@ class PolymarketWeb3Client:
|
|
|
123
159
|
Explicitly passing the proxy address is faster due to only one contract function call.
|
|
124
160
|
"""
|
|
125
161
|
if address is None:
|
|
126
|
-
address = self.
|
|
127
|
-
self.account.address
|
|
128
|
-
).call()
|
|
162
|
+
address = self.get_poly_proxy_address()
|
|
129
163
|
balance_res = self.usdc.functions.balanceOf(address).call()
|
|
130
164
|
return float(balance_res / 1e6)
|
|
131
165
|
|
|
@@ -133,10 +167,15 @@ class PolymarketWeb3Client:
|
|
|
133
167
|
self, token_id: str, address: EthAddress | None = None
|
|
134
168
|
) -> float:
|
|
135
169
|
"""Get the token balance of the given address."""
|
|
136
|
-
if address
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
170
|
+
if not address:
|
|
171
|
+
match self.signature_type:
|
|
172
|
+
case 1:
|
|
173
|
+
address = self.get_poly_proxy_address(self.account.address)
|
|
174
|
+
case 2:
|
|
175
|
+
address = self.get_safe_proxy_address(self.account.address)
|
|
176
|
+
case _:
|
|
177
|
+
msg = "Invalid signature_type: choose 1 for Magic/Email wallet or 2 for Safe/Gnosis wallet"
|
|
178
|
+
raise ValueError(msg)
|
|
140
179
|
balance_res = self.conditional_tokens.functions.balanceOf(
|
|
141
180
|
address, int(token_id)
|
|
142
181
|
).call()
|
|
@@ -178,34 +217,75 @@ class PolymarketWeb3Client:
|
|
|
178
217
|
self, condition_id: Keccak256, amount: int, neg_risk: bool = True
|
|
179
218
|
):
|
|
180
219
|
"""Splits usdc into two complementary positions of equal size."""
|
|
181
|
-
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
182
220
|
amount = int(amount * 1e6)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
"to": self.neg_risk_adapter_address
|
|
221
|
+
data = self._encode_split(condition_id, amount)
|
|
222
|
+
to = (
|
|
223
|
+
self.neg_risk_adapter_address
|
|
187
224
|
if neg_risk
|
|
188
|
-
else self.conditional_tokens_address
|
|
189
|
-
"value": 0,
|
|
190
|
-
"data": self._encode_split(condition_id, amount),
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
# Send transaction through proxy factory
|
|
194
|
-
txn_data = self.proxy_factory.functions.proxy([proxy_txn]).build_transaction(
|
|
195
|
-
{
|
|
196
|
-
"nonce": nonce,
|
|
197
|
-
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
198
|
-
"gas": 1000000,
|
|
199
|
-
"from": self.account.address,
|
|
200
|
-
}
|
|
225
|
+
else self.conditional_tokens_address
|
|
201
226
|
)
|
|
202
227
|
|
|
228
|
+
match self.signature_type:
|
|
229
|
+
case 1:
|
|
230
|
+
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
231
|
+
proxy_txn = {
|
|
232
|
+
"typeCode": 1,
|
|
233
|
+
"to": to,
|
|
234
|
+
"value": 0,
|
|
235
|
+
"data": data,
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
txn_data = self.proxy_factory.functions.proxy(
|
|
239
|
+
[proxy_txn]
|
|
240
|
+
).build_transaction(
|
|
241
|
+
{
|
|
242
|
+
"nonce": nonce,
|
|
243
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
244
|
+
"gas": 1000000,
|
|
245
|
+
"from": self.account.address,
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
case 2:
|
|
249
|
+
nonce = self.safe.functions.nonce().call()
|
|
250
|
+
safe_txn = {
|
|
251
|
+
"to": to,
|
|
252
|
+
"data": data,
|
|
253
|
+
"operation": 0, # 1 for delegatecall, 0 for call
|
|
254
|
+
"value": 0,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
packed_sig = sign_safe_transaction(
|
|
258
|
+
self.account, self.safe, safe_txn, nonce
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
txn_data = self.safe.functions.execTransaction(
|
|
262
|
+
safe_txn["to"],
|
|
263
|
+
safe_txn["value"],
|
|
264
|
+
safe_txn["data"],
|
|
265
|
+
safe_txn.get("operation", 0),
|
|
266
|
+
0, # safeTxGas
|
|
267
|
+
0, # baseGas
|
|
268
|
+
0, # gasPrice
|
|
269
|
+
ADDRESS_ZERO, # gasToken
|
|
270
|
+
ADDRESS_ZERO, # refundReceiver
|
|
271
|
+
packed_sig,
|
|
272
|
+
).build_transaction(
|
|
273
|
+
{
|
|
274
|
+
"nonce": self.w3.eth.get_transaction_count(
|
|
275
|
+
self.account.address
|
|
276
|
+
),
|
|
277
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
278
|
+
"gas": 1000000,
|
|
279
|
+
"from": self.account.address,
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
|
|
203
283
|
# Sign and send transaction
|
|
204
284
|
signed_txn = self.account.sign_transaction(txn_data)
|
|
205
285
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
206
286
|
tx_hash_hex = tx_hash.hex()
|
|
207
287
|
|
|
208
|
-
print(f"Txn hash: {tx_hash_hex}")
|
|
288
|
+
print(f"Txn hash: 0x{tx_hash_hex}")
|
|
209
289
|
|
|
210
290
|
# Wait for transaction to be mined
|
|
211
291
|
self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
@@ -216,34 +296,74 @@ class PolymarketWeb3Client:
|
|
|
216
296
|
self, condition_id: Keccak256, amount: int, neg_risk: bool = True
|
|
217
297
|
):
|
|
218
298
|
"""Merges two complementary positions into usdc."""
|
|
219
|
-
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
220
299
|
amount = int(amount * 1e6)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"to": self.neg_risk_adapter_address
|
|
300
|
+
data = self._encode_merge(condition_id, amount)
|
|
301
|
+
to = (
|
|
302
|
+
self.neg_risk_adapter_address
|
|
225
303
|
if neg_risk
|
|
226
|
-
else self.conditional_tokens_address
|
|
227
|
-
"value": 0,
|
|
228
|
-
"data": self._encode_merge(condition_id, amount),
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
# Send transaction through proxy factory
|
|
232
|
-
txn_data = self.proxy_factory.functions.proxy([proxy_txn]).build_transaction(
|
|
233
|
-
{
|
|
234
|
-
"nonce": nonce,
|
|
235
|
-
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
236
|
-
"gas": 1000000,
|
|
237
|
-
"from": self.account.address,
|
|
238
|
-
}
|
|
304
|
+
else self.conditional_tokens_address
|
|
239
305
|
)
|
|
240
306
|
|
|
307
|
+
match self.signature_type:
|
|
308
|
+
case 1:
|
|
309
|
+
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
310
|
+
proxy_txn = {
|
|
311
|
+
"typeCode": 1,
|
|
312
|
+
"to": to,
|
|
313
|
+
"value": 0,
|
|
314
|
+
"data": data,
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
txn_data = self.proxy_factory.functions.proxy(
|
|
318
|
+
[proxy_txn]
|
|
319
|
+
).build_transaction(
|
|
320
|
+
{
|
|
321
|
+
"nonce": nonce,
|
|
322
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
323
|
+
"gas": 1000000,
|
|
324
|
+
"from": self.account.address,
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
case 2:
|
|
328
|
+
nonce = self.safe.functions.nonce().call()
|
|
329
|
+
safe_txn = {
|
|
330
|
+
"to": to,
|
|
331
|
+
"data": data,
|
|
332
|
+
"operation": 0, # 1 for delegatecall, 0 for call
|
|
333
|
+
"value": 0,
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
packed_sig = sign_safe_transaction(
|
|
337
|
+
self.account, self.safe, safe_txn, nonce
|
|
338
|
+
)
|
|
339
|
+
txn_data = self.safe.functions.execTransaction(
|
|
340
|
+
safe_txn["to"],
|
|
341
|
+
safe_txn["value"],
|
|
342
|
+
safe_txn["data"],
|
|
343
|
+
safe_txn.get("operation", 0),
|
|
344
|
+
0, # safeTxGas
|
|
345
|
+
0, # baseGas
|
|
346
|
+
0, # gasPrice
|
|
347
|
+
ADDRESS_ZERO, # gasToken
|
|
348
|
+
ADDRESS_ZERO, # refundReceiver
|
|
349
|
+
packed_sig,
|
|
350
|
+
).build_transaction(
|
|
351
|
+
{
|
|
352
|
+
"nonce": self.w3.eth.get_transaction_count(
|
|
353
|
+
self.account.address
|
|
354
|
+
),
|
|
355
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
356
|
+
"gas": 1000000,
|
|
357
|
+
"from": self.account.address,
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
|
|
241
361
|
# Sign and send transaction
|
|
242
362
|
signed_txn = self.account.sign_transaction(txn_data)
|
|
243
363
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
244
364
|
tx_hash_hex = tx_hash.hex()
|
|
245
365
|
|
|
246
|
-
print(f"Txn hash: {tx_hash_hex}")
|
|
366
|
+
print(f"Txn hash: 0x{tx_hash_hex}")
|
|
247
367
|
|
|
248
368
|
# Wait for transaction to be mined
|
|
249
369
|
self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
@@ -260,36 +380,78 @@ class PolymarketWeb3Client:
|
|
|
260
380
|
where x is the number of shares of the first outcome
|
|
261
381
|
y is the number of shares of the second outcome.
|
|
262
382
|
"""
|
|
263
|
-
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
264
383
|
amounts = [int(amount * 1e6) for amount in amounts]
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
"typeCode": 1,
|
|
268
|
-
"to": self.neg_risk_adapter_address
|
|
384
|
+
data = (
|
|
385
|
+
self._encode_redeem_neg_risk(condition_id, amounts)
|
|
269
386
|
if neg_risk
|
|
270
|
-
else self.
|
|
271
|
-
|
|
272
|
-
|
|
387
|
+
else self._encode_redeem(condition_id)
|
|
388
|
+
)
|
|
389
|
+
to = (
|
|
390
|
+
self.neg_risk_adapter_address
|
|
273
391
|
if neg_risk
|
|
274
|
-
else self.
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
# Send transaction through proxy factory
|
|
278
|
-
txn_data = self.proxy_factory.functions.proxy([proxy_txn]).build_transaction(
|
|
279
|
-
{
|
|
280
|
-
"nonce": nonce,
|
|
281
|
-
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
282
|
-
"gas": 1000000,
|
|
283
|
-
"from": self.account.address,
|
|
284
|
-
}
|
|
392
|
+
else self.conditional_tokens_address
|
|
285
393
|
)
|
|
286
394
|
|
|
395
|
+
match self.signature_type:
|
|
396
|
+
case 1:
|
|
397
|
+
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
398
|
+
proxy_txn = {
|
|
399
|
+
"typeCode": 1,
|
|
400
|
+
"to": to,
|
|
401
|
+
"value": 0,
|
|
402
|
+
"data": data,
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
txn_data = self.proxy_factory.functions.proxy(
|
|
406
|
+
[proxy_txn]
|
|
407
|
+
).build_transaction(
|
|
408
|
+
{
|
|
409
|
+
"nonce": nonce,
|
|
410
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
411
|
+
"gas": 1000000,
|
|
412
|
+
"from": self.account.address,
|
|
413
|
+
}
|
|
414
|
+
)
|
|
415
|
+
case 2:
|
|
416
|
+
nonce = self.safe.functions.nonce().call()
|
|
417
|
+
safe_txn = {
|
|
418
|
+
"to": to,
|
|
419
|
+
"data": data,
|
|
420
|
+
"operation": 0, # 1 for delegatecall, 0 for call
|
|
421
|
+
"value": 0,
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
packed_sig = sign_safe_transaction(
|
|
425
|
+
self.account, self.safe, safe_txn, nonce
|
|
426
|
+
)
|
|
427
|
+
txn_data = self.safe.functions.execTransaction(
|
|
428
|
+
safe_txn["to"],
|
|
429
|
+
safe_txn["value"],
|
|
430
|
+
safe_txn["data"],
|
|
431
|
+
safe_txn.get("operation", 0),
|
|
432
|
+
0, # safeTxGas
|
|
433
|
+
0, # baseGas
|
|
434
|
+
0, # gasPrice
|
|
435
|
+
ADDRESS_ZERO, # gasToken
|
|
436
|
+
ADDRESS_ZERO, # refundReceiver
|
|
437
|
+
packed_sig,
|
|
438
|
+
).build_transaction(
|
|
439
|
+
{
|
|
440
|
+
"nonce": self.w3.eth.get_transaction_count(
|
|
441
|
+
self.account.address
|
|
442
|
+
),
|
|
443
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
444
|
+
"gas": 1000000,
|
|
445
|
+
"from": self.account.address,
|
|
446
|
+
}
|
|
447
|
+
)
|
|
448
|
+
|
|
287
449
|
# Sign and send transaction
|
|
288
450
|
signed_txn = self.account.sign_transaction(txn_data)
|
|
289
451
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
290
452
|
tx_hash_hex = tx_hash.hex()
|
|
291
453
|
|
|
292
|
-
print(f"Txn hash: {tx_hash_hex}")
|
|
454
|
+
print(f"Txn hash: 0x{tx_hash_hex}")
|
|
293
455
|
|
|
294
456
|
# Wait for transaction to be mined
|
|
295
457
|
self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
@@ -301,31 +463,71 @@ class PolymarketWeb3Client:
|
|
|
301
463
|
):
|
|
302
464
|
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
303
465
|
amount = int(amount * 1e6)
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
"typeCode": 1,
|
|
307
|
-
"to": self.neg_risk_adapter_address,
|
|
308
|
-
"value": 0,
|
|
309
|
-
"data": self._encode_convert(
|
|
310
|
-
neg_risk_market_id, get_index_set(question_ids), amount
|
|
311
|
-
),
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
txn_data = self.proxy_factory.functions.proxy([proxy_txn]).build_transaction(
|
|
315
|
-
{
|
|
316
|
-
"nonce": nonce,
|
|
317
|
-
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
318
|
-
"gas": 1000000,
|
|
319
|
-
"from": self.account.address,
|
|
320
|
-
}
|
|
466
|
+
data = self._encode_convert(
|
|
467
|
+
neg_risk_market_id, get_index_set(question_ids), amount
|
|
321
468
|
)
|
|
469
|
+
to = self.neg_risk_adapter_address
|
|
470
|
+
|
|
471
|
+
match self.signature_type:
|
|
472
|
+
case 1:
|
|
473
|
+
nonce = self.w3.eth.get_transaction_count(self.account.address)
|
|
474
|
+
proxy_txn = {
|
|
475
|
+
"typeCode": 1,
|
|
476
|
+
"to": to,
|
|
477
|
+
"value": 0,
|
|
478
|
+
"data": data,
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
txn_data = self.proxy_factory.functions.proxy(
|
|
482
|
+
[proxy_txn]
|
|
483
|
+
).build_transaction(
|
|
484
|
+
{
|
|
485
|
+
"nonce": nonce,
|
|
486
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
487
|
+
"gas": 1000000,
|
|
488
|
+
"from": self.account.address,
|
|
489
|
+
}
|
|
490
|
+
)
|
|
491
|
+
case 2:
|
|
492
|
+
nonce = self.safe.functions.nonce().call()
|
|
493
|
+
safe_txn = {
|
|
494
|
+
"to": to,
|
|
495
|
+
"data": data,
|
|
496
|
+
"operation": 0, # 1 for delegatecall, 0 for call
|
|
497
|
+
"value": 0,
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
packed_sig = sign_safe_transaction(
|
|
501
|
+
self.account, self.safe, safe_txn, nonce
|
|
502
|
+
)
|
|
503
|
+
txn_data = self.safe.functions.execTransaction(
|
|
504
|
+
safe_txn["to"],
|
|
505
|
+
safe_txn["value"],
|
|
506
|
+
safe_txn["data"],
|
|
507
|
+
safe_txn.get("operation", 0),
|
|
508
|
+
0, # safeTxGas
|
|
509
|
+
0, # baseGas
|
|
510
|
+
0, # gasPrice
|
|
511
|
+
ADDRESS_ZERO, # gasToken
|
|
512
|
+
ADDRESS_ZERO, # refundReceiver
|
|
513
|
+
packed_sig,
|
|
514
|
+
).build_transaction(
|
|
515
|
+
{
|
|
516
|
+
"nonce": self.w3.eth.get_transaction_count(
|
|
517
|
+
self.account.address
|
|
518
|
+
),
|
|
519
|
+
"gasPrice": int(1.05 * self.w3.eth.gas_price),
|
|
520
|
+
"gas": 1000000,
|
|
521
|
+
"from": self.account.address,
|
|
522
|
+
}
|
|
523
|
+
)
|
|
322
524
|
|
|
323
525
|
# Sign and send transaction
|
|
324
526
|
signed_txn = self.account.sign_transaction(txn_data)
|
|
325
527
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
326
528
|
tx_hash_hex = tx_hash.hex()
|
|
327
529
|
|
|
328
|
-
print(f"Txn hash: {tx_hash_hex}")
|
|
530
|
+
print(f"Txn hash: 0x{tx_hash_hex}")
|
|
329
531
|
|
|
330
532
|
# Wait for transaction to be mined
|
|
331
533
|
self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
@@ -17,7 +17,7 @@ from pydantic import (
|
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
from ..types.common import EthAddress, Keccak256, TimeseriesPoint
|
|
20
|
-
from ..utilities.constants import
|
|
20
|
+
from ..utilities.constants import ADDRESS_ZERO
|
|
21
21
|
|
|
22
22
|
logger = logging.getLogger(__name__)
|
|
23
23
|
|
|
@@ -428,7 +428,7 @@ class OrderArgs(BaseModel):
|
|
|
428
428
|
Timestamp after which the order is expired.
|
|
429
429
|
"""
|
|
430
430
|
|
|
431
|
-
taker: str =
|
|
431
|
+
taker: str = ADDRESS_ZERO
|
|
432
432
|
"""
|
|
433
433
|
Address of the order taker. The zero address is used to indicate a public order.
|
|
434
434
|
"""
|
|
@@ -466,7 +466,7 @@ class MarketOrderArgs(BaseModel):
|
|
|
466
466
|
Nonce used for onchain cancellations.
|
|
467
467
|
"""
|
|
468
468
|
|
|
469
|
-
taker: str =
|
|
469
|
+
taker: str = ADDRESS_ZERO
|
|
470
470
|
"""
|
|
471
471
|
Address of the order taker. The zero address is used to indicate a public order.
|
|
472
472
|
"""
|
|
@@ -189,6 +189,14 @@ class GammaMarket(BaseModel):
|
|
|
189
189
|
rfq_enabled: Optional[bool] = Field(None, alias="rfqEnabled")
|
|
190
190
|
event_start_time: Optional[datetime] = Field(None, alias="eventStartTime")
|
|
191
191
|
clob_rewards: Optional[list[ClobReward]] = Field(None, alias="clobRewards")
|
|
192
|
+
submitted_by: Optional[str] = None
|
|
193
|
+
approved: Optional[bool] = None
|
|
194
|
+
pager_duty_notification_enabled: Optional[bool] = Field(
|
|
195
|
+
None, alias="pagerDutyNotificationEnabled"
|
|
196
|
+
)
|
|
197
|
+
holding_rewards_enabled: Optional[bool] = Field(None, alias="holdingRewardsEnabled")
|
|
198
|
+
fees_enabled: Optional[bool] = Field(None, alias="feesEnabled")
|
|
199
|
+
cyom: Optional[bool] = Field(None, alias="cyom")
|
|
192
200
|
|
|
193
201
|
@field_validator("condition_id", mode="wrap")
|
|
194
202
|
@classmethod
|
|
@@ -487,6 +495,7 @@ class Event(BaseModel):
|
|
|
487
495
|
liquidity_amm: Optional[float] = Field(None, alias="liquidityAmm")
|
|
488
496
|
liquidity_clob: Optional[float] = Field(None, alias="liquidityClob")
|
|
489
497
|
neg_risk: Optional[bool] = Field(None, alias="negRisk")
|
|
498
|
+
neg_risk_augmented: Optional[bool] = Field(None, alias="negRiskAugmented")
|
|
490
499
|
neg_risk_market_id: Optional[str] = Field(None, alias="negRiskMarketID")
|
|
491
500
|
neg_risk_fee_bips: Optional[int] = Field(None, alias="negRiskFeeBips")
|
|
492
501
|
comment_count: Optional[int] = Field(None, alias="commentCount")
|
|
@@ -14,7 +14,7 @@ L1_AUTH_UNAVAILABLE = "A private key is needed to interact with this endpoint!"
|
|
|
14
14
|
|
|
15
15
|
L2_AUTH_UNAVAILABLE = "API Credentials are needed to interact with this endpoint!"
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"
|
|
18
18
|
HASH_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
19
19
|
|
|
20
20
|
AMOY = 80002
|