refactor: remove solana-streamer-sdk dependency and migrate type definitions locally
This refactoring migrates protocol-related type definitions from solana-streamer-sdk to local modules: - Add local type files: bonk_types.rs, pumpswap_types.rs, raydium_amm_v4_types.rs, raydium_cpmm_types.rs - Add BorshDeserialize support for all types - Refactor BondingCurveAccount to support Borsh deserialization - Update import paths across all protocol utility modules (bonk, pumpfun, pumpswap, raydium) - Refactor trade parameter construction methods from event objects to individual parameters for better flexibility - Fix nonce_cache import path to use local SolanaRpcClient
This commit is contained in:
+1
-46
@@ -1,49 +1,4 @@
|
||||
use solana_streamer_sdk::streaming::event_parser::protocols::bonk::types::PoolState;
|
||||
|
||||
use crate::{
|
||||
constants::decimals::{DEFAULT_TOKEN_DECIMALS, SOL_DECIMALS},
|
||||
constants::WSOL_TOKEN_ACCOUNT,
|
||||
};
|
||||
|
||||
/// Calculate the token price in WSOL based on pool state
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `pool_state` - Pool state
|
||||
///
|
||||
/// # Returns
|
||||
/// Token price in WSOL as f64
|
||||
pub fn price_token_in_wsol_with_pool_state(pool_state: &PoolState) -> f64 {
|
||||
if pool_state.quote_mint != WSOL_TOKEN_ACCOUNT {
|
||||
log::error!("Quote mint is not WSOL: {:?}", pool_state.quote_mint);
|
||||
return 0.0;
|
||||
}
|
||||
price_base_in_quote(
|
||||
pool_state.virtual_base,
|
||||
pool_state.virtual_quote,
|
||||
pool_state.real_base,
|
||||
pool_state.real_quote,
|
||||
pool_state.base_decimals,
|
||||
pool_state.quote_decimals,
|
||||
)
|
||||
}
|
||||
|
||||
/// Calculate the price of base in quote based on pool state
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `pool_state` - Pool state
|
||||
///
|
||||
/// # Returns
|
||||
/// The price of base in quote
|
||||
pub fn price_base_in_quote_with_pool_state(pool_state: &PoolState) -> f64 {
|
||||
price_base_in_quote(
|
||||
pool_state.virtual_base,
|
||||
pool_state.virtual_quote,
|
||||
pool_state.real_base,
|
||||
pool_state.real_quote,
|
||||
pool_state.base_decimals,
|
||||
pool_state.quote_decimals,
|
||||
)
|
||||
}
|
||||
use crate::constants::decimals::{DEFAULT_TOKEN_DECIMALS, SOL_DECIMALS};
|
||||
|
||||
/// Calculate the price of token in WSOL
|
||||
///
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
use solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::types::BondingCurve;
|
||||
|
||||
use crate::instruction::utils::pumpfun::global_constants::{LAMPORTS_PER_SOL, SCALE};
|
||||
|
||||
/// Calculate the token price in SOL based on virtual reserves
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `bonding_curve` - Bonding curve account
|
||||
///
|
||||
/// # Returns
|
||||
/// Token price in SOL as f64
|
||||
pub fn price_token_in_sol_with_bonding_curve(bonding_curve: &BondingCurve) -> f64 {
|
||||
price_token_in_sol(bonding_curve.virtual_sol_reserves, bonding_curve.virtual_token_reserves)
|
||||
}
|
||||
|
||||
/// Calculate the token price in SOL based on virtual reserves
|
||||
///
|
||||
/// # Arguments
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use solana_streamer_sdk::streaming::event_parser::protocols::raydium_clmm::types::PoolState;
|
||||
|
||||
/// Calculate the price of token0 in token1
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -36,33 +34,3 @@ pub fn price_token1_in_token0(
|
||||
) -> f64 {
|
||||
1.0 / price_token0_in_token1(sqrt_price_x64, decimals_token0, decimals_token1)
|
||||
}
|
||||
|
||||
/// Calculate the price of token0 in token1 based on pool state
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `pool_state` - The pool state
|
||||
///
|
||||
/// # Returns
|
||||
/// The price of token0 in token1
|
||||
pub fn price_token0_in_token1_with_pool_state(pool_state: &PoolState) -> f64 {
|
||||
price_token0_in_token1(
|
||||
pool_state.sqrt_price_x64,
|
||||
pool_state.mint_decimals0,
|
||||
pool_state.mint_decimals1,
|
||||
)
|
||||
}
|
||||
|
||||
/// Calculate the price of token1 in token0 based on pool state
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `pool_state` - The pool state
|
||||
///
|
||||
/// # Returns
|
||||
/// The price of token1 in token0
|
||||
pub fn price_token1_in_token0_with_pool_state(pool_state: &PoolState) -> f64 {
|
||||
price_token1_in_token0(
|
||||
pool_state.sqrt_price_x64,
|
||||
pool_state.mint_decimals0,
|
||||
pool_state.mint_decimals1,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user