#!/usr/bin/env bash # One-shot: ensure grid mnemonic on disk, export 6,534 addresses, optionally fund first tranche from deployer. # # Usage: # bash scripts/deployment/pmm-soak-complete-operator-bootstrap.sh # bash scripts/deployment/pmm-soak-complete-operator-bootstrap.sh --apply-funds --to-linear 19 # # Flags: # --init-mnemonic Create ~/.secure-secrets/chain138-pmm-soak-grid.mnemonic if missing (cast new-mnemonic). # --apply-funds After export, run native + cUSDT funding (requires PRIVATE_KEY). # --to-linear N Last linear index for funding tranche (default 19). # --skip-export Use existing PMM_SOAK_GRID_JSON (default config/pmm-soak-wallet-grid.json). # # Env: # PMM_SOAK_GRID_MNEMONIC_FILE — default ~/.secure-secrets/chain138-pmm-soak-grid.mnemonic # PMM_SOAK_GRID_JSON — output path (default: $PROJECT_ROOT/config/pmm-soak-wallet-grid.json) # NATIVE_AMOUNT_WEI — default 20000000000000000 (0.02 native per wallet) # FUND_TOKEN / AMOUNT_WEI_PER_WALLET — ERC-20 tranche (defaults: cUSDT, 50000000 = 50 USDT face) # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" # shellcheck source=/dev/null source "${PROJECT_ROOT}/scripts/lib/pmm-soak-dotenv-override.sh" pmm_soak_snapshot_pool_env_for_restore # shellcheck source=/dev/null [[ -f "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" ]] && source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" pmm_soak_restore_pool_env_after_dotenv if [[ -n "${PMM_SOAK_RPC_URL_OVERRIDE:-}" ]]; then export RPC_URL_138="$PMM_SOAK_RPC_URL_OVERRIDE" export CHAIN138_RPC_URL="$RPC_URL_138" export CHAIN138_RPC="$RPC_URL_138" export ETH_RPC_URL="$RPC_URL_138" fi INIT_MN=0 APPLY_FUND=0 SKIP_EXPORT=0 TO_LINEAR=19 while [[ $# -gt 0 ]]; do case "$1" in --init-mnemonic) INIT_MN=1 ;; --apply-funds) APPLY_FUND=1 ;; --skip-export) SKIP_EXPORT=1 ;; --to-linear) TO_LINEAR="$2" shift ;; -h | --help) sed -n '2,19p' "$0" exit 0 ;; *) echo "[bootstrap] unknown arg: $1" >&2 exit 2 ;; esac shift done SECRETS_DIR="${HOME}/.secure-secrets" MN_FILE="${PMM_SOAK_GRID_MNEMONIC_FILE:-${SECRETS_DIR}/chain138-pmm-soak-grid.mnemonic}" OUT_JSON="${PMM_SOAK_GRID_JSON:-${PROJECT_ROOT}/config/pmm-soak-wallet-grid.json}" NATIVE_AMT="${NATIVE_AMOUNT_WEI:-20000000000000000}" FUND_TOKEN="${FUND_TOKEN:-0x93E66202A11B1772E55407B32B44e5Cd8eda7f22}" ERC20_AMT="${AMOUNT_WEI_PER_WALLET:-50000000}" require_cmd() { command -v "$1" >/dev/null 2>&1 || { echo "[bootstrap] missing: $1" >&2 exit 1 } } require_cmd cast require_cmd python3 mkdir -p "$SECRETS_DIR" if [[ ! -f "$MN_FILE" ]]; then if [[ "$INIT_MN" -eq 1 ]] || [[ "${PMM_SOAK_AUTO_INIT_GRID_MNEMONIC:-}" == "1" ]]; then echo "[bootstrap] creating grid mnemonic at $MN_FILE (chmod 600)" cast wallet new-mnemonic 2>&1 | awk 'f{print; exit} /^Phrase:/{f=1}' | tr -d '\r\n' >"$MN_FILE" chmod 600 "$MN_FILE" echo "[bootstrap] BACK UP this file; it controls all 6,534 grid addresses." else echo "[bootstrap] No mnemonic file at $MN_FILE" >&2 echo " Option A: PMM_SOAK_GRID_MNEMONIC='twelve words...' $0" >&2 echo " Option B: $0 --init-mnemonic (creates file; then re-run with export/funds)" >&2 exit 1 fi fi if [[ -n "${PMM_SOAK_GRID_MNEMONIC:-}" ]]; then export PMM_SOAK_GRID_MNEMONIC elif [[ -f "$MN_FILE" ]]; then PMM_SOAK_GRID_MNEMONIC="$(tr -d '\r\n' <"$MN_FILE")" export PMM_SOAK_GRID_MNEMONIC else echo "[bootstrap] internal error: no mnemonic" >&2 exit 1 fi if [[ "$SKIP_EXPORT" -eq 0 ]]; then echo "[bootstrap] exporting 6,534 addresses to $OUT_JSON (parallel cast; may take a few minutes)..." python3 "${PROJECT_ROOT}/scripts/deployment/pmm-soak-export-wallet-grid.py" --out "$OUT_JSON" --jobs 8 else echo "[bootstrap] skip export; using existing $OUT_JSON" [[ -f "$OUT_JSON" ]] || { echo "[bootstrap] missing $OUT_JSON" >&2 exit 1 } fi if [[ "$APPLY_FUND" -eq 1 ]]; then PK="${DEPLOYER_PRIVATE_KEY:-${PRIVATE_KEY:-}}" if [[ -z "$PK" ]]; then echo "[bootstrap] --apply-funds needs PRIVATE_KEY / DEPLOYER_PRIVATE_KEY" >&2 exit 1 fi echo "[bootstrap] funding linear 0..$TO_LINEAR native=$NATIVE_AMT wei" PMM_SOAK_GRID_JSON="$OUT_JSON" NATIVE_AMOUNT_WEI="$NATIVE_AMT" \ bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --native --apply --from-linear 0 --to-linear "$TO_LINEAR" echo "[bootstrap] funding same range ERC-20 token=$FUND_TOKEN amount=$ERC20_AMT" PMM_SOAK_GRID_JSON="$OUT_JSON" TOKEN="$FUND_TOKEN" AMOUNT_WEI_PER_WALLET="$ERC20_AMT" \ bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --apply --from-linear 0 --to-linear "$TO_LINEAR" fi echo "[bootstrap] done. Grid JSON: $OUT_JSON Mnemonic file: $MN_FILE" echo "[bootstrap] Next: export PMM_SOAK_GRID_MNEMONIC from $MN_FILE, set PMM_SOAK_GRID_JSON=$OUT_JSON, run chain138-pmm-soak-grid-bot.sh --dry-run then --apply (e.g. --pool-preset stable or cusdt-cusdc; default swap path is pool - see docs/11-references/CHAIN138_GRID_6534_WALLET_FUNDING_PLAN.md)."