Skip to content

Commit

Permalink
Better documentation and install triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Apr 15, 2024
1 parent 4d6f100 commit 03a289c
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
era_test_node --version && \
rm era_test_node.tar.gz
- run: make lint coverage
- run: make coverage lint
14 changes: 9 additions & 5 deletions boa_zksync/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import boa

from boa_zksync.env import ZksyncEnv
from boa_zksync.interpret import compile_zksync, load_zksync, loads_zksync, load_zksync_partial, loads_zksync_partial, eval_zksync
from boa_zksync.environment import ZksyncEnv
from boa_zksync.interpret import (
compile_zksync,
eval_zksync,
load_zksync,
load_zksync_partial,
loads_zksync,
loads_zksync_partial,
)


def set_zksync_env(url):
Expand All @@ -11,10 +18,7 @@ def set_zksync_env(url):
def set_zksync_browser_env(address=None):
# import locally because jupyter is generally not installed
from boa_zksync.browser import ZksyncBrowserEnv
from boa.integrations.jupyter import browser

# Set a larger shared memory as the zkSync transactions are larger
browser.SHARED_MEMORY_LENGTH = 100 * 1024 + 1
boa.set_env(ZksyncBrowserEnv(address))


Expand Down
2 changes: 1 addition & 1 deletion boa_zksync/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Please be careful when importing the browser files outside of Jupyter env."
)

from boa_zksync.env import _ZksyncEnvMixin
from boa_zksync.environment import _ZksyncEnvMixin


class ZksyncBrowserEnv(_ZksyncEnvMixin, BrowserEnv):
Expand Down
34 changes: 20 additions & 14 deletions boa_zksync/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ZksyncCompilerData:
"""
Represents the output of the Zksync Vyper compiler (combined_json format).
"""

method_identifiers: dict
abi: list
bytecode: str
Expand All @@ -18,20 +19,25 @@ class ZksyncCompilerData:


def compile_zksync(file_name: str, compiler_args=None) -> ZksyncCompilerData:
compile_result = subprocess.run([
"zkvyper",
# make sure zkvyper uses the same vyper as boa
"--vyper",
which("vyper"),
# request JSON output
"-f",
"combined_json",
# pass any extra compiler args
*(compiler_args or []),
# pass the file name
"--",
file_name,
], capture_output=True)
vyper_path = which("vyper")
assert vyper_path, "Vyper executable not found"
compile_result = subprocess.run(
[
"zkvyper",
# make sure zkvyper uses the same vyper as boa
"--vyper",
vyper_path,
# request JSON output
"-f",
"combined_json",
# pass any extra compiler args
*(compiler_args or []),
# pass the file name
"--",
file_name,
],
capture_output=True,
)

assert compile_result.returncode == 0, compile_result.stderr.decode()
output = json.loads(compile_result.stdout.decode())
Expand Down
5 changes: 2 additions & 3 deletions boa_zksync/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from boa import Env
from boa.contracts.abi.abi_contract import ABIContract, ABIContractFactory, ABIFunction
from boa.rpc import to_bytes
from boa.util.abi import Address

from boa_zksync.compile import ZksyncCompilerData
from boa_zksync.env import _ZksyncEnvMixin


class ZksyncDeployer(ABIContractFactory):
Expand All @@ -25,14 +25,13 @@ def __init__(self, compiler_data: ZksyncCompilerData, name: str, filename: str):
def deploy(self, *args, value=0, **kwargs):
env = Env.get_singleton()

initcode = bytes.fromhex(self.compiler_data.bytecode.removeprefix("0x"))
initcode = to_bytes(self.compiler_data.bytecode)
constructor_calldata = (
self.constructor.prepare_calldata(*args, **kwargs)
if args or kwargs
else b""
)

assert isinstance(env, _ZksyncEnvMixin)
address, _ = env.deploy_code(
bytecode=initcode, value=value, constructor_calldata=constructor_calldata
)
Expand Down
111 changes: 0 additions & 111 deletions boa_zksync/env.py

This file was deleted.

Loading

0 comments on commit 03a289c

Please sign in to comment.