simulator-api 0.22.1

Wire-protocol types for the Solana simulator backtest WebSocket API
Documentation
//! The source-agnostic input both reports consume — one row of a reroute population,
//! whether it arrived as a websocket notification or a session-DB row. Adapters own the
//! mapping; nothing here does I/O.

use solana_address::Address;

use crate::route_plan::RoutePlan;

/// Whether the swap fixes the input amount (`ExactIn`) or the output amount (`ExactOut`).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SwapMode {
    ExactIn,
    ExactOut,
}

impl SwapMode {
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::ExactIn => "ExactIn",
            Self::ExactOut => "ExactOut",
        }
    }

    /// Anything unrecognized reads as `ExactIn`, the overwhelming default in every source.
    pub fn parse(raw: &str) -> Self {
        match raw == Self::ExactOut.as_str() {
            true => Self::ExactOut,
            false => Self::ExactIn,
        }
    }
}

/// One re-quoted swap. The three plans share one shape ([`RoutePlan`]); a side that was not
/// recorded is `None`, never an empty plan.
#[derive(Debug, Clone)]
pub struct LegRecord {
    pub original_signature: String,
    pub input_mint: Address,
    pub output_mint: Address,
    /// In the input token for ExactIn, the output token for ExactOut.
    pub amount: u64,
    pub swap_mode: SwapMode,
    /// The replacement never landed — a reverted simulation or a not-ok execution. Neither
    /// report column counts it as flow, but pricing still reads the original's side.
    pub failed: bool,
    /// The original failed on L1, so its route events are not flow any venue served.
    pub original_failed: bool,
    /// What the replacement actually produced; `None` when unattributable.
    pub realized_output_amount: Option<u64>,
    /// What the historical original produced. `None` when it cannot be attributed to this
    /// record alone — a multi-swap transaction's total is nobody's single leg.
    pub original_realized_output_amount: Option<u64>,
    /// The route the replacement was quoted over.
    pub route_plan: Option<RoutePlan>,
    /// The route the original actually took on L1.
    pub original_route_plan: Option<RoutePlan>,
    /// What the replacement's own simulation moved, hop by hop — the fill to compare
    /// `original_route_plan` against.
    pub realized_route_plan: Option<RoutePlan>,
}