eth-prototype 1.1.0__py3-none-any.whl → 1.2.0b1__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.
- {eth_prototype-1.1.0.dist-info → eth_prototype-1.2.0b1.dist-info}/METADATA +3 -3
- eth_prototype-1.2.0b1.dist-info/RECORD +14 -0
- {eth_prototype-1.1.0.dist-info → eth_prototype-1.2.0b1.dist-info}/WHEEL +1 -1
- ethproto/aa_bundler.py +38 -19
- ethproto/w3wrappers.py +9 -7
- eth_prototype-1.1.0.dist-info/RECORD +0 -14
- {eth_prototype-1.1.0.dist-info → eth_prototype-1.2.0b1.dist-info}/AUTHORS.rst +0 -0
- {eth_prototype-1.1.0.dist-info → eth_prototype-1.2.0b1.dist-info}/LICENSE.txt +0 -0
- {eth_prototype-1.1.0.dist-info → eth_prototype-1.2.0b1.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: eth-prototype
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.2.0b1
|
4
4
|
Summary: Prototype Ethereum Smart Contracts in Python
|
5
5
|
Home-page: https://github.com/gnarvaja/eth-prototype
|
6
6
|
Author: Guillermo M. Narvaja
|
@@ -28,10 +28,10 @@ Requires-Dist: setuptools; extra == "testing"
|
|
28
28
|
Requires-Dist: pytest; extra == "testing"
|
29
29
|
Requires-Dist: gmpy2; extra == "testing"
|
30
30
|
Requires-Dist: pytest-cov; extra == "testing"
|
31
|
-
Requires-Dist: web3[tester]==
|
31
|
+
Requires-Dist: web3[tester]==7.*; extra == "testing"
|
32
32
|
Requires-Dist: boto3; extra == "testing"
|
33
33
|
Provides-Extra: web3
|
34
|
-
Requires-Dist: web3==
|
34
|
+
Requires-Dist: web3==7.*; extra == "web3"
|
35
35
|
|
36
36
|
# eth-prototype
|
37
37
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
ethproto/__init__.py,sha256=YWkAFysBp4tZjLWWB2FFmp5yG23pUYhQvgQW9b3soXs,579
|
2
|
+
ethproto/aa_bundler.py,sha256=R4P3o6Cmt05StuVsReMRlhpSTzsGSEhj0Mcfy8HqFv8,9460
|
3
|
+
ethproto/build_artifacts.py,sha256=xwCd5hJUHP82IA-y3sSfX6fV15kjCGtV19RxNRcoor0,5441
|
4
|
+
ethproto/contracts.py,sha256=rNVbCK1hURy7lWKhzSdXgVWo3wx9O_Ghk-6PfgOsRNk,18662
|
5
|
+
ethproto/defender_relay.py,sha256=05A8TfRZwiBhCpo924Pf9CjfKSir2Wvgg1p_asFxJbw,1777
|
6
|
+
ethproto/w3wrappers.py,sha256=fEkqvzWFCHirUsfQqyoqsrpDlNfMIgBBik3yTFws8Is,21260
|
7
|
+
ethproto/wadray.py,sha256=JBsu5KcyU9k70bDK03T2IY6qPVFO30WbYPhwrAHdXao,8262
|
8
|
+
ethproto/wrappers.py,sha256=9qDwRDOXw3wquzvGfIsub-VPWm98GBWP7dHLFOUPWzg,17307
|
9
|
+
eth_prototype-1.2.0b1.dist-info/AUTHORS.rst,sha256=Ui-05yYXtDZxna6o1yNcfdm8Jt68UIDQ01osiLxlYlU,95
|
10
|
+
eth_prototype-1.2.0b1.dist-info/LICENSE.txt,sha256=U_Q6_nDYDwZPIuhttHi37hXZ2qU2-HlV2geo9hzHXFw,1087
|
11
|
+
eth_prototype-1.2.0b1.dist-info/METADATA,sha256=hz3CfguoZtt1YZck0PhTaVDAcTeX2dlk4MBvcwLobWY,2484
|
12
|
+
eth_prototype-1.2.0b1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
13
|
+
eth_prototype-1.2.0b1.dist-info/top_level.txt,sha256=Dl0X7m6N1hxeo4JpGpSNqWC2gtsN0731g-DL1J0mpjc,9
|
14
|
+
eth_prototype-1.2.0b1.dist-info/RECORD,,
|
ethproto/aa_bundler.py
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
import random
|
2
|
-
from warnings import warn
|
3
2
|
from enum import Enum
|
4
|
-
import
|
3
|
+
from warnings import warn
|
4
|
+
|
5
5
|
from environs import Env
|
6
6
|
from eth_abi import encode
|
7
7
|
from eth_account import Account
|
8
8
|
from eth_account.messages import encode_defunct
|
9
|
+
from eth_utils import add_0x_prefix
|
9
10
|
from hexbytes import HexBytes
|
10
11
|
from web3 import Web3
|
11
|
-
from .
|
12
|
+
from web3.constants import ADDRESS_ZERO
|
12
13
|
|
14
|
+
from .contracts import RevertError
|
13
15
|
|
14
16
|
env = Env()
|
15
17
|
|
@@ -17,6 +19,9 @@ AA_BUNDLER_SENDER = env.str("AA_BUNDLER_SENDER", None)
|
|
17
19
|
AA_BUNDLER_ENTRYPOINT = env.str("AA_BUNDLER_ENTRYPOINT", "0x0000000071727De22E5E9d8BAf0edAc6f37da032")
|
18
20
|
AA_BUNDLER_EXECUTOR_PK = env.str("AA_BUNDLER_EXECUTOR_PK", None)
|
19
21
|
AA_BUNDLER_PROVIDER = env.str("AA_BUNDLER_PROVIDER", "alchemy")
|
22
|
+
AA_BUNDLER_GAS_LIMIT_FACTOR = env.float("AA_BUNDLER_GAS_LIMIT_FACTOR", 1)
|
23
|
+
AA_BUNDLER_PRIORITY_GAS_PRICE_FACTOR = env.float("AA_BUNDLER_PRIORITY_GAS_PRICE_FACTOR", 1)
|
24
|
+
AA_BUNDLER_BASE_GAS_PRICE_FACTOR = env.float("AA_BUNDLER_BASE_GAS_PRICE_FACTOR", 1)
|
20
25
|
|
21
26
|
NonceMode = Enum(
|
22
27
|
"NonceMode",
|
@@ -51,8 +56,8 @@ RANDOM_NONCE_KEY = None
|
|
51
56
|
|
52
57
|
|
53
58
|
def pack_two(a, b):
|
54
|
-
a = HexBytes(a).hex()
|
55
|
-
b = HexBytes(b).hex()
|
59
|
+
a = HexBytes(a).hex()
|
60
|
+
b = HexBytes(b).hex()
|
56
61
|
return "0x" + a.zfill(32) + b.zfill(32)
|
57
62
|
|
58
63
|
|
@@ -98,23 +103,23 @@ def hash_packed_user_operation_only(packed_user_op):
|
|
98
103
|
hash_paymaster_and_data,
|
99
104
|
],
|
100
105
|
).hex()
|
101
|
-
)
|
106
|
+
)
|
102
107
|
|
103
108
|
|
104
109
|
def hash_packed_user_operation(packed_user_op, chain_id, entry_point):
|
105
110
|
return Web3.keccak(
|
106
111
|
hexstr=encode(
|
107
112
|
["bytes32", "address", "uint256"],
|
108
|
-
[
|
113
|
+
[hash_packed_user_operation_only(packed_user_op), entry_point, chain_id],
|
109
114
|
).hex()
|
110
|
-
)
|
115
|
+
)
|
111
116
|
|
112
117
|
|
113
118
|
def sign_user_operation(private_key, user_operation, chain_id, entry_point):
|
114
119
|
packed_user_op = pack_user_operation(user_operation)
|
115
120
|
hash = hash_packed_user_operation(packed_user_op, chain_id, entry_point)
|
116
|
-
signature = Account.sign_message(encode_defunct(hexstr=hash), private_key)
|
117
|
-
return signature.signature
|
121
|
+
signature = Account.sign_message(encode_defunct(hexstr=hash.hex()), private_key)
|
122
|
+
return signature.signature
|
118
123
|
|
119
124
|
|
120
125
|
def make_nonce(nonce_key, nonce):
|
@@ -147,7 +152,7 @@ def get_nonce_and_key(w3, tx, nonce_mode, entry_point=AA_BUNDLER_ENTRYPOINT, fet
|
|
147
152
|
|
148
153
|
if nonce is None:
|
149
154
|
if fetch or nonce_mode == NonceMode.FIXED_KEY_FETCH_ALWAYS:
|
150
|
-
nonce = fetch_nonce(w3, tx
|
155
|
+
nonce = fetch_nonce(w3, get_sender(tx), entry_point, nonce_key)
|
151
156
|
elif nonce_key not in NONCE_CACHE:
|
152
157
|
nonce = 0
|
153
158
|
else:
|
@@ -168,7 +173,16 @@ def handle_response_error(resp, w3, tx, retry_nonce):
|
|
168
173
|
|
169
174
|
def get_base_fee(w3):
|
170
175
|
blk = w3.eth.get_block("latest")
|
171
|
-
return blk["baseFeePerGas"]
|
176
|
+
return int(_to_uint(blk["baseFeePerGas"]) * AA_BUNDLER_BASE_GAS_PRICE_FACTOR)
|
177
|
+
|
178
|
+
|
179
|
+
def get_sender(tx):
|
180
|
+
if "from" not in tx or tx["from"] == ADDRESS_ZERO:
|
181
|
+
if AA_BUNDLER_SENDER is None:
|
182
|
+
raise RuntimeError("Must define AA_BUNDLER_SENDER or send 'from' in the TX")
|
183
|
+
return AA_BUNDLER_SENDER
|
184
|
+
else:
|
185
|
+
return tx["from"]
|
172
186
|
|
173
187
|
|
174
188
|
def send_transaction(w3, tx, retry_nonce=None):
|
@@ -185,7 +199,7 @@ def send_transaction(w3, tx, retry_nonce=None):
|
|
185
199
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
|
186
200
|
)
|
187
201
|
user_operation = {
|
188
|
-
"sender": tx
|
202
|
+
"sender": get_sender(tx),
|
189
203
|
"nonce": hex(make_nonce(nonce_key, nonce)),
|
190
204
|
"callData": call_data,
|
191
205
|
"signature": dummy_signature,
|
@@ -203,9 +217,12 @@ def send_transaction(w3, tx, retry_nonce=None):
|
|
203
217
|
resp = w3.provider.make_request("rundler_maxPriorityFeePerGas", [])
|
204
218
|
if "error" in resp:
|
205
219
|
raise RevertError(resp["error"]["message"])
|
206
|
-
max_priority_fee_per_gas = resp["result"]
|
207
|
-
user_operation["maxPriorityFeePerGas"] = max_priority_fee_per_gas
|
208
|
-
user_operation["maxFeePerGas"] = hex(
|
220
|
+
max_priority_fee_per_gas = int(_to_uint(resp["result"]) * AA_BUNDLER_PRIORITY_GAS_PRICE_FACTOR)
|
221
|
+
user_operation["maxPriorityFeePerGas"] = hex(max_priority_fee_per_gas)
|
222
|
+
user_operation["maxFeePerGas"] = hex(max_priority_fee_per_gas + get_base_fee(w3))
|
223
|
+
user_operation["callGasLimit"] = hex(
|
224
|
+
int(_to_uint(user_operation["callGasLimit"]) * AA_BUNDLER_GAS_LIMIT_FACTOR)
|
225
|
+
)
|
209
226
|
elif AA_BUNDLER_PROVIDER == "gelato":
|
210
227
|
user_operation.update(
|
211
228
|
{
|
@@ -216,8 +233,10 @@ def send_transaction(w3, tx, retry_nonce=None):
|
|
216
233
|
"maxPriorityFeePerGas": "0x00",
|
217
234
|
}
|
218
235
|
)
|
219
|
-
user_operation["signature"] =
|
220
|
-
|
236
|
+
user_operation["signature"] = add_0x_prefix(
|
237
|
+
sign_user_operation(
|
238
|
+
AA_BUNDLER_EXECUTOR_PK, user_operation, tx["chainId"], AA_BUNDLER_ENTRYPOINT
|
239
|
+
).hex()
|
221
240
|
)
|
222
241
|
# Remove paymaster related fields
|
223
242
|
user_operation.pop("paymaster", None)
|
@@ -231,4 +250,4 @@ def send_transaction(w3, tx, retry_nonce=None):
|
|
231
250
|
|
232
251
|
# Store nonce in the cache, so next time uses a new nonce
|
233
252
|
NONCE_CACHE[nonce_key] = nonce + 1
|
234
|
-
return resp["result"]
|
253
|
+
return {"userOpHash": resp["result"]}
|
ethproto/w3wrappers.py
CHANGED
@@ -9,7 +9,7 @@ from eth_utils.abi import event_abi_to_log_topic
|
|
9
9
|
from hexbytes import HexBytes
|
10
10
|
from web3.contract import Contract
|
11
11
|
from web3.exceptions import ContractLogicError, ExtraDataLengthError
|
12
|
-
from web3.middleware import
|
12
|
+
from web3.middleware import ExtraDataToPOAMiddleware
|
13
13
|
|
14
14
|
from .build_artifacts import ArtifactLibrary
|
15
15
|
from .contracts import RevertError
|
@@ -68,9 +68,9 @@ def register_w3_provider(provider_key="w3", tester=None, provider_kwargs={}):
|
|
68
68
|
try:
|
69
69
|
w3.eth.get_block("latest")
|
70
70
|
except ExtraDataLengthError:
|
71
|
-
w3.middleware_onion.inject(
|
71
|
+
w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
72
72
|
elif W3_POA == "yes":
|
73
|
-
w3.middleware_onion.inject(
|
73
|
+
w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
74
74
|
|
75
75
|
# If address_book not provided and there are envs with W3_ADDRESS_BOOK_PREFIX,
|
76
76
|
# use W3EnvAddressBook
|
@@ -375,6 +375,8 @@ class W3ETHCall(ETHCall):
|
|
375
375
|
def normalize_receipt(self, wrapper, receipt):
|
376
376
|
if W3_TRANSACT_MODE == "defender-async":
|
377
377
|
return receipt # Don't do anything because the receipt is just a dict of not-yet-mined tx
|
378
|
+
elif W3_TRANSACT_MODE == "aa-bundler-async":
|
379
|
+
return receipt # Don't do anything because the receipt is just a dict of {"userOpHash": "..."}
|
378
380
|
return ReceiptWrapper(receipt, wrapper.contract)
|
379
381
|
|
380
382
|
def _handle_exception(self, err):
|
@@ -442,7 +444,7 @@ class W3Provider(BaseProvider):
|
|
442
444
|
def get_events(self, eth_wrapper, event_name, filter_kwargs={}):
|
443
445
|
"""Returns a list of events given a filter, like this:
|
444
446
|
|
445
|
-
>>> provider.get_events(currencywrapper, "Transfer", dict(
|
447
|
+
>>> provider.get_events(currencywrapper, "Transfer", dict(from_block=0))
|
446
448
|
[AttributeDict({
|
447
449
|
'args': AttributeDict(
|
448
450
|
{'from': '0x0000000000000000000000000000000000000000',
|
@@ -461,8 +463,8 @@ class W3Provider(BaseProvider):
|
|
461
463
|
"""
|
462
464
|
contract = eth_wrapper.contract
|
463
465
|
event = getattr(contract.events, event_name)
|
464
|
-
if "
|
465
|
-
filter_kwargs["
|
466
|
+
if "from_block" not in filter_kwargs:
|
467
|
+
filter_kwargs["from_block"] = self.get_first_block(eth_wrapper)
|
466
468
|
event_filter = event.create_filter(**filter_kwargs)
|
467
469
|
return event_filter.get_all_entries()
|
468
470
|
|
@@ -488,7 +490,7 @@ class W3Provider(BaseProvider):
|
|
488
490
|
constructor_params, init_params = init_params
|
489
491
|
real_contract = self.construct(eth_contract, constructor_params, {"from": eth_wrapper.owner})
|
490
492
|
ERC1967Proxy = self.get_contract_factory("ERC1967Proxy")
|
491
|
-
init_data = eth_contract.
|
493
|
+
init_data = eth_contract.encode_abi(abi_element_identifier="initialize", args=init_params)
|
492
494
|
proxy_contract = self.construct(
|
493
495
|
ERC1967Proxy,
|
494
496
|
(real_contract.address, init_data),
|
@@ -1,14 +0,0 @@
|
|
1
|
-
ethproto/__init__.py,sha256=YWkAFysBp4tZjLWWB2FFmp5yG23pUYhQvgQW9b3soXs,579
|
2
|
-
ethproto/aa_bundler.py,sha256=34yXgQw_vV81Wmf9cFxcLTxLUb1jzCrBE7XOw5RIjtI,8652
|
3
|
-
ethproto/build_artifacts.py,sha256=xwCd5hJUHP82IA-y3sSfX6fV15kjCGtV19RxNRcoor0,5441
|
4
|
-
ethproto/contracts.py,sha256=rNVbCK1hURy7lWKhzSdXgVWo3wx9O_Ghk-6PfgOsRNk,18662
|
5
|
-
ethproto/defender_relay.py,sha256=05A8TfRZwiBhCpo924Pf9CjfKSir2Wvgg1p_asFxJbw,1777
|
6
|
-
ethproto/w3wrappers.py,sha256=UbSuaB5_TYF4kiGNwIzvPPE7f0A6soZ7gc5jd180mVM,21065
|
7
|
-
ethproto/wadray.py,sha256=JBsu5KcyU9k70bDK03T2IY6qPVFO30WbYPhwrAHdXao,8262
|
8
|
-
ethproto/wrappers.py,sha256=9qDwRDOXw3wquzvGfIsub-VPWm98GBWP7dHLFOUPWzg,17307
|
9
|
-
eth_prototype-1.1.0.dist-info/AUTHORS.rst,sha256=Ui-05yYXtDZxna6o1yNcfdm8Jt68UIDQ01osiLxlYlU,95
|
10
|
-
eth_prototype-1.1.0.dist-info/LICENSE.txt,sha256=U_Q6_nDYDwZPIuhttHi37hXZ2qU2-HlV2geo9hzHXFw,1087
|
11
|
-
eth_prototype-1.1.0.dist-info/METADATA,sha256=uOJw45vu6Xwc3uzJ1IfWV0RW1i2ST_ZHJ775Uwbi7zk,2482
|
12
|
-
eth_prototype-1.1.0.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
13
|
-
eth_prototype-1.1.0.dist-info/top_level.txt,sha256=Dl0X7m6N1hxeo4JpGpSNqWC2gtsN0731g-DL1J0mpjc,9
|
14
|
-
eth_prototype-1.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|