feat: add USDC quote support for swap protocols

This commit is contained in:
tommggo
2025-10-12 12:01:21 +08:00
parent d567477bdb
commit 163882c7f3
12 changed files with 228 additions and 151 deletions
+8 -30
View File
@@ -119,47 +119,25 @@ pub async fn calculate_price(
Ok(price)
}
/// Helper function to get vault account address
/// Helper function to get token vault account address
///
/// # Parameters
/// - `pool_state`: Pool state account address
/// - `token_mint`: Token mint address
/// - `protocol_params`: Protocol parameters
/// - `is_wsol`: Whether it's a wSOL token
///
/// # Returns
/// Returns the corresponding vault account address
/// Returns the corresponding token vault account address
pub fn get_vault_account(
pool_state: &Pubkey,
token_mint: &Pubkey,
protocol_params: &RaydiumCpmmParams,
is_wsol: bool,
) -> Pubkey {
if is_wsol {
// If it's wSOL, check if it's the base mint
if protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
&& protocol_params.base_vault != Pubkey::default()
{
protocol_params.base_vault
} else if protocol_params.quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
&& protocol_params.quote_vault != Pubkey::default()
{
protocol_params.quote_vault
} else {
get_vault_pda(pool_state, &crate::constants::WSOL_TOKEN_ACCOUNT).unwrap()
}
if protocol_params.base_mint == *token_mint && protocol_params.base_vault != Pubkey::default() {
protocol_params.base_vault
} else if protocol_params.quote_mint == *token_mint && protocol_params.quote_vault != Pubkey::default() {
protocol_params.quote_vault
} else {
// For other tokens, check if it's the base or quote mint
if *token_mint == protocol_params.base_mint
&& protocol_params.base_vault != Pubkey::default()
{
protocol_params.base_vault
} else if *token_mint == protocol_params.quote_mint
&& protocol_params.quote_vault != Pubkey::default()
{
protocol_params.quote_vault
} else {
get_vault_pda(pool_state, token_mint).unwrap()
}
get_vault_pda(pool_state, token_mint).unwrap()
}
}
}