This library provides an easy-to-use interface for creating SPL tokens, managing liquidity pools on Raydium, performing swaps, and handling LP tokens.
It is designed for developers building projects on the Solana blockchain using Node.js.
- Mints a new SPL token.
- Mints initial supply to creator wallet.
- Disables mint authority for trust.
- Creates an Associated Token Account (ATA) for holding the token.
- Mints more tokens to a given ATA (only if mint authority exists).
- Permanently disables minting.
(These functions wrap Raydium AMM program calls)
- Initializes a new pool with token + base (SOL or USDC).
- Calculates initial price.
- Returns LP token mint and address.
- Adds more liquidity to an existing pool.
- Mints LP tokens to the provider.
- Burns LP tokens.
- Returns proportional SOL + token reserves to the wallet.
- Returns reserves, LP supply, price, volume.
- Swap SOL/USDC for your token.
- Swap your token for SOL/USDC.
- Get how many tokens you’ll receive for a given swap.
- Uses Raydium's constant product formula:
amountOut = (amountIn * reserveOut) / (reserveIn + amountIn)
- Shows LP token balance for the user.
- Returns current token price in base currency.
- Burns all LP tokens in wallet and withdraws liquidity.
// =========================
// A. TOKEN MANAGEMENT
// =========================
pub fn create_token(
name: &str,
symbol: &str,
decimals: u8,
initial_supply: u64,
) -> Result<Pubkey, ProgramError>;
pub fn create_ata(
wallet: &Pubkey,
mint_address: &Pubkey,
) -> Result<Pubkey, ProgramError>;
pub fn mint_tokens(
mint_address: &Pubkey,
destination: &Pubkey,
amount: u64,
) -> Result<(), ProgramError>;
pub fn disable_mint_authority(
mint_address: &Pubkey,
) -> Result<(), ProgramError>;
// =========================
// B. LIQUIDITY POOL (Raydium)
// =========================
pub fn create_pool(
token_mint: &Pubkey,
base_mint: &Pubkey,
token_amount: u64,
base_amount: u64,
) -> Result<Pubkey, ProgramError>;
pub fn add_liquidity(
pool_id: &Pubkey,
token_amount: u64,
base_amount: u64,
) -> Result<(), ProgramError>;
pub fn remove_liquidity(
pool_id: &Pubkey,
lp_amount: u64,
) -> Result<(), ProgramError>;
pub fn get_pool_info(
pool_id: &Pubkey,
) -> Result<PoolInfo, ProgramError>;
// =========================
// C. SWAPPING
// =========================
pub fn swap_base_to_token(
pool_id: &Pubkey,
base_amount: u64,
min_token_out: u64,
) -> Result<(), ProgramError>;
pub fn swap_token_to_base(
pool_id: &Pubkey,
token_amount: u64,
min_base_out: u64,
) -> Result<(), ProgramError>;
pub fn get_swap_quote(
pool_id: &Pubkey,
amount_in: u64,
direction: SwapDirection,
) -> Result<u64, ProgramError>;
// =========================
// D. UTILITY / ADMIN
// =========================
pub fn get_lp_balance(
wallet: &Pubkey,
lp_mint: &Pubkey,
) -> Result<u64, ProgramError>;
pub fn get_price(
pool_id: &Pubkey,
) -> Result<f64, ProgramError>;
pub fn withdraw_all_liquidity(
pool_id: &Pubkey,
) -> Result<(), ProgramError>;
// =========================
// DATA STRUCTURES
// =========================
pub struct PoolInfo {
pub reserve_token: u64,
pub reserve_base: u64,
pub lp_supply: u64,
pub price: f64,
pub volume_24h: f64,
}
pub enum SwapDirection {
BaseToToken,
TokenToBase,
}Pubkeyis the Solana public key type.ProgramErroris the standard Solana program error type.Result<_, ProgramError>ensures proper error handling in on-chain programs.PoolInfostruct holds relevant pool data.SwapDirectionenum clarifies swap direction without needing a bool flag.