Skip to content

Commit

Permalink
Relocates custom logic into 'deploymnets' package; Removes stale scri…
Browse files Browse the repository at this point in the history
…pts that use legacy deployment methods
  • Loading branch information
KPrasch committed Sep 26, 2023
1 parent e9dff3e commit da3ca9c
Show file tree
Hide file tree
Showing 29 changed files with 151 additions and 609 deletions.
Empty file added deployment/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions deployment/confirm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from collections import OrderedDict

from deployment.constants import NULL_ADDRESS


def _confirm_deployment(contract_name: str) -> None:
"""Asks the user to confirm the deployment of a single contract."""
answer = input(f"Deploy {contract_name} Y/N? ")
if answer.lower().strip() == "n":
print("Aborting deployment!")
exit(-1)


def _confirm_null_address() -> None:
answer = input("Null Address detected for deployment parameter; Continue? Y/N? ")
if answer.lower().strip() == "n":
print("Aborting deployment!")
exit(-1)


def _confirm_resolution(resolved_params: OrderedDict, contract_name: str) -> None:
"""Asks the user to confirm the resolved constructor parameters for a single contract."""
if len(resolved_params) == 0:
print(f"\n(i) No constructor parameters for {contract_name}")
_confirm_deployment(contract_name)
return

print(f"\nConstructor parameters for {contract_name}")
contains_null_address = False
for name, resolved_value in resolved_params.items():
print(f"\t{name}={resolved_value}")
if not contains_null_address:
contains_null_address = resolved_value == NULL_ADDRESS
_confirm_deployment(contract_name)
if contains_null_address:
_confirm_null_address()
20 changes: 20 additions & 0 deletions deployment/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

from ape import networks, project

import deployment

LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["local"]
PRODUCTION_ENVIRONMENTS = ["mainnet", "polygon-main"]
CURRENT_NETWORK = networks.network.name
DEPLOYMENT_DIR = Path(deployment.__file__).parent
CONSTRUCTOR_PARAMS_DIR = DEPLOYMENT_DIR / "constructor_params"
ARTIFACTS_DIR = DEPLOYMENT_DIR / "artifacts"
ETHERSCAN_API_KEY_ENVVAR = "ETHERSCAN_API_KEY"
WEB3_INFURA_API_KEY_ENVVAR = "WEB3_INFURA_API_KEY"
NULL_ADDRESS = "0x" + "0" * 40
VARIABLE_PREFIX = "$"
PROXY_DECLARATION_DELIMETER = ":"
SPECIAL_VALUE_VARIABLES = {"EMPTY_BYTES": b""}
PROXY_NAME = "TransparentUpgradeableProxy"
OZ_DEPENDENCY = project.dependencies["openzeppelin"]["4.9.1"]
77 changes: 8 additions & 69 deletions scripts/deployment.py → deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,17 @@
from typing import Any, List

from ape import chain, project
from ape.api import AccountAPI
from ape.cli import get_user_selected_account
from ape.contracts.base import ContractContainer, ContractInstance
from scripts.constants import NULL_ADDRESS
from scripts.utils import check_etherscan_plugin, check_infura_plugin, check_registry_filepath
from web3.auto.gethdev import w3

VARIABLE_PREFIX = "$"
PROXY_DECLARATION_DELIMETER = ":"

SPECIAL_VALUE_VARIABLES = {"EMPTY_BYTES": b""}

PROXY_NAME = "TransparentUpgradeableProxy"


def prepare_deployment(
params_filepath: Path, registry_filepath: Path, publish: bool = False
) -> typing.Tuple[AccountAPI, "ApeDeploymentParameters"]:
"""
Prepares the deployment by loading the deployment parameters
and checking the pre-deployment conditions.
NOTE: publish is False by default because we use customized artifact tracking
that is not compatible with the ape publish command.
"""

# pre-deployment checks
check_registry_filepath(registry_filepath=registry_filepath)
check_etherscan_plugin()
check_infura_plugin()

# load (and implicitly validate) deployment parameters
constructor_parameters = ConstructorParameters.from_file(params_filepath)
deployment_parameters = ApeDeploymentParameters(constructor_parameters, publish)

# do this last so that the user can see any failed
# pre-deployment checks or validation errors.
deployer_account = get_user_selected_account()
return deployer_account, deployment_parameters
from deployment.confirm import _confirm_resolution
from deployment.constants import (
NULL_ADDRESS,
VARIABLE_PREFIX,
PROXY_DECLARATION_DELIMETER,
SPECIAL_VALUE_VARIABLES,
PROXY_NAME
)


def _is_proxy_variable(variable: str):
Expand Down Expand Up @@ -236,39 +208,6 @@ def validate_constructor_parameters(config: typing.OrderedDict[str, Any]) -> Non
)


def _confirm_deployment(contract_name: str) -> None:
"""Asks the user to confirm the deployment of a single contract."""
answer = input(f"Deploy {contract_name} Y/N? ")
if answer.lower().strip() == "n":
print("Aborting deployment!")
exit(-1)


def _confirm_null_address() -> None:
answer = input("Null Address detected for deployment parameter; Continue? Y/N? ")
if answer.lower().strip() == "n":
print("Aborting deployment!")
exit(-1)


def _confirm_resolution(resolved_params: OrderedDict, contract_name: str) -> None:
"""Asks the user to confirm the resolved constructor parameters for a single contract."""
if len(resolved_params) == 0:
print(f"\n(i) No constructor parameters for {contract_name}")
_confirm_deployment(contract_name)
return

print(f"\nConstructor parameters for {contract_name}")
contains_null_address = False
for name, resolved_value in resolved_params.items():
print(f"\t{name}={resolved_value}")
if not contains_null_address:
contains_null_address = resolved_value == NULL_ADDRESS
_confirm_deployment(contract_name)
if contains_null_address:
_confirm_null_address()


class ConstructorParameters:
"""Represents the constructor parameters for a set of contracts."""

Expand Down
15 changes: 14 additions & 1 deletion scripts/registry.py → deployment/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from ape.contracts import ContractInstance
from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address
from scripts.utils import check_registry_filepath

from deployment.params import get_contract_container
from deployment.utils import check_registry_filepath


class RegistryEntry(NamedTuple):
Expand Down Expand Up @@ -187,3 +189,14 @@ def merge_registries(
print(f"Merged registry output to {output_filepath}")

return output_filepath


def contracts_from_registry(registry_filepath: Path):
registry_entries = read_registry(filepath=registry_filepath)
deployments = list()
for registry_entry in registry_entries:
contract_type = registry_entry.contract_name
contract_container = get_contract_container(contract_type)
contract_instance = contract_container.at(registry_entry.contract_address)
deployments.append(contract_instance)
return deployments
82 changes: 44 additions & 38 deletions scripts/utils.py → deployment/utils.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
import os
import typing
from pathlib import Path
from typing import List

from ape import accounts, project
from web3 import Web3
from ape import networks
from ape.api import AccountAPI
from ape.cli import get_user_selected_account
from ape.contracts import ContractInstance

from scripts.constants import (
from deployment.constants import (
CURRENT_NETWORK,
ETHERSCAN_API_KEY_ENVVAR,
LOCAL_BLOCKCHAIN_ENVIRONMENTS,
WEB3_INFURA_API_KEY_ENVVAR
)


def deploy_mocks(deployer):
"""This function should deploy nucypher_token and t_staking and return the
corresponding contract addresses"""
nucypher_token = project.NuCypherToken.deploy(1_000_000_000, sender=deployer)
t_staking_for_escrow = project.ThresholdStakingForStakingEscrowMock.deploy(sender=deployer)
t_staking_for_taco = project.ThresholdStakingForTACoApplicationMock.deploy(sender=deployer)
total_supply = Web3.to_wei(10_000_000_000, "ether")
t_token = project.TToken.deploy(total_supply, sender=deployer)
work_lock = project.WorkLockForStakingEscrowMock.deploy(nucypher_token, sender=deployer)
staking_escrow = project.StakingEscrow.deploy(
nucypher_token, work_lock, t_staking_for_escrow, sender=deployer
)
return (
nucypher_token,
t_staking_for_escrow,
t_staking_for_taco,
work_lock,
staking_escrow,
t_token,
)


def get_account(_id):
if CURRENT_NETWORK not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
if _id is None:
raise ValueError("Must specify account id when deploying to production networks")
else:
return accounts.load(_id)

elif CURRENT_NETWORK in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
return accounts.test_accounts[0]
else:
return None
from deployment.params import (
ApeDeploymentParameters,
ConstructorParameters
)


def check_registry_filepath(registry_filepath: Path) -> None:
Expand Down Expand Up @@ -91,3 +64,36 @@ def check_infura_plugin() -> None:
raise ValueError(f"{WEB3_INFURA_API_KEY_ENVVAR} is not set.")
if not len(api_key) == 32:
raise ValueError(f"{WEB3_INFURA_API_KEY_ENVVAR} is not valid.")


def verify_contracts(contracts: List[ContractInstance]) -> None:
explorer = networks.provider.network.explorer
for instance in contracts:
print(f"(i) Verifying {instance.contract_type.name}...")
explorer.publish_contract(instance.address)


def prepare_deployment(
params_filepath: Path, registry_filepath: Path, publish: bool = False
) -> typing.Tuple[AccountAPI, "ApeDeploymentParameters"]:
"""
Prepares the deployment by loading the deployment parameters
and checking the pre-deployment conditions.
NOTE: publish is False by default because we use customized artifact tracking
that is not compatible with the ape publish command.
"""

# pre-deployment checks
check_registry_filepath(registry_filepath=registry_filepath)
check_etherscan_plugin()
check_infura_plugin()

# load (and implicitly validate) deployment parameters
constructor_parameters = ConstructorParameters.from_file(params_filepath)
deployment_parameters = ApeDeploymentParameters(constructor_parameters, publish)

# do this last so that the user can see any failed
# pre-deployment checks or validation errors.
deployer_account = get_user_selected_account()
return deployer_account, deployment_parameters
32 changes: 0 additions & 32 deletions scripts/check_xchain.py

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/constants.py

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/deploy_coordinator.py

This file was deleted.

Loading

0 comments on commit da3ca9c

Please sign in to comment.