# 30-Min TWAP Spot Settlement & TP/SL

Thin-liquidity tokens suffer from 1-second MEV sandwiches, rogue wicks, and empty perp orderbooks. The Druid Circle eliminates wick liquidations and exit slippage by settling every close, liquidation, TP/SL trigger, and option expiry against a **covered 30-minute time-weighted average spot price (TWAP30)**.

## Sampling & Window Parameters

| Parameter | Constant | Value | Role |
|---|---|---|---|
| TWAP Window | `TWAP_S` | `1800s` (30 min) | Trailing time-weighted average of live DEX spot samples |
| Stale Threshold | `STALE_S` | `600s` (10 min) | Max gap allowed before feed pauses cleanly |
| Poller Cadence | `POLL_S` | `300s` (5 min) | Background mark & solvency sampling interval |
| Entry Drift Guard | `ENTRY_DRIFT` | `1.0%` | Max spot drift allowed between 60s quote lock and fill |
| Quote TTL | `QUOTE_HOLD_S` | `60s` | Locked quote validity window before re-quote required |

## Zero 1-Second Wick Stop-Outs

- **Liquidations** evaluate strictly against `TWAP30` on a **covered window** (zero stale gaps and zero errored fetches inside the trailing 30 minutes).
- **Take-Profit & Stop-Loss (`TP/SL`)** on open perps are also evaluated strictly on `TWAP30`:
  - **Short TP:** triggers when `TWAP30 <= take_profit_px`
  - **Short SL:** triggers when `TWAP30 >= stop_loss_px`
  - **Long TP:** triggers when `TWAP30 >= take_profit_px`
  - **Long SL:** triggers when `TWAP30 <= stop_loss_px`
- A single 2-second scam wick on Raydium or Uniswap cannot hunt your stop-loss or liquidate your stone.

## Gap & Stale Feed Protection

If an upstream DEX feed stalls for longer than `600s` (10 minutes) or returns an error:
1. A gap interval `[last_fresh_ts + 600, next_fresh_ts]` is recorded on the coin.
2. **Circle Carry pauses automatically** during the gap — carry is a pure integral over live intervals, never a runaway counter.
3. **Liquidations and early closes pause** until a fresh, covered 30-minute window resumes (returning `409` instead of settling on bad data).
4. **Dead Pool Rule:** If a pool drains completely and has no live price left, the token is marked dead and settles cleanly at `$0.00` — shorts and puts receive full `+100%` max payout.

## Zero Orderbook Slippage on Exit

Because the vault reserves 100% of every position's worst-case payout upfront, clicking **Close Perp** (or calling `POST /v1/positions/{id}/close`) settles directly against the vault at the current covered `TWAP30` — whether the coin is a `$150M` mid-cap or a `$500k` wilderness breakout.
