use serde::{Deserialize, Serialize};
use solana_address::Address;
use crate::route_plan::RoutePlan;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SwapMode {
ExactIn,
ExactOut,
}
impl SwapMode {
pub const fn as_str(self) -> &'static str {
match self {
Self::ExactIn => "ExactIn",
Self::ExactOut => "ExactOut",
}
}
pub fn parse(raw: &str) -> Self {
match raw == Self::ExactOut.as_str() {
true => Self::ExactOut,
false => Self::ExactIn,
}
}
}
#[derive(Debug, Clone)]
pub struct LegRecord {
pub original_signature: String,
pub input_mint: Address,
pub output_mint: Address,
pub amount: u64,
pub swap_mode: SwapMode,
pub failed: bool,
pub original_failed: bool,
pub realized_output_amount: Option<u64>,
pub original_realized_output_amount: Option<u64>,
pub route_plan: Option<RoutePlan>,
pub original_route_plan: Option<RoutePlan>,
pub realized_route_plan: Option<RoutePlan>,
pub template: Option<String>,
pub quoted_output_amount: Option<u64>,
pub new_output_amount: Option<u64>,
pub error_category: Option<String>,
pub output_bps: Option<i64>,
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use crate::SwapMode;
#[rstest]
#[case::exact_in(SwapMode::ExactIn)]
#[case::exact_out(SwapMode::ExactOut)]
fn swap_mode_serializes_as_its_as_str(#[case] mode: SwapMode) {
assert_eq!(serde_json::to_value(mode).unwrap(), mode.as_str());
}
}