Add the current price for obtaining pumpswap tokens
This commit is contained in:
+17
@@ -640,6 +640,23 @@ impl PumpFun {
|
|||||||
Ok(actual_sol_reserves)
|
Ok(actual_sol_reserves)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn get_current_price_with_pumpswap(&self, pool_address: &Pubkey) -> Result<f64, anyhow::Error> {
|
||||||
|
let pool = pumpswap::pool::Pool::fetch(&self.rpc, pool_address).await?;
|
||||||
|
|
||||||
|
let (base_amount, quote_amount) = pool.get_token_balances(&self.rpc).await?;
|
||||||
|
|
||||||
|
// Calculate price using constant product formula (x * y = k)
|
||||||
|
// Price = quote_amount / base_amount
|
||||||
|
if base_amount == 0 {
|
||||||
|
return Err(anyhow::anyhow!("Base amount is zero, cannot calculate price"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let price = quote_amount as f64 / base_amount as f64;
|
||||||
|
|
||||||
|
Ok(price)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn get_real_sol_reserves_with_pumpswap(&self, pool_address: &Pubkey) -> Result<u64, anyhow::Error> {
|
pub async fn get_real_sol_reserves_with_pumpswap(&self, pool_address: &Pubkey) -> Result<u64, anyhow::Error> {
|
||||||
let pool = pumpswap::pool::Pool::fetch(&self.rpc, pool_address).await?;
|
let pool = pumpswap::pool::Pool::fetch(&self.rpc, pool_address).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user