Skip to content

Commit

Permalink
Derive the registry filepath from the specified domain cli option, in…
Browse files Browse the repository at this point in the history
…stead of taking the registry filepath as a cli option.
  • Loading branch information
derekpierre committed Oct 15, 2023
1 parent 96b8b6e commit 6eb9eb6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
21 changes: 14 additions & 7 deletions deployment/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import json
import os
from pathlib import Path
from typing import List, Dict
from typing import Dict, List

import yaml
from ape import networks, project
from ape.contracts import ContractInstance, ContractContainer
from ape.contracts import ContractContainer, ContractInstance
from ape_etherscan.utils import API_KEY_ENV_KEY_MAP

from deployment.constants import (
ARTIFACTS_DIR
)
from deployment.constants import ARTIFACTS_DIR
from deployment.networks import is_local_network


Expand Down Expand Up @@ -51,7 +48,9 @@ def validate_config(config: Dict) -> Path:
if not config_chain_id:
raise ValueError("chain_id is not set in params file.")

config_chain_id = int(config_chain_id) # Convert chain_id to int here after ensuring it is not None
config_chain_id = int(
config_chain_id
) # Convert chain_id to int here after ensuring it is not None
chain_mismatch = config_chain_id != networks.provider.network.chain_id
live_deployment = not is_local_network()
if chain_mismatch and live_deployment:
Expand Down Expand Up @@ -145,3 +144,11 @@ def get_contract_container(contract: str) -> ContractContainer:
contract_container = _get_dependency_contract_container(contract)

return contract_container


def registry_filepath_from_domain(domain: str) -> Path:
p = ARTIFACTS_DIR / f"{domain}.json"
if not p.exists():
raise ValueError(f"No registry found for domain '{domain}'")

return p
19 changes: 8 additions & 11 deletions scripts/authorize_enrico.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/usr/bin/python3
from pathlib import Path

import click
from ape import project
from ape.cli import NetworkBoundCommand, account_option, network_option
from eth_utils import to_checksum_address

from deployment.params import Transactor
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins
from deployment.utils import check_plugins, registry_filepath_from_domain
from eth_utils import to_checksum_address


@click.command(cls=NetworkBoundCommand)
@network_option(required=True)
@account_option()
@click.option(
"--registry-filepath",
"-r",
help="Filepath to registry file",
type=click.Path(dir_okay=False, exists=True, path_type=Path),
"--domain",
"-d",
help="TACo domain",
type=click.STRING,
required=True,
)
@click.option(
Expand All @@ -35,10 +33,10 @@
type=str,
required=False,
)
def cli(network, account, registry_filepath, ritual_id, enrico_address):
def cli(network, account, domain, ritual_id, enrico_address):
check_plugins()
print(f"network: {network}")
transactor = Transactor(account=account)
registry_filepath = registry_filepath_from_domain(domain=domain)
chain_id = project.chain_manager.chain_id
deployments = contracts_from_registry(filepath=registry_filepath, chain_id=chain_id)
global_allow_list = deployments[project.GlobalAllowList.contract_type.name]
Expand All @@ -48,5 +46,4 @@ def cli(network, account, registry_filepath, ritual_id, enrico_address):


if __name__ == "__main__":

cli()
14 changes: 7 additions & 7 deletions scripts/grant_initiator_role.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/usr/bin/python3
from pathlib import Path

import click
from ape import networks, project
from ape.cli import NetworkBoundCommand, account_option, network_option
from deployment.params import Transactor
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins
from deployment.utils import check_plugins, registry_filepath_from_domain


@click.command(cls=NetworkBoundCommand)
@network_option(required=True)
@account_option()
@click.option(
"--registry-filepath",
"-r",
help="Filepath to registry file",
type=click.Path(dir_okay=False, exists=True, path_type=Path),
"--domain",
"-d",
help="TACo domain",
type=click.STRING,
required=True,
)
def cli(network, account, registry_filepath):
def cli(network, account, domain):
check_plugins()
transactor = Transactor(account)
registry_filepath = registry_filepath_from_domain(domain=domain)
deployments = contracts_from_registry(
filepath=registry_filepath, chain_id=networks.active_provider.chain_id
)
Expand Down
31 changes: 12 additions & 19 deletions scripts/initiate_ritual.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
#!/usr/bin/python3
from pathlib import Path

import click
from ape import project
from ape.cli import (
NetworkBoundCommand,
account_option,
network_option
)

from ape.cli import NetworkBoundCommand, account_option, network_option
from deployment.constants import LYNX_NODES
from deployment.params import Transactor
from deployment.registry import contracts_from_registry
from deployment.utils import check_plugins
from deployment.utils import check_plugins, registry_filepath_from_domain


@click.command(cls=NetworkBoundCommand)
@network_option(required=True)
@account_option()
@click.option(
"--registry-filepath",
"-r",
help="Filepath to registry file",
type=click.Path(dir_okay=False, exists=True, path_type=Path),
"--domain",
"-d",
help="TACo domain",
type=click.STRING,
required=True,
)
@click.option(
"--duration",
"-d",
"-t",
help="Duration of the ritual",
type=int,
default=86400,
show_default=True,
)
def cli(registry_filepath, duration, network, account):
def cli(domain, duration, network, account):
check_plugins()
print(f"Using network: {network}")
print(f"Using domain: {domain}")
print(f"Using account: {account}")
transactor = Transactor(account=account)

registry_filepath = registry_filepath_from_domain(domain=domain)

chain_id = project.chain_manager.chain_id
deployments = contracts_from_registry(filepath=registry_filepath, chain_id=chain_id)
coordinator = deployments[project.Coordinator.contract_type.name]
Expand All @@ -49,11 +46,7 @@ def cli(registry_filepath, duration, network, account):

while True:
transactor.transact(
coordinator.initiateRitual,
providers,
authority,
duration,
global_allow_list.address
coordinator.initiateRitual, providers, authority, duration, global_allow_list.address
)
if not input("Another? [y/n] ").lower().startswith("y"):
break
Expand Down
19 changes: 11 additions & 8 deletions scripts/verify.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
from pathlib import Path

import click
from ape import networks
from ape.cli import NetworkBoundCommand, network_option
from deployment.registry import contracts_from_registry
from deployment.utils import verify_contracts
from deployment.utils import registry_filepath_from_domain, verify_contracts


@click.command(cls=NetworkBoundCommand)
@network_option(required=True)
@click.option(
"--registry-filepath",
"-r",
help="Filepath to registry file",
type=click.Path(dir_okay=False, exists=True, path_type=Path),
"--domain",
"-d",
help="TACo domain",
type=click.STRING,
required=True,
)
def cli(network, registry_filepath):
def cli(network, domain):
"""Verify deployed contracts from a registry file."""
registry_filepath = registry_filepath_from_domain(domain=domain)
contracts = contracts_from_registry(
registry_filepath, chain_id=networks.active_provider.chain_id
)
verify_contracts(list(contracts.values()))


if __name__ == "__main__":
cli()

0 comments on commit 6eb9eb6

Please sign in to comment.