From 909c5ee0042d03ace11c33fc494410f79f660362 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 2 Oct 2024 19:27:49 -0400 Subject: [PATCH] fix lint, make some simplifications --- boa/contracts/vvm/vvm_contract.py | 9 ++------- boa/contracts/vyper/vyper_contract.py | 15 +++++++-------- boa/util/eip5202.py | 4 ++-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/boa/contracts/vvm/vvm_contract.py b/boa/contracts/vvm/vvm_contract.py index 2802deec..299ad6bc 100644 --- a/boa/contracts/vvm/vvm_contract.py +++ b/boa/contracts/vvm/vvm_contract.py @@ -2,11 +2,8 @@ from functools import cached_property from boa.contracts.abi.abi_contract import ABIContractFactory, ABIFunction -from boa.contracts.base_evm_contract import ( - DEFAULT_BLUEPRINT_PREAMBLE, - generate_blueprint_bytecode, -) from boa.environment import Env +from boa.util.eip5202 import generate_blueprint_bytecode # TODO: maybe this doesn't detect release candidates VERSION_RE = re.compile(r"\s*#\s*(pragma\s+version|@version)\s+(\d+\.\d+\.\d+)") @@ -80,9 +77,7 @@ def _blueprint_deployer(self): # TODO: add filename return ABIContractFactory.from_abi_dict([]) - def deploy_as_blueprint( - self, env=None, blueprint_preamble=DEFAULT_BLUEPRINT_PREAMBLE, **kwargs - ): + def deploy_as_blueprint(self, env=None, blueprint_preamble=None, **kwargs): """ Deploy a new blueprint from this contract. :param blueprint_preamble: The preamble to use for the blueprint. diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index e85e64fe..25957202 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -35,11 +35,9 @@ from boa import BoaError from boa.contracts.base_evm_contract import ( - DEFAULT_BLUEPRINT_PREAMBLE, StackTrace, _BaseEVMContract, _handle_child_trace, - generate_blueprint_bytecode, ) from boa.contracts.call_trace import TraceSource from boa.contracts.vyper.ast_utils import get_fn_ancestor_from_node, reason_at @@ -58,6 +56,7 @@ from boa.environment import Env from boa.profiling import cache_gas_used_for_computation from boa.util.abi import Address, abi_decode, abi_encode +from boa.util.eip5202 import generate_blueprint_bytecode from boa.util.lrudict import lrudict from boa.vm.gas_meters import ProfilingGasMeter from boa.vm.utils import to_bytes, to_int @@ -185,7 +184,7 @@ def __init__( compiler_data, env=None, override_address=None, - blueprint_preamble=DEFAULT_BLUEPRINT_PREAMBLE, + blueprint_preamble=None, filename=None, gas=None, ): @@ -193,12 +192,12 @@ def __init__( # maybe use common base class? super().__init__(compiler_data, env, filename) + blueprint_bytecode = generate_blueprint_bytecode( + compiler_data.bytecode, blueprint_preamble + ) + addr, computation = self.env.deploy( - bytecode=generate_blueprint_bytecode( - compiler_data.bytecode, blueprint_preamble - ), - override_address=override_address, - gas=gas, + bytecode=blueprint_bytecode, override_address=override_address, gas=gas ) if computation.is_error: raise computation.error diff --git a/boa/util/eip5202.py b/boa/util/eip5202.py index 21574a96..10b7c321 100644 --- a/boa/util/eip5202.py +++ b/boa/util/eip5202.py @@ -3,14 +3,14 @@ from eth_utils import to_canonical_address, to_checksum_address from vyper.utils import keccak256 -DEFAULT_ERC5202_PREAMBLE = b"\xFE\x71\x00" +DEFAULT_BLUEPRINT_PREAMBLE = b"\xFE\x71\x00" def generate_blueprint_bytecode( contract_bytecode: bytes, blueprint_preamble: bytes = None ): if blueprint_preamble is None: - blueprint_preamble = DEFAULT_ERC5202_PREAMBLE + blueprint_preamble = DEFAULT_BLUEPRINT_PREAMBLE blueprint_bytecode = blueprint_preamble + contract_bytecode