Skip to content

Commit

Permalink
Modify contracts_from_registry to take chain id as a parameter.
Browse files Browse the repository at this point in the history
Modify scripts to use chain id when calling `contracts_from_registry` by using active blockchain's chain id.
  • Loading branch information
derekpierre committed Oct 11, 2023
1 parent 1c0b07a commit 55797e3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
4 changes: 3 additions & 1 deletion deployment/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ def merge_registries(
return output_filepath


def contracts_from_registry(filepath: Path) -> Dict[str, ContractInstance]:
def contracts_from_registry(filepath: Path, chain_id: ChainId) -> Dict[str, ContractInstance]:
"""Returns a dictionary of contract instances from a nucypher-style contract registry."""
registry_entries = read_registry(filepath=filepath)
deployments = dict()
for registry_entry in registry_entries:
if registry_entry.chain_id != chain_id:
continue
contract_type = registry_entry.name
contract_container = get_contract_container(contract_type)
contract_instance = contract_container.at(registry_entry.address)
Expand Down
15 changes: 9 additions & 6 deletions scripts/lynx/configure_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins

ROOT_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-root-registry.json"
CHILD_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-child-registry.json"
LYNX_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx.json"


def configure_goerli_root(transactor: Transactor) -> int:
"""Configures ThresholdStaking and TACoApplication on Goerli."""
deployments = contracts_from_registry(filepath=ROOT_REGISTRY_FILEPATH)

# Set up lynx stakes on Goerli
eth_network = networks.ethereum.goerli
with eth_network.use_provider("infura"):
deployments = contracts_from_registry(
filepath=LYNX_REGISTRY_FILEPATH, chain_id=eth_network.chain_id
)

taco_application_contract = deployments[project.TACoApplication.contract_type.name]
threshold_staking_contract = deployments[project.TestnetThresholdStaking.contract_type.name]

Expand Down Expand Up @@ -47,11 +48,13 @@ def configure_goerli_root(transactor: Transactor) -> int:

def configure_mumbai_root(transactor: Transactor, stake_size: int):
"""Configures MockTACoApplication on Mumbai."""
deployments = contracts_from_registry(filepath=CHILD_REGISTRY_FILEPATH)

# Set up lynx stakes on Mumbai
poly_network = networks.polygon.mumbai
with poly_network.use_provider("infura"):
deployments = contracts_from_registry(
filepath=LYNX_REGISTRY_FILEPATH, chain_id=poly_network.chain_id
)

mock_taco_application_contract = deployments[project.MockPolygonChild.contract_type.name]

for staking_provider, operator in LYNX_NODES.items():
Expand Down
8 changes: 5 additions & 3 deletions scripts/lynx/confirm_operator_addresses.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/python3


from ape import project
from ape import networks, project
from deployment.constants import ARTIFACTS_DIR, LYNX_NODES
from deployment.params import Transactor
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins

ROOT_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx" / "lynx-alpha-13-root-registry.json"
LYNX_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx.json"


def main():
Expand All @@ -18,7 +18,9 @@ def main():
"""
check_plugins()
transactor = Transactor()
deployments = contracts_from_registry(filepath=ROOT_REGISTRY_FILEPATH)
deployments = contracts_from_registry(
filepath=LYNX_REGISTRY_FILEPATH, chain_id=networks.active_provider.chain_id
)
mock_polygon_root = deployments[project.MockPolygonRoot.contract_type.name]
for _, operator in LYNX_NODES.items():
transactor.transact(mock_polygon_root.confirmOperatorAddress, operator)
7 changes: 5 additions & 2 deletions scripts/lynx/verify.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from ape import networks
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"
LYNX_REGISTRY_FILEPATH = ARTIFACTS_DIR / "lynx.json"


def main():
contracts = contracts_from_registry(REGISTRY_FILEPATH)
contracts = contracts_from_registry(
filepath=LYNX_REGISTRY_FILEPATH, chain_id=networks.active_provider.chain_id
)
verify_contracts(list(contracts.values()))
4 changes: 2 additions & 2 deletions scripts/merge_registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
@click.option(
"--registry-1",
help="Filepath to registry file 1",
type=click.Path(dir_okay=False, path_type=Path),
type=click.Path(dir_okay=False, exists=True, path_type=Path),
required=True,
)
@click.option(
"--registry-2",
help="Filepath to registry file 2",
type=click.Path(dir_okay=False, path_type=Path),
type=click.Path(dir_okay=False, exists=True, path_type=Path),
required=True,
)
@click.option(
Expand Down
12 changes: 8 additions & 4 deletions scripts/tapir/configure_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

def configure_sepolia_root(transactor: Transactor) -> int:
"""Configures ThresholdStaking and TACoApplication on Sepolia."""
deployments = contracts_from_registry(filepath=TAPIR_REGISTRY_FILEPATH)

# Set up Tapir stakes on Sepolia
eth_network = networks.ethereum.sepolia
with eth_network.use_provider("infura"):
deployments = contracts_from_registry(
filepath=TAPIR_REGISTRY_FILEPATH, chain_id=eth_network.chain_id
)

taco_application_contract = deployments[project.TACoApplication.contract_type.name]
threshold_staking_contract = deployments[project.TestnetThresholdStaking.contract_type.name]

Expand Down Expand Up @@ -45,11 +47,13 @@ def configure_sepolia_root(transactor: Transactor) -> int:

def configure_mumbai_root(transactor: Transactor, stake_size: int):
"""Configures MockTACoApplication on Mumbai."""
deployments = contracts_from_registry(filepath=TAPIR_REGISTRY_FILEPATH)

# Set up Tapir stakes on Mumbai
poly_network = networks.polygon.mumbai
with poly_network.use_provider("infura"):
deployments = contracts_from_registry(
filepath=TAPIR_REGISTRY_FILEPATH, chain_id=poly_network.chain_id
)

mock_taco_application_contract = deployments[project.MockPolygonChild.contract_type.name]

for staking_provider, operator in TAPIR_NODES.items():
Expand Down
6 changes: 4 additions & 2 deletions scripts/tapir/confirm_operator_addresses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

from ape import project
from ape import networks, project
from deployment.constants import ARTIFACTS_DIR, TAPIR_NODES
from deployment.params import Transactor
from deployment.registry import contracts_from_registry
Expand All @@ -17,7 +17,9 @@ def main():
"""
check_plugins()
transactor = Transactor()
deployments = contracts_from_registry(filepath=REGISTRY_FILEPATH)
deployments = contracts_from_registry(
filepath=REGISTRY_FILEPATH, chain_id=networks.active_provider.chain_id
)
mock_polygon_root = deployments[project.MockPolygonRoot.contract_type.name]
for _, operator in TAPIR_NODES.items():
transactor.transact(mock_polygon_root.confirmOperatorAddress, operator)
9 changes: 5 additions & 4 deletions scripts/tapir/grant_initiator_role.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/python3


from ape import project

from ape import networks, project
from deployment.constants import ARTIFACTS_DIR
from deployment.params import Transactor
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins

ROOT_REGISTRY_FILEPATH = ARTIFACTS_DIR / "tapir.json"
TAPIR_REGISTRY_FILEPATH = ARTIFACTS_DIR / "tapir.json"


def main():
check_plugins()
transactor = Transactor()
deployments = contracts_from_registry(filepath=ROOT_REGISTRY_FILEPATH)
deployments = contracts_from_registry(
filepath=TAPIR_REGISTRY_FILEPATH, chain_id=networks.active_provider.chain_id
)
coordinator = deployments[project.Coordinator.contract_type.name]
initiator_role_hash = coordinator.INITIATOR_ROLE()
transactor.transact(
Expand Down

0 comments on commit 55797e3

Please sign in to comment.