diff --git a/deployment/__init__.py b/deployment/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/deployments/artifacts/lynx/lynx-alpha-13-child-registry.json b/deployment/artifacts/lynx/lynx-alpha-13-child-registry.json similarity index 100% rename from deployments/artifacts/lynx/lynx-alpha-13-child-registry.json rename to deployment/artifacts/lynx/lynx-alpha-13-child-registry.json diff --git a/deployments/artifacts/lynx/lynx-alpha-13-root-registry.json b/deployment/artifacts/lynx/lynx-alpha-13-root-registry.json similarity index 100% rename from deployments/artifacts/lynx/lynx-alpha-13-root-registry.json rename to deployment/artifacts/lynx/lynx-alpha-13-root-registry.json diff --git a/deployment/confirm.py b/deployment/confirm.py new file mode 100644 index 00000000..d688e77a --- /dev/null +++ b/deployment/confirm.py @@ -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() diff --git a/deployment/constants.py b/deployment/constants.py new file mode 100644 index 00000000..a4844a91 --- /dev/null +++ b/deployment/constants.py @@ -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"] diff --git a/deployments/constructor_params/lynx/lynx-alpha-13-child-params.json b/deployment/constructor_params/lynx/lynx-alpha-13-child-params.json similarity index 100% rename from deployments/constructor_params/lynx/lynx-alpha-13-child-params.json rename to deployment/constructor_params/lynx/lynx-alpha-13-child-params.json diff --git a/deployments/constructor_params/lynx/lynx-alpha-13-root-params.json b/deployment/constructor_params/lynx/lynx-alpha-13-root-params.json similarity index 100% rename from deployments/constructor_params/lynx/lynx-alpha-13-root-params.json rename to deployment/constructor_params/lynx/lynx-alpha-13-root-params.json diff --git a/scripts/deployment.py b/deployment/params.py similarity index 77% rename from scripts/deployment.py rename to deployment/params.py index 1f4100fc..654f1b5a 100644 --- a/scripts/deployment.py +++ b/deployment/params.py @@ -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): @@ -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.""" diff --git a/scripts/registry.py b/deployment/registry.py similarity index 91% rename from scripts/registry.py rename to deployment/registry.py index 9e07030b..ff688f41 100644 --- a/scripts/registry.py +++ b/deployment/registry.py @@ -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): @@ -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 diff --git a/scripts/utils.py b/deployment/utils.py similarity index 54% rename from scripts/utils.py rename to deployment/utils.py index c19b075f..506fb44a 100644 --- a/scripts/utils.py +++ b/deployment/utils.py @@ -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: @@ -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 diff --git a/scripts/check_xchain.py b/scripts/check_xchain.py deleted file mode 100644 index 039e7c3b..00000000 --- a/scripts/check_xchain.py +++ /dev/null @@ -1,32 +0,0 @@ -import time - -from ape import accounts, networks, project - - -def main(): - deployer = accounts.load("TGoerli") - print("*******") - print("WARNING: This script will take 40 mins to run to allow messages to sync from L1 to L2") - print("*******") - with networks.ethereum.goerli.use_provider("infura"): - root = project.PolygonRoot.at("0xD2Cb2A8fbE29adBa1C287b2A0b49f5C4fDc1f5BE") - root.updateOperator( - "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", - "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", - sender=deployer, - ) - # check every 5 minutes - print("Now: {}".format(time.time())) - for i in range(12): - time.sleep(60 * i * 5) - print("Now: {}".format(time.time())) - with networks.polygon.mumbai.use_provider("infura"): - taco_child = project.TACoChildApplication.at( - "0x68E95C2548363Bf5856667065Bc1B89CC498969F" - ) - print( - taco_child.stakingProviderFromOperator("0xAe87D865F3A507185656aD0ef52a8E0B9f3d58f8") - ) - print( - taco_child.stakingProviderFromOperator("0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600") - ) diff --git a/scripts/constants.py b/scripts/constants.py deleted file mode 100644 index 24a596d8..00000000 --- a/scripts/constants.py +++ /dev/null @@ -1,14 +0,0 @@ -from pathlib import Path - -from ape import config, networks - -LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["local"] -PRODUCTION_ENVIRONMENTS = ["mainnet", "polygon-main"] -CURRENT_NETWORK = networks.network.name -DEPLOYMENTS_CONFIG = config.get_config("deployments")["ethereum"][CURRENT_NETWORK][0] -PROJECT_ROOT = Path(__file__).parent.parent -CONSTRUCTOR_PARAMS_DIR = PROJECT_ROOT / "deployments" / "constructor_params" -ARTIFACTS_DIR = PROJECT_ROOT / "deployments" / "artifacts" -ETHERSCAN_API_KEY_ENVVAR = "ETHERSCAN_API_KEY" -WEB3_INFURA_API_KEY_ENVVAR = "WEB3_INFURA_API_KEY" -NULL_ADDRESS = "0x" + "0" * 40 diff --git a/scripts/deploy_coordinator.py b/scripts/deploy_coordinator.py deleted file mode 100644 index 55472f2a..00000000 --- a/scripts/deploy_coordinator.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from ape.cli import get_user_selected_account -from scripts.constants import DEPLOYMENTS_CONFIG - - -def main(account_id=None): - deployer = get_user_selected_account() - deployments_config = DEPLOYMENTS_CONFIG - - coordinator = project.Coordinator.deploy( - deployments_config.get("taco_child_contract"), - deployments_config.get("ritual_timeout"), - deployments_config.get("max_dkg_size"), - sender=deployer, - publish=deployments_config.get("verify"), - ) - return coordinator diff --git a/scripts/deploy_coordinator_with_fee_model.py b/scripts/deploy_coordinator_with_fee_model.py deleted file mode 100644 index ac0d568e..00000000 --- a/scripts/deploy_coordinator_with_fee_model.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/python3 - -import os - -import click -from ape import config, networks, project -from ape.cli import NetworkBoundCommand, account_option, network_option -from ape.utils import ZERO_ADDRESS -from ape_etherscan.utils import API_KEY_ENV_KEY_MAP - - -@click.command(cls=NetworkBoundCommand) -@network_option() -@account_option() -@click.option("--currency", default=ZERO_ADDRESS) -@click.option("--rate", default=None) -@click.option("--timeout", default=None) -@click.option("--admin", default=None) -@click.option("--max_size", default=None) -@click.option("--verify/--no-verify", default=True) -def cli(network, account, currency, rate, timeout, admin, max_size, verify): - - deployer = account - click.echo(f"Deployer: {deployer}") - - if rate and currency == ZERO_ADDRESS: - raise ValueError("ERC20 contract address needed for currency") - - # Network - ecosystem_name = networks.provider.network.ecosystem.name - network_name = networks.provider.network.name - provider_name = networks.provider.name - click.echo(f"You are connected to network '{ecosystem_name}:{network_name}:{provider_name}'.") - - # TODO: Move this to a common deployment utilities module - # Validate Etherscan verification parameters. - # This import fails if called before the click network options are evaluated - from scripts.constants import LOCAL_BLOCKCHAIN_ENVIRONMENTS - - is_public_deployment = network_name not in LOCAL_BLOCKCHAIN_ENVIRONMENTS - if not is_public_deployment: - verify = False - elif verify: - env_var_key = API_KEY_ENV_KEY_MAP.get(ecosystem_name) - api_key = os.environ.get(env_var_key) - print(api_key) - if not api_key: - raise ValueError(f"{env_var_key} is not set") - - # Use deployment information for currency, if possible - try: - deployments = config.deployments[ecosystem_name][network_name] - except KeyError: - pass # TODO: Further validate currency address? - else: - print(deployments) - try: - currency = next(d for d in deployments if d["contract_type"] == currency)["address"] - except StopIteration: - pass - - try: - stakes = next(d for d in deployments if d["contract_type"] == "TACoChildApplication")[ - "address" - ] - except StopIteration: - raise ValueError("TACoChildApplication deployment needed") - - # Parameter defaults - admin = admin or deployer - rate = rate or 1 - timeout = timeout or 60 * 60 - max_size = max_size or 64 - - params = (stakes, timeout, max_size, admin, currency, rate) - print("Deployment parameters:", params) - return project.Coordinator.deploy(*params, sender=deployer, publish=verify) diff --git a/scripts/deploy_flat_rate_fee_model.py b/scripts/deploy_flat_rate_fee_model.py deleted file mode 100644 index 9ebc3b1f..00000000 --- a/scripts/deploy_flat_rate_fee_model.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python3 - -import os - -import click -from ape import config, networks, project -from ape.cli import NetworkBoundCommand, account_option, network_option -from ape.utils import ZERO_ADDRESS -from ape_etherscan.utils import API_KEY_ENV_KEY_MAP - - -@click.command(cls=NetworkBoundCommand) -@network_option() -@account_option() -@click.option("--currency", default=ZERO_ADDRESS) -@click.option("--rate", default=0) -@click.option("--verify/--no-verify", default=True) -def cli(network, account, currency, rate, verify): - deployer = account # get_account(account_id) - click.echo(f"Deployer: {deployer}") - - if rate and currency == ZERO_ADDRESS: - raise ValueError("ERC20 contract address needed for currency") - - # Network - ecosystem_name = networks.provider.network.ecosystem.name - network_name = networks.provider.network.name - provider_name = networks.provider.name - click.echo(f"You are connected to network '{ecosystem_name}:{network_name}:{provider_name}'.") - - # TODO: Move this to a common deployment utilities module - # Validate Etherscan verification parameters. - # This import fails if called before the click network options are evaluated - from scripts.constants import LOCAL_BLOCKCHAIN_ENVIRONMENTS - - is_public_deployment = network_name not in LOCAL_BLOCKCHAIN_ENVIRONMENTS - if not is_public_deployment: - verify = False - elif verify: - env_var_key = API_KEY_ENV_KEY_MAP.get(ecosystem_name) - api_key = os.environ.get(env_var_key) - if not api_key: - raise ValueError(f"{env_var_key} is not set") - - # Use deployment information for currency, if possible - try: - deployments = config.deployments[ecosystem_name][network_name] - except KeyError: - pass # TODO: Further validate currency address? - else: - try: - currency = next(d for d in deployments if d["contract_type"] == currency)["address"] - except StopIteration: - pass - - try: - stakes = next(d for d in deployments if d["contract_type"] == "TACoChildApplication")[ - "address" - ] - except StopIteration: - raise ValueError("TACoChildApplication deployment needed") - - flat_rate_fee_model = project.FlatRateFeeModel.deploy( - currency, - rate, - stakes, - sender=deployer, - publish=verify, - ) - return flat_rate_fee_model diff --git a/scripts/deploy_nucypher_token.py b/scripts/deploy_nucypher_token.py deleted file mode 100644 index 53b02c9c..00000000 --- a/scripts/deploy_nucypher_token.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from scripts.utils import get_account -from scripts.constants import DEPLOYMENTS_CONFIG - - -def main(account_id=None): - deployer = get_account(account_id) - deployments_config = DEPLOYMENTS_CONFIG - nucypher_token_supply = deployments_config.get("nu_token_supply") - - nucypher_token = project.NuCypherToken.deploy( - nucypher_token_supply, - sender=deployer, - publish=deployments_config.get("verify"), - ) - return nucypher_token diff --git a/scripts/deploy_staking_escrow.py b/scripts/deploy_staking_escrow.py deleted file mode 100644 index c543488d..00000000 --- a/scripts/deploy_staking_escrow.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from scripts.utils import ( - deploy_mocks, - get_account, -) -from scripts.constants import LOCAL_BLOCKCHAIN_ENVIRONMENTS, CURRENT_NETWORK, DEPLOYMENTS_CONFIG - - -def main(account_id=None): - deployer = get_account(account_id) - deployments_config = DEPLOYMENTS_CONFIG - if CURRENT_NETWORK in LOCAL_BLOCKCHAIN_ENVIRONMENTS: - nucypher_token, t_staking, _, work_lock, _, _ = deploy_mocks(deployer) - else: - nucypher_token = deployments_config.get("nu_token") - t_staking = deployments_config.get("t_staking") - work_lock = deployments_config.get("work_lock") - - staking_escrow = project.StakingEscrow.deploy( - nucypher_token, - work_lock, - t_staking, - sender=deployer, - publish=deployments_config.get("verify"), - ) - return staking_escrow diff --git a/scripts/deploy_subscription_manager.py b/scripts/deploy_subscription_manager.py deleted file mode 100644 index 564195e3..00000000 --- a/scripts/deploy_subscription_manager.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from scripts.utils import get_account -from web3 import Web3 - -INITIAL_FEE_RATE = Web3.to_wei(1, "gwei") - - -def main(id=None): - deployer = get_account(id) - dependency = project.dependencies["openzeppelin"]["4.9.1"] - - proxy_admin = deployer.deploy(dependency.ProxyAdmin) - - subscription_manager_logic = deployer.deploy(project.SubscriptionManager) - calldata = subscription_manager_logic.initialize.encode_input(INITIAL_FEE_RATE) - transparent_proxy = dependency.TransparentUpgradeableProxy.deploy( - subscription_manager_logic.address, proxy_admin.address, calldata, sender=deployer - ) - - subscription_manager = project.SubscriptionManager.at(transparent_proxy.address) - return subscription_manager diff --git a/scripts/deploy_taco_application.py b/scripts/deploy_taco_application.py deleted file mode 100644 index c62dfbb2..00000000 --- a/scripts/deploy_taco_application.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from scripts.utils import ( - deploy_mocks, - get_account, -) -from scripts.constants import LOCAL_BLOCKCHAIN_ENVIRONMENTS, CURRENT_NETWORK, DEPLOYMENTS_CONFIG - - -def main(account_id=None): - deployer = get_account(account_id) - deployments_config = DEPLOYMENTS_CONFIG - - if CURRENT_NETWORK in LOCAL_BLOCKCHAIN_ENVIRONMENTS: - _, _, t_staking, _, _, t_token = deploy_mocks(deployer) - else: - t_staking = deployments_config.get("t_staking") - t_token = deployments_config.get("t_token") - - # TODO deploy proxy - taco_app = project.TACoApplication.deploy( - t_token, - t_staking, - deployments_config.get("pre_min_authorization"), - deployments_config.get("pre_min_operator_seconds"), - deployments_config.get("reward_duration"), - deployments_config.get("deauthorization_duration"), - [ - deployments_config.get("commitment_duration_1"), - deployments_config.get("commitment_duration_2"), - ], - sender=deployer, - publish=deployments_config.get("verify"), - ) - return taco_app diff --git a/scripts/deploy_testnet_threshold_staking.py b/scripts/deploy_testnet_threshold_staking.py deleted file mode 100644 index f6f0d3cc..00000000 --- a/scripts/deploy_testnet_threshold_staking.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/python3 -from ape import project -from scripts.utils import get_account -from scripts.constants import DEPLOYMENTS_CONFIG - - -def main(account_id=None): - deployer = get_account(account_id) - deployments_config = DEPLOYMENTS_CONFIG - testnet_staking = project.TestnetThresholdStaking.deploy( - sender=deployer, - publish=deployments_config.get("verify"), - ) - return testnet_staking diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py deleted file mode 100644 index edb4c9d2..00000000 --- a/scripts/deploy_xchain_test.py +++ /dev/null @@ -1,135 +0,0 @@ -import click -from ape import accounts, config, networks, project -from ape.cli import NetworkBoundCommand, account_option - -DEPENDENCY = project.dependencies["openzeppelin"]["4.9.1"] - - -def convert_config(config): - result = {} - for item in config: - if "contract_type" in item: - result[item["contract_type"]] = item["address"] - else: - result.update(item) - return result - - -def deploy_eth_contracts(deployer, child_address, config, eth_network): - # Connect to the Ethereum network - with eth_network.use_provider("infura"): - - token = project.TToken.deploy( - 100_000_000_000 * 10**18, - sender=deployer, - ) - - threshold_staking = project.ThresholdStakingForTACoApplicationMock.deploy( - sender=deployer, - ) - - taco_app = project.TACoApplication.deploy( - token, - threshold_staking, - config["pre_min_authorization"], - config["pre_min_operator_seconds"], - config["reward_duration"], - config["deauthorization_duration"], - sender=deployer, - ) - - proxy_admin = DEPENDENCY.ProxyAdmin.deploy(sender=deployer) - proxy = DEPENDENCY.TransparentUpgradeableProxy.deploy( - taco_app.address, - proxy_admin.address, - taco_app.initialize.encode_input(), - sender=deployer, - ) - - proxy_contract = project.TACoApplication.at(proxy.address) - threshold_staking.setApplication(proxy_contract.address, sender=deployer) - - root = project.PolygonRoot.deploy( - config["checkpoint_manager"], - config["fx_root"], - proxy_contract.address, - child_address, - sender=deployer, - publish=False, - ) - proxy_contract.setChildApplication(root.address, sender=deployer) - - return root, proxy_contract, threshold_staking - - -def deploy_polygon_contracts(deployer, config, poly_network): - # Connect to the Polygon network - with poly_network.use_provider("infura"): - polygon_child = project.PolygonChild.deploy( - config["fx_child"], - sender=deployer, - publish=False, - ) - - TACoChild = project.TestnetTACoChildApplication.deploy( - polygon_child.address, - sender=deployer, - publish=False, - ) - proxy_admin = DEPENDENCY.ProxyAdmin.deploy(sender=deployer) - proxy = DEPENDENCY.TransparentUpgradeableProxy.deploy( - TACoChild.address, - proxy_admin.address, - b"", - sender=deployer, - ) - proxy_contract = project.TestnetTACoChildApplication.at(proxy.address) - polygon_child.setChildApplication(proxy_contract.address, sender=deployer) - - coordinator = project.CoordinatorForTACoChildApplicationMock.deploy( - proxy_contract.address, sender=deployer - ) - proxy_contract.initialize(coordinator.address, [deployer], sender=deployer) - - return polygon_child, proxy_contract, coordinator - - -# TODO: Figure out better way to retrieve the TACo app contract address -@click.command(cls=NetworkBoundCommand) -@click.option("--network_type", type=click.Choice(["mainnet", "testnet"])) -@account_option() -def cli(network_type, account): - deployer = account - if network_type == "mainnet": - eth_config = config.get_config("deployments")["ethereum"]["mainnet"] - poly_config = config.get_config("deployments")["polygon"]["mainnet"] - eth_network = networks.ethereum.mainnet - poly_network = networks.polygon.mainnet - elif network_type == "testnet": - eth_config = config.get_config("deployments")["ethereum"]["goerli"] - poly_config = config.get_config("deployments")["polygon"]["mumbai"] - eth_network = networks.ethereum.goerli - poly_network = networks.polygon.mumbai - - print("Deployer: {}".format(deployer)) - print("ETH CONFIG: {}".format(eth_config)) - print("POLYGON CONFIG: {}".format(poly_config)) - - with accounts.use_sender(deployer): - poly_child, taco_child_app, coordinator = deploy_polygon_contracts( - deployer, convert_config(poly_config), poly_network - ) - root, taco_root_app, threshold_staking = deploy_eth_contracts( - deployer, poly_child.address, convert_config(eth_config), eth_network - ) - - # Set the root contract address in the child contract - with poly_network.use_provider("infura"): - poly_child.setFxRootTunnel(root.address) - - print("CHILD: {}".format(poly_child.address)) - print("TACo CHILD APP: {}".format(taco_child_app.address)) - print("COORDINATOR: {}".format(coordinator.address)) - print("ROOT: {}".format(root.address)) - print("THRESHOLD STAKING: {}".format(threshold_staking.address)) - print("TACO ROOT APP: {}".format(taco_root_app.address)) diff --git a/scripts/configure_lynx_staking.py b/scripts/lynx/configure_staking.py similarity index 94% rename from scripts/configure_lynx_staking.py rename to scripts/lynx/configure_staking.py index 224beaad..d6bda2fd 100644 --- a/scripts/configure_lynx_staking.py +++ b/scripts/lynx/configure_staking.py @@ -1,7 +1,7 @@ from ape import project from ape.cli import get_user_selected_account -from scripts.constants import ARTIFACTS_DIR -from scripts.registry import read_registry +from deployment.constants import ARTIFACTS_DIR +from deployment.registry import read_registry REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-root-registry.json" diff --git a/scripts/deploy_lynx_child.py b/scripts/lynx/deploy_child.py similarity index 84% rename from scripts/deploy_lynx_child.py rename to scripts/lynx/deploy_child.py index 108fb357..cbcf1650 100644 --- a/scripts/deploy_lynx_child.py +++ b/scripts/lynx/deploy_child.py @@ -1,21 +1,19 @@ #!/usr/bin/python3 from ape import networks, project -from scripts.constants import ( +from deployment.constants import ( ARTIFACTS_DIR, CONSTRUCTOR_PARAMS_DIR, CURRENT_NETWORK, - LOCAL_BLOCKCHAIN_ENVIRONMENTS, + LOCAL_BLOCKCHAIN_ENVIRONMENTS, OZ_DEPENDENCY, ) -from scripts.deployment import prepare_deployment -from scripts.registry import registry_from_ape_deployments +from deployment.registry import registry_from_ape_deployments +from deployment.utils import verify_contracts, prepare_deployment VERIFY = CURRENT_NETWORK not in LOCAL_BLOCKCHAIN_ENVIRONMENTS CONSTRUCTOR_PARAMS_FILEPATH = CONSTRUCTOR_PARAMS_DIR / "lynx" / "lynx-alpha-13-child-params.json" REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-child-registry.json" -OZ_DEPENDENCY = project.dependencies["openzeppelin"]["4.9.1"] - def main(): """ @@ -84,7 +82,4 @@ def main(): print(f"(i) Registry written to {output_filepath}!") if VERIFY: - etherscan = networks.provider.network.explorer - for deployment in deployments: - print(f"(i) Verifying {deployment.contract_type.name}...") - etherscan.publish_contract(deployment.address) + verify_contracts(contracts=deployments) diff --git a/scripts/deploy_lynx_root.py b/scripts/lynx/deploy_root.py similarity index 91% rename from scripts/deploy_lynx_root.py rename to scripts/lynx/deploy_root.py index 0658685b..3016603f 100644 --- a/scripts/deploy_lynx_root.py +++ b/scripts/lynx/deploy_root.py @@ -1,21 +1,19 @@ #!/usr/bin/python3 from ape import networks, project -from scripts.constants import ( +from deployment.constants import ( ARTIFACTS_DIR, CONSTRUCTOR_PARAMS_DIR, CURRENT_NETWORK, - LOCAL_BLOCKCHAIN_ENVIRONMENTS, + LOCAL_BLOCKCHAIN_ENVIRONMENTS, OZ_DEPENDENCY, ) -from scripts.deployment import prepare_deployment -from scripts.registry import registry_from_ape_deployments +from deployment.utils import prepare_deployment +from deployment.registry import registry_from_ape_deployments VERIFY = CURRENT_NETWORK not in LOCAL_BLOCKCHAIN_ENVIRONMENTS CONSTRUCTOR_PARAMS_FILEPATH = CONSTRUCTOR_PARAMS_DIR / "lynx" / "lynx-alpha-13-root-params.json" REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-root-registry.json" -OZ_DEPENDENCY = project.dependencies["openzeppelin"]["4.9.1"] - def main(): """ diff --git a/scripts/merge_lynx_deployment_registries.py b/scripts/lynx/merge_registries.py similarity index 84% rename from scripts/merge_lynx_deployment_registries.py rename to scripts/lynx/merge_registries.py index 5feeb38b..47dcd999 100644 --- a/scripts/merge_lynx_deployment_registries.py +++ b/scripts/lynx/merge_registries.py @@ -1,5 +1,5 @@ -from scripts.constants import ARTIFACTS_DIR -from scripts.registry import merge_registries +from deployment.constants import ARTIFACTS_DIR +from deployment.registry import merge_registries lynx_child_deployment_registry = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-child-registry.json" diff --git a/scripts/lynx/verify.py b/scripts/lynx/verify.py new file mode 100644 index 00000000..9d5228c3 --- /dev/null +++ b/scripts/lynx/verify.py @@ -0,0 +1,10 @@ +from deployment.constants import ARTIFACTS_DIR +from deployment.registry import contracts_from_registry +from deployment.utils import verify_contracts + +REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-child-registry.json" + + +def main(): + contracts = contracts_from_registry(REGISTRY_FILEPATH) + verify_contracts(contracts) diff --git a/scripts/verify_lynx.py b/scripts/verify_lynx.py deleted file mode 100644 index fe368f53..00000000 --- a/scripts/verify_lynx.py +++ /dev/null @@ -1,20 +0,0 @@ -from ape import networks -from scripts.constants import ARTIFACTS_DIR -from scripts.deployment import get_contract_container -from scripts.registry import read_registry - -REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-child-registry.json" - -registry_entries = read_registry(filepath=REGISTRY_FILEPATH) - -deployments = [] -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) - -etherscan = networks.provider.network.explorer -for deployment in deployments: - print(f"(i) Verifying {deployment.contract_type.name}...") - etherscan.publish_contract(deployment.address) diff --git a/setup.cfg b/setup.cfg index 5fe53284..358ba231 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,3 +8,6 @@ include_trailing_comma = True line_length = 100 multi_line_output = 3 use_parentheses = True + +[options] +packages = find: diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..60684932 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup()