diff --git a/docker-compose.yaml b/docker-compose.yaml index 4f1c823..aefb29e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -62,7 +62,7 @@ services: - ${GRAPH_NODE_STATUS_PORT}:8030 - ${GRAPH_NODE_METRICS_PORT}:8040 volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro healthcheck: @@ -79,7 +79,7 @@ services: depends_on: chain: { condition: service_healthy } volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config environment: @@ -96,7 +96,7 @@ services: graph-contracts: { condition: service_completed_successfully } stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -121,7 +121,7 @@ services: ports: ["${INDEXER_MANAGEMENT_PORT}:7600"] stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro healthcheck: @@ -140,7 +140,7 @@ services: graph-contracts: { condition: service_completed_successfully } graph-node: { condition: service_healthy } volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro @@ -151,7 +151,7 @@ services: subgraph-deploy: { condition: service_completed_successfully } indexer-agent: { condition: service_healthy } volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro @@ -195,7 +195,7 @@ services: ports: ["${TAP_AGGREGATOR_PORT}:7610"] stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -214,7 +214,7 @@ services: redpanda: { condition: service_healthy } stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -234,7 +234,7 @@ services: ports: ["${GATEWAY_PORT}:7700"] stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -257,7 +257,7 @@ services: - "${INDEXER_SERVICE_PORT}:7601" stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -278,7 +278,7 @@ services: subgraph-deploy: { condition: service_completed_successfully } stop_signal: SIGKILL volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -299,7 +299,7 @@ services: redpanda: { condition: service_healthy } gateway: { condition: service_healthy } volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: @@ -366,7 +366,7 @@ services: - "${DIPPER_ADMIN_RPC_PORT}:${DIPPER_ADMIN_RPC_PORT}" - "${DIPPER_INDEXER_RPC_PORT}:${DIPPER_INDEXER_RPC_PORT}" volumes: - - ./containers/shared:/opt/shared:ro + - ./shared:/opt/shared:ro - ./.env:/opt/config/.env:ro - config-local:/opt/config:ro environment: diff --git a/docs/testing/reo/CurationSignal.md b/docs/testing/reo/CurationSignal.md index db0dda5..332dcbf 100644 --- a/docs/testing/reo/CurationSignal.md +++ b/docs/testing/reo/CurationSignal.md @@ -25,7 +25,7 @@ Small change (~20-30 lines) in `start-indexing/run.sh`. No new services, no new | L2GraphToken | `horizon.json` | `.["1337"].L2GraphToken.address` | | L2GNS | `subgraph-service.json` | `.["1337"].L2GNS.address` | -Addresses resolved via `contract_addr` helper in [containers/shared/lib.sh](../../../containers/shared/lib.sh). +Addresses resolved via `contract_addr` helper in [shared/lib.sh](../../../shared/lib.sh). ### Insertion Point diff --git a/scripts/add-subgraph.sh b/scripts/add-subgraph.sh index 0b5d4f8..c28c5d9 100755 --- a/scripts/add-subgraph.sh +++ b/scripts/add-subgraph.sh @@ -1,6 +1,12 @@ +#!/bin/bash set -xe -source .env -[ -f .env.local ] && source .env.local +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +source "$REPO_ROOT/.env" +[ -f "$REPO_ROOT/.env.local" ] && source "$REPO_ROOT/.env.local" +source "$REPO_ROOT/shared/lib.sh" + name=$1 if [ -z "$name" ]; then echo "Usage: $0 " @@ -23,7 +29,7 @@ deployment_hex="$(curl -s -X POST "http://${IPFS_HOST}:${IPFS_RPC_PORT}/api/v0/c deployment_hex="${deployment_hex#f01701220}" echo "deployment_hex=${deployment_hex}" -gns="$(jq -r '."1337".L2GNS.address' subgraph-service.json)" +gns="$(contract_addr L2GNS.address subgraph-service)" # https://github.com/graphprotocol/contracts/blob/3eb16c80d4652c238d3e6b2c396da712af5072b4/packages/sdk/src/deployments/network/actions/gns.ts#L38 cast send --rpc-url="http://${CHAIN_HOST}:${CHAIN_RPC_PORT}" --confirmations=0 --mnemonic="${MNEMONIC}" \ diff --git a/scripts/advance-epoch.sh b/scripts/advance-epoch.sh index 0db7c31..f7d0040 100755 --- a/scripts/advance-epoch.sh +++ b/scripts/advance-epoch.sh @@ -1,11 +1,15 @@ #!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +source "$REPO_ROOT/.env" +[ -f "$REPO_ROOT/.env.local" ] && source "$REPO_ROOT/.env.local" +source "$REPO_ROOT/shared/lib.sh" # Get number of epochs to advance (default to 1 if not provided) EPOCHS_TO_ADVANCE=${1:-1} -# Get the EpochManager contract address from horizon.json -EPOCH_MANAGER_ADDRESS=$(jq -r '."1337".EpochManager.address' horizon.json) - +EPOCH_MANAGER_ADDRESS=$(contract_addr EpochManager.address horizon) RPC_URL="http://${CHAIN_HOST:-localhost}:${CHAIN_RPC_PORT:-8545}" # Get current epoch @@ -33,7 +37,7 @@ echo "Advancing by $EPOCHS_TO_ADVANCE epoch(s)" echo "Blocks to mine: $BLOCKS_TO_MINE" # Mine blocks until next epoch using mine-block.sh -./scripts/mine-block.sh $BLOCKS_TO_MINE +"$SCRIPT_DIR/mine-block.sh" $BLOCKS_TO_MINE # Verify we're in the next epoch NEW_EPOCH=$(cast call $EPOCH_MANAGER_ADDRESS "currentEpoch()(uint256)" --rpc-url "$RPC_URL") diff --git a/scripts/query_balance.sh b/scripts/query_balance.sh index 292b57b..da7c178 100755 --- a/scripts/query_balance.sh +++ b/scripts/query_balance.sh @@ -1,8 +1,13 @@ #!/bin/bash -source .env -[ -f .env.local ] && source .env.local +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +source "$REPO_ROOT/.env" +[ -f "$REPO_ROOT/.env.local" ] && source "$REPO_ROOT/.env.local" +source "$REPO_ROOT/shared/lib.sh" + address_to_query="${ACCOUNT0_ADDRESS}" -token_address=$(jq -r '."1337".L2GraphToken.address' horizon.json) +token_address=$(contract_addr L2GraphToken.address horizon) rpc_url="http://${CHAIN_HOST:-localhost}:${CHAIN_RPC_PORT}" cast call --trace "$token_address" "balanceOf(address)(uint256)" "$address_to_query" --rpc-url "$rpc_url" cast balance $address_to_query --rpc-url "$rpc_url" diff --git a/scripts/reo-config.sh b/scripts/reo-config.sh index 31e24fe..31eedbd 100755 --- a/scripts/reo-config.sh +++ b/scripts/reo-config.sh @@ -17,12 +17,13 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # Load environment # shellcheck source=../.env . "$REPO_ROOT/.env" +# shellcheck source=../shared/lib.sh +. "$REPO_ROOT/shared/lib.sh" RPC_URL="http://${CHAIN_HOST:-localhost}:${CHAIN_RPC_PORT}" # Read REO contract address from config-local volume -REO_ADDRESS=$(docker exec graph-node cat /opt/config/issuance.json 2>/dev/null \ - | jq -r '.["1337"].RewardsEligibilityOracle.address // empty' 2>/dev/null || true) +REO_ADDRESS=$(contract_addr RewardsEligibilityOracle.address issuance 2>/dev/null) || true if [ -z "$REO_ADDRESS" ]; then echo "ERROR: RewardsEligibilityOracle address not found." echo " Is the local network running with the REO contract deployed?" diff --git a/scripts/test-baseline-state.sh b/scripts/test-baseline-state.sh index 603e512..9956f06 100755 --- a/scripts/test-baseline-state.sh +++ b/scripts/test-baseline-state.sh @@ -23,6 +23,8 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # shellcheck source=../.env . "$REPO_ROOT/.env" +# shellcheck source=../shared/lib.sh +. "$REPO_ROOT/shared/lib.sh" SUBGRAPH_URL="http://${GRAPH_NODE_HOST:-localhost}:${GRAPH_NODE_GRAPHQL_PORT}/subgraphs/name/graph-network" AGENT_URL="http://${INDEXER_AGENT_HOST:-localhost}:${INDEXER_MANAGEMENT_PORT}" @@ -225,8 +227,7 @@ echo "" # ============================================================ # REO (if deployed) # ============================================================ -REO_ADDRESS=$(docker exec graph-node cat /opt/config/issuance.json 2>/dev/null \ - | jq -r '.["1337"].RewardsEligibilityOracle.address // empty' 2>/dev/null || true) +REO_ADDRESS=$(contract_addr RewardsEligibilityOracle.address issuance 2>/dev/null) || true if [ -n "$REO_ADDRESS" ]; then echo "--- REO Contract ---" diff --git a/scripts/test-indexer-guide-queries.sh b/scripts/test-indexer-guide-queries.sh index 8fc0c7b..af5d957 100755 --- a/scripts/test-indexer-guide-queries.sh +++ b/scripts/test-indexer-guide-queries.sh @@ -18,6 +18,8 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # shellcheck source=../.env . "$REPO_ROOT/.env" +# shellcheck source=../shared/lib.sh +. "$REPO_ROOT/shared/lib.sh" # Ensure cast is on PATH export PATH="$HOME/.foundry/bin:$PATH" @@ -82,8 +84,7 @@ echo " Indexer: $INDEXER" echo "" # -- Resolve REO contract address -- -REO_ADDRESS=$(docker exec graph-node cat /opt/config/issuance.json 2>/dev/null \ - | jq -r '.["1337"].RewardsEligibilityOracle.address // empty' 2>/dev/null || true) +REO_ADDRESS=$(contract_addr RewardsEligibilityOracle.address issuance 2>/dev/null) || true if [ -z "$REO_ADDRESS" ]; then echo " WARNING: REO contract not found. Skipping cast tests." @@ -95,8 +96,7 @@ else fi # -- Resolve RewardsManager address -- -REWARDS_MANAGER=$(docker exec graph-node cat /opt/config/horizon.json 2>/dev/null \ - | jq -r '.["1337"].RewardsManager.address // empty' 2>/dev/null || true) +REWARDS_MANAGER=$(contract_addr RewardsManager.address horizon 2>/dev/null) || true if [ -n "$REWARDS_MANAGER" ]; then echo " RM: $REWARDS_MANAGER" diff --git a/scripts/test-reo-eligibility.sh b/scripts/test-reo-eligibility.sh index 94648a0..47aa8d5 100755 --- a/scripts/test-reo-eligibility.sh +++ b/scripts/test-reo-eligibility.sh @@ -19,6 +19,8 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # Load environment # shellcheck source=../.env . "$REPO_ROOT/.env" +# shellcheck source=../shared/lib.sh +. "$REPO_ROOT/shared/lib.sh" # Host-side defaults (containers use internal hostnames) RPC_URL="http://${CHAIN_HOST:-localhost}:${CHAIN_RPC_PORT}" @@ -29,8 +31,7 @@ REO_POLL_TIMEOUT=150 # Max wait: 2.5 cycles (worst case: just missed a cycle) REO_POLL_INTERVAL=10 # Check every 10s # -- Read REO contract address from config-local volume -- -REO_ADDRESS=$(docker exec graph-node cat /opt/config/issuance.json 2>/dev/null \ - | jq -r '.["1337"].RewardsEligibilityOracle.address // empty' 2>/dev/null || true) +REO_ADDRESS=$(contract_addr RewardsEligibilityOracle.address issuance 2>/dev/null) || true if [ -z "$REO_ADDRESS" ]; then echo "ERROR: RewardsEligibilityOracle address not found." echo " Is the local network running? Is the REO contract deployed (Phase 4)?" diff --git a/containers/shared/lib.sh b/shared/lib.sh similarity index 58% rename from containers/shared/lib.sh rename to shared/lib.sh index c17694e..2fd6981 100644 --- a/containers/shared/lib.sh +++ b/shared/lib.sh @@ -1,17 +1,26 @@ #!/bin/sh -# Shared shell utilities for local-network services +# Shared shell utilities for local-network (container services and host scripts) require_jq() { - _val=$(jq -r "$1 // empty" "$2") + _val=$(jq -r "$1 // empty" ${2:+"$2"}) if [ -z "$_val" ]; then - echo "Error: $1 not found in $2" >&2 + echo "Error: $1 not found in ${2:-stdin}" >&2 exit 1 fi printf '%s' "$_val" } +# contract_addr CONTRACT_NAME ADDRESS_BOOK +# Gets a contract address from a config file +# Supports both host and container execution contexts. +# Example: contract_addr L2GraphToken.address horizon contract_addr() { - require_jq ".\"1337\".$1" "/opt/config/$2.json" + if [ -d "/opt/config" ]; then + require_jq ".\"1337\".$1" "/opt/config/$2.json" + else + docker exec graph-node cat "/opt/config/$2.json" \ + | require_jq ".\"1337\".$1" + fi } # wait_for_gql URL QUERY JQ_FILTER [TIMEOUT]