-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57d4c64
commit 4f10378
Showing
5 changed files
with
76 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import subprocess | ||
from collections import namedtuple | ||
from shutil import which | ||
|
||
ZksyncCompilerData = namedtuple("ZksyncCompilerData", [ | ||
'method_identifiers', 'abi', 'bytecode', 'bytecode_runtime', 'warnings', 'factory_deps', | ||
]) | ||
|
||
|
||
def compile_zksync(file_name: str, compiler_args = None) -> ZksyncCompilerData: | ||
output = json.loads(_call_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, | ||
)) | ||
return ZksyncCompilerData(**output[file_name]) | ||
|
||
|
||
def _call_zkvyper(*args): | ||
result = subprocess.run(["zkvyper", *args], capture_output=True) | ||
if result.returncode == 0: | ||
return result.stdout.decode() | ||
raise Exception(result.stderr.decode()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from functools import cached_property | ||
|
||
from boa import Env | ||
from boa.contracts.abi.abi_contract import ABIContractFactory, ABIFunction, ABIContract | ||
from boa.util.abi import Address | ||
|
||
from boa_zksync.compile import ZksyncCompilerData | ||
|
||
|
||
class ZksyncDeployer(ABIContractFactory): | ||
def __init__(self, compiler_data: ZksyncCompilerData, name: str, filename: str): | ||
super().__init__( | ||
name, | ||
compiler_data.abi, | ||
functions=[ | ||
ABIFunction(item, name) for item in compiler_data.abi | ||
if item.get("type") == "function" | ||
], | ||
filename=filename, | ||
) | ||
self.compiler_data = compiler_data | ||
|
||
def deploy(self, *args, value=0, **kwargs): | ||
env = Env.get_singleton() | ||
|
||
initcode = bytes.fromhex(self.compiler_data.bytecode.removeprefix("0x")) | ||
constructor_calldata = self.constructor.prepare_calldata(*args, **kwargs) if args or kwargs else b"" | ||
|
||
address, _ = env.deploy_code(bytecode=initcode, value=value, constructor_calldata=constructor_calldata) | ||
return ABIContract( | ||
self._name, | ||
self.abi, | ||
self._functions, | ||
address=Address(address), | ||
filename=self._filename, | ||
env=env, | ||
) | ||
|
||
@cached_property | ||
def constructor(self): | ||
ctor_abi = next(i for i in self.abi if i["type"] == "constructor") | ||
return ABIFunction(ctor_abi, contract_name=self._name) |
Oops, something went wrong.