pub mod launchpad;
pub mod liquidity;
pub mod typs;
use solana_network_client::SolanaClient;
use solana_sdk::pubkey::Pubkey;
use std::{str::FromStr, sync::Arc};
use crate::{
launchpad::{LaunchpadPool, LaunchpadPoolData},
liquidity::{
clmm::{RaydiumLiquidityPoolCLMM, RaydiumLiquidityPoolCLMMData},
cpmm::{RaydiumLiquidityPoolCPMM, RaydiumLiquidityPoolCPMMData},
v4::{RaydiumLiquidityPoolData, RaydiumLiquidityPoolV4},
},
};
pub struct Raydium {
pub solana_client: Arc<SolanaClient>,
}
impl Raydium {
pub fn new(solana_client: Arc<SolanaClient>) -> Self {
Self {
solana_client: solana_client,
}
}
pub async fn get_liquidity_pool_v4(
&self,
address: &str,
) -> Result<RaydiumLiquidityPoolData, String> {
let v = self
.solana_client
.client_arc()
.get_account_data(
&Pubkey::from_str(address)
.map_err(|e| format!("{:?}", e))
.unwrap(),
)
.await
.map_err(|e| format!("{:?}", e))?;
let pool =
RaydiumLiquidityPoolV4::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_cpmm(
&self,
address: &str,
) -> Result<RaydiumLiquidityPoolCPMMData, String> {
let v = self
.solana_client
.client_arc()
.get_account_data(
&Pubkey::from_str(address)
.map_err(|e| format!("{:?}", e))
.unwrap(),
)
.await
.map_err(|e| format!("{:?}", e))?;
let pool = RaydiumLiquidityPoolCPMM::get_liquidity_pool_info(&v)
.map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_clmm(
&self,
address: &str,
) -> Result<RaydiumLiquidityPoolCLMMData, String> {
let v = self
.solana_client
.client_arc()
.get_account_data(
&Pubkey::from_str(address)
.map_err(|e| format!("{:?}", e))
.unwrap(),
)
.await
.map_err(|e| format!("{:?}", e))?;
let pool = RaydiumLiquidityPoolCLMM::get_liquidity_pool_info(&v)
.map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_launchpad(
&self,
address: &str,
) -> Result<LaunchpadPoolData, String> {
let v = self
.solana_client
.client_arc()
.get_account_data(
&Pubkey::from_str(address)
.map_err(|e| format!("{:?}", e))
.unwrap(),
)
.await
.map_err(|e| format!("{:?}", e))?;
let pool = LaunchpadPool::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_token_price_by_address(&self) {}
}