CONCEPTS

Clusters, cycles, and the state machine.

Three primitives define how ESEC operates: the liquidation cluster (off-chain), the vault (on-chain), and the cycle (deploy → recover / stop-loss / timeout). Understand these and the rest follows.

Liquidation cluster

A cluster is a price bin where multiple leveraged positions liquidate simultaneously. The off-chain monitor scans every open position across Drift, Marginfi, Kamino, and Jupiter Lend, computes each position's liquidation price, and aggregates them into 50 bps bins per asset.

pub struct Cluster {
    pub asset: Pubkey,           // SOL, BTC, ETH, ...
    pub trigger_price_low: u64,  // floor of the bin
    pub trigger_price_high: u64, // ceiling of the bin
    pub forced_size_usd: u64,    // total $ at this price
    pub confidence: u8,          // 0-100
    pub computed_at_slot: u64,
}

Clusters with forced_size_usd >= $1M and confidence >= 80 are deployable. The off-chain monitor watches the oracle price; when spot approaches a cluster (within 2%), it signals the vault to deploy.

Vault state machine

Idle ──pre-position──▶ Deployed ──recover──▶ Idle
                       Deployed ──stop-loss──▶ Idle (loss recorded)
                       Deployed ──timeout────▶ Idle (no fill, no loss)
  • Idle → Deployed: monitor authority calls deploy_lp. Vault atomically deploys concentrated LP at the cluster price via Jito bundle to Raydium / Orca / Meteora.
  • Deployed → Idle (recover): spot price recovers above the deploy price by the configured bps threshold. Monitor calls exit_lp. Vault withdraws LP, captures fees plus price improvement, applies performance fee to fee_treasury.
  • Deployed → Idle (stop-loss): spot falls 5% below deploy price. Anyone can call stop_loss_crank (permissionless). Vault withdraws fast, books bounded loss.
  • Deployed → Idle (timeout): 30 minutes elapsed without recovery or stop-loss. Anyone calls timeout_crank. Vault exits at current price, frees capital for next cluster.

The cycle

A single cycle is a complete deploy → exit round trip. The vault is capital-efficient because it is idle 95% of the time and active only when a cluster signal fires. P&L per cycle:

pnl = deployed_amount * (exit_price - deploy_price) / deploy_price
    + LP fees collected during the deployed window
    - performance fee (20% of net gain to fee_treasury)
    - stop-loss losses (if applicable)

Why pre-position

Reactive cascade detection requires threshold guessing, suffers from false positives, and competes with sub-slot bots for the same window. Pre-positioning sidesteps all three:

  • Deterministic prices: liquidation thresholds are computable from public position data plus maintenance margin formulas. No guessing.
  • Already there: when the cascade fires, our LP is the depth that absorbs the forced selling. We don't race to enter; we're the counterparty.
  • Bounded downside: on-chain stop-loss at 5% below deploy price means a wrong cluster read costs a bounded amount, not a runaway loss.