Skip to content

Commit

Permalink
Abstracts deployment into integrated Deployer object (formerly ApeDep…
Browse files Browse the repository at this point in the history
…loymentParameters) with added variable suport.
  • Loading branch information
KPrasch committed Sep 27, 2023
1 parent 60b9e59 commit 682c3c0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 71 deletions.
44 changes: 35 additions & 9 deletions deployment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, List

from ape import chain, project
from ape.api import AccountAPI
from ape.contracts.base import (
ContractContainer,
ContractInstance
Expand Down Expand Up @@ -93,9 +94,12 @@ def _get_contract_instance(contract_container: ContractContainer) -> typing.Unio
return contract_instance


def _resolve_deployer(variable: str) -> str:
breakpoint()
assert False
def _resolve_deployer() -> str:
deployer_account = Deployer.get_account()
if deployer_account is None:
return ZERO_ADDRESS
else:
return deployer_account.address


def _resolve_contract_address(variable: str) -> str:
Expand All @@ -113,7 +117,7 @@ def _resolve_special_variable(variable: str) -> Any:
elif _is_proxy_variable(variable):
result = _resolve_proxy_address(variable)
elif _is_deployer(variable):
result = _resolve_deployer(variable)
result = _resolve_deployer()
else:
raise ValueError(f"Invalid special variable {variable}")
return result
Expand Down Expand Up @@ -279,21 +283,43 @@ def resolve(self, contract_name: str) -> OrderedDict:
return result


class ApeDeploymentParameters:
"""Represents ape deployment parameters for a set of contracts."""
class Deployer:
"""
Represents ape an ape deployment account plus
deployment parameters for a set of contracts.
"""

def __init__(self, constructor_parameters: ConstructorParameters, publish: bool):
__DEPLOYER_ACCOUNT: AccountAPI = None

def __init__(self, deployer: AccountAPI, constructor_parameters: ConstructorParameters, publish: bool):
self.constructor_parameters = constructor_parameters
self.publish = publish
self._set_deployer(deployer)

@classmethod
def get_account(cls) -> AccountAPI:
"""Returns the deployer account."""
return cls.__DEPLOYER_ACCOUNT

@classmethod
def _set_deployer(cls, deployer: AccountAPI) -> None:
"""Sets the deployer account."""
cls.__DEPLOYER_ACCOUNT = deployer

def get_kwargs(self) -> typing.Dict[str, Any]:
def _get_kwargs(self) -> typing.Dict[str, Any]:
"""Returns the deployment kwargs."""
return {"publish": self.publish}

def get(self, container: ContractContainer) -> List[Any]:
def _get_args(self, container: ContractContainer) -> List[Any]:
"""Resolves the deployment parameters for a single contract."""
contract_name = container.contract_type.name
resolved_constructor_params = self.constructor_parameters.resolve(contract_name)
_confirm_resolution(resolved_constructor_params, contract_name)
deployment_params = [container, *resolved_constructor_params.values()]
return deployment_params

def deploy(self, container: ContractContainer) -> ContractInstance:
deployer_account = self.get_account()
args, kwargs = self._get_args(container), self._get_kwargs()
instance = deployer_account.deploy(*args, **kwargs)
return instance
21 changes: 8 additions & 13 deletions deployment/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import typing
from pathlib import Path
from typing import List

from ape import networks
from ape.api import AccountAPI
from ape.cli import get_user_selected_account
from ape.contracts import ContractInstance
from ape_etherscan.utils import API_KEY_ENV_KEY_MAP
Expand All @@ -14,7 +12,7 @@
LOCAL_BLOCKCHAIN_ENVIRONMENTS
)
from deployment.params import (
ApeDeploymentParameters,
Deployer,
ConstructorParameters
)

Expand Down Expand Up @@ -78,25 +76,22 @@ def verify_contracts(contracts: List[ContractInstance]) -> None:

def prepare_deployment(
params_filepath: Path, registry_filepath: Path, publish: bool = False
) -> typing.Tuple[AccountAPI, "ApeDeploymentParameters"]:
) -> "Deployer":
"""
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
deployment_parameters = Deployer(
deployer=deployer_account,
constructor_parameters=constructor_parameters,
publish=publish,
)
return deployment_parameters
40 changes: 14 additions & 26 deletions scripts/lynx/deploy_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,34 @@ def main():
eth-ape 0.6.20
"""

deployer, params = prepare_deployment(
deployer = prepare_deployment(
params_filepath=CONSTRUCTOR_PARAMS_FILEPATH,
registry_filepath=REGISTRY_FILEPATH,
)

mock_polygon_child = deployer.deploy(
*params.get(project.MockPolygonChild), **params.get_kwargs()
)

proxy_admin = deployer.deploy(*params.get(OZ_DEPENDENCY.ProxyAdmin), **params.get_kwargs())

taco_implementation = deployer.deploy(
*params.get(project.LynxTACoChildApplication), **params.get_kwargs()
)

proxy = deployer.deploy(
*params.get(OZ_DEPENDENCY.TransparentUpgradeableProxy), **params.get_kwargs()
)
mock_polygon_child = deployer.deploy(project.MockPolygonChild)
proxy_admin = deployer.deploy(OZ_DEPENDENCY.ProxyAdmin)
taco_implementation = deployer.deploy(project.LynxTACoChildApplication)
proxy = deployer.deploy(OZ_DEPENDENCY.TransparentUpgradeableProxy)

print("\nWrapping TACoChildApplication in proxy")
taco_child_application = project.TACoChildApplication.at(proxy.address)

print(
f"\nSetting TACoChildApplication proxy ({taco_child_application.address}) as child application on MockPolygonChild ({mock_polygon_child.address})"
)
print(f"\nSetting TACoChildApplication proxy ({taco_child_application.address})"
f" as child application on MockPolygonChild ({mock_polygon_child.address})")
mock_polygon_child.setChildApplication(
taco_child_application.address,
sender=deployer,
sender=deployer.get_account(),
)

ritual_token = deployer.deploy(*params.get(project.LynxRitualToken), **params.get_kwargs())
ritual_token = deployer.deploy(project.LynxRitualToken)
coordinator = deployer.deploy(project.Coordinator)

coordinator = deployer.deploy(*params.get(project.Coordinator), **params.get_kwargs())

print(
f"\nInitializing TACoChildApplication proxy ({taco_child_application.address}) with Coordinator ({coordinator.address})"
)
taco_child_application.initialize(coordinator.address, sender=deployer)
print(f"\nInitializing TACoChildApplication proxy ({taco_child_application.address}) "
f"with Coordinator ({coordinator.address})")
taco_child_application.initialize(coordinator.address, sender=deployer.get_account())

global_allow_list = deployer.deploy(*params.get(project.GlobalAllowList), **params.get_kwargs())
global_allow_list = deployer.deploy(project.GlobalAllowList)

deployments = [
mock_polygon_child,
Expand Down
36 changes: 13 additions & 23 deletions scripts/lynx/deploy_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,31 @@ def main():
eth-ape 0.6.20
"""

deployer, params = prepare_deployment(
deployer = prepare_deployment(
params_filepath=CONSTRUCTOR_PARAMS_FILEPATH,
registry_filepath=REGISTRY_FILEPATH,
)

reward_token = deployer.deploy(*params.get(project.LynxStakingToken), **params.get_kwargs())

mock_threshold_staking = deployer.deploy(
*params.get(project.TestnetThresholdStaking), **params.get_kwargs()
)

proxy_admin = deployer.deploy(*params.get(OZ_DEPENDENCY.ProxyAdmin), **params.get_kwargs())

_ = deployer.deploy(*params.get(project.TACoApplication), **params.get_kwargs())

proxy = deployer.deploy(
*params.get(OZ_DEPENDENCY.TransparentUpgradeableProxy), **params.get_kwargs()
)
reward_token = deployer.deploy(project.LynxStakingToken)
mock_threshold_staking = deployer.deploy(project.TestnetThresholdStaking)
proxy_admin = deployer.deploy(OZ_DEPENDENCY.ProxyAdmin)
_ = deployer.deploy(project.TACoApplication)
proxy = deployer.deploy(OZ_DEPENDENCY.TransparentUpgradeableProxy)

print("\nWrapping TACoApplication in proxy")
taco_application = project.TACoApplication.at(proxy.address)

print(
f"\nSetting TACoApplication proxy ({taco_application.address}) on ThresholdStakingMock ({mock_threshold_staking.address})"
)
mock_threshold_staking.setApplication(taco_application.address, sender=deployer)
print(f"\nSetting TACoApplication proxy ({taco_application.address}) on "
f"ThresholdStakingMock ({mock_threshold_staking.address})")
mock_threshold_staking.setApplication(taco_application.address, sender=deployer.get_account())

print("\nInitializing TACoApplication proxy")
taco_application.initialize(sender=deployer)
taco_application.initialize(sender=deployer.get_account())

mock_polygon_root = deployer.deploy(*params.get(project.MockPolygonRoot), **params.get_kwargs())
mock_polygon_root = deployer.deploy(project.MockPolygonRoot)

print(
f"\nSetting child application on TACoApplication proxy ({taco_application.address}) to MockPolygonChild ({mock_polygon_root.address})"
)
print(f"\nSetting child application on TACoApplication proxy "
f"({taco_application.address}) to MockPolygonChild ({mock_polygon_root.address})")
taco_application.setChildApplication(mock_polygon_root.address, sender=deployer)

deployments = [
Expand Down

0 comments on commit 682c3c0

Please sign in to comment.