#!/usr/bin/env bash # GPUPark FLOP Testnet Daily 10-FLOP Voucher Autopilot (Single-Wallet, Non-Custodial) # Usage: # FLOP_KEY_PASSWORD="your-password" KEYSTORE_FILE="$PWD/agent.json" ./daily-autopilot.sh # Optional env: # MAX_SPEND_FLOP=9.9 # Spend cap per run (default 9.9 FLOP) # MAX_TOKENS=512 # Output token cap (default 512) # FAUCET_RETRIES=6 # Polite retries on 503 faucet_busy (default 6) # FAUCET_WAIT_SEC=35 # Wait seconds between faucet retries (default 35, >=25s recommended) # CUSTOM_PROMPT="..." # Optional custom real prompt # SKIP_CLAIM=1 # Set 1 to skip faucet claim and only run session set -euo pipefail INDEXER_URL="${FLOP_INDEXER_URL:-https://gpupark.xyz}" KEYSTORE_FILE="${KEYSTORE_FILE:-$PWD/agent.json}" MAX_SPEND_FLOP="${MAX_SPEND_FLOP:-9.9}" MAX_TOKENS="${MAX_TOKENS:-512}" FAUCET_RETRIES="${FAUCET_RETRIES:-6}" FAUCET_WAIT_SEC="${FAUCET_WAIT_SEC:-35}" CLI_PKG="${FLOP_CLI_PKG:-@flop-labs/cli@0.10.5}" for bin in curl jq npx awk; do command -v "$bin" >/dev/null 2>&1 || { echo "[error] missing required command: $bin" >&2; exit 1; } done if [[ -z "${FLOP_KEY_PASSWORD:-}" ]]; then echo "[error] FLOP_KEY_PASSWORD is required." >&2 exit 1 fi if [[ ! -f "$KEYSTORE_FILE" ]]; then echo "[error] KEYSTORE_FILE not found: $KEYSTORE_FILE" >&2 exit 1 fi ADDRESS="$(jq -r '.address // empty' "$KEYSTORE_FILE")" if [[ -z "$ADDRESS" ]]; then echo "[error] Could not read .address from $KEYSTORE_FILE" >&2 exit 1 fi echo "[gpupark-autopilot] Wallet: $ADDRESS" LOOKUP="$(curl -fsSL "$INDEXER_URL/api/lookup?address=$ADDRESS")" FREE_FLOP="$(echo "$LOOKUP" | jq -r '.freeFlop // 0')" VOUCHERS_BEFORE="$(echo "$LOOKUP" | jq -r '.agentVouchers // 0')" UNLOCKED="$(echo "$LOOKUP" | jq -r '.refillUnlocked // false')" REQ_MIN="$(echo "$LOOKUP" | jq -r '.requiredMinEscrowFlop // 3.49')" NEXT_ACTION="$(echo "$LOOKUP" | jq -r '.nextAction // "unknown"')" echo "[gpupark-autopilot] Before -> freeFlop=$FREE_FLOP | agentVouchers=$VOUCHERS_BEFORE | refillUnlocked=$UNLOCKED | minFloor=$REQ_MIN | nextAction=$NEXT_ACTION" if [[ "$NEXT_ACTION" == "gas_paused" ]]; then echo "[gpupark-autopilot] Chain fee multiplier is temporarily high (gas paused). Try again in 10 minutes." exit 0 fi if [[ "$NEXT_ACTION" == "unlock_starter_first" ]]; then echo "[gpupark-autopilot] Day-1 wallet detected (freeFlop=$FREE_FLOP, agentVouchers=0)." echo "[gpupark-autopilot] Complete one ~0.9 FLOP starter session first to unlock 10 FLOP/day refills, then re-run this script from Day 2 onward." exit 0 fi NEED_CLAIM="$(awk -v f="$FREE_FLOP" -v m="$REQ_MIN" 'BEGIN { print (f < m + 0.15) ? 1 : 0 }')" if [[ "${SKIP_CLAIM:-0}" != "1" && "$NEED_CLAIM" == "1" ]]; then echo "[gpupark-autopilot] Balance below floor ($FREE_FLOP < $REQ_MIN + 0.15); attempting polite faucet claim..." CLAIMED=0 for ((i=1; i<=FAUCET_RETRIES; i++)); do OUT="$(npx --yes "$CLI_PKG" --network testnet --keystore "$KEYSTORE_FILE" --password-env FLOP_KEY_PASSWORD faucet claim 2>&1 || true)" echo "[faucet try $i/$FAUCET_RETRIES] $(echo "$OUT" | tail -n 3)" if echo "$OUT" | grep -qiE "txHash|credited|accepted|granted|finalized|included"; then CLAIMED=1 sleep 6 break fi if echo "$OUT" | grep -qiE "cooldown|daily_cap|agent_daily_cap|agent_spend_missing|ip_cooldown"; then echo "[gpupark-autopilot] Faucet returned definitive cooldown/cap refusal; stopping retries politely." break fi if (( i < FAUCET_RETRIES )); then echo "[gpupark-autopilot] Faucet busy; sleeping ${FAUCET_WAIT_SEC}s before next polite retry..." sleep "$FAUCET_WAIT_SEC" fi done LOOKUP="$(curl -fsSL "$INDEXER_URL/api/lookup?address=$ADDRESS")" FREE_FLOP="$(echo "$LOOKUP" | jq -r '.freeFlop // 0')" REQ_MIN="$(echo "$LOOKUP" | jq -r '.requiredMinEscrowFlop // 3.49')" fi SPEND="$(awk -v f="$FREE_FLOP" -v cap="$MAX_SPEND_FLOP" 'BEGIN { s = f - 0.15; if (s > cap) s = cap; if (s < 0) s = 0; printf "%.2f", int(s * 100) / 100 }')" CAN_SPEND="$(awk -v s="$SPEND" -v m="$REQ_MIN" 'BEGIN { print (s >= m) ? 1 : 0 }')" if [[ "$CAN_SPEND" != "1" ]]; then echo "[gpupark-autopilot] Not enough spendable FLOP yet (spendable=$SPEND, minFloor=$REQ_MIN). Will try again on next scheduled run." exit 0 fi LIVE="$(curl -fsSL "$INDEXER_URL/live")" PICK="$(echo "$LIVE" | jq -r --argjson sp "$SPEND" '[.miners[] | select(.offer_available == true and (.min_escrow_flop <= $sp))] | sort_by(.in_progress, .min_escrow_flop, .latency_ms) | .[0] | "\(.miner)|\(.endpoint)|\(.model)|\(.min_escrow_flop)"')" if [[ -z "$PICK" || "$PICK" == "null|null|null|null" ]]; then echo "[gpupark-autopilot] No ready miner currently fits spendable=$SPEND FLOP." exit 0 fi IFS='|' read -r MINER ENDPOINT MODEL MINER_FLOOR <<< "$PICK" PROMPTS=( "Compare Raft and Paxos consensus failure recovery in 4 concise bullet points with one practical trade-off each." "Explain how SQLite WAL mode improves concurrent read/write throughput and list 3 operational caveats." "Outline a clean zero-downtime database migration checklist for adding a non-null indexed column to a large PostgreSQL table." "Summarize the key differences between HTTP/2 and HTTP/3 (QUIC) for mobile latency and connection migration." "Explain how consistent hashing with virtual nodes minimizes key movement during cluster scaling, with a short numerical example." "Describe 4 common memory leak patterns in long-running Node.js services and how to diagnose each one." "Compare B-trees and LSM-trees for write-heavy time-series workloads in 5 crisp bullet points." "Give a concise technical overview of how TLS 1.3 reduces handshake latency compared to TLS 1.2." ) DAY_IDX="$(($(date +%s) / 3600 + RANDOM))" PROMPT="${CUSTOM_PROMPT:-${PROMPTS[$((DAY_IDX % ${#PROMPTS[@]}))]}}" echo "[gpupark-autopilot] Running cooperative --via offer on $ENDPOINT ($MODEL, floor=$MINER_FLOOR) with max-flop=$SPEND..." FLOP_INDEXER_URL="$INDEXER_URL" npx --yes "$CLI_PKG" --network testnet \ --keystore "$KEYSTORE_FILE" --password-env FLOP_KEY_PASSWORD \ session run --via offer --max-flop "$SPEND" --max-tokens "$MAX_TOKENS" --max-duration 1200 \ --miner "$MINER" --endpoint "$ENDPOINT" --model "$MODEL" \ --prompt "$PROMPT" --json sleep 5 AFTER="$(curl -fsSL "$INDEXER_URL/api/lookup?address=$ADDRESS")" VOUCHERS_AFTER="$(echo "$AFTER" | jq -r '.agentVouchers // 0')" FREE_AFTER="$(echo "$AFTER" | jq -r '.freeFlop // 0')" echo "[gpupark-autopilot] Done! freeFlop=$FREE_AFTER | agentVouchers: $VOUCHERS_BEFORE -> $VOUCHERS_AFTER"