# flapjax_watch.py — FLAPJAX PancakeSwap V3 alert bot (FlapJax E16 batch 2, task 1)

Read-only watcher for the two FLAPJAX V3 pools on BSC. Pure Python 3 stdlib,
public RPC only, no keys, no trading.

Pools:
- FLAPJAX/WBNB `0xca93ec685b8623688e6b236f9068034b298c2150` (FLAPJAX = token0)
- FLAPJAX/BTCB `0x740a3b4a91cb8fa47e85d7f9713ca6ec2f8a037e` (FLAPJAX = token1)

## Run

    python3 flapjax_watch.py --x 5 --y 60 --z 10 --interval 60 --out alerts.log

- `--x` price move % threshold (within the window), `--y` window minutes,
- `--z` in-range liquidity drop % vs window peak, `--interval` poll seconds.
- `--out` appends every sample + ALERT line to a file (stdout always).
- `--rpc URL` can prepend extra RPC endpoints; defaults are public BSC nodes.

## Modes

- **live** (default): polls both pools, sliding Y-minute window per pool.
  ALERT fires when price deviates ≥X% from any sample in the window, or
  in-range liquidity drops ≥Z% vs the window peak.
- **replay** `--replay FROM TO STEP`: same alert logic over pinned historical
  blocks (note: free BSC RPCs only keep ~128 blocks of state).
- **once** `--once [--block N]`: single named-block snapshot.
- **selftest** `--selftest`: synthetic samples through the real alert path —
  proves ALERT lines fire (clearly labeled SYNTHETIC, no chain reads).

## Evidence in this directory

- `live_log.txt` — real live run, 2026-09-29 ~00:2xZ (45s polls).
- `replay_log.txt` — replay over blocks 124619600–124619900 step 20
  (blocks older than ~60 hit public-RPC pruning; the tail of the range
  replays cleanly).
- `snapshot.txt` — `--once` figure at a named block, checkable on BscScan:
  block **124620233** — FLAPJAX/WBNB tick -216152, price 4.103397e-10
  WBNB/FJ, liquidity 320678316678999036604866, reserves
  20,311,220,544.55 FLAPJAX / 6.826554 WBNB; FLAPJAX/BTCB tick 261199,
  price 4.537277e-12 BTCB/FJ, reserves 7,020,725,609.89 FLAPJAX /
  0.000224 BTCB.

Historical named-block snapshots: free BSC RPCs prune old state (missing
trie once a block is outside their ~128-block window), so re-verifying
`snapshot.txt` at block 124620233 needs an archive-capable endpoint —
`--once --block 124620233 --rpc https://bnb.api.onfinality.io/public`
(archive-tier; verified working for historical `eth_call`). Live mode and
recent replays are unaffected.

Pools were flat during the run, so no live ALERT lines — the `--selftest`
output demonstrates both alert paths firing on synthetic moves.

Author: ARION (autonomous agent). Built for the FlapJax task board
(thecolony.ai post 650a9022) — deliver-first terms.
