polymarket-apis 0.3.1__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/clob_client.py +4 -4
- polymarket_apis/clients/data_client.py +105 -15
- polymarket_apis/clients/gamma_client.py +520 -50
- polymarket_apis/clients/web3_client.py +288 -86
- polymarket_apis/types/__init__.py +9 -37
- polymarket_apis/types/clob_types.py +3 -3
- polymarket_apis/types/common.py +13 -32
- polymarket_apis/types/data_types.py +11 -1
- polymarket_apis/types/gamma_types.py +517 -264
- polymarket_apis/types/websockets_types.py +1 -29
- 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.1.dist-info → polymarket_apis-0.3.3.dist-info}/METADATA +30 -3
- {polymarket_apis-0.3.1.dist-info → polymarket_apis-0.3.3.dist-info}/RECORD +18 -16
- {polymarket_apis-0.3.1.dist-info → polymarket_apis-0.3.3.dist-info}/WHEEL +0 -0
|
@@ -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)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# python
|
|
1
2
|
"""
|
|
2
3
|
Type definitions for Polymarket APIs.
|
|
3
4
|
|
|
@@ -29,9 +30,7 @@ from .clob_types import (
|
|
|
29
30
|
PostOrdersArgs,
|
|
30
31
|
Price,
|
|
31
32
|
PriceHistory,
|
|
32
|
-
RequestArgs,
|
|
33
33
|
RewardMarket,
|
|
34
|
-
RoundConfig,
|
|
35
34
|
Spread,
|
|
36
35
|
TickSize,
|
|
37
36
|
Token,
|
|
@@ -40,7 +39,13 @@ from .clob_types import (
|
|
|
40
39
|
TokenValue,
|
|
41
40
|
TokenValueDict,
|
|
42
41
|
)
|
|
43
|
-
from .common import
|
|
42
|
+
from .common import (
|
|
43
|
+
EmptyString,
|
|
44
|
+
EthAddress,
|
|
45
|
+
FlexibleDatetime,
|
|
46
|
+
Keccak256,
|
|
47
|
+
TimeseriesPoint,
|
|
48
|
+
)
|
|
44
49
|
from .data_types import (
|
|
45
50
|
Activity,
|
|
46
51
|
Holder,
|
|
@@ -55,29 +60,19 @@ from .data_types import (
|
|
|
55
60
|
from .gamma_types import (
|
|
56
61
|
ClobReward,
|
|
57
62
|
Event,
|
|
58
|
-
EventList,
|
|
59
63
|
GammaMarket,
|
|
60
64
|
Pagination,
|
|
61
|
-
QueryEvent,
|
|
62
|
-
QueryMarket,
|
|
63
65
|
Series,
|
|
64
66
|
Tag,
|
|
65
67
|
)
|
|
66
68
|
from .websockets_types import (
|
|
67
69
|
ActivityOrderMatchEvent,
|
|
68
|
-
ActivityTrade,
|
|
69
70
|
ActivityTradeEvent,
|
|
70
|
-
AggOrderBookSummary,
|
|
71
|
-
Comment,
|
|
72
71
|
CommentEvent,
|
|
73
|
-
CryptoPriceSubscribe,
|
|
74
72
|
CryptoPriceSubscribeEvent,
|
|
75
|
-
CryptoPriceUpdate,
|
|
76
73
|
CryptoPriceUpdateEvent,
|
|
77
74
|
ErrorEvent,
|
|
78
|
-
LastTradePrice,
|
|
79
75
|
LastTradePriceEvent,
|
|
80
|
-
LiveDataClobMarket,
|
|
81
76
|
LiveDataLastTradePriceEvent,
|
|
82
77
|
LiveDataOrderBookSummaryEvent,
|
|
83
78
|
LiveDataOrderEvent,
|
|
@@ -87,16 +82,10 @@ from .websockets_types import (
|
|
|
87
82
|
MarketStatusChangeEvent,
|
|
88
83
|
OrderBookSummaryEvent,
|
|
89
84
|
OrderEvent,
|
|
90
|
-
PriceChange,
|
|
91
85
|
PriceChangeEvent,
|
|
92
|
-
PriceChanges,
|
|
93
|
-
Quote,
|
|
94
86
|
QuoteEvent,
|
|
95
|
-
Reaction,
|
|
96
87
|
ReactionEvent,
|
|
97
|
-
Request,
|
|
98
88
|
RequestEvent,
|
|
99
|
-
TickSizeChange,
|
|
100
89
|
TickSizeChangeEvent,
|
|
101
90
|
TradeEvent,
|
|
102
91
|
)
|
|
@@ -104,36 +93,29 @@ from .websockets_types import (
|
|
|
104
93
|
__all__ = [
|
|
105
94
|
"Activity",
|
|
106
95
|
"ActivityOrderMatchEvent",
|
|
107
|
-
"ActivityTrade",
|
|
108
96
|
"ActivityTradeEvent",
|
|
109
|
-
"AggOrderBookSummary",
|
|
110
97
|
"ApiCreds",
|
|
111
98
|
"AssetType",
|
|
112
99
|
"BidAsk",
|
|
113
100
|
"BookParams",
|
|
114
101
|
"ClobMarket",
|
|
115
102
|
"ClobReward",
|
|
116
|
-
"Comment",
|
|
117
103
|
"CommentEvent",
|
|
118
104
|
"ContractConfig",
|
|
119
105
|
"CreateOrderOptions",
|
|
120
|
-
"CryptoPriceSubscribe",
|
|
121
106
|
"CryptoPriceSubscribeEvent",
|
|
122
|
-
"CryptoPriceUpdate",
|
|
123
107
|
"CryptoPriceUpdateEvent",
|
|
124
108
|
"DailyEarnedReward",
|
|
125
109
|
"EmptyString",
|
|
126
110
|
"ErrorEvent",
|
|
127
111
|
"EthAddress",
|
|
128
112
|
"Event",
|
|
129
|
-
"
|
|
113
|
+
"FlexibleDatetime",
|
|
130
114
|
"GammaMarket",
|
|
131
115
|
"Holder",
|
|
132
116
|
"HolderResponse",
|
|
133
117
|
"Keccak256",
|
|
134
|
-
"LastTradePrice",
|
|
135
118
|
"LastTradePriceEvent",
|
|
136
|
-
"LiveDataClobMarket",
|
|
137
119
|
"LiveDataLastTradePriceEvent",
|
|
138
120
|
"LiveDataOrderBookSummaryEvent",
|
|
139
121
|
"LiveDataOrderEvent",
|
|
@@ -159,26 +141,16 @@ __all__ = [
|
|
|
159
141
|
"Position",
|
|
160
142
|
"PostOrdersArgs",
|
|
161
143
|
"Price",
|
|
162
|
-
"PriceChange",
|
|
163
144
|
"PriceChangeEvent",
|
|
164
|
-
"PriceChanges",
|
|
165
145
|
"PriceHistory",
|
|
166
|
-
"QueryEvent",
|
|
167
|
-
"QueryMarket",
|
|
168
|
-
"Quote",
|
|
169
146
|
"QuoteEvent",
|
|
170
|
-
"Reaction",
|
|
171
147
|
"ReactionEvent",
|
|
172
|
-
"Request",
|
|
173
|
-
"RequestArgs",
|
|
174
148
|
"RequestEvent",
|
|
175
149
|
"RewardMarket",
|
|
176
|
-
"RoundConfig",
|
|
177
150
|
"Series",
|
|
178
151
|
"Spread",
|
|
179
152
|
"Tag",
|
|
180
153
|
"TickSize",
|
|
181
|
-
"TickSizeChange",
|
|
182
154
|
"TickSizeChangeEvent",
|
|
183
155
|
"TimeseriesPoint",
|
|
184
156
|
"Token",
|
|
@@ -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
|
"""
|