The Raydium class provides methods to interact with the Raydium decentralized exchange on the Solana blockchain. It allows watching for pool creation and swap events, retrieving liquidity pool information, and executing swaps. This class extends the Subscribable class, enabling subscription to Raydium-related events.
Methods
watchCreatePools
Description Watches for the creation of new liquidity pools and invokes a callback when an event occurs.
Signature
public async watchCreatePools(
callback: (event: RaydiumCreatePool) => void
): Promise<SubscriptionResult>
Parameters
callback ((event: RaydiumCreatePool) => void): The callback function to handle pool creation events.
Returns
Promise<SubscriptionResult>: The result of the subscription operation.
watchSwaps
Description Watches for swap events and invokes a callback when a swap occurs on Raydium.
Signature
public async watchSwaps(
callback: (event: RaydiumSwap) => void
): Promise<SubscriptionResult>
Parameters
callback ((event: RaydiumSwap) => void): The callback function to handle swap events.
Returns
Promise<SubscriptionResult>: The result of the subscription operation.
getLiquidityPools
Description Fetches liquidity pools that match the specified baseMint and optionally a quoteMint.
Signature
public async getLiquidityPools(
baseMint: PublicKeyOrString,
quoteMint?: PublicKeyOrString
): Promise<LiquidityPool[]>
Parameters
baseMint (PublicKeyOrString): The base mint of the liquidity pool.
quoteMint (PublicKeyOrString): Optional. The quote mint of the liquidity pool.
Returns
Promise<LiquidityPool[]>: An array of matching liquidity pool objects.
inputMint (PublicKeyOrString): The input token's mint address.
outputMint (PublicKeyOrString): The output token's mint address.
amount (string | number): The amount of the input token to swap.
autoSlippage (boolean): Optional. Whether to automatically adjust slippage.
computeBudgetMicroLamports (string | number): Optional. Compute budget in micro-lamports.
computeBudgetUnits (string | number): Optional. Compute budget in units.
priorityFee (string | number): Optional. The priority fee in lamports.
priorityFeeEstimate (string): Optional. An estimate of the priority fee.
slippageBps (string | number): Optional. The slippage in basis points.
Returns
Promise<VersionedTransaction>: A VersionedTransaction object representing the swap transaction.
Example Usage
const swapTx = await raydium.swap({
inputMint: "So11111111111111111111111111111111111111112", // Example SOL mint address
outputMint: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", // Example USDC mint address
amount: 1000000, // Amount in lamports (1 SOL)
});