Skip to content

Commit e93a25d

Browse files
Merge pull request #2 from zksync-sdk/v0.1.0
V0.1.0
2 parents f8c3b58 + 7cd19f6 commit e93a25d

File tree

9 files changed

+709
-490
lines changed

9 files changed

+709
-490
lines changed

README.md

Lines changed: 357 additions & 162 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zksync2"
7-
version = "0.0.2"
7+
version = "0.1.0"
88
authors = [
99
{ name="Viktor Yastrebov", email="[email protected]" },
1010
]

tests/contracts/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import importlib.resources as pkg_resources
22
import json
3+
4+
from eth_typing import HexStr
5+
36
from tests import contracts
7+
from eth_utils import remove_0x_prefix
48

59

610
def get_binary(name: str) -> bytes:
@@ -15,7 +19,7 @@ def get_hex_binary(name: str) -> bytes:
1519
with p.open(mode='r') as contact_file:
1620
lines = contact_file.readlines()
1721
data = "".join(lines)
18-
return bytes.fromhex(data)
22+
return bytes.fromhex(remove_0x_prefix(HexStr(data)))
1923

2024

2125
def get_abi(name: str):

tests/test_zksync_web3.py

Lines changed: 177 additions & 209 deletions
Large diffs are not rendered by default.

zksync2/manage_contracts/erc20_contract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ def __init__(self, web3_eth: Web3, abi: Optional[dict] = None):
4747
abi = _erc_20_abi_default()
4848
self.contract = web3_eth.eth.contract(address=None, abi=abi)
4949

50-
def encode_method(self, fn_name, args):
50+
def encode_method(self, fn_name, args) -> HexStr:
5151
return self.contract.encodeABI(fn_name=fn_name, args=args)

zksync2/module/request_types.py

Lines changed: 11 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
from enum import Enum
12
from dataclasses import dataclass
2-
from typing import TypedDict, List, Optional
3+
from typing import List, Optional
4+
from web3._utils.compat import (
5+
TypedDict,
6+
)
7+
38
from eth_typing import HexStr
4-
from web3 import Web3
59
from web3.types import AccessList
610
from zksync2.core.types import PaymasterParams
7-
from zksync2.manage_contracts.contract_deployer import ContractDeployer
8-
from zksync2.manage_contracts.deploy_addresses import ZkSyncAddresses
9-
from enum import Enum
1011

1112

1213
@dataclass
@@ -19,111 +20,21 @@ class EIP712Meta:
1920
paymaster_params: Optional[PaymasterParams] = None
2021

2122

22-
Transaction = TypedDict(
23-
"Transaction",
24-
{
23+
Transaction = TypedDict("Transaction", {
24+
"chain_id": int,
25+
"nonce": int,
2526
"from": HexStr,
2627
"to": HexStr,
2728
"gas": int,
2829
"gasPrice": int,
30+
"maxPriorityFeePerGas": int,
2931
"value": int,
3032
"data": HexStr,
3133
"transactionType": int,
3234
"accessList": Optional[AccessList],
3335
"eip712Meta": EIP712Meta,
34-
}, total=False)
36+
}, total=False)
3537

3638

3739
class TransactionType(Enum):
3840
EIP_712_TX_TYPE = 113
39-
40-
41-
def create_function_call_transaction(from_: HexStr,
42-
to: HexStr,
43-
ergs_price: int,
44-
ergs_limit: int,
45-
data: HexStr,
46-
value: int = 0):
47-
eip712_meta_default = EIP712Meta()
48-
tx: Transaction = {
49-
"from": from_,
50-
"to": to,
51-
"gas": ergs_limit,
52-
"gasPrice": ergs_price,
53-
"value": value,
54-
"data": data,
55-
"transactionType": TransactionType.EIP_712_TX_TYPE.value,
56-
"eip712Meta": eip712_meta_default
57-
}
58-
return tx
59-
60-
61-
def create2_contract_transaction(web3: Web3,
62-
from_: HexStr,
63-
ergs_price: int,
64-
ergs_limit: int,
65-
bytecode: bytes,
66-
deps: List[bytes] = None,
67-
call_data: Optional[bytes] = None,
68-
value: int = 0,
69-
salt: Optional[bytes] = None):
70-
contract_deployer = ContractDeployer(web3)
71-
call_data = contract_deployer.encode_create2(bytecode=bytecode,
72-
call_data=call_data,
73-
salt=salt)
74-
factory_deps = []
75-
if deps is not None:
76-
for dep in deps:
77-
factory_deps.append(dep)
78-
factory_deps.append(bytecode)
79-
80-
eip712_meta = EIP712Meta(ergs_per_pub_data=EIP712Meta.ERGS_PER_PUB_DATA_DEFAULT,
81-
custom_signature=None,
82-
factory_deps=factory_deps,
83-
paymaster_params=None)
84-
tx: Transaction = {
85-
"from": from_,
86-
"to": Web3.toChecksumAddress(ZkSyncAddresses.CONTRACT_DEPLOYER_ADDRESS.value),
87-
"gas": ergs_limit,
88-
"gasPrice": ergs_price,
89-
"value": value,
90-
"data": HexStr(call_data),
91-
"transactionType": TransactionType.EIP_712_TX_TYPE.value,
92-
"eip712Meta": eip712_meta
93-
}
94-
return tx
95-
96-
97-
def create_contract_transaction(web3: Web3,
98-
from_: HexStr,
99-
ergs_price: int,
100-
ergs_limit: int,
101-
bytecode: bytes,
102-
deps: List[bytes] = None,
103-
call_data: Optional[bytes] = None,
104-
value: int = 0,
105-
salt: Optional[bytes] = None):
106-
contract_deployer = ContractDeployer(web3)
107-
call_data = contract_deployer.encode_create(bytecode=bytecode,
108-
call_data=call_data,
109-
salt_data=salt)
110-
factory_deps = []
111-
if deps is not None:
112-
for dep in deps:
113-
factory_deps.append(dep)
114-
factory_deps.append(bytecode)
115-
eip712_meta = EIP712Meta(ergs_per_pub_data=EIP712Meta.ERGS_PER_PUB_DATA_DEFAULT,
116-
custom_signature=None,
117-
factory_deps=factory_deps,
118-
paymaster_params=None)
119-
tx: Transaction = {
120-
"from": from_,
121-
"to": Web3.toChecksumAddress(ZkSyncAddresses.CONTRACT_DEPLOYER_ADDRESS.value),
122-
"gas": ergs_limit,
123-
"gasPrice": ergs_price,
124-
"value": value,
125-
"data": HexStr(call_data),
126-
"transactionType": TransactionType.EIP_712_TX_TYPE.value,
127-
"eip712Meta": eip712_meta
128-
}
129-
return tx

zksync2/module/zksync_module.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
zks_estimate_fee_rpc = RPCEndpoint("zks_estimateFee")
3838
zks_main_contract_rpc = RPCEndpoint("zks_getMainContract")
39-
zks_get_l1_withdraw_tx_rpc = RPCEndpoint("zks_getL1WithdrawalTx")
4039
zks_get_confirmed_tokens_rpc = RPCEndpoint("zks_getConfirmedTokens")
4140
zks_get_token_price_rpc = RPCEndpoint("zks_getTokenPrice")
4241
zks_l1_chain_id_rpc = RPCEndpoint("zks_L1ChainId")
@@ -76,12 +75,13 @@ def meta_formatter(eip712: EIP712Meta) -> dict:
7675
'from': to_checksum_address,
7776
'gas': to_hex_if_integer,
7877
'gasPrice': to_hex_if_integer,
78+
'maxPriorityFeePerGas': to_hex_if_integer,
7979
'nonce': to_hex_if_integer,
8080
'to': to_checksum_address,
8181
'value': to_hex_if_integer,
8282
'chainId': to_hex_if_integer,
8383
'transactionType': to_hex_if_integer,
84-
'eip712Meta': meta_formatter
84+
'eip712Meta': meta_formatter,
8585
}
8686

8787
zks_transaction_request_formatter = apply_formatters_to_dict(ZKS_TRANSACTION_PARAMS_FORMATTERS)
@@ -182,11 +182,6 @@ class ZkSync(Eth, ABC):
182182
mungers=None
183183
)
184184

185-
_zks_get_l1_withdraw_tx: Method[Callable[[L2WithdrawTxHash], TransactionHash]] = Method(
186-
zks_get_l1_withdraw_tx_rpc,
187-
mungers=[default_root_munger]
188-
)
189-
190185
_zks_get_confirmed_tokens: Method[Callable[[From, Limit], ZksTokens]] = Method(
191186
zks_get_confirmed_tokens_rpc,
192187
mungers=[default_root_munger],
@@ -221,7 +216,7 @@ class ZkSync(Eth, ABC):
221216
request_formatters=zksync_get_request_formatters
222217
)
223218

224-
_eth_estimate_gas: Method[Callable[[Transaction], str]] = Method(
219+
_eth_estimate_gas: Method[Callable[[Transaction], int]] = Method(
225220
eth_estimate_gas_rpc,
226221
mungers=[default_root_munger],
227222
request_formatters=zksync_get_request_formatters
@@ -258,9 +253,6 @@ def zks_estimate_fee(self, transaction: Transaction) -> Fee:
258253
def zks_main_contract(self) -> HexStr:
259254
return self._zks_main_contract()
260255

261-
def zks_get_l1_withdraw_tx(self, withdraw_hash: L2WithdrawTxHash) -> TransactionHash:
262-
return self._zks_get_l1_withdraw_tx(withdraw_hash)
263-
264256
def zks_get_confirmed_tokens(self, offset: From, limit: Limit) -> List[Token]:
265257
return self._zks_get_confirmed_tokens(offset, limit)
266258

@@ -286,7 +278,7 @@ def zks_get_l2_to_l1_msg_proof(self,
286278
def zks_get_testnet_paymaster_address(self) -> HexStr:
287279
return self._zks_get_testnet_paymaster_address()
288280

289-
def eth_estimate_gas(self, tx: Transaction) -> str:
281+
def eth_estimate_gas(self, tx: Transaction) -> int:
290282
return self._eth_estimate_gas(tx)
291283

292284
def wait_for_transaction_receipt(self,

zksync2/signer/eth_signer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from abc import abstractmethod, ABC
33
from eip712_structs import make_domain, EIP712Struct
44
from eth_account.datastructures import SignedMessage
5+
from eth_account.signers.base import BaseAccount
56
from eth_typing import ChecksumAddress, HexStr
67
from eth_utils import keccak
7-
from eth_account.signers.local import LocalAccount
88
from eth_account.messages import encode_defunct, SignableMessage
99

1010

@@ -23,7 +23,7 @@ class PrivateKeyEthSigner(EthSignerBase, ABC):
2323
_NAME = "zkSync"
2424
_VERSION = "2"
2525

26-
def __init__(self, creds: LocalAccount, chain_id: int):
26+
def __init__(self, creds: BaseAccount, chain_id: int):
2727
self.credentials = creds
2828
self.chain_id = chain_id
2929
self.default_domain = make_domain(name=self._NAME,

0 commit comments

Comments
 (0)