- pmm-soak-operator-fund-grid: PMM_SOAK_FUND_PROGRESS_EVERY, ERR trap, help text comments only - pmm-soak-complete-grid-funding-operator: PMM_SOAK_START_LEG resume, per-leg and total wall time - pmm-soak-operator-fund-full-grid-tranches: PMM_SOAK_RPC_URL_OVERRIDE, bash --noprofile --norc, manual hint - pmm-soak-mint-mirror-usdc-deployer-shortfall: ASCII-only operator messages - CHAIN138_GRID_6534_WALLET_FUNDING_PLAN: full-grid orchestrator, env vars, log markers Made-with: Cursor
196 lines
8.3 KiB
Bash
Executable File
196 lines
8.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Fund all grid wallets (0..6533) in linear tranches — native + ERC-20 from deployer.
|
|
# Each tranche invokes pmm-soak-operator-fund-grid.sh (one tx per recipient per tranche).
|
|
#
|
|
# Usage (dry-run first):
|
|
# bash scripts/deployment/pmm-soak-operator-fund-full-grid-tranches.sh --dry-run
|
|
# bash scripts/deployment/pmm-soak-operator-fund-full-grid-tranches.sh --apply
|
|
#
|
|
# Env (optional overrides):
|
|
# PMM_SOAK_GRID_JSON — default config/pmm-soak-wallet-grid.json
|
|
# PMM_SOAK_FUND_CHUNK — wallets per tranche (default 250)
|
|
# NATIVE_AMOUNT_WEI — default 20000000000000000 (0.02)
|
|
# PMM_SOAK_SEED_CUSDT_RAW / PMM_SOAK_SEED_CUSDC_RAW / PMM_SOAK_SEED_MIRROR_USDT_RAW — 6-decimal raw per wallet (default 100000000 = 100 face)
|
|
# PMM_SOAK_SEED_MIRROR_USDC_RAW — per-wallet raw amount (default 100000000).
|
|
# PMM_SOAK_SKIP_MIRROR_USDC_OWNER_MINT=1 — do not auto-mint OfficialStableMirrorToken USDC to deployer when balance is short (default: mint shortfall via owner mint() before transfers).
|
|
# PMM_SOAK_WAIT_NONCE_CLEAR_SEC — before owner-mint, wait up to this many seconds for deployer latest==pending nonce (default 7200). Avoids "replacement transaction underpriced" when another process holds the next nonce.
|
|
# PMM_SOAK_RPC_URL_OVERRIDE — after dotenv load, force RPC_URL_138 (same as complete-grid / fund-grid long runs).
|
|
#
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# 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
|
|
|
|
GRID_JSON="${PMM_SOAK_GRID_JSON:-${PROJECT_ROOT}/config/pmm-soak-wallet-grid.json}"
|
|
CHUNK="${PMM_SOAK_FUND_CHUNK:-250}"
|
|
NATIVE_WEI="${NATIVE_AMOUNT_WEI:-20000000000000000}"
|
|
SEED_CUSDT="${PMM_SOAK_SEED_CUSDT_RAW:-100000000}"
|
|
SEED_CUSDC="${PMM_SOAK_SEED_CUSDC_RAW:-100000000}"
|
|
SEED_USDT="${PMM_SOAK_SEED_MIRROR_USDT_RAW:-100000000}"
|
|
SEED_USDC="${PMM_SOAK_SEED_MIRROR_USDC_RAW:-100000000}"
|
|
|
|
CUSDT=0x93E66202A11B1772E55407B32B44e5Cd8eda7f22
|
|
CUSDC=0xf22258f57794CC8E06237084b353Ab30fFfa640b
|
|
USDT_M=0x004b63A7B5b0E06f6bB6adb4a5F9f590BF3182D1
|
|
USDC_M=0x71D6687F38b93CCad569Fa6352c876eea967201b
|
|
|
|
RPC="${RPC_URL_138:-http://192.168.11.211:8545}"
|
|
PK="${DEPLOYER_PRIVATE_KEY:-${PRIVATE_KEY:-}}"
|
|
D=0x4A666F96fC8764181194447A7dFdb7d471b301C8
|
|
|
|
APPLY=0
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--apply) APPLY=1 ;;
|
|
--dry-run) APPLY=0 ;;
|
|
-h | --help)
|
|
sed -n '1,28p' "$0" | tail -n +2
|
|
exit 0
|
|
;;
|
|
*) echo "unknown: $1" >&2; exit 2 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ "$APPLY" -eq 1 && -z "$PK" ]]; then
|
|
echo "[fund-tranches] FATAL: --apply needs PRIVATE_KEY / DEPLOYER_PRIVATE_KEY" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$GRID_JSON" ]]; then
|
|
echo "[fund-tranches] missing $GRID_JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
MAX_LI=6533
|
|
GAS_WEI="${CHAIN138_DEPLOY_GAS_PRICE_WEI:-1000}"
|
|
|
|
refresh_usdc_bal() {
|
|
USDC_BAL="$(cast call "$USDC_M" 'balanceOf(address)(uint256)' "$D" --rpc-url "$RPC" | awk '{print $1}')"
|
|
}
|
|
|
|
# Wait until deployer has no pending txs (latest nonce tag == pending nonce tag).
|
|
wait_deployer_nonce_mempool_clear() {
|
|
local max_wait="${PMM_SOAK_WAIT_NONCE_CLEAR_SEC:-7200}"
|
|
local start="$SECONDS"
|
|
while true; do
|
|
local nl np
|
|
nl="$(cast nonce "$D" --rpc-url "$RPC" -B latest)"
|
|
np="$(cast nonce "$D" --rpc-url "$RPC" -B pending)"
|
|
if [[ "$nl" == "$np" ]]; then
|
|
echo "[fund-tranches] deployer nonce clear (latest=pending=$nl)"
|
|
return 0
|
|
fi
|
|
if (( SECONDS - start > max_wait )); then
|
|
echo "[fund-tranches] FATAL: deployer still has pending nonce (latest=$nl pending=$np) after ${max_wait}s — stop other deployer senders or raise PMM_SOAK_WAIT_NONCE_CLEAR_SEC" >&2
|
|
exit 1
|
|
fi
|
|
echo "[fund-tranches] waiting for deployer mempool (latest=$nl pending=$np) …"
|
|
sleep 3
|
|
done
|
|
}
|
|
|
|
USDC_NEEDED="$(python3 -c "print(int('$SEED_USDC') * (int('$MAX_LI') + 1))")"
|
|
refresh_usdc_bal
|
|
DO_MIRROR_USDC=1
|
|
if (( USDC_BAL < USDC_NEEDED )); then
|
|
SHORTFALL="$(python3 -c "print(int('$USDC_NEEDED') - int('$USDC_BAL'))")"
|
|
if [[ "${PMM_SOAK_SKIP_MIRROR_USDC_OWNER_MINT:-0}" == "1" ]]; then
|
|
DO_MIRROR_USDC=0
|
|
echo "[fund-tranches] WARN: deployer mirror USDC balance $USDC_BAL < need $USDC_NEEDED; PMM_SOAK_SKIP_MIRROR_USDC_OWNER_MINT=1 — skipping mirror USDC tranches"
|
|
elif [[ "$APPLY" -eq 0 ]]; then
|
|
echo "[fund-tranches] deployer mirror USDC $USDC_BAL < need $USDC_NEEDED — dry-run: on --apply would owner-mint $SHORTFALL to deployer then fund mirror USDC"
|
|
echo " cast send $USDC_M 'mint(address,uint256)' $D $SHORTFALL --rpc-url \"\$RPC_URL_138\" --private-key \"\$PRIVATE_KEY\" --legacy --gas-price $GAS_WEI"
|
|
DO_MIRROR_USDC=1
|
|
elif [[ -z "$PK" ]]; then
|
|
DO_MIRROR_USDC=0
|
|
echo "[fund-tranches] WARN: shortfall $SHORTFALL but no PRIVATE_KEY — cannot mint; skipping mirror USDC tranches" >&2
|
|
else
|
|
echo "[fund-tranches] owner-mint mirror USDC shortfall $SHORTFALL to deployer (need $USDC_NEEDED, have $USDC_BAL)"
|
|
wait_deployer_nonce_mempool_clear
|
|
cast send "$USDC_M" 'mint(address,uint256)' "$D" "$SHORTFALL" \
|
|
--rpc-url "$RPC" --private-key "$PK" --legacy --gas-price "$GAS_WEI"
|
|
refresh_usdc_bal
|
|
if (( USDC_BAL < USDC_NEEDED )); then
|
|
echo "[fund-tranches] FATAL: after mint deployer USDC $USDC_BAL still < $USDC_NEEDED" >&2
|
|
exit 1
|
|
fi
|
|
echo "[fund-tranches] deployer mirror USDC balance now $USDC_BAL"
|
|
fi
|
|
fi
|
|
|
|
run_native() {
|
|
local from="$1" to="$2"
|
|
echo "[fund-tranches] === native linear $from..$to (apply=$APPLY) ==="
|
|
if [[ "$APPLY" -eq 1 ]]; then
|
|
PMM_SOAK_GRID_JSON="$GRID_JSON" NATIVE_AMOUNT_WEI="$NATIVE_WEI" \
|
|
bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --apply --native --from-linear "$from" --to-linear "$to"
|
|
else
|
|
PMM_SOAK_GRID_JSON="$GRID_JSON" NATIVE_AMOUNT_WEI="$NATIVE_WEI" \
|
|
bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --native --from-linear "$from" --to-linear "$to"
|
|
fi
|
|
}
|
|
|
|
run_erc20() {
|
|
local from="$1" to="$2" tok="$3" amt="$4"
|
|
echo "[fund-tranches] === ERC-20 $tok linear $from..$to amount=$amt (apply=$APPLY) ==="
|
|
if [[ "$APPLY" -eq 1 ]]; then
|
|
PMM_SOAK_GRID_JSON="$GRID_JSON" TOKEN="$tok" AMOUNT_WEI_PER_WALLET="$amt" \
|
|
bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --apply --from-linear "$from" --to-linear "$to"
|
|
else
|
|
PMM_SOAK_GRID_JSON="$GRID_JSON" TOKEN="$tok" AMOUNT_WEI_PER_WALLET="$amt" \
|
|
bash --noprofile --norc "${PROJECT_ROOT}/scripts/deployment/pmm-soak-operator-fund-grid.sh" --from-linear "$from" --to-linear "$to"
|
|
fi
|
|
}
|
|
|
|
for ((from = 0; from <= MAX_LI; from += CHUNK)); do
|
|
to=$((from + CHUNK - 1))
|
|
[[ "$to" -gt "$MAX_LI" ]] && to="$MAX_LI"
|
|
run_native "$from" "$to"
|
|
done
|
|
|
|
for ((from = 0; from <= MAX_LI; from += CHUNK)); do
|
|
to=$((from + CHUNK - 1))
|
|
[[ "$to" -gt "$MAX_LI" ]] && to="$MAX_LI"
|
|
run_erc20 "$from" "$to" "$CUSDT" "$SEED_CUSDT"
|
|
done
|
|
|
|
for ((from = 0; from <= MAX_LI; from += CHUNK)); do
|
|
to=$((from + CHUNK - 1))
|
|
[[ "$to" -gt "$MAX_LI" ]] && to="$MAX_LI"
|
|
run_erc20 "$from" "$to" "$CUSDC" "$SEED_CUSDC"
|
|
done
|
|
|
|
for ((from = 0; from <= MAX_LI; from += CHUNK)); do
|
|
to=$((from + CHUNK - 1))
|
|
[[ "$to" -gt "$MAX_LI" ]] && to="$MAX_LI"
|
|
run_erc20 "$from" "$to" "$USDT_M" "$SEED_USDT"
|
|
done
|
|
|
|
if [[ "$DO_MIRROR_USDC" -eq 1 ]]; then
|
|
for ((from = 0; from <= MAX_LI; from += CHUNK)); do
|
|
to=$((from + CHUNK - 1))
|
|
[[ "$to" -gt "$MAX_LI" ]] && to="$MAX_LI"
|
|
run_erc20 "$from" "$to" "$USDC_M" "$SEED_USDC"
|
|
done
|
|
else
|
|
echo "[fund-tranches] mirror USDC tranches skipped (see WARN above). Options: unset PMM_SOAK_SKIP_MIRROR_USDC_OWNER_MINT and re-run --apply (auto-mint), or manual mint then:"
|
|
echo " PMM_SOAK_GRID_JSON=$GRID_JSON TOKEN=$USDC_M AMOUNT_WEI_PER_WALLET=$SEED_USDC bash --noprofile --norc scripts/deployment/pmm-soak-operator-fund-grid.sh --apply --from-linear 0 --to-linear $MAX_LI"
|
|
fi
|
|
|
|
echo "[fund-tranches] done (apply=$APPLY)"
|