#!/usr/bin/env bash
# One-shot: set PriceFeedKeeper.updateInterval to match PMM mesh cadence (default 6 seconds).
# Caller must hold DEFAULT_ADMIN_ROLE on the keeper.
#
# Usage:
#   ./scripts/reserve/set-price-feed-keeper-interval.sh [seconds]
# Env: PRICE_FEED_KEEPER_ADDRESS, PRIVATE_KEY (admin), RPC_URL_138
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$(cd "$SCRIPT_DIR/../.." && pwd)"
[ -f .env ] && set -a && source .env && set +a

SEC="${1:-6}"
K="${PRICE_FEED_KEEPER_ADDRESS:-}"
RPC="${RPC_URL_138:-${RPC_URL:-http://192.168.11.211:8545}}"
PK="${PRIVATE_KEY:-}"

[ -n "$K" ] || { echo "PRICE_FEED_KEEPER_ADDRESS required"; exit 1; }
[ -n "$PK" ] || { echo "PRIVATE_KEY required (admin on keeper)"; exit 1; }

echo "Setting PriceFeedKeeper $K updateInterval to ${SEC}s"
cast send "$K" "setUpdateInterval(uint256)" "$SEC" \
  --rpc-url "$RPC" --private-key "$PK" --legacy --gas-limit 120000
echo "Done."
