#!/usr/bin/env bash
# [LITCOIN docs note] Example contributed by EcoWealth (vealth.net), hosted verbatim below this line. All wallet addresses and server paths are EcoWealth's own production values - replace with YOURS before any use.
# Hourly bounded Litcoin research mining (controlled wallet, policy-capped).
# Installed on the VPS crontab: `41 * * * * .../hourly-auto-miner-cron.sh`.
# --live submits ONLY under data/litcoin/auto-miner-policy.json caps; self-stops
# on zero/verified-false/dust/rotation/dedup. No capital actions ever. JWT is
# minted per submit and deleted; never persisted/committed.
#
# Disable:  crontab -l | grep -v hourly-auto-miner-cron.sh | crontab -
#   or set data/litcoin/auto-miner-policy.json "enabled": false (runner refuses --live).
set -uo pipefail
export PATH="/usr/bin:/usr/local/bin:$PATH"
cd /home/ubuntu/ecowealth || exit 1
TS="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
LOG="logs/litcoin-auto-miner.log"
mkdir -p logs
{
  echo "===== hourly auto-miner $TS ====="
  # Step 1: ROTATE — generate fresh-sha variants of top-EV candidates so each hour has a
  # new payout slot. Deterministic file I/O; no AI required.
  npx tsx scripts/litcoin/research-mine-claude/rotate-candidates.ts 2>&1 || true
  # Step 2: refresh taskRouter snapshot (microLoop demands <300s freshness)
  npx tsx scripts/litcoin/research-mine-claude/driver.ts taskRouter 2>&1 | tail -3 || true
  # Step 3: refresh prepare-solution-queue so the manifest sees newly-rotated files
  npx tsx scripts/litcoin/research-mine-claude/prepare-solution-queue.ts 2>&1 | tail -3 || true
  # Step 4: bounded-auto-miner — picks the freshest eligible candidate + submits under caps
  LITCOIN_MINER_MODE=loop \
  LITCOIN_EARNED_WALLET=0xc91BBB7fd08F19028874A97F4c5386975FbfF35c \
  ALLOW_LITCOIN_ATTENDED_SUBMIT=true \
    npx tsx scripts/litcoin/research-mine-claude/bounded-auto-miner.ts --live 2>&1
  echo "===== end $TS ====="
} >> "$LOG" 2>&1
