### Example: Collect Reward 0 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/clmm.md An example demonstrating how to call the `collect_remaining_rewards` function to collect the reward at index 0. ```rust raydium_clmm::collect_remaining_rewards(cpi_ctx, 0) // Collect reward 0 ``` -------------------------------- ### Example of Claiming Creator Fee Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md This snippet shows how to call the claim_creator_fee function using a CPI context. ```rust raydium_launchpad::claim_creator_fee(cpi_ctx) ``` -------------------------------- ### VestingNotStarted Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Demonstrates the condition for `VestingNotStarted` error when attempting to claim vested tokens before the cliff time has been reached. ```rust // VestingNotStarted claim_vested_token(ctx)?; // If current_time < cliff_time ``` -------------------------------- ### Rust: Slippage Error Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Demonstrates the `AmountOutBelowMinimum` error, which occurs when the swap output falls below the specified minimum threshold due to market slippage. The example shows a swap call where the minimum expected output is set. ```rust swap_v2(ctx, 1_000_000, 1_000_000, 0, true)?; // If market moves unfavorably, output might be only 900k < 1M minimum ``` -------------------------------- ### PoolFundingEnded Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Illustrates the condition for `PoolFundingEnded` error when calling `buy_exact_in` after the fundraising period has ended and the pool has not been migrated. ```rust // PoolFundingEnded buy_exact_in(ctx, 1_000_000, 900_000, 0)?; // If current_time > fundraising_end_time and not migrated ``` -------------------------------- ### Initialize AMM Pool Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/amm.md Creates and invokes an Initialize2 instruction for the AMM pool using CPI. This example demonstrates setting up the necessary accounts and parameters for pool creation, including nonce, open time, and initial token amounts. ```rust use anchor_lang::prelude::*; use raydium_amm_cpi::raydium_amm; pub fn initialize_amm_pool(ctx: Context) -> Result<()> { let cpi_ctx = CpiContext::new( ctx.accounts.amm_program.to_account_info(), raydium_amm::Initialize2 { amm: ctx.accounts.amm.to_account_info(), amm_authority: ctx.accounts.authority.to_account_info(), // ... remaining accounts }, ); raydium_amm::initialize( cpi_ctx, 42, // nonce for PDA derivation 0, // open_time: immediate 5_000_000, // init_pc_amount: 5M 10_000_000, // init_coin_amount: 10M ) } ``` -------------------------------- ### Perform AMM Swap with Native Instructions Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md Use this function to execute a swap on the Raydium AMM. Ensure all required accounts for the swap are correctly provided in the context. This example uses `swap_base_in`. ```rust use raydium_amm_cpi::{self, raydium_amm}; pub fn swap_amm( ctx: Context, amount_in: u64, min_out: u64, ) -> Result<()> { let cpi_program = ctx.accounts.amm_program.to_account_info(); let cpi_accounts = raydium_amm::SwapBaseIn { amm: ctx.accounts.amm.to_account_info(), amm_authority: ctx.accounts.amm_authority.to_account_info(), amm_open_orders: ctx.accounts.amm_open_orders.to_account_info(), amm_coin_vault: ctx.accounts.amm_coin_vault.to_account_info(), amm_pc_vault: ctx.accounts.amm_pc_vault.to_account_info(), market_program: ctx.accounts.market_program.to_account_info(), market: ctx.accounts.market.to_account_info(), market_bids: ctx.accounts.market_bids.to_account_info(), market_asks: ctx.accounts.market_asks.to_account_info(), market_event_queue: ctx.accounts.market_event_queue.to_account_info(), market_coin_vault: ctx.accounts.market_coin_vault.to_account_info(), market_pc_vault: ctx.accounts.market_pc_vault.to_account_info(), market_vault_signer: ctx.accounts.market_vault_signer.to_account_info(), user_token_source: ctx.accounts.user_token_source.to_account_info(), user_token_destination: ctx.accounts.user_token_destination.to_account_info(), user_source_owner: ctx.accounts.user.to_account_info(), // ... additional accounts }; let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts); raydium_amm::swap_base_in( cpi_ctx, amount_in, min_out, ) } ``` -------------------------------- ### AmountOutBelowMinimum Error Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Shows the `AmountOutBelowMinimum` error during a swap. This occurs when the actual output amount is less than the specified minimum acceptable amount, usually due to adverse market price movements. ```rust // AmountOutBelowMinimum swap_base_input(ctx, 1_000_000, 2_000_000)?; // Market moved against user, output only 1_900_000 < minimum ``` -------------------------------- ### Create Platform Configuration Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Initializes a new launch platform's configuration. This includes setting the platform's fee rate, name, website, and image URL. ```rust pub fn create_platform_config( ctx: Context, platform_params: PlatformParams, ) -> Result<()> ``` ```rust raydium_launchpad::create_platform_config( cpi_ctx, PlatformParams { fee_rate: 1000, // 10% fee name: "MyLaunchPlatform".to_string(), web: "https://example.com".to_string(), img: "ipfs://...".to_string(), }, ) ``` -------------------------------- ### Rust: Invalid Reward Index Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Shows the `InvalidRewardIndex` error, which occurs when an attempt is made to collect rewards using an index that is out of the valid range (0-2). The example calls `collect_remaining_rewards` with an invalid index. ```rust collect_remaining_rewards(ctx, 5)?; // Only 0-2 valid, max 3 rewards ``` -------------------------------- ### initialize Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Creates a basic launch pool with specified curve and vesting parameters. ```APIDOC ## initialize ### Description Creates a basic launch pool with specified curve and vesting parameters. ### Method `initialize` ### Parameters #### Context - `ctx` (Context) - Required - Pool and account setup context #### Base Mint Parameters - `base_mint_param` (MintParams) - Required - Base token configuration - `name` (string) - Base token name - `symbol` (string) - Token symbol - `uri` (string) - Metadata URI #### Curve Parameters - `curve_param` (CurveParams) - Required - Bonding curve settings - `curve_type` (integer) - 0=Constant Product, 1=Fixed Price, 2=Linear Price - `initial_real_token_amount` (uint64) - Initial token supply - `initial_quote_amount` (uint64) - Initial quote token amount - `linear_coe` (uint64) - Coefficient for linear curves - `linear_coe_quote` (uint64) - Quote coefficient for linear curves - `fixed_price` (uint64) - Price for fixed-price curves - `fundraising_goal` (uint64) - Target quote amount to raise - `fundraising_end_time` (integer) - End timestamp for fundraising - `migrate_type` (integer) - 0=AMM, 1=CPSWAP #### Vesting Parameters - `vesting_param` (VestingParams) - Required - Token vesting configuration - `cliff_time` (integer) - Time before first vest - `cliff_amount` (uint64) - Amount available at cliff - `vesting_period` (integer) - Vesting period duration - `percent_per_period` (uint16) - Percentage released per period ### Returns - `Result<()>` ### Example ```rust use raydium_launch_cpi::raydium_launchpad; use raydium_launch_cpi::{MintParams, CurveParams, VestingParams}; pub fn launch_token(ctx: Context) -> Result<()> { let cpi_ctx = CpiContext::new( ctx.accounts.launch_program.to_account_info(), raydium_launchpad::Initialize { // ... accounts }, ); raydium_launchpad::initialize( cpi_ctx, MintParams { name: "MyToken".to_string(), symbol: "MT".to_string(), uri: "ipfs://...".to_string(), }, CurveParams { curve_type: 0, // Constant Product initial_real_token_amount: 1_000_000_000, initial_quote_amount: 100_000_000, linear_coe: 0, linear_coe_quote: 0, fixed_price: 0, fundraising_goal: 500_000_000, fundraising_end_time: 1735689600, // Jan 1, 2025 migrate_type: 0, // AMM }, VestingParams { cliff_time: 2592000, // 30 days cliff_amount: 100_000_000, vesting_period: 86400, // 1 day percent_per_period: 1000, // 0.1% per day }, ) } ``` ``` -------------------------------- ### initialize_v2 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Creates a launch pool with AMM fee configuration. ```APIDOC ## initialize_v2 ### Description Creates a launch pool with AMM fee configuration. ### Method `initialize_v2` ### Parameters #### Context - `ctx` (Context) - Required - Pool and account setup context #### Base Mint Parameters - `base_mint_param` (MintParams) - Required - Base token configuration - `name` (string) - Base token name - `symbol` (string) - Token symbol - `uri` (string) - Metadata URI #### Curve Parameters - `curve_param` (CurveParams) - Required - Bonding curve settings - `curve_type` (integer) - 0=Constant Product, 1=Fixed Price, 2=Linear Price - `initial_real_token_amount` (uint64) - Initial token supply - `initial_quote_amount` (uint64) - Initial quote token amount - `linear_coe` (uint64) - Coefficient for linear curves - `linear_coe_quote` (uint64) - Quote coefficient for linear curves - `fixed_price` (uint64) - Price for fixed-price curves - `fundraising_goal` (uint64) - Target quote amount to raise - `fundraising_end_time` (integer) - End timestamp for fundraising - `migrate_type` (integer) - 0=AMM, 1=CPSWAP #### Vesting Parameters - `vesting_param` (VestingParams) - Required - Token vesting configuration - `cliff_time` (integer) - Time before first vest - `cliff_amount` (uint64) - Amount available at cliff - `vesting_period` (integer) - Vesting period duration - `percent_per_period` (uint16) - Percentage released per period #### AMM Fee Configuration - `amm_fee_on` (AmmCreatorFeeOn) - Required - Fee collection model for migration - Options: `QuoteToken` (Collect fees in quote token only), `BothToken` (Collect fees in both base and quote) ### Returns - `Result<()>` ``` -------------------------------- ### initialize_with_token_2022 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Creates a launch pool with Token2022 base token support. ```APIDOC ## initialize_with_token_2022 ### Description Creates a launch pool with Token2022 base token support. ### Method `initialize_with_token_2022` ### Parameters #### Context - `ctx` (Context) - Required - Pool and account setup context #### Base Mint Parameters - `base_mint_param` (MintParams) - Required - Base token configuration - `name` (string) - Base token name - `symbol` (string) - Token symbol - `uri` (string) - Metadata URI #### Curve Parameters - `curve_param` (CurveParams) - Required - Bonding curve settings - `curve_type` (integer) - 0=Constant Product, 1=Fixed Price, 2=Linear Price - `initial_real_token_amount` (uint64) - Initial token supply - `initial_quote_amount` (uint64) - Initial quote token amount - `linear_coe` (uint64) - Coefficient for linear curves - `linear_coe_quote` (uint64) - Quote coefficient for linear curves - `fixed_price` (uint64) - Price for fixed-price curves - `fundraising_goal` (uint64) - Target quote amount to raise - `fundraising_end_time` (integer) - End timestamp for fundraising - `migrate_type` (integer) - 0=AMM, 1=CPSWAP #### Vesting Parameters - `vesting_param` (VestingParams) - Required - Token vesting configuration - `cliff_time` (integer) - Time before first vest - `cliff_amount` (uint64) - Amount available at cliff - `vesting_period` (integer) - Vesting period duration - `percent_per_period` (uint16) - Percentage released per period #### AMM Fee Configuration - `amm_fee_on` (AmmCreatorFeeOn) - Required - Fee collection model for migration - Options: `QuoteToken` (Collect fees in quote token only), `BothToken` (Collect fees in both base and quote) #### Transfer Fee Extension Parameters - `transfer_fee_extension_param` (Option) - Optional - Token2022 transfer fee extension config - `transfer_fee_basis_points` (uint16) - Fee in basis points - `maximum_fee` (uint64) - Maximum fee amount ### Note Pools created with Token2022 must migrate to CPSWAP (curve_param.migrate_type = 1). ### Returns - `Result<()>` ``` -------------------------------- ### initialize Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/cpmm.md Creates a standard CPMM pool with equal fee distribution. Requires a context with necessary accounts and initial token amounts. ```APIDOC ## initialize ### Description Creates a standard CPMM pool with equal fee distribution. ### Method CPI Call (Rust SDK) ### Parameters #### Context Accounts (`ctx`) - `creator` (signer, mut) - Address funding pool creation - `amm_config` - Pool configuration account - `authority` - Pool vault authority (PDA) - `pool_state` (init) - Pool state account - `token_0_mint` - First token mint (must be < token_1_mint) - `token_1_mint` - Second token mint - `lp_mint` (init) - LP token mint - `creator_token_0`, `creator_token_1` (mut) - Creator's token accounts - `creator_lp_token` (init) - Creator's LP token account - `token_0_vault`, `token_1_vault` (mut) - Pool token vaults - `create_pool_fee` (mut) - Fee recipient account - `observation_state` (init) - Oracle observations - Token programs and system program #### Function Parameters - **init_amount_0** (u64) - Required - Initial deposit of token 0 (with decimals) - **init_amount_1** (u64) - Required - Initial deposit of token 1 (with decimals) - **open_time** (u64) - Required - Unix timestamp when swaps are enabled (0 for immediate) ### Returns - `Result<()>` ### Request Example ```rust use anchor_lang::prelude::* use raydium_cpmm_cpi::raydium_cpmm; pub fn create_constant_product_pool( ctx: Context, ) -> Result<()> { let cpi_ctx = CpiContext::new( ctx.accounts.cpmm_program.to_account_info(), raydium_cpmm::Initialize { creator: ctx.accounts.payer.to_account_info(), amm_config: ctx.accounts.config.to_account_info(), // ... other accounts }, ); raydium_cpmm::initialize( cpi_ctx, 1_000_000, // init_amount_0: 1M 2_000_000, // init_amount_1: 2M 0, // open_time: immediate ) } ``` ``` -------------------------------- ### Typical Integration Flow Steps Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/00-START-HERE.md This outlines the general steps for integrating with Raydium's CPI. It covers dependency management, module selection, context creation, CPI function calls, result handling, and deployment. ```text 1. Add Dependencies └─ Cargo.toml: add raydium-*-cpi packages 2. Pick a Module └─ Use decision matrix above 3. Create Anchor Context └─ Map all required accounts 4. Call CPI Function └─ wrap in CpiContext with accounts └─ call module function with parameters 5. Handle Results └─ check Result(()) └─ read errors.md for failure patterns 6. Deploy └─ devnet first (with devnet feature) └─ integrate monitoring └─ follow production checklist ``` -------------------------------- ### Rust - Initialize Launch Pool Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Use this function to create a basic launch pool with specified curve and vesting parameters. Ensure all required accounts and parameters are correctly configured. ```rust pub fn initialize( ctx: Context, base_mint_param: MintParams, curve_param: CurveParams, vesting_param: VestingParams, ) -> Result<()> ``` ```rust use raydium_launch_cpi:: raydium_launchpad, MintParams, CurveParams, VestingParams, }; pub fn launch_token(ctx: Context) -> Result<()> { let cpi_ctx = CpiContext::new( ctx.accounts.launch_program.to_account_info(), raydium_launchpad::Initialize { // ... accounts }, ); raydium_launchpad::initialize( cpi_ctx, MintParams { name: "MyToken".to_string(), symbol: "MT".to_string(), uri: "ipfs://...".to_string(), }, CurveParams { curve_type: 0, // Constant Product initial_real_token_amount: 1_000_000_000, initial_quote_amount: 100_000_000, linear_coe: 0, linear_coe_quote: 0, fixed_price: 0, fundraising_goal: 500_000_000, fundraising_end_time: 1735689600, // Jan 1, 2025 migrate_type: 0, // AMM }, VestingParams { cliff_time: 2592000, // 30 days cliff_amount: 100_000_000, vesting_period: 86400, // 1 day percent_per_period: 1000, // 0.1% per day }, ) } ``` -------------------------------- ### InvalidCurveType Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Shows how `InvalidCurveType` error can occur during initialization if an unrecognized curve type (e.g., 5) is provided. Only curve types 0-2 are valid. ```rust // InvalidCurveType in initialize CurveParams { curve_type: 5, ... } // Only 0-2 valid ``` -------------------------------- ### Lock CLMM Position with Raydium Locking CPI Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md Use this function to lock a CLMM position. Ensure all required accounts are mapped correctly. This example includes metadata. ```rust use raydium_locking_cpi::{self, raydium_liquidity_locking}; pub fn lock_position( ctx: Context, ) -> Result<()> { let cpi_program = ctx.accounts.locking_program.to_account_info(); let cpi_accounts = raydium_liquidity_locking::LockClmmPosition { position_owner: ctx.accounts.owner.to_account_info(), position_nft_mint: ctx.accounts.nft_mint.to_account_info(), position_nft_account: ctx.accounts.nft_account.to_account_info(), position: ctx.accounts.position.to_account_info(), // ... map all accounts }; let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts); raydium_liquidity_locking::lock_clmm_position( cpi_ctx, true, // With metadata ) } ``` -------------------------------- ### Swap on Launch with Raydium CPI Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md Execute a token swap on a Raydium launchpad. This function allows buyers to purchase tokens using a specified input amount. Set min_output and referral_fee to 0 for launchpad swaps. ```rust pub fn buy_on_launch( ctx: Context, amount_in: u64, ) -> Result<()> { let cpi_program = ctx.accounts.launch_program.to_account_info(); let cpi_accounts = raydium_launchpad::Swap { payer: ctx.accounts.buyer.to_account_info(), // ... map all accounts }; let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts); raydium_launchpad::buy_exact_in( cpi_ctx, amount_in, 0, // Min output (no protection for launch) 0, // No referral fee ) } ``` -------------------------------- ### TokenMintOrdering Error Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Illustrates the `TokenMintOrdering` error, which occurs when the lexicographical order of token mint addresses is incorrect during pool initialization. Ensure `token_0_mint` is less than `token_1_mint`. ```rust // TokenMintOrdering initialize(ctx, 1_000_000, 2_000_000, 0)?; // If token_0 > token_1 lexicographically ``` -------------------------------- ### initialize_with_permission Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/cpmm.md Creates a pool with an optional creator fee structure, allowing for flexible fee collection models. ```APIDOC ## initialize_with_permission ### Description Creates a pool with optional creator fee structure. ### Method CPI Call (Rust SDK) ### Parameters #### Context Accounts (`ctx`) - `creator` (signer, mut) - Address funding pool creation - `amm_config` - Pool configuration account - `authority` - Pool vault authority (PDA) - `pool_state` (init) - Pool state account - `token_0_mint` - First token mint (must be < token_1_mint) - `token_1_mint` - Second token mint - `lp_mint` (init) - LP token mint - `creator_token_0`, `creator_token_1` (mut) - Creator's token accounts - `creator_lp_token` (init) - Creator's LP token account - `token_0_vault`, `token_1_vault` (mut) - Pool token vaults - `create_pool_fee` (mut) - Fee recipient account - `observation_state` (init) - Oracle observations - Token programs and system program #### Function Parameters - **init_amount_0** (u64) - Required - Initial token 0 deposit - **init_amount_1** (u64) - Required - Initial token 1 deposit - **open_time** (u64) - Required - Swap enable timestamp - **creator_fee_on** (`CreatorFeeOn`) - Required - Fee collection model - `BothToken` - Creator fee collected from both token 0 and token 1 (depends on input) - `OnlyToken0` - Creator fee only from token 0 - `OnlyToken1` - Creator fee only from token 1 ### Returns - `Result<()>` ### Request Example ```rust raydium_cpmm::initialize_with_permission( cpi_ctx, 1_000_000, 2_000_000, 0, CreatorFeeOn::BothToken, // Collect fee from both tokens ) ``` ``` -------------------------------- ### Launch API Reference Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/MANIFEST.txt Documentation for the Launch module, supporting multiple pool creation variants, swap operations, vesting management, and platform configuration. ```APIDOC ## create_pool (3 variants) Launch ### Description Creates a new launchpool with one of three supported variants. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## swap (4 variants) Launch ### Description Performs a buy or sell swap operation within a launchpool, with four variants available. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## create_vesting Launch ### Description Creates a vesting schedule for tokens. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## claim_vesting Launch ### Description Claims vested tokens. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## config_platform Launch ### Description Configures platform settings for the launchpad. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## collect_platform_fee Launch ### Description Collects platform fees from launchpad operations. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` ```APIDOC ## creator_fee_operations Launch ### Description Manages creator fee operations within the launchpad. ### Method (Not specified, likely a program instruction) ### Endpoint (Not specified) ### Parameters (Details not provided in source) ### Request Example (Not provided in source) ### Response (Details not provided in source) ``` -------------------------------- ### Implement Slippage Protection in Raydium CLMM Swaps Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md Protect your swaps from unfavorable price movements by simulating the swap off-chain and applying slippage bounds. This example uses a 0.5% slippage tolerance. ```rust // Simulate swap first (off-chain) let simulated_output = simulate_swap(pool, amount_in); // Apply 0.5% slippage protection let min_output = (simulated_output * 995) / 1000; // Execute with protection raydium_clmm::swap_v2( cpi_ctx, amount_in, min_output, 0, true, )?; ``` -------------------------------- ### create_platform_config Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Creates configuration for a launch platform. This function allows for the initialization of settings specific to a launch platform, including fee rates and metadata. ```APIDOC ## create_platform_config ### Description Creates configuration for a launch platform. ### Signature ```rust pub fn create_platform_config( ctx: Context, platform_params: PlatformParams, ) -> Result<()> ``` ### Parameters #### Path Parameters - `ctx` (Context) - Required - Platform config account - `platform_params` (PlatformParams) - Required - Platform configuration ### PlatformParams Fields - `fee_rate` (u64) - Platform fee percentage (basis points) - `name` (string) - Platform name (max 64 chars) - `web` (string) - Platform website URL (max 256 chars) - `img` (string) - Platform image URL (max 256 chars) ### Request Example ```rust raydium_launchpad::create_platform_config( cpi_ctx, PlatformParams { fee_rate: 1000, // 10% fee name: "MyLaunchPlatform".to_string(), web: "https://example.com".to_string(), img: "ipfs://...".to_string(), }, ) ``` ### Response #### Success Response (Result<()>) - Indicates successful creation of platform configuration. ``` -------------------------------- ### Rust - Initialize Launch Pool with Token2022 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md This function creates a launch pool supporting Token2022 base tokens. It includes parameters for AMM fees and an optional configuration for Token2022 transfer fees. Note that Token2022 pools must migrate to CPSWAP. ```rust pub fn initialize_with_token_2022( ctx: Context, base_mint_param: MintParams, curve_param: CurveParams, vesting_param: VestingParams, amm_fee_on: AmmCreatorFeeOn, transfer_fee_extension_param: Option, ) -> Result<()> ``` -------------------------------- ### SlippageExceeded Error Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Demonstrates the `SlippageExceeded` error during a deposit operation. This error is triggered if the actual amounts of tokens received or paid exceed the acceptable slippage thresholds, indicating significant market movement. ```rust // SlippageExceeded deposit(ctx, 1_000_000, 500_000, 2_000_000)?; // If ratio changed, actual token amounts might exceed maximums ``` -------------------------------- ### Rust: Price Limit Exceeded Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Illustrates the `PriceLimitExceeded` error scenario during a swap operation. This error occurs when the execution price moves beyond the specified `sqrt_price_limit_x64` before the desired output amount is reached. ```rust swap_v2(ctx, 1_000_000, 0, 100_000_000, true)?; // Price moves beyond sqrt_price_limit_x64 before output reached ``` -------------------------------- ### Buy Exact In with Raydium Launchpad CPI Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Use this function to purchase base tokens by specifying the exact amount of quote tokens you want to spend. Ensure the `minimum_amount_out` is set to avoid slippage. ```rust pub fn buy_exact_in<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, amount_in: u64, minimum_amount_out: u64, share_fee_rate: u64, ) -> Result<()> ``` ```rust raydium_launchpad::buy_exact_in( cpi_ctx, 1_000_000, // Spend 1M quote tokens 950_000, // Expect at least 950k base tokens 0, // No referral fee ) ``` -------------------------------- ### Rust: Invalid Tick Boundary Example Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/errors.md Illustrates the `TickLowerGreaterThanUpper` error when the lower tick is greater than the upper tick. Also shows `InvalidTickSpacing` if the provided tick does not align with the pool's tick spacing. ```rust open_position_v2(ctx, -10000, -20000, ...)?; // -10000 > -20000! open_position_v2(ctx, -10001, 10000, ...)?; // -10001 % 60 != 0 ``` -------------------------------- ### Initialize CPMM Pool with Permission Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/cpmm.md Creates a pool with a configurable creator fee structure. Allows specifying how fees are collected from token 0 and token 1 deposits. ```rust pub fn initialize_with_permission( ctx: Context, init_amount_0: u64, init_amount_1: u64, open_time: u64, creator_fee_on: CreatorFeeOn, ) -> Result<()> ``` ```rust raydium_cpmm::initialize_with_permission( cpi_ctx, 1_000_000, 2_000_000, 0, CreatorFeeOn::BothToken, // Collect fee from both tokens ) ``` -------------------------------- ### Add Raydium CPI Dependencies to Cargo.toml Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/00-START-HERE.md To integrate with Raydium's CPI modules, add the relevant raydium-*-cpi packages to your Cargo.toml file. This example shows how to add the core CPI packages. ```toml [dependencies] raydium_cpi = "^0.1.0" raydium_clmm_cpi = "^0.1.0" raydium_cpmm_cpi = "^0.1.0" ``` -------------------------------- ### Add Launchpad CPI Dependency Source: https://github.com/raydium-io/raydium-cpi/blob/master/README.md Include this dependency in your Cargo.toml to call Launchpad through CPI. ```toml [dependencies] anchor-lang = "=0.32.1" anchor-spl = "=0.32.1" raydium-amm-cpi = { git = "https://github.com/raydium-io/raydium-cpi", package = "raydium-launch-cpi" } ``` -------------------------------- ### Buy Exact Out with Raydium Launchpad CPI Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Use this function to purchase a specific amount of base tokens. Set `maximum_amount_in` to control the maximum quote tokens you are willing to spend to prevent overspending. ```rust pub fn buy_exact_out<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, amount_out: u64, maximum_amount_in: u64, share_fee_rate: u64, ) -> Result<()> ``` ```rust raydium_launchpad::buy_exact_out( cpi_ctx, 1_000_000, // Want exactly 1M base tokens 1_100_000, // Max 1.1M quote tokens 500, // 5% referral fee ) ``` -------------------------------- ### Initialize CPMM Pool Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/cpmm.md Creates a standard CPMM pool with equal fee distribution. Requires initial deposits for both tokens and an optional open time for swap enablement. ```rust pub fn initialize( ctx: Context, init_amount_0: u64, init_amount_1: u64, open_time: u64, ) -> Result<()> ``` ```rust use anchor_lang::prelude::*; use raydium_cpmm_cpi::raydium_cpmm; pub fn create_constant_product_pool( ctx: Context, ) -> Result<()> { let cpi_ctx = CpiContext::new( ctx.accounts.cpmm_program.to_account_info(), raydium_cpmm::Initialize { creator: ctx.accounts.payer.to_account_info(), amm_config: ctx.accounts.config.to_account_info(), // ... other accounts }, ); raydium_cpmm::initialize( cpi_ctx, 1_000_000, // init_amount_0: 1M 2_000_000, // init_amount_1: 2M 0, // open_time: immediate ) } ``` -------------------------------- ### Simulate Swap Calculation Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md This test simulates the constant product formula to calculate swap output based on reserves and input amount, including a 0.25% fee. ```rust #[cfg(test)] mod tests { use super::*; #[test] fn test_swap_calculation() { // Simulate constant product formula let reserve_0 = 1_000_000; let reserve_1 = 2_000_000; let amount_in = 100_000; let fee = (amount_in * 9975) / 10000; // 0.25% fee let output = (fee * reserve_1) / (reserve_0 + fee); assert!(output > 0); } } ``` -------------------------------- ### Open Position With Token22 NFT Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/clmm.md Creates a position using Token2022 NFT without relying on the metadata program. This is recommended over `open_position_v2` as it reduces transaction costs by eliminating the metadata program dependency. ```rust pub fn open_position_with_token22_nft<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, OpenPositionWithToken22Nft<'info>>, tick_lower_index: i32, tick_upper_index: i32, tick_array_lower_start_index: i32, tick_array_upper_start_index: i32, liquidity: u128, amount_0_max: u64, amount_1_max: u64, with_metadata: bool, base_flag: Option, ) -> Result<()> ``` -------------------------------- ### Execute Swap with Exact Output Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/clmm.md Use this function to swap an uncertain amount of input tokens for a precise amount of output tokens. It includes slippage protection and an optional price limit. ```rust raydium_clmm::swap_v2( cpi_ctx, 1_050_000, // Max 1.05M input tokens 1_000_000, // Want exactly 1M output tokens 0, // No price limit false, // Swap for exact output ) ``` -------------------------------- ### Rust - Initialize Launch Pool V2 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Use this function to create a launch pool with an AMM fee configuration. It accepts the same parameters as `initialize` plus an `amm_fee_on` parameter to define the fee collection model. ```rust pub fn initialize_v2( ctx: Context, base_mint_param: MintParams, curve_param: CurveParams, vesting_param: VestingParams, amm_fee_on: AmmCreatorFeeOn, ) -> Result<()> ``` -------------------------------- ### Execute Swap with Exact Input Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/clmm.md Use this function to swap a precise amount of input tokens for an uncertain amount of output tokens. It includes slippage protection and an optional price limit. ```rust pub fn swap_v2<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, SwapSingleV2<'info>>, amount: u64, other_amount_threshold: u64, sqrt_price_limit_x64: u128, is_base_input: bool, ) -> Result<()> ``` ```rust raydium_clmm::swap_v2( cpi_ctx, 1_000_000, // Swap 1M input tokens 950_000, // Expect at least 950k output (5% slippage) 0, // No price limit true, // Swap with exact input ) ``` -------------------------------- ### Launch Program Constants Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md These constants are used for deriving program addresses and defining state sizes within the launch program. ```rust pub const AUTH_SEED: &str = "vault_auth_seed"; ``` ```rust pub const GLOBAL_CONFIG_SEED: &str = "global_config"; ``` ```rust pub const POOL_SEED: &str = "pool"; ``` ```rust pub const POOL_VAULT_SEED: &str = "pool_vault"; ``` ```rust pub const POOL_VESTING_SEED: &str = "pool_vesting"; ``` ```rust pub const PLATFORM_FEE_VAULT_AUTH_SEED: &str = "platform_fee_vault_auth_seed"; ``` ```rust pub const CREATOR_FEE_VAULT_AUTH_SEED: &str = "creator_fee_vault_auth_seed"; ``` ```rust pub const PLATFORM_CONFIG_SEED: &str = "platform_config"; ``` ```rust pub const NAME_SIZE: usize = 64; ``` ```rust pub const WEB_SIZE: usize = 256; ``` ```rust pub const IMG_SIZE: usize = 256; ``` -------------------------------- ### Open Position V2 Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/clmm.md Creates a new position with optional metadata, supporting Token2022. When liquidity is 0 and base_flag is specified, liquidity is computed from the maximum amount of the base token to reduce slippage risk. ```rust pub fn open_position_v2<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, OpenPositionV2<'info>>, tick_lower_index: i32, tick_upper_index: i32, tick_array_lower_start_index: i32, tick_array_upper_start_index: i32, liquidity: u128, amount_0_max: u64, amount_1_max: u64, with_matedata: bool, base_flag: Option, ) -> Result<()> ``` ```rust raydium_clmm::open_position_v2( cpi_ctx, -10000, // tick_lower_index 10000, // tick_upper_index -10016, // tick_array_lower_start_index 10000, // tick_array_upper_start_index 10_000_000, // liquidity: 10M 1_000_000, // amount_0_max: 1M 1_000_000, // amount_1_max: 1M true, // with_metadata None, // base_flag ) ``` -------------------------------- ### Sell Exact In with Raydium Launchpad CPI Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/api-reference/launch.md Use this function to sell a specified amount of base tokens for quote tokens. The `minimum_amount_out` parameter ensures you receive at least a certain amount of quote tokens. ```rust pub fn sell_exact_in<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, amount_in: u64, minimum_amount_out: u64, share_fee_rate: u64, ) -> Result<()> ``` ```rust raydium_launchpad::sell_exact_in( cpi_ctx, 500_000, // Sell 500k base tokens 480_000, // Expect at least 480k quote tokens 0, ) ``` -------------------------------- ### Initialize CPMM Pool Source: https://github.com/raydium-io/raydium-cpi/blob/master/_autodocs/integration-guide.md Use this snippet to initialize a new CPMM pool. Ensure that token mints satisfy the condition token_0_mint < token_1_mint. All necessary accounts must be provided. ```rust use raydium_cpmm_cpi::{self, raydium_cpmm, AmmConfig, PoolState}; #[derive(Accounts)] pub struct InitializeCPMM<'info> { #[account(mut)] pub creator: Signer<'info>, pub cpmm_program: Program<'info, raydium_cpmm_cpi::Raydium>, pub amm_config: Box>, /// Mints must satisfy: token_0_mint < token_1_mint pub token_0_mint: Box>, pub token_1_mint: Box>, #[account(mut)] pub creator_token_0: Box>, #[account(mut)] pub creator_token_1: Box>, pub token_program: Program<'info, Token>, pub token_0_program: Interface<'info, TokenInterface>, pub token_1_program: Interface<'info, TokenInterface>, pub associated_token_program: Program<'info, AssociatedToken>, pub system_program: Program<'info, System>, pub rent: Sysvar<'info, Rent>, } pub fn initialize_cpmm( ctx: Context, amount_0: u64, amount_1: u64, ) -> Result<()> { let cpi_program = ctx.accounts.cpmm_program.to_account_info(); let cpi_accounts = raydium_cpmm::Initialize { creator: ctx.accounts.creator.to_account_info(), amm_config: ctx.accounts.amm_config.to_account_info(), // ... map all accounts }; let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts); raydium_cpmm::initialize( cpi_ctx, amount_0, amount_1, 0, // open_time: immediate ) } ```