# DEX Live State Machine

This file is the control system for the scheduled Codex agent. The agent may explore, but every action must move one explicit gate.

## S0_DATA_INTEGRITY

Goal: exact event-level datasets exist and are trustworthy enough for strategy proof.

Exit gate:
- exact-event NPZ exists for target pools/monthly windows, especially WETH/USDC 0.30% and the current paper-live BIO/CHECK candidates;
- lineage is documented: raw RPC, TheGraph, or other source;
- unit/fee conversion is checked;
- smoke replay works;
- collector can resume after 429/rate-limit without corrupting output.

Allowed work:
- raw RPC/TheGraph/event collectors;
- checkpointing and resume logic;
- NPZ builders;
- lineage reports;
- smoke tests.

Forbidden work:
- signed transactions;
- scaling capital;
- broad unrelated strategy search when the data gate is blocked.

## S1_BACKTEST_PROOF

Goal: candidate strategies survive cross-pool, cross-window, walk-forward validation.

Exit gate:
- candidate has either same-config stability or explicit regime-gated stability;
- MDD target is respected;
- p95/p99 liquidity-share/capacity metrics are acceptable;
- no obvious directional-only overfit;
- proof uses exact-event data, not only OHLCV proxy.

Allowed work:
- backtests;
- walk-forward validation;
- regime filter validation;
- capacity analysis;
- adversarial/critic passes.

Forbidden work:
- signed transactions;
- selling/proclaiming a strategy as live-ready without paper-live evidence.

## S2_PAPER_LIVE_PROOF

Goal: virtual LP / paper-live behavior matches the backtest model on fresh data.

Exit gate:
- 7-14 days paper-live or enough fresh event-driven replay;
- virtual LP state is logged;
- fee accrual, inventory PnL, and rebalance decisions are logged;
- divergence vs backtest is measured and explained;
- no unit/fee/capacity bug remains unresolved.

Allowed work:
- paper-live runner;
- tmux watcher;
- virtual LP state;
- backtest/live comparison;
- alerting/log summaries.

Forbidden work:
- signed transactions.

## S3_SIGNED_PILOT

Goal: very small signed pilot.

Entry gate:
- explicit human approval in the latest instruction;
- wallet funded only with the allowed amount;
- max capital explicitly capped;
- kill switch exists;
- transaction preview is logged before sending.

Forbidden work:
- autonomous scaling;
- silent wallet changes;
- using secrets from docs/logs.

## S4_SCALE

Not active. Do not work on scaling until S3 has real measured results.

## Run Rule

Each scheduled run must answer:

1. Current stage?
2. Blocking gate?
3. One main action taken to move that gate?
4. Evidence generated?
5. Next single action?

If no useful progress is possible, write why and stop. Do not invent work.
