#!/usr/bin/env bash # Verify token-aggregation HTTP surface for Chain 138 (pools, quotes, bridge routes, and GRU preflight). # Usage: BASE_URL=https://explorer.d-bis.org bash scripts/verify/check-token-aggregation-chain138-api.sh # Tries both /api/v1/* and /token-aggregation/api/v1/* (explorer nginx layouts differ). set -euo pipefail BASE_URL="${BASE_URL:-https://explorer.d-bis.org}" BASE_URL="${BASE_URL%/}" CUSDT="0x93E66202A11B1772E55407B32B44e5Cd8eda7f22" CUSDC="0xf22258f57794CC8E06237084b353Ab30fFfa640b" WETH10="0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f" USDT="0x004b63A7B5b0E06f6bB6adb4a5F9f590BF3182D1" USDC="0x71D6687F38b93CCad569Fa6352c876eea967201b" ROOT_V1_CODE="000" TOKEN_AGG_V1_CODE="000" V2_CAPS_CODE="000" V2_PLAN_CODE="000" V2_INTERNAL_PLAN_CODE="000" try_path() { local prefix="$1" local path="$2" local url="${BASE_URL}${prefix}${path}" local code code=$(curl -sS -o /tmp/ta-check.json -w "%{http_code}" -m 25 "$url" || echo "000") echo " $code ${prefix}${path}" if [[ "$code" == 200 ]]; then head -c 220 /tmp/ta-check.json echo fi } try_post_path() { local prefix="$1" local path="$2" local body="$3" local url="${BASE_URL}${prefix}${path}" local code code=$(curl -sS -o /tmp/ta-check.json -w "%{http_code}" -m 25 \ -H "content-type: application/json" \ -X POST \ --data "$body" \ "$url" || echo "000") echo " $code POST ${prefix}${path}" if [[ "$code" == 200 || "$code" == 400 ]]; then head -c 260 /tmp/ta-check.json echo fi } echo "== Token-aggregation checks against ${BASE_URL} ==" for prefix in "" "/token-aggregation"; do echo "" echo "-- prefix: ${prefix:-/} (root /api/v1) --" try_path "${prefix}" "/api/v1/tokens?chainId=138&limit=3&includeDodoPool=true" try_path "${prefix}" "/api/v1/tokens/${CUSDT}/pools?chainId=138" try_path "${prefix}" "/api/v1/quote?chainId=138&tokenIn=${CUSDT}&tokenOut=${CUSDC}&amountIn=1000000" if command -v jq >/dev/null 2>&1; then qurl="${BASE_URL}${prefix}/api/v1/quote?chainId=138&tokenIn=${CUSDT}&tokenOut=${CUSDC}&amountIn=1000000" qcode=$(curl -sS -o /tmp/ta-quote.json -w "%{http_code}" -m 25 "$qurl" 2>/dev/null || echo "000") if [[ "$qcode" == "200" ]]; then qe=$(jq -r '.quoteEngine // "absent"' /tmp/ta-quote.json 2>/dev/null || echo "?") echo " quoteEngine=${qe} (${BASE_URL}${prefix}/api/v1/quote cUSDT→cUSDC)" if [[ "$qe" == "constant-product" ]]; then echo " (hint: PMM on-chain not used — RPC unset, blocked, or pool not DODO; publication deploy sets RPC_URL_138)" fi if [[ "$qe" == "absent" ]]; then echo " (hint: redeploy token-aggregation from repo — older build omits quoteEngine; run deploy-token-aggregation-for-publication.sh on explorer host)" fi fi fi try_path "${prefix}" "/api/v1/bridge/routes" try_path "${prefix}" "/api/v1/bridge/status" try_path "${prefix}" "/api/v1/bridge/preflight" try_path "${prefix}" "/api/v1/report/gas-registry?chainId=10" try_path "${prefix}" "/api/v1/networks" done echo "" echo "== planner-v2 checks ==" echo "" echo "-- prefix: /token-aggregation (published v2 path) --" V2_CAPS_CODE=$(curl -sS -o /tmp/ta-check.json -w "%{http_code}" -m 25 \ "${BASE_URL}/token-aggregation/api/v2/providers/capabilities?chainId=138" 2>/dev/null || echo "000") echo " $V2_CAPS_CODE /token-aggregation/api/v2/providers/capabilities?chainId=138" if [[ "$V2_CAPS_CODE" == "200" ]]; then head -c 220 /tmp/ta-check.json echo fi if [[ -f /tmp/ta-check.json ]] && head -c 20 /tmp/ta-check.json | grep -qi '/dev/null || echo "000") echo " $V2_PLAN_CODE POST /token-aggregation/api/v2/routes/plan" if [[ "$V2_PLAN_CODE" == "200" || "$V2_PLAN_CODE" == "400" ]]; then head -c 260 /tmp/ta-check.json echo fi V2_INTERNAL_PLAN_CODE=$(curl -sS -o /tmp/ta-check.json -w "%{http_code}" -m 25 \ -H "content-type: application/json" \ -X POST \ --data "{\"sourceChainId\":138,\"tokenIn\":\"${WETH10}\",\"tokenOut\":\"${USDT}\",\"amountIn\":\"100000000000000000\"}" \ "${BASE_URL}/token-aggregation/api/v2/routes/internal-execution-plan" 2>/dev/null || echo "000") echo " $V2_INTERNAL_PLAN_CODE POST /token-aggregation/api/v2/routes/internal-execution-plan" if [[ "$V2_INTERNAL_PLAN_CODE" == "200" || "$V2_INTERNAL_PLAN_CODE" == "400" ]]; then head -c 260 /tmp/ta-check.json echo fi echo "" echo "== DODO stable depth sanity ==" for prefix in "" "/token-aggregation"; do code=$(curl -sS -o /tmp/ta-depth.json -w "%{http_code}" -m 20 \ "${BASE_URL}${prefix}/api/v1/routes/tree?chainId=138&tokenIn=${CUSDC}&tokenOut=${USDC}&amountIn=1000000" \ 2>/dev/null || echo 000) echo "${prefix:-/} -> HTTP $code" if [[ "$code" == "200" ]] && command -v jq >/dev/null 2>&1; then jq '{pool: .pools[0].poolAddress, tvlUsd: .pools[0].depth.tvlUsd, estimatedTradeCapacityUsd: .pools[0].depth.estimatedTradeCapacityUsd}' /tmp/ta-depth.json 2>/dev/null || head -c 220 /tmp/ta-depth.json echo fi done echo "" echo "" echo "== bridge summary ==" for prefix in "" "/token-aggregation"; do code=$(curl -sS -o /tmp/br.json -w "%{http_code}" -m 20 "${BASE_URL}${prefix}/api/v1/bridge/routes" 2>/dev/null || echo 000) echo "${prefix:-/} -> HTTP $code" if [[ "$code" == "200" ]] && command -v jq >/dev/null 2>&1; then jq '{weth9: .chain138Bridges.weth9, weth10: .chain138Bridges.weth10}' /tmp/br.json 2>/dev/null || head -c 200 /tmp/br.json echo fi done echo "" echo "== bridge/preflight summary ==" for prefix in "" "/token-aggregation"; do code=$(curl -sS -o /tmp/gru-preflight.json -w "%{http_code}" -m 20 "${BASE_URL}${prefix}/api/v1/bridge/preflight" 2>/dev/null || echo 000) echo "${prefix:-/} -> HTTP $code" if [[ "$code" == "200" ]] && command -v jq >/dev/null 2>&1; then jq '{transportPairs: .gruTransport.summary.transportPairs, runtimeReadyTransportPairs: .gruTransport.summary.runtimeReadyTransportPairs, blockedPairs: (.gruTransport.blockedPairs | length)}' /tmp/gru-preflight.json 2>/dev/null || head -c 200 /tmp/gru-preflight.json echo fi done echo "" echo "== gas-registry summary ==" for prefix in "" "/token-aggregation"; do code=$(curl -sS -o /tmp/gas-registry.json -w "%{http_code}" -m 20 "${BASE_URL}${prefix}/api/v1/report/gas-registry?chainId=10" 2>/dev/null || echo 000) echo "${prefix:-/} -> HTTP $code" if [[ "$code" == "200" ]] && command -v jq >/dev/null 2>&1; then jq '{gasAssetFamilies: (.gasAssetFamilies | length), gasRedeemGroups: (.gasRedeemGroups | length), chains: (.chains | length), gasProtocolExposure: (.gasProtocolExposure | length)}' /tmp/gas-registry.json 2>/dev/null || head -c 200 /tmp/gas-registry.json echo fi done echo "" echo "Notes:" echo " - Empty tokens/pools: set DATABASE_URL, then run bash smom-dbis-138/services/token-aggregation/scripts/apply-lightweight-schema.sh for standalone deployments; RPC to 138; PMM integration now defaults on-chain if env unset." echo " - bridge/routes 404: redeploy token-aggregation from repo (implements GET /api/v1/bridge/routes)." echo " - bridge/preflight blocked pairs: run bash scripts/verify/check-gru-transport-preflight.sh [BASE_URL] for exact missing refs." echo " - gas-registry 404: redeploy token-aggregation from repo (implements GET /api/v1/report/gas-registry)." echo " - Health: curl -s http://127.0.0.1:3001/health on explorer VM (not always proxied as /health)." echo " - planner-v2 publishes under /token-aggregation/api/v2/* so it does not collide with Blockscout /api/v2/* on explorer.d-bis.org." echo " - Apex https://explorer.d-bis.org/api/v1/* returns 400 while /token-aggregation/api/v1/* works: add HTTP+HTTPS location /api/v1/ → token-aggregation (scripts/fix-explorer-http-api-v1-proxy.sh on explorer VM)." echo " - If POST /token-aggregation/api/v2/* returns 405 or HTML instead of JSON, insert the v2 proxy block (scripts/fix-explorer-token-aggregation-api-v2-proxy.sh on VMID 5000)." echo " - Fresh binary + PMM env: bash scripts/deploy-token-aggregation-for-publication.sh then rsync dist/node_modules/.env to /opt/token-aggregation; systemctl restart token-aggregation (see TOKEN_AGGREGATION_REPORT_API_RUNBOOK.md)." echo " - DODO v3 pilot routes should return provider=dodo_v3, routePlanPresent=true, and an internal-execution-plan object targeting EnhancedSwapRouterV2 when CHAIN138_ENABLE_DODO_V3_EXECUTION is live." echo " - The funded canonical cUSDC/USDC DODO pool should report non-zero route-tree depth on Chain 138; if it falls back to near-zero TVL again, check the DODO valuation path and the canonical PMM integration address." ROOT_V1_CODE=$(curl -sS -o /tmp/ta-root-v1.json -w "%{http_code}" -m 25 \ "${BASE_URL}/api/v1/tokens?chainId=138&limit=1" 2>/dev/null || echo "000") TOKEN_AGG_V1_CODE=$(curl -sS -o /tmp/ta-tokenagg-v1.json -w "%{http_code}" -m 25 \ "${BASE_URL}/token-aggregation/api/v1/tokens?chainId=138&limit=1" 2>/dev/null || echo "000") echo "" echo "== summary ==" echo "root_v1=$ROOT_V1_CODE token_aggregation_v1=$TOKEN_AGG_V1_CODE v2_caps=$V2_CAPS_CODE v2_plan=$V2_PLAN_CODE v2_internal_plan=$V2_INTERNAL_PLAN_CODE" if [[ "$V2_CAPS_CODE" != "200" || "$V2_PLAN_CODE" != "200" || "$V2_INTERNAL_PLAN_CODE" != "200" ]]; then echo "[fail] planner-v2 publication is unhealthy" >&2 exit 1 fi if [[ "$TOKEN_AGG_V1_CODE" == "502" || "$TOKEN_AGG_V1_CODE" == "000" ]]; then echo "[fail] published /token-aggregation/api/v1 surface is unhealthy" >&2 exit 1 fi if [[ "$ROOT_V1_CODE" == "400" ]]; then echo "[warn] apex /api/v1 remains routed to Blockscout and not token-aggregation; use /token-aggregation/api/v1 or add the dedicated apex proxy if required." >&2 fi echo "[OK] token-aggregation planner-v2 is healthy; published v1 surface is reachable."