raydium-launchlab-sdk 0.1.1

Rust SDK for Raydium LaunchLab program
Documentation
//! PDA derivation functions for Raydium LaunchLab

use solana_program::pubkey::Pubkey;
use crate::constants::*;

/// Derives the vault authority PDA
///
/// Seeds: ["vault_auth_seed"]
pub fn get_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[AUTH_SEED], &PROGRAM_ID)
}

/// Derives the pool state PDA for a given base/quote mint pair
///
/// Seeds: ["pool", base_mint, quote_mint]
pub fn get_pool_state_pda(base_mint: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[POOL_SEED, base_mint.as_ref(), quote_mint.as_ref()],
        &PROGRAM_ID,
    )
}

/// Derives the pool vault PDA for a given pool and token mint
///
/// Seeds: ["pool_vault", pool_state, token_mint]
pub fn get_pool_vault_pda(pool_state: &Pubkey, token_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[POOL_VAULT_SEED, pool_state.as_ref(), token_mint.as_ref()],
        &PROGRAM_ID,
    )
}

/// Derives the global config PDA for a given quote token mint and curve type
///
/// Seeds: ["global_config", quote_token_mint, curve_type, index]
pub fn get_global_config_pda(
    quote_token_mint: &Pubkey,
    curve_type: u8,
    index: u16,
) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[
            GLOBAL_CONFIG_SEED,
            quote_token_mint.as_ref(),
            &[curve_type],
            &index.to_le_bytes(),
        ],
        &PROGRAM_ID,
    )
}

/// Derives the platform config PDA for a given platform admin
///
/// Seeds: ["platform_config", platform_admin]
pub fn get_platform_config_pda(platform_admin: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[PLATFORM_CONFIG_SEED, platform_admin.as_ref()],
        &PROGRAM_ID,
    )
}

/// Derives the vesting record PDA for a given pool and beneficiary
///
/// Seeds: ["pool_vesting", pool_state, beneficiary]
pub fn get_vesting_record_pda(pool_state: &Pubkey, beneficiary: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[
            POOL_VESTING_SEED,
            pool_state.as_ref(),
            beneficiary.as_ref(),
        ],
        &PROGRAM_ID,
    )
}

/// Derives the event authority PDA
///
/// Seeds: ["__event_authority"]
pub fn get_event_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &PROGRAM_ID)
}

/// Derives the creator fee vault authority PDA
///
/// Seeds: ["creator_fee_vault_auth_seed"]
pub fn get_creator_fee_vault_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[CREATOR_FEE_VAULT_AUTH_SEED], &PROGRAM_ID)
}

/// Derives the creator fee vault PDA
///
/// Seeds: [creator, quote_mint]
pub fn get_creator_fee_vault_pda(creator: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[creator.as_ref(), quote_mint.as_ref()],
        &PROGRAM_ID,
    )
}

/// Derives the platform fee vault authority PDA
///
/// Seeds: ["platform_fee_vault_auth_seed"]
pub fn get_platform_fee_vault_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[PLATFORM_FEE_VAULT_AUTH_SEED], &PROGRAM_ID)
}

/// Derives the platform fee vault PDA
///
/// Seeds: [platform_config, quote_mint]
pub fn get_platform_fee_vault_pda(platform_config: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[platform_config.as_ref(), quote_mint.as_ref()],
        &PROGRAM_ID,
    )
}

/// Derives the associated token account address
pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
    spl_associated_token_account::get_associated_token_address(owner, mint)
}

/// Derives the associated token account address for Token-2022
pub fn get_associated_token_address_2022(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
    spl_associated_token_account::get_associated_token_address_with_program_id(
        owner,
        mint,
        &TOKEN_2022_PROGRAM_ID,
    )
}

/// Derives the metadata account address
pub fn get_metadata_address(mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[
            b"metadata",
            METADATA_PROGRAM_ID.as_ref(),
            mint.as_ref(),
        ],
        &METADATA_PROGRAM_ID,
    )
}

// =============================================================================
// CPSwap PDAs (for migration)
// =============================================================================

/// Derives the CPSwap pool vault PDA
///
/// Seeds: ["pool_vault", cpswap_pool, token_mint] with CPSwap program
pub fn get_cpswap_vault_pda(cpswap_pool: &Pubkey, token_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[b"pool_vault", cpswap_pool.as_ref(), token_mint.as_ref()],
        &CPSWAP_PROGRAM_ID,
    )
}

/// Derives the CPSwap LP mint PDA
///
/// Seeds: ["pool_lp_mint", cpswap_pool] with CPSwap program
pub fn get_cpswap_lp_mint_pda(cpswap_pool: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[b"pool_lp_mint", cpswap_pool.as_ref()],
        &CPSWAP_PROGRAM_ID,
    )
}

/// Derives the CPSwap authority PDA
///
/// Seeds: ["vault_and_lp_mint_auth_seed"] with CPSwap program
pub fn get_cpswap_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[b"vault_and_lp_mint_auth_seed"],
        &CPSWAP_PROGRAM_ID,
    )
}

/// Derives the CPSwap observation PDA
///
/// Seeds: ["observation", cpswap_pool] with CPSwap program
pub fn get_cpswap_observation_pda(cpswap_pool: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[b"observation", cpswap_pool.as_ref()],
        &CPSWAP_PROGRAM_ID,
    )
}

/// Derives the lock authority PDA
///
/// Seeds: ["lock_cp_authority_seed"] with Lock program
pub fn get_lock_authority_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[b"lock_cp_authority_seed"],
        &LOCK_PROGRAM_ID,
    )
}