Skip to content

Commit

Permalink
Utility to convert legacy NPM artifacts to new-style artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
KPrasch committed Oct 6, 2023
1 parent bdb84b9 commit 809ebaa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
46 changes: 46 additions & 0 deletions deployment/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

def get_creation_info(api_key: str, chain_id: int, contract_address: ChecksumAddress) -> tuple:
networks = {
1: ("", "etherscan.io"),
5: ("-goerli", "etherscan.io"),
80001: ("-testnet", "polygonscan.com")
}
Expand Down Expand Up @@ -81,3 +82,48 @@ def convert_legacy_registry(
new_registry_entries.append(new_registry_entry)
write_registry(entries=new_registry_entries, filepath=output_filepath)
print(f"Converted legacy registry to {output_filepath}")


def convert_legacy_npm_artifacts(
directory: Path,
chain_id: ChainId,
output_filepath: Path
) -> None:
if output_filepath.exists():
raise FileExistsError(f"Registry already exists at {output_filepath}")

if not directory.exists():
raise FileNotFoundError(f"Directory not found at {directory}")

api_key = os.environ.get("ETHERSCAN_API_KEY")
if not api_key:
raise ValueError("Please set the ETHERSCAN_API_KEY environment variable.")

entries = list()
for filepath in directory.glob("*.json"):
data = _load_json(filepath=filepath)

name = filepath.name.replace(".json", "")
abi = data['abi']
address = data['address']

tx_hash, block_number, deployer = get_creation_info(
api_key=api_key,
chain_id=chain_id,
contract_address=address
)

entry = RegistryEntry(
chain_id=chain_id,
name=name,
address=address,
abi=abi,
tx_hash=tx_hash,
block_number=block_number,
deployer=deployer
)

entries.append(entry)

write_registry(entries=entries, filepath=output_filepath)
print(f"Converted legacy registry to {output_filepath}")
19 changes: 19 additions & 0 deletions scripts/mainnet/convert_artifacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path

from deployment.confirm import _continue
from deployment.constants import ARTIFACTS_DIR
from deployment.legacy import convert_legacy_npm_artifacts

INPUT_DIR = Path(__file__).parent.parent.parent / "artifacts"
OUTPUT_FILEPATH = ARTIFACTS_DIR / "mainnet.json"


def main():
print(f"input_dir: {INPUT_DIR.absolute()}")
_continue()

convert_legacy_npm_artifacts(
directory=INPUT_DIR,
chain_id=1,
output_filepath=OUTPUT_FILEPATH
)

0 comments on commit 809ebaa

Please sign in to comment.