Skip to main content

Raydium CPMM program composability libraries

Repository

Raydium CPMM program Solidity libraries

Exmaple contract

CallRaydiumCPMMProgram - example contract demonstrating how the Raydium program Solidity libraries can be used in practice to interact with Solana's Raydium program.

Libraries

LibRaydiumCPMMProgram library

This library provides helper functions for formatting instructions to be executed by Solana's Raydium program.

Available Raydium CPMM program instructions

  • createPoolInstruction - Deploying CPMM pool on Raydium for selected tokens pair. This method also returns the needed lamports amount for the instruction to be processed successfully in Solana, this amount constains several account creations plus the pool creation fee paid to Raydium. Info
  • addLiquidityInstruction - Adding liquidity for selected tokens pair. Info
  • withdrawLiquidityInstruction - Withdrawing liquidity from selected tokens pair. Info
  • lockLiquidityInstruction - Locking liquidity position. This method also returns the needed lamports amount for the instruction to be processed successfully in Solana, this amount constains several account creations plus a fee if withMetadata is set to true. Info
  • collectFeesInstruction - Collecting fees for locked LP position. This instruction can be sent to Solana only if there is already existing locked LP position and there are some pending fees to be collected. Info
  • swapInputInstruction - Swapping exact token input amount, example - swap 100 tokensA for X tokensB. Info
  • swapOutputInstruction - Swapping tokens to exact token output amount, example - swap X tokensA for 100 tokensB. Info

LibRaydiumCPMMData library

This library provides a set of getter functions for querying different accounts & data. Also some calculations such as swap input or output amount; convert LP amount to tokens amounts; etc. Here are some of the getters:

  • getPoolData - Returns the data of Raydium CPMM pool. Info
  • getConfigData - Returns the data for requested utils index. Info
  • getTokenReserve - Returns pool token reserve for selected token mint. Info
  • getPoolLpAmount - Returns the pool's LP amount. Info
  • lpToAmount - Converts LP amount to reserves amounts. Info
  • getSwapOutput - Returns a swap quote of provided exact input amount. Info
  • getSwapInput - Returns a swap quote of provided exact output amount. Info

LibRaydiumCPMMErrors library

This library provides a set of custom errors that may be thrown when using LibRaydiumCPMMProgram and LibRaydiumCPMMData libraries.

Was this page helpful?