Skip to main content

raydium_sdk/
lib.rs

1pub mod launchpad;
2pub mod liquidity;
3pub mod typs;
4
5use solana_network_client::SolanaClient;
6use solana_sdk::pubkey::Pubkey;
7
8use std::{str::FromStr, sync::Arc};
9
10use crate::{
11    launchpad::{LaunchpadPool, LaunchpadPoolData},
12    liquidity::{
13        clmm::{RaydiumLiquidityPoolCLMM, RaydiumLiquidityPoolCLMMData},
14        cpmm::{RaydiumLiquidityPoolCPMM, RaydiumLiquidityPoolCPMMData},
15        v4::{RaydiumLiquidityPoolData, RaydiumLiquidityPoolV4},
16    },
17};
18
19/// raydium data structure
20pub struct Raydium {
21    pub solana_client: Arc<SolanaClient>,
22}
23
24impl Raydium {
25    /// crreate raydium
26    /// Example
27    /// ```rust
28    /// let sol = Solana::new(solana_network_sdk::types::Mode::MAIN);
29    /// let raydium = Raydium::new(Arc::new(sol));
30    /// ```
31    pub fn new(solana_client: Arc<SolanaClient>) -> Self {
32        Self {
33            solana_client: solana_client,
34        }
35    }
36    /// get v4 raydium liquidity pool
37    /// Example
38    /// ```rust
39    /// let sol = Solana::new(solana_network_sdk::types::Mode::MAIN);
40    /// let raydium = Raydium::new(Arc::new(sol));
41    /// // 58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2 SOL-USDC pool
42    /// let pool_data = raydium.get_liquidity_pool_v4("58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2").await;
43    /// ```
44    pub async fn get_liquidity_pool_v4(
45        &self,
46        address: &str,
47    ) -> Result<RaydiumLiquidityPoolData, String> {
48        let v = self
49            .solana_client
50            .client_arc()
51            .get_account_data(
52                &Pubkey::from_str(address)
53                    .map_err(|e| format!("{:?}", e))
54                    .unwrap(),
55            )
56            .await
57            .map_err(|e| format!("{:?}", e))?;
58        let pool =
59            RaydiumLiquidityPoolV4::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
60        Ok(pool)
61    }
62
63    pub async fn get_liquidity_pool_cpmm(
64        &self,
65        address: &str,
66    ) -> Result<RaydiumLiquidityPoolCPMMData, String> {
67        let v = self
68            .solana_client
69            .client_arc()
70            .get_account_data(
71                &Pubkey::from_str(address)
72                    .map_err(|e| format!("{:?}", e))
73                    .unwrap(),
74            )
75            .await
76            .map_err(|e| format!("{:?}", e))?;
77        let pool = RaydiumLiquidityPoolCPMM::get_liquidity_pool_info(&v)
78            .map_err(|e| format!("{:?}", e))?;
79        Ok(pool)
80    }
81
82    pub async fn get_liquidity_pool_clmm(
83        &self,
84        address: &str,
85    ) -> Result<RaydiumLiquidityPoolCLMMData, String> {
86        let v = self
87            .solana_client
88            .client_arc()
89            .get_account_data(
90                &Pubkey::from_str(address)
91                    .map_err(|e| format!("{:?}", e))
92                    .unwrap(),
93            )
94            .await
95            .map_err(|e| format!("{:?}", e))?;
96        let pool = RaydiumLiquidityPoolCLMM::get_liquidity_pool_info(&v)
97            .map_err(|e| format!("{:?}", e))?;
98        Ok(pool)
99    }
100
101    pub async fn get_liquidity_pool_launchpad(
102        &self,
103        address: &str,
104    ) -> Result<LaunchpadPoolData, String> {
105        let v = self
106            .solana_client
107            .client_arc()
108            .get_account_data(
109                &Pubkey::from_str(address)
110                    .map_err(|e| format!("{:?}", e))
111                    .unwrap(),
112            )
113            .await
114            .map_err(|e| format!("{:?}", e))?;
115        let pool = LaunchpadPool::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
116        Ok(pool)
117    }
118    // get token price by address
119    pub async fn get_token_price_by_address(&self) {}
120}