Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Apr 11, 2024
1 parent 57d4c64 commit 4f10378
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 131 deletions.
29 changes: 29 additions & 0 deletions boa_zksync/compile.py
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())
87 changes: 0 additions & 87 deletions boa_zksync/contract.py

This file was deleted.

42 changes: 42 additions & 0 deletions boa_zksync/deployer.py
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)
Loading

0 comments on commit 4f10378

Please sign in to comment.