Files
proxmox/scripts/verify/check-contracts-on-chain-138.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

156 lines
7.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Check that Chain 138 deployed contracts have bytecode on-chain.
# Usage: ./scripts/verify/check-contracts-on-chain-138.sh [RPC_URL] [--dry-run]
# Default RPC: from env RPC_URL_138 (Chain 138 Core standard) or config/ip-addresses.conf, else https://rpc-core.d-bis.org
# Optional: SKIP_EXIT=1 to exit 0 even when some addresses MISS (e.g. when RPC unreachable from this host).
# Optional: --dry-run to print RPC and address list only (no RPC calls).
#
# Why "0 present, 26 missing"? RPC is unreachable from this host: rpc-core.d-bis.org often doesn't resolve
# (internal DNS) and config uses 192.168.11.211 (LAN-only). Run from a host on VPN/LAN, or pass a reachable
# RPC: ./scripts/verify/check-contracts-on-chain-138.sh http://YOUR_RPC:8545
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Load project env so RPC_URL_138 (Chain 138 Core) from config/ip-addresses.conf or smom-dbis-138/.env is used
[[ -f "${SCRIPT_DIR}/../lib/load-project-env.sh" ]] && source "${SCRIPT_DIR}/../lib/load-project-env.sh" 2>/dev/null || true
# Parse args: first non-option is RPC_URL; --dry-run = print only, no cast calls
DRY_RUN=""
RPC_ARG=""
for a in "$@"; do
if [[ "$a" == "--dry-run" ]]; then DRY_RUN=1; else [[ -z "$RPC_ARG" ]] && RPC_ARG="$a"; fi
done
RPC="${RPC_ARG:-${RPC_URL_138:-https://rpc-core.d-bis.org}}"
RPC="${RPC:-https://rpc-core.d-bis.org}"
# Addresses to exclude from Chain 138 bytecode check (EOAs or Mainnet-only contracts listed for reference)
EXCLUDE_138=(
"0x4A666F96fC8764181194447A7dFdb7d471b301C8" # Deployer_Admin (EOA)
"0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619" # Tether_USDT_Chain138 / MainnetTether (Mainnet only)
"0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9" # Transaction_Mirror (Mainnet only)
)
# Chain 138 deployed addresses: from config/smart-contracts-master.json when available, else fallback list
if [[ -n "${CONTRACTS_MASTER_JSON:-}" && -f "${CONTRACTS_MASTER_JSON}" ]] && command -v jq &>/dev/null; then
ALL_RAW=($(jq -r '.chains["138"].contracts | to_entries[] | .value' "$CONTRACTS_MASTER_JSON" | sort -u))
ADDRESSES=()
for a in "${ALL_RAW[@]}"; do
skip=0
for ex in "${EXCLUDE_138[@]}"; do [[ "$a" == "$ex" ]] && skip=1 && break; done
[[ $skip -eq 0 ]] && ADDRESSES+=("$a")
done
else
ADDRESSES=(
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # WETH9
"0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f" # WETH10
"0x99b3511a2d315a497c8112c1fdd8d508d4b1e506" # Multicall / Oracle Aggregator
"0x3304b747e565a97ec8ac220b0b6a1f6ffdb837e6" # Oracle Proxy
"0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e" # CCIP Router
"0x105F8A15b819948a89153505762444Ee9f324684" # CCIP Sender
"0x971cD9D156f193df8051E48043C476e53ECd4693" # CCIPWETH9Bridge
"0xe0E93247376aa097dB308B92e6Ba36bA015535D0" # CCIPWETH10Bridge
"0xb7721dD53A8c629d9f1Ba31a5819AFe250002b03" # LINK
"0x93E66202A11B1772E55407B32B44e5Cd8eda7f22" # cUSDT
"0xf22258f57794CC8E06237084b353Ab30fFfa640b" # cUSDC
"0x91Efe92229dbf7C5B38D422621300956B55870Fa" # TokenRegistry
"0xEBFb5C60dE5f7C4baae180CA328D3BB39E1a5133" # TokenFactory
"0xbc54fe2b6fda157c59d59826bcfdbcc654ec9ea1" # ComplianceRegistry
"0x31884f84555210FFB36a19D2471b8eBc7372d0A8" # BridgeVault
"0xF78246eB94c6CB14018E507E60661314E5f4C53f" # FeeCollector
"0x95BC4A997c0670d5DAC64d55cDf3769B53B63C28" # DebtRegistry
"0x0C4FD27018130A00762a802f91a72D6a64a60F14" # PolicyManager
"0x0059e237973179146237aB49f1322E8197c22b21" # TokenImplementation
"0xD3AD6831aacB5386B8A25BB8D8176a6C8a026f04" # Price Feed Keeper
"0x16D9A2cB94A0b92721D93db4A6Cd8023D3338800" # MerchantSettlementRegistry
"0xe77cb26eA300e2f5304b461b0EC94c8AD6A7E46D" # WithdrawalEscrow
"0xAEE4b7fBe82E1F8295951584CBc772b8BBD68575" # UniversalAssetRegistry (proxy)
"0xA6891D5229f2181a34D4FF1B515c3Aa37dd90E0e" # GovernanceController (proxy)
"0xCd42e8eD79Dc50599535d1de48d3dAFa0BE156F8" # UniversalCCIPBridge (proxy)
"0x89aB428c437f23bAB9781ff8Db8D3848e27EeD6c" # BridgeOrchestrator (proxy)
"0x302aF72966aFd21C599051277a48DAa7f01a5f54" # PaymentChannelManager
"0xe5e3bB424c8a0259FDE23F0A58F7e36f73B90aBd" # GenericStateChannelManager
"0x439Fcb2d2ab2f890DCcAE50461Fa7d978F9Ffe1A" # AddressMapper
"0x6eD905A30c552a6e003061A38FD52A5A427beE56" # MirrorManager
"0xFce6f50B312B3D936Ea9693C5C9531CF92a3324c" # Lockbox138
"0x750E4a8adCe9f0e67A420aBE91342DC64Eb90825" # CREATE2Factory
"0xC98602aa574F565b5478E8816BCab03C9De0870f" # UniversalAssetRegistry (proxy, deterministic)
"0x532DE218b94993446Be30eC894442f911499f6a3" # UniversalCCIPBridge (proxy, deterministic)
"0x6427F9739e6B6c3dDb4E94fEfeBcdF35549549d8" # MirrorRegistry
"0x66FEBA2fC9a0B47F26DD4284DAd24F970436B8Dc" # AlltraAdapter
"0x7131F887DBEEb2e44c1Ed267D2A68b5b83285afc" # TransactionMirror Chain 138 (deployed 2026-02-27; set TRANSACTION_MIRROR_ADDRESS in .env)
"0x9fcB06Aa1FD5215DC0E91Fd098aeff4B62fEa5C8" # DODO cUSDT-cUSDC pool (pending until CreateCUSDTCUSDCPool succeeds)
)
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Chain 138 — on-chain contract check"
echo "RPC: $RPC"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [[ -n "$DRY_RUN" ]]; then
echo "(--dry-run: listing ${#ADDRESSES[@]} addresses; no RPC calls)"
echo ""
for addr in "${ADDRESSES[@]}"; do echo " ... $addr"; done
echo ""
echo "Run without --dry-run to check bytecode on-chain (requires cast and reachable RPC)."
exit 0
fi
# Pre-flight: detect unreachable RPC and print clear resolution (avoids 26 MISS with no explanation)
rpc_reachable=""
if command -v cast &>/dev/null; then
if chain_id=$(cast chain-id --rpc-url "$RPC" 2>/dev/null); then
rpc_reachable=1
fi
fi
if [[ -z "$rpc_reachable" ]]; then
echo "WARN: RPC unreachable from this host: $RPC" >&2
if echo "$RPC" | grep -q "rpc-core.d-bis.org"; then
echo " (rpc-core.d-bis.org often does not resolve off-LAN/VPN.)" >&2
fi
echo " To run successfully: (1) Run from a host on the same LAN as 192.168.11.x or on VPN, or" >&2
echo " (2) Set RPC_URL_138 in smom-dbis-138/.env or pass a reachable URL: $0 <RPC_URL>" >&2
echo "" >&2
fi
OK=0
MISS=0
MISS_ADDRS=()
for addr in "${ADDRESSES[@]}"; do
code=$(cast code "$addr" --rpc-url "$RPC" 2>/dev/null || true)
if [[ -n "$code" && "$code" != "0x" ]]; then
echo " OK $addr"
OK=$((OK + 1))
else
echo " MISS $addr"
MISS=$((MISS + 1))
MISS_ADDRS+=("$addr")
fi
done
echo ""
echo "Total: $OK present, $MISS missing/empty (${#ADDRESSES[@]} addresses). Explorer: https://explorer.d-bis.org/address/<ADDR>"
if [[ $MISS -gt 0 && -z "$rpc_reachable" ]]; then
echo " → RPC was unreachable from this host; see WARN above. Run from LAN/VPN or pass a reachable RPC URL." >&2
fi
# Expected missing (pending deploy or confirm): TransactionMirror, DODO pool; exit 0 when only these are missing
EXPECTED_MISSING=("0xb5876547c52CaBf49d7f40233B6f6a140F403d25" "0x9fcB06Aa1FD5215DC0E91Fd098aeff4B62fEa5C8")
if [[ -n "${SKIP_EXIT:-}" && "${SKIP_EXIT}" != "0" ]]; then
exit 0
fi
if [[ $MISS -eq 0 ]]; then
exit 0
fi
# Exit 0 if every missing address is in EXPECTED_MISSING (e.g. pool not yet deployed)
all_expected=1
for m in "${MISS_ADDRS[@]}"; do
found=0
for exp in "${EXPECTED_MISSING[@]}"; do [[ "$m" == "$exp" ]] && found=1 && break; done
[[ $found -eq 0 ]] && all_expected=0 && break
done
[[ $all_expected -eq 1 ]]