From c8ad04af1433a7a283160451fd59189fd04527e8 Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 12 Nov 2024 00:15:16 +0200 Subject: [PATCH] Use env file --- Makefile | 4 ++++ docker-compose.yml | 34 ++++----------------------------- indexers-v2/entrypoint.sh | 2 +- indexers-v2/main.py | 37 ++++++++++++++++++++++++------------ indexers-v2/requirements.txt | 3 ++- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index d4cb4492..09b61b84 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,10 @@ extract: docker compose run extractors python main.py configs/arbitrum_mainnet.yaml docker compose run extractors python main.py configs/arbitrum_sepolia.yaml +index: + docker compose run indexers-v2 --network_name base_mainnet --config_name synthetix-v3 + docker compose run indexers-v2 --network_name arbitrum_mainnet --config_name synthetix-v3 + synths: docker compose run transformer python scripts/get_synths.py diff --git a/docker-compose.yml b/docker-compose.yml index 658a491f..f27172a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,44 +29,18 @@ services: tmpfs: - /dev/shm:size=4g - arbitrum-mainnet-indexer: + indexer-v2: build: context: ./indexers-v2 dockerfile: Dockerfile networks: - data - depends_on: - - db - restart: always - environment: - DB_HOST: db - DB_PORT: 5432 - DB_NAME: arbitrum_mainnet - DB_PASS: $PG_PASSWORD - GQL_PORT: 4350 - RPC_ENDPOINT: wss://arbitrum-one-rpc.publicnode.com - NETWORK_NAME: arbitrum_mainnet - volumes: - - ./parquet-data:/parquet-data - - base-mainnet-indexer: - build: - context: ./indexers-v2 - dockerfile: Dockerfile - networks: - - data - depends_on: - - db restart: always + env_file: + - .env environment: - DB_HOST: db - DB_PORT: 5432 - DB_NAME: base_mainnet - DB_PASS: $PG_PASSWORD - GQL_PORT: 4350 - RPC_ENDPOINT: https://mainnet.base.org NETWORK_NAME: base_mainnet - CONFIG_NAME: base_mainnet_parquet + CONFIG_NAME: synthetix-v3 volumes: - ./parquet-data:/parquet-data diff --git a/indexers-v2/entrypoint.sh b/indexers-v2/entrypoint.sh index d4691a5a..63ec356c 100644 --- a/indexers-v2/entrypoint.sh +++ b/indexers-v2/entrypoint.sh @@ -4,7 +4,7 @@ set -e # Get contract data from SDK and generate squidgen.yaml and squid.yaml -python3 main.py --network_name "$NETWORK_NAME" --rpc_endpoint "$RPC_ENDPOINT" --config_name "$CONFIG_NAME" +python3 main.py --network_name $NETWORK_NAME --config_name $CONFIG_NAME "$@" # Generate squid processor npm run generate:processor diff --git a/indexers-v2/main.py b/indexers-v2/main.py index 067686f2..7b07fbec 100644 --- a/indexers-v2/main.py +++ b/indexers-v2/main.py @@ -1,9 +1,13 @@ import json import os import argparse +from dotenv import load_dotenv import yaml from synthetix import Synthetix +# load environment variables +load_dotenv() + def save_abi(abi, contract_name): os.makedirs("abi", exist_ok=True) @@ -73,31 +77,34 @@ def load_network_config(path): "--config_name", type=str, help="Name of the configuration to use", + required=True, + ) + parser.add_argument( + "--contract_names", + type=str, + help="Comma-separated list of contract names to index.", ) - parser.add_argument("--rpc_endpoint", type=str, help="RPC URL", required=True) args = parser.parse_args() - rpc_endpoint = args.rpc_endpoint - if rpc_endpoint is None: - message = "RPC_ENDPOINT environment variable is not set" - raise Exception(message) - - # Load config file for network network_name = args.network_name + config_name = args.config_name + contract_names = args.contract_names + + # Get contract names + if contract_names is not None: + parsed_contract_names = [name.strip() for name in contract_names.split(",")] + + # Load network config path = f"networks/{network_name}" config_file = load_network_config(path) - # Get config name - config_name = args.config_name - if config_name is None: - raise Exception("Config name is required") - # Load shared network-level details network_params = config_file["network"] if network_params is None: message = f"Network '{network_name}' not found in {path}/network_config.yaml" raise Exception(message) network_id = network_params["network_id"] + rpc_endpoint = os.getenv(f"NETWORK_{network_id}_RPC") archive_url = network_params.get("archive_url", "None") # Load custom config @@ -131,6 +138,9 @@ def load_network_config(path): if "contracts_from_sdk" in custom_config: contracts_from_sdk = custom_config["contracts_from_sdk"] for contract in contracts_from_sdk: + if contract_names is not None: + if contract["name"] not in parsed_contract_names: + continue name = contract["name"] package = contract["package"] contract_data = snx.contracts[package][name] @@ -139,6 +149,9 @@ def load_network_config(path): elif "contracts_from_abi" in custom_config: contracts_from_abi = custom_config["contracts_from_abi"] for contract in contracts_from_abi: + if contract_names is not None: + if contract["name"] not in parsed_contract_names: + continue name = contract["name"] address = contract["address"] with open(f"{path}/abi/{name}.json", "r") as file: diff --git a/indexers-v2/requirements.txt b/indexers-v2/requirements.txt index 5f446a2c..dcd9863a 100644 --- a/indexers-v2/requirements.txt +++ b/indexers-v2/requirements.txt @@ -1,2 +1,3 @@ synthetix==0.1.21 -PyYAML \ No newline at end of file +PyYAML +python-dotenv \ No newline at end of file