raydium-launchlab-sdk 0.1.1

Rust SDK for Raydium LaunchLab program
Documentation
//! Type definitions for Raydium LaunchLab

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;

// =============================================================================
// Enums
// =============================================================================

/// Pool status enum
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum PoolStatus {
    /// Pool is funding
    #[default]
    Fund = 0,
    /// Pool funding is end, waiting for migration
    Migrate = 1,
    /// Pool migration is done
    Trade = 2,
}

/// Trade direction enum
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum TradeDirection {
    Buy = 0,
    Sell = 1,
}

/// AMM creator fee on enum
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum AmmCreatorFeeOn {
    /// No creator fee
    #[default]
    Off = 0,
    /// Creator fee on quote token only
    Quote = 1,
    /// Creator fee on both tokens
    Both = 2,
}

/// Curve type enum
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum CurveType {
    /// Constant product curve (x * y = k)
    #[default]
    ConstantProduct = 0,
    /// Fixed price curve
    FixedPrice = 1,
    /// Linear price curve
    LinearPrice = 2,
}

/// Migrate type enum
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum MigrateType {
    /// Migrate to AMM
    #[default]
    Amm = 0,
    /// Migrate to CPSwap
    CpSwap = 1,
}

// =============================================================================
// Instruction Parameters
// =============================================================================

/// Parameters for creating a new token mint
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct MintParams {
    /// Decimals of the token
    pub decimals: u8,
    /// Name of the token
    pub name: String,
    /// Symbol of the token
    pub symbol: String,
    /// URI for token metadata
    pub uri: String,
}

/// Parameters for bonding curve configuration
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct CurveParams {
    /// Total supply of base token to sell
    pub supply: u64,
    /// Total quote token to raise
    pub total_quote_fund_raising: u64,
    /// Migrate type: 0 = AMM, 1 = CPSwap
    pub migrate_type: u8,
    /// Migrate fee
    pub migrate_fee: u64,
}

/// Parameters for vesting configuration
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct VestingParams {
    /// Total amount of tokens to be locked for vesting
    pub total_locked_amount: u64,
    /// Cliff period in seconds
    pub cliff_period: u64,
    /// Unlock period in seconds (duration for full unlock after cliff)
    pub unlock_period: u64,
}

/// Vesting schedule stored in pool state
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct VestingSchedule {
    /// Total amount of tokens locked for vesting
    pub total_locked_amount: u64,
    /// Cliff period in seconds
    pub cliff_period: u64,
    /// Unlock period in seconds
    pub unlock_period: u64,
    /// Start time of vesting (Unix timestamp)
    pub start_time: u64,
    /// Total allocated share amount
    pub allocated_share_amount: u64,
}

/// Platform configuration parameters
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct PlatformParams {
    /// Migration NFT info
    pub migrate_nft_info: MigrateNftInfo,
    /// Platform fee rate
    pub fee_rate: u64,
    /// Platform name
    pub name: String,
    /// Platform website URL
    pub web: String,
    /// Platform image URL
    pub img: String,
    /// Creator fee rate
    pub creator_fee_rate: u64,
}

/// Migration NFT info
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct MigrateNftInfo {
    /// NFT symbol
    pub symbol: String,
    /// NFT name
    pub name: String,
    /// NFT URI
    pub uri: String,
    /// Is mutable metadata
    pub is_mutable: bool,
}

/// Bonding curve parameters for platform launch configuration
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct BondingCurveParam {
    /// Supply of base token
    pub supply: u64,
    /// Total quote fund raising target
    pub total_quote_fund_raising: u64,
    /// Migration fee
    pub migrate_fee: u64,
    /// Whether to enable creator fee on AMM
    pub allow_creator_fee_on: bool,
    /// Number of decimals for base token
    pub decimals: u8,
    /// Token name
    pub name: String,
    /// Token symbol
    pub symbol: String,
    /// Token URI
    pub uri: String,
}

/// Platform config update parameters
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub enum PlatformConfigParam {
    /// Update fee wallet
    FeeWallet(Pubkey),
    /// Update NFT wallet
    NftWallet(Pubkey),
    /// Update fee rate
    FeeRate(u64),
    /// Update NFT info
    NftInfo(MigrateNftInfo),
    /// Update CPSwap config
    CpswapConfig(Pubkey),
    /// Update platform name
    Name(String),
    /// Update platform web
    Web(String),
    /// Update platform image
    Img(String),
    /// Update creator fee rate
    CreatorFeeRate(u64),
    /// Update transfer fee extension authority
    TransferFeeExtensionAuthority(Pubkey),
}

/// Transfer fee extension parameters (for Token-2022)
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Default)]
pub struct TransferFeeExtensionParams {
    /// Transfer fee in basis points (denominator is 10000)
    pub transfer_fee_basis_points: u16,
    /// Maximum fee on each transfer
    pub maximum_fee: u64,
}

// =============================================================================
// Events
// =============================================================================

/// Emitted when a pool is created
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub struct PoolCreateEvent {
    pub pool_state: Pubkey,
    pub creator: Pubkey,
    pub config: Pubkey,
    pub base_mint_param: MintParams,
    pub curve_param: CurveParams,
    pub vesting_param: VestingParams,
    pub amm_fee_on: AmmCreatorFeeOn,
}

/// Emitted when trade event occurs
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub struct TradeEvent {
    pub pool_state: Pubkey,
    pub total_base_sell: u64,
    pub virtual_base: u64,
    pub virtual_quote: u64,
    pub real_base_before: u64,
    pub real_quote_before: u64,
    pub real_base_after: u64,
    pub real_quote_after: u64,
    pub amount_in: u64,
    pub amount_out: u64,
    pub protocol_fee: u64,
    pub platform_fee: u64,
    pub creator_fee: u64,
    pub share_fee: u64,
    pub trade_direction: TradeDirection,
    pub pool_status: PoolStatus,
    pub exact_in: bool,
}

/// Emitted when vesting account is created
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub struct CreateVestingEvent {
    pub pool: Pubkey,
    pub beneficiary: Pubkey,
    pub share_amount: u64,
}

/// Emitted when vested tokens are claimed
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
pub struct ClaimVestedEvent {
    pub pool: Pubkey,
    pub beneficiary: Pubkey,
    pub amount: u64,
}

// =============================================================================
// Discriminators (8-byte instruction prefixes)
// =============================================================================

pub mod discriminators {
    /// buy_exact_in instruction discriminator
    pub const BUY_EXACT_IN: [u8; 8] = [250, 234, 13, 123, 213, 156, 19, 236];
    
    /// buy_exact_out instruction discriminator
    pub const BUY_EXACT_OUT: [u8; 8] = [24, 211, 116, 40, 105, 3, 153, 56];
    
    /// sell_exact_in instruction discriminator
    pub const SELL_EXACT_IN: [u8; 8] = [149, 39, 222, 155, 211, 124, 152, 26];
    
    /// sell_exact_out instruction discriminator
    pub const SELL_EXACT_OUT: [u8; 8] = [95, 200, 71, 34, 8, 9, 11, 166];
    
    /// initialize instruction discriminator
    pub const INITIALIZE: [u8; 8] = [175, 175, 109, 31, 13, 152, 155, 237];
    
    /// initialize_v2 instruction discriminator
    pub const INITIALIZE_V2: [u8; 8] = [67, 153, 175, 39, 218, 16, 38, 32];
    
    /// initialize_with_token_2022 instruction discriminator
    pub const INITIALIZE_WITH_TOKEN_2022: [u8; 8] = [37, 190, 126, 222, 44, 154, 171, 17];
    
    /// claim_creator_fee instruction discriminator
    pub const CLAIM_CREATOR_FEE: [u8; 8] = [26, 97, 138, 203, 132, 171, 141, 252];
    
    /// claim_platform_fee instruction discriminator
    pub const CLAIM_PLATFORM_FEE: [u8; 8] = [156, 39, 208, 135, 76, 237, 61, 72];
    
    /// claim_platform_fee_from_vault instruction discriminator
    pub const CLAIM_PLATFORM_FEE_FROM_VAULT: [u8; 8] = [117, 241, 198, 168, 248, 218, 80, 29];
    
    /// claim_vested_token instruction discriminator
    pub const CLAIM_VESTED_TOKEN: [u8; 8] = [49, 33, 104, 30, 189, 157, 79, 35];
    
    /// collect_fee instruction discriminator
    pub const COLLECT_FEE: [u8; 8] = [60, 173, 247, 103, 4, 93, 130, 48];
    
    /// collect_migrate_fee instruction discriminator
    pub const COLLECT_MIGRATE_FEE: [u8; 8] = [255, 186, 150, 223, 235, 118, 201, 186];
    
    /// create_config instruction discriminator
    pub const CREATE_CONFIG: [u8; 8] = [201, 207, 243, 114, 75, 111, 47, 189];
    
    /// create_platform_config instruction discriminator
    pub const CREATE_PLATFORM_CONFIG: [u8; 8] = [176, 90, 196, 175, 253, 113, 220, 20];
    
    /// create_vesting_account instruction discriminator
    pub const CREATE_VESTING_ACCOUNT: [u8; 8] = [129, 178, 2, 13, 217, 172, 230, 218];
    
    /// migrate_to_amm instruction discriminator
    pub const MIGRATE_TO_AMM: [u8; 8] = [207, 82, 192, 145, 254, 207, 145, 223];
    
    /// migrate_to_cpswap instruction discriminator
    pub const MIGRATE_TO_CPSWAP: [u8; 8] = [136, 92, 200, 103, 28, 218, 144, 140];
    
    /// update_config instruction discriminator
    pub const UPDATE_CONFIG: [u8; 8] = [29, 158, 252, 191, 10, 83, 219, 99];
    
    /// update_platform_config instruction discriminator
    pub const UPDATE_PLATFORM_CONFIG: [u8; 8] = [195, 60, 76, 129, 146, 45, 67, 143];
    
    /// update_platform_curve_param instruction discriminator
    pub const UPDATE_PLATFORM_CURVE_PARAM: [u8; 8] = [138, 144, 138, 250, 220, 128, 4, 57];
    
    /// remove_platform_curve_param instruction discriminator
    pub const REMOVE_PLATFORM_CURVE_PARAM: [u8; 8] = [27, 30, 62, 169, 93, 224, 24, 145];
}

/// Account discriminators
pub mod account_discriminators {
    /// GlobalConfig account discriminator
    pub const GLOBAL_CONFIG: [u8; 8] = [149, 8, 156, 202, 160, 252, 176, 217];
    
    /// PlatformConfig account discriminator
    pub const PLATFORM_CONFIG: [u8; 8] = [160, 78, 128, 0, 248, 83, 230, 160];
    
    /// PoolState account discriminator
    pub const POOL_STATE: [u8; 8] = [247, 237, 227, 245, 215, 195, 222, 70];
    
    /// VestingRecord account discriminator
    pub const VESTING_RECORD: [u8; 8] = [106, 243, 221, 205, 230, 126, 85, 83];
}