Skip to content

Commit

Permalink
Move deployment/registry python modules to scripts folder.
Browse files Browse the repository at this point in the history
Fix parameters to deploy() command to include ContractContainer value.
Add check_etherscan_plugin to utils
Rename ConstructorParams to DeploymentConfig; get_params to get_constructor_params.
  • Loading branch information
derekpierre committed Sep 19, 2023
1 parent 88d80cb commit 9eab251
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 55 deletions.
File renamed without changes.
46 changes: 21 additions & 25 deletions scripts/testnet/deploy_lynx.py → scripts/deploy_lynx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from ape import project
from ape.cli import get_user_selected_account

from utils.deployment import ConstructorParams
from utils.registry import registry_from_ape_deployments
from utils.misc import check_etherscan_plugin
from scripts.deployment import DeploymentConfig
from scripts.registry import registry_from_ape_deployments
from scripts.utils import check_etherscan_plugin

PUBLISH = False
CONSTRUCTOR_PARAMS_FILEPATH = Path('')
DEPLOYMENT_REGISTRY_FILEPATH = Path("lynx_testnet_registry.json") # TODO: move to artifacts and make unique
DEPLOYMENT_CONFIG_FILEPATH = Path(__file__).parent / "configs" / "lynx_config.json"
DEPLOYMENT_REGISTRY_FILEPATH = (
Path(__file__).parent.parent / "artifacts" / "lynx_testnet_registry.json"
) # TODO: make unique


def main():
Expand All @@ -33,15 +34,17 @@ def main():

check_etherscan_plugin()
deployer = get_user_selected_account()
config = ConstructorParams.from_file(CONSTRUCTOR_PARAMS_FILEPATH)
config = DeploymentConfig.from_file(DEPLOYMENT_CONFIG_FILEPATH)

LynxRootApplication = deployer.deploy(
*config.get_params(project.LynxRootApplication, locals()),
publish=PUBLISH
project.LynxRootApplication, # TODO should the container be returned by call below?
*config.get_constructor_params(project.LynxRootApplication, locals()),
publish=PUBLISH,
)

LynxTACoChildApplication = deployer.deploy(
*config.get_params(project.LynxRootApplication, locals()),
project.LynxTACoChildApplication,
*config.get_constructor_params(project.LynxTACoChildApplication, locals()),
publish=PUBLISH,
)

Expand All @@ -52,29 +55,22 @@ def main():
)

LynxRitualToken = deployer.deploy(
*config.get_params(project.LynxRitualToken, locals()),
publish=PUBLISH
project.LynxRitualToken,
*config.get_constructor_params(project.LynxRitualToken, locals()),
publish=PUBLISH,
)

# Lynx Coordinator
Coordinator = deployer.deploy(
*config.get_params(project.Coordinator, locals()),
project.Coordinator,
*config.get_constructor_params(project.Coordinator, locals()),
publish=PUBLISH,
)

LynxTACoChildApplication.setCoordinator(
Coordinator.address,
sender=deployer
)
LynxTACoChildApplication.setCoordinator(Coordinator.address, sender=deployer)

deployments = [
LynxRootApplication,
LynxTACoChildApplication,
LynxRitualToken,
Coordinator
]
deployments = [LynxRootApplication, LynxTACoChildApplication, LynxRitualToken, Coordinator]

registry_from_ape_deployments(
deployments=deployments,
output_filepath=DEPLOYMENT_REGISTRY_FILEPATH
deployments=deployments, output_filepath=DEPLOYMENT_REGISTRY_FILEPATH
)
49 changes: 19 additions & 30 deletions utils/deployment.py → scripts/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def _resolve_param(value: Any, context: typing.Dict[str, Any]) -> Any:
return contract_instance.address


def _resolve_parameters(
parameters: OrderedDict,
context: typing.Dict[str, Any]
) -> OrderedDict:
def _resolve_parameters(parameters: OrderedDict, context: typing.Dict[str, Any]) -> OrderedDict:
resolved_params = OrderedDict()
for name, value in parameters.items():
if isinstance(value, list):
Expand All @@ -42,20 +39,15 @@ def _resolve_parameters(
return resolved_params


def _validate_param(
param: Any,
contracts: List[str]
) -> None:
def _validate_param(param: Any, contracts: List[str]) -> None:
if not is_variable(param):
return
variable = param.strip(VARIABLE_PREFIX)
if variable not in contracts:
raise DeploymentConfigError(f"Variable {param} is not resolvable")


def validate_deployment_config(
config: typing.OrderedDict[str, Any]
) -> None:
def validate_deployment_config(config: typing.OrderedDict[str, Any]) -> None:
available_contracts = list(config.keys())
for contract, parameters in config.items():
for name, value in parameters.items():
Expand All @@ -66,44 +58,41 @@ def validate_deployment_config(
_validate_param(value, available_contracts)


def _confirm_resolution(
resolved_params: OrderedDict,
contract_name: str
) -> None:
def _confirm_resolution(resolved_params: OrderedDict, contract_name: str) -> None:
if len(resolved_params) == 0:
# Nothing really to confirm
print(f"(i) No constructor parameters for {contract_name}; proceeding")
return

print(f"Resolved constructor parameters for {contract_name}")
for name, resolved_value in resolved_params:
for name, resolved_value in resolved_params.items():
print(f"\t{name}={resolved_value}")
answer = input("Continue Y/N? ")
if answer.lower().strip() == "n":
print("Aborting deployment!")
exit(-1)


class ConstructorParams:
def __init__(self, constructor_values: OrderedDict):
self.params = constructor_values
class DeploymentConfig:
def __init__(self, contracts_configuration: OrderedDict):
validate_deployment_config(contracts_configuration)
self.contracts_configuration = contracts_configuration

@classmethod
def from_file(cls, config_filepath: Path) -> "ConstructorParams":
def from_file(cls, config_filepath: Path) -> "DeploymentConfig":
with open(config_filepath, "r") as config_file:
config = OrderedDict(json.load(config_file))
return cls(config)

def get_params(
self,
container: ContractContainer,
context: typing.Dict[str, Any],
interactive: bool = True
def get_constructor_params(
self, container: ContractContainer, context: typing.Dict[str, Any], interactive: bool = True
) -> List[Any]:
contract_name = container.contract_type.name
contract_parameters = self.params[contract_name]
contract_parameters = self.contracts_configuration[contract_name]
resolved_params = _resolve_parameters(
contract_parameters,
context,
)
if interactive:
_confirm_resolution(
resolved_params,
contract_name
)
_confirm_resolution(resolved_params, contract_name)
return list(resolved_params.values())
File renamed without changes.
11 changes: 11 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ape import accounts, config, networks, project
from web3 import Web3

Expand Down Expand Up @@ -40,3 +42,12 @@ def get_account(id):
return accounts.test_accounts[0]
else:
return None


def check_etherscan_plugin():
try:
import ape_etherscan # noqa: F401
except ImportError:
raise ImportError("Please install the ape-etherscan plugin to use this script.")
if not os.environ.get("ETHERSCAN_API_KEY"):
raise ValueError("ETHERSCAN_API_KEY is not set.")
Empty file removed utils/__init__.py
Empty file.

0 comments on commit 9eab251

Please sign in to comment.