7: Advanced topics

Token Migration

When real_quote >= total_quote_fund_raising, the pool becomes eligible for migration.

1

Pool status update

Pool status changes from 0 (Funding) to 1 (Migrate).

2

Migration call

Raydium team calls migrate_to_amm instruction.

3

Liquidity movement

Liquidity is moved to Raydium CPMM.

4

Pool becomes tradable on AMM

Pool status changes to 2 (Trade).

5

Post-migration trading

Future trades occur on AMM, not bonding curve.

Post-Migration:

  • Token is now tradable on Raydium AMM

  • Bonding curve trading is disabled

  • LP tokens are locked or distributed according to platform config


Error Codes

Common errors from the program:

Code
Name
Description

6000

NotApproved

Action not authorized

6001

InvalidOwner

Account owner mismatch

6002

InvalidInput

Invalid input parameters

6003

InputNotMatchCurveConfig

Input doesn't match curve configuration

6004

ExceededSlippage

Trade exceeds slippage tolerance

6005

PoolFunding

Pool is still in funding phase

6006

PoolMigrated

Pool has already migrated

6007

MigrateTypeNotMatch

Migration type mismatch

6008

MathOverflow

Arithmetic overflow


Events

The program emits events for monitoring:

PoolCreateEvent - Emitted when a new pool is created

PoolCreateEvent.ts
{
  pool_state: PublicKey;
  creator: PublicKey;
  config: PublicKey;
  base_mint_param: MintParams;
  curve_param: CurveParams;
  vesting_param: VestingParams;
}

TradeEvent - Emitted on every buy/sell

TradeEvent.ts
{
  pool_state: PublicKey;
  amount_in: u64;
  amount_out: u64;
  protocol_fee: u64;
  platform_fee: u64;
  creator_fee: u64;
  trade_direction: 'Buy' | 'Sell';
  pool_status: 'Fund' | 'Migrate' | 'Trade';
  exact_in: boolean;
}

Monitoring Pools

WebSocket Subscription:

monitor-all.ts
import { Connection } from '@solana/web3.js';

const connection = new Connection('wss://api.mainnet-beta.solana.com');

// Monitor all program account changes
const subscriptionId = connection.onProgramAccountChange(
  LAUNCHLAB_PROGRAM_ID,
  (accountInfo, context) => {
    console.log('Account changed:', accountInfo);
    // Decode pool state and react to changes
  },
  'confirmed'
);

Filter Specific Token:

monitor-pool.ts
// Monitor specific pool state
const subscriptionId = connection.onAccountChange(
  poolStateAddress,
  (accountInfo, context) => {
    // Decode and handle pool state update
    const poolState = decodePoolState(accountInfo.data);
    console.log('Pool updated:', poolState.status);
  },
  'confirmed'
);

Last updated