eth-prototype 1.1.0__py3-none-any.whl → 1.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eth-prototype
3
- Version: 1.1.0
3
+ Version: 1.2.0
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]==6.*; extra == "testing"
31
+ Requires-Dist: web3[tester]==7.*; extra == "testing"
32
32
  Requires-Dist: boto3; extra == "testing"
33
33
  Provides-Extra: web3
34
- Requires-Dist: web3==6.*; extra == "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=4ZEnJFrc8bV1qHG4dNdom4FL1gEUhgoJORY6cGzlJDk,21549
7
+ ethproto/wadray.py,sha256=JBsu5KcyU9k70bDK03T2IY6qPVFO30WbYPhwrAHdXao,8262
8
+ ethproto/wrappers.py,sha256=9qDwRDOXw3wquzvGfIsub-VPWm98GBWP7dHLFOUPWzg,17307
9
+ eth_prototype-1.2.0.dist-info/AUTHORS.rst,sha256=Ui-05yYXtDZxna6o1yNcfdm8Jt68UIDQ01osiLxlYlU,95
10
+ eth_prototype-1.2.0.dist-info/LICENSE.txt,sha256=U_Q6_nDYDwZPIuhttHi37hXZ2qU2-HlV2geo9hzHXFw,1087
11
+ eth_prototype-1.2.0.dist-info/METADATA,sha256=861SU0czUjLc6u-wuWlcAeyAN8a5HSkzJDn3yqQQu88,2482
12
+ eth_prototype-1.2.0.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
13
+ eth_prototype-1.2.0.dist-info/top_level.txt,sha256=Dl0X7m6N1hxeo4JpGpSNqWC2gtsN0731g-DL1J0mpjc,9
14
+ eth_prototype-1.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
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 requests
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 .contracts import RevertError
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()[2:]
55
- b = HexBytes(b).hex()[2:]
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
- ).hex()
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
- [HexBytes(hash_packed_user_operation_only(packed_user_op)), entry_point, chain_id],
113
+ [hash_packed_user_operation_only(packed_user_op), entry_point, chain_id],
109
114
  ).hex()
110
- ).hex()
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.hex()
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.get("from", AA_BUNDLER_SENDER), entry_point, nonce_key)
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.get("from", AA_BUNDLER_SENDER),
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(_to_uint(max_priority_fee_per_gas) + _to_uint(get_base_fee(w3)))
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"] = sign_user_operation(
220
- AA_BUNDLER_EXECUTOR_PK, user_operation, tx["chainId"], AA_BUNDLER_ENTRYPOINT
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 geth_poa_middleware
12
+ from web3.middleware import ExtraDataToPOAMiddleware
13
13
 
14
14
  from .build_artifacts import ArtifactLibrary
15
15
  from .contracts import RevertError
@@ -49,14 +49,21 @@ class W3TimeControl:
49
49
  return self.w3.eth.get_block("latest").timestamp
50
50
 
51
51
 
52
- def register_w3_provider(provider_key="w3", tester=None, provider_kwargs={}):
52
+ def register_w3_provider(provider_key="w3", w3=None, tester=None, provider_kwargs=None):
53
+ if w3 is not None and tester is not None:
54
+ raise ValueError("Cannot inject w3 and use tester at the same time")
55
+
56
+ provider_kwargs = provider_kwargs or {}
53
57
  if tester is None:
54
58
  try:
55
59
  import eth_tester # noqa
56
60
  except ImportError:
57
61
  tester = False
58
62
 
59
- if tester:
63
+ if w3 is not None:
64
+ # the provided w3 instance takes precedence over all other args
65
+ pass
66
+ elif tester:
60
67
  from web3 import Web3
61
68
 
62
69
  w3 = Web3(Web3.EthereumTesterProvider())
@@ -68,9 +75,9 @@ def register_w3_provider(provider_key="w3", tester=None, provider_kwargs={}):
68
75
  try:
69
76
  w3.eth.get_block("latest")
70
77
  except ExtraDataLengthError:
71
- w3.middleware_onion.inject(geth_poa_middleware, layer=0)
78
+ w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
72
79
  elif W3_POA == "yes":
73
- w3.middleware_onion.inject(geth_poa_middleware, layer=0)
80
+ w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
74
81
 
75
82
  # If address_book not provided and there are envs with W3_ADDRESS_BOOK_PREFIX,
76
83
  # use W3EnvAddressBook
@@ -375,6 +382,8 @@ class W3ETHCall(ETHCall):
375
382
  def normalize_receipt(self, wrapper, receipt):
376
383
  if W3_TRANSACT_MODE == "defender-async":
377
384
  return receipt # Don't do anything because the receipt is just a dict of not-yet-mined tx
385
+ elif W3_TRANSACT_MODE == "aa-bundler-async":
386
+ return receipt # Don't do anything because the receipt is just a dict of {"userOpHash": "..."}
378
387
  return ReceiptWrapper(receipt, wrapper.contract)
379
388
 
380
389
  def _handle_exception(self, err):
@@ -442,7 +451,7 @@ class W3Provider(BaseProvider):
442
451
  def get_events(self, eth_wrapper, event_name, filter_kwargs={}):
443
452
  """Returns a list of events given a filter, like this:
444
453
 
445
- >>> provider.get_events(currencywrapper, "Transfer", dict(fromBlock=0))
454
+ >>> provider.get_events(currencywrapper, "Transfer", dict(from_block=0))
446
455
  [AttributeDict({
447
456
  'args': AttributeDict(
448
457
  {'from': '0x0000000000000000000000000000000000000000',
@@ -461,8 +470,8 @@ class W3Provider(BaseProvider):
461
470
  """
462
471
  contract = eth_wrapper.contract
463
472
  event = getattr(contract.events, event_name)
464
- if "fromBlock" not in filter_kwargs:
465
- filter_kwargs["fromBlock"] = self.get_first_block(eth_wrapper)
473
+ if "from_block" not in filter_kwargs:
474
+ filter_kwargs["from_block"] = self.get_first_block(eth_wrapper)
466
475
  event_filter = event.create_filter(**filter_kwargs)
467
476
  return event_filter.get_all_entries()
468
477
 
@@ -488,7 +497,7 @@ class W3Provider(BaseProvider):
488
497
  constructor_params, init_params = init_params
489
498
  real_contract = self.construct(eth_contract, constructor_params, {"from": eth_wrapper.owner})
490
499
  ERC1967Proxy = self.get_contract_factory("ERC1967Proxy")
491
- init_data = eth_contract.encodeABI(fn_name="initialize", args=init_params)
500
+ init_data = eth_contract.encode_abi(abi_element_identifier="initialize", args=init_params)
492
501
  proxy_contract = self.construct(
493
502
  ERC1967Proxy,
494
503
  (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,,