use std::{str::FromStr, sync::Arc};
use solana_network_client::SolanaClient;
use solana_sdk::pubkey::Pubkey;
use solana_transaction::Address;
use crate::{
dbc::{DynamicBondingCurvePool, DynamicBondingCurvePoolData},
liquidity::{
dlmmpool::{DLMMLiquidityPool, DLMMLiquidityPoolData},
dynpool::{DAMMLiquidityPool, DAMMLiquidityPoolData},
dynv2pool::{DAMMV2LiquidityPool, DAMMV2LiquidityPoolData},
},
};
pub mod dbc;
pub mod liquidity;
pub struct Meteora {
pub solana_client: Arc<SolanaClient>,
}
impl Meteora {
pub fn new(solana_client: Arc<SolanaClient>) -> Self {
Self { solana_client }
}
pub async fn get_liquidity_pool_dynv2(
&self,
address: &str,
) -> Result<DAMMV2LiquidityPoolData, 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 =
DAMMV2LiquidityPool::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_dyn(
&self,
address: &str,
) -> Result<DAMMLiquidityPoolData, 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 =
DAMMLiquidityPool::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_dlmm(
&self,
address: &str,
) -> Result<DLMMLiquidityPoolData, 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 =
DLMMLiquidityPool::get_liquidity_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
pub async fn get_liquidity_pool_dbc(
&self,
address: &str,
) -> Result<DynamicBondingCurvePoolData, 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 =
DynamicBondingCurvePool::get_dbc_pool_info(&v).map_err(|e| format!("{:?}", e))?;
Ok(pool)
}
}