pub mod raydium;
pub mod orca;
pub mod meteora;
pub mod jupiter;
pub mod raydium_state;
use anyhow::Result;
use async_trait::async_trait;
use scematica_core::types::DexKind;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
use std::sync::Arc;
pub trait StateDecoder: Send + Sync {
fn decode_pool_state(&self, data: &[u8]) -> Result<(u64, u64)>;
}
#[async_trait]
pub trait SwapInstructionBuilder: Send + Sync {
fn dex(&self) -> DexKind;
async fn build_swap(
&self,
pool: &Pubkey,
owner: &Pubkey,
token_in: &Pubkey,
token_out: &Pubkey,
ata_in: &Pubkey,
ata_out: &Pubkey,
amount_in: u64,
min_amount_out: u64,
) -> Result<Vec<Instruction>>;
}
pub fn get_builder(dex: DexKind, rpc: Arc<RpcClient>) -> Option<Box<dyn SwapInstructionBuilder>> {
match dex {
DexKind::Raydium => Some(Box::new(raydium::RaydiumBuilder::new(rpc.clone()))),
DexKind::Orca => Some(Box::new(orca::OrcaBuilder::new(rpc.clone()))),
DexKind::Meteora => Some(Box::new(meteora::MeteoraBuilder::new(rpc.clone()))),
DexKind::Jupiter => Some(Box::new(jupiter::JupiterBuilder::new())),
_ => None,
}
}