### Raydium SDK V2 Examples Source: https://docs.raydium.io/raydium/protocol/developers This snippet provides practical examples of how to utilize the Raydium SDK V2. These examples serve as a starting point for developers to understand and implement Raydium's functionalities, such as trading and liquidity management. ```TypeScript https://github.com/raydium-io/raydium-sdk-V2-demo ``` -------------------------------- ### Install Raydium SDK v2 Source: https://docs.raydium.io/raydium/traders/trade-api Installs the Raydium SDK v2 using yarn. This is the first step to integrate Raydium's trading functionalities into your project. ```bash yarn add @raydium-io/raydium-sdk-v2 ``` -------------------------------- ### Swap Tokens on Raydium Source: https://docs.raydium.io/raydium/~/changes/RaVY5reeE9b0iaInst59/traders/swapping This guide explains the process of swapping tokens on Raydium. It details how to connect a wallet, select the 'from' and 'to' tokens, enter the amount, and execute the swap. It also highlights important considerations like Price Impact and Minimum Received. ```English 1. Navigate to Swap using the tabs at the of the app, then connect your wallet. 2. Next, select from the drop-down the tokens you want to swap. For this example, we'll be swapping **From** SOL **To** USDC. 3. Enter the amount of tokens you wish to swap. Finally, click Swap! 4. Shortly after the transaction is confirmed you should be able to see your new balance, although this can sometimes take a few seconds to refresh. ``` -------------------------------- ### Swap Tokens on Raydium Source: https://docs.raydium.io/raydium/~/changes/RaVY5reeE9b0iaInst59/traders This guide explains the process of swapping tokens on Raydium. It details connecting a wallet, selecting 'From' and 'To' tokens, entering the amount, and executing the swap. It also highlights the importance of understanding Price Impact and Minimum Received for efficient trading. ```English 1. Navigate to Swap using the tabs at the of the app, then connect your wallet. 2. Next, select from the drop-down the tokens you want to swap. For this example, we'll be swapping **From** SOL **To** USDC. 3. Enter the amount of tokens you wish to swap. Finally, click Swap! 4. Shortly after the transaction is confirmed you should be able to see your new balance, although this can sometimes take a few seconds to refresh. Pay close attention to Price Impact and remember to check 'Minimum Received' when executing large swaps or when swapping in a low liquidity pool. **Minimum Received** is the least amount of tokens a user will receive on a trade. **Price Impact** is the difference between the market price and the estimated execution price based on the size of the trade. **Slippage Tolerance** is the maximum difference between a user's estimated price and execution price. You can access this parameter both by clicking "settings" on the navigation tab and "more information" on the swap interface. ``` -------------------------------- ### Install LaunchLab TypeScript SDK Source: https://docs.raydium.io/raydium/pool-creation/launchlab/launchlab-typescript-sdk Installs the LaunchLab TypeScript SDK using Yarn. This SDK provides tools for interacting with LaunchLab bonding curves, enabling the creation of platform configurations and bonding curves with custom settings and fee structures. ```bash $ yarn add @raydium-io/raydium-sdk-v2 ``` -------------------------------- ### Selling Digital Assets on Raydium.io Source: https://docs.raydium.io/raydium/getting-started/spl-wallets/buying-and-selling-digital-assets Guide on how to sell digital assets through Raydium.io using the Moonpay off-ramping service. This process requires connecting a wallet and accessing the off-ramping feature. ```English To sell digital assets on Raydium, connect your wallet in the top right corner, then click on your wallet, and finally click 'off-ramping with Moonpay'. How-to-sell with Moonpay: https://support.moonpay.com/customers/docs/how-can-i-sell-cryptocurrency-using-moonpay ``` -------------------------------- ### LaunchLab TypeScript SDK Source: https://docs.raydium.io/raydium/traders/raydium-perps/trading-basics Information about the LaunchLab TypeScript SDK, likely used for creating and managing tokens or projects within the Raydium ecosystem. Specific functionalities or usage examples are not provided in this text. ```TypeScript // LaunchLab TypeScript SDK // Specific code examples or functionalities are not detailed in the provided text. ``` -------------------------------- ### Get Swap Quote from Raydium API Source: https://docs.raydium.io/raydium/traders/trade-api Fetches a swap quote from the Raydium API for a specified token swap. This involves making a GET request to the compute/swap-base-in endpoint with relevant parameters. ```javascript const { data: swapResponse } = await axios.get( `${API_URLS.SWAP_HOST}/compute/swap-base-in?inputMint=${inputMint}&outputMint=${outputMint}&amount=${amount}&slippageBps=${slippage * 100}&txVersion=${txVersion}` ) // Use the URL xxx/swap-base-in or xxx/swap-base-out to define the swap type. ``` -------------------------------- ### Creating an Ecosystem Farm - Step 1 Source: https://docs.raydium.io/raydium/~/changes/RaVY5reeE9b0iaInst59/pool-creation/creating-a-standard-amm-pool/creating-an-ecosystem-farm This snippet outlines the first step in creating an ecosystem farm on Raydium: connecting a wallet and selecting the target liquidity pool. It emphasizes the importance of linking the farm to a valid AMM ID and verifying the pool's TVL. ```text 1: Connect wallet and choose target liquidity pool Navigate to the farms' page and click “Create Farm.” Ensure your wallet is connected. Search for the liquidity pool by name or paste the AMM ID. Verify the pool TVL. ``` -------------------------------- ### Get Quote Parameters for Raydium Trade API Source: https://docs.raydium.io/raydium/traders/trade-api This section details the parameters required to get quote information for a token swap using the Raydium Trade API. It includes input/output token mint addresses, the amount to swap (considering decimals), and slippage tolerance. ```json { "inputMint": "string", "outputMint": "string", "amount": "number", "slippageBps": "number" } ``` -------------------------------- ### Calculate Farm APR Example Source: https://docs.raydium.io/raydium/updates/archive/creating-an-openbook-amm-pool/creating-an-ecosystem-farm This example demonstrates how to calculate the Annual Percentage Rate (APR) for a farm based on daily rewards and the total value locked (TVL) in the liquidity pool. ```text ($500 rewards per day/$100,000 in liquidity)*365 days = 183% APR ``` -------------------------------- ### LaunchLab TypeScript SDK for Raydium Source: https://docs.raydium.io/raydium/pool-creation/creating-a-clmm-pool-and-farm This section mentions the LaunchLab TypeScript SDK, suggesting a programmatic way to interact with Raydium's features, likely for creating tokens or managing liquidity. Specific code examples are not provided in this text. ```TypeScript // LaunchLab TypeScript SDK is mentioned as a tool for creating tokens and managing farms. // Specific code examples are not available in the provided text. ``` -------------------------------- ### RAY Staking Guide Source: https://docs.raydium.io/raydium/protocol/the-ray-token/stake-ray This section provides a step-by-step guide on how to stake RAY tokens on the Raydium platform. It covers the process from entering the amount to stake to approving the transaction and viewing rewards. It also explains how to unstake tokens. ```English 1. To stake your RAY tokens, navigate to the staking section of the Raydium platform. 2. Enter the amount of tokens you wish to stake, then click 'Stake' and then approve the transaction. 3. You should now see the balance of your staked tokens, as well as your pending rewards. If you want to unstake, simply click the '-' button. That's it! You're now staking on Raydium! ``` -------------------------------- ### Initialize LaunchLab SDK Source: https://docs.raydium.io/raydium/pool-creation/launchlab/launchlab-typescript-sdk Initializes the LaunchLab SDK by importing necessary components from the raydium-sdk-v2 library. This includes program IDs, utility functions, and data structures for interacting with Solana programs. ```typescript import { TxVersion, DEV_LAUNCHPAD_PROGRAM, printSimulate, getPdaLaunchpadPoolId, Curve, PlatformConfig, LAUNCHPAD_PROGRAM, } from'@raydium-io/raydium-sdk-v2' import { initSdk } from'../config' import BN from'bn.js' import { PublicKey } from'@solana/web3.js' import { NATIVE_MINT } from'@solana/spl-token' import Decimal from'decimal.js' ``` -------------------------------- ### LaunchLab TypeScript SDK for Token Creation Source: https://docs.raydium.io/raydium/getting-started/best-practices This section details the LaunchLab TypeScript SDK, a tool for creating tokens and managing their distribution on the Raydium platform. It likely includes functions for token minting, managing creator fees, and earning referral rewards. ```TypeScript // Example usage of LaunchLab TypeScript SDK (hypothetical) import { LaunchLabClient } from '@raydium/launchlab-sdk'; async function createToken() { const client = new LaunchLabClient('YOUR_API_KEY'); const tokenDetails = { name: 'MyToken', symbol: 'MTK', supply: 1000000, decimals: 6, creatorFeePercentage: 1.5 }; const newToken = await client.createToken(tokenDetails); console.log('Token created:', newToken); } ``` -------------------------------- ### APR Calculation Example Source: https://docs.raydium.io/raydium/~/changes/RaVY5reeE9b0iaInst59/pool-creation/creating-a-standard-amm-pool/creating-an-ecosystem-farm This example demonstrates how to calculate the Annual Percentage Rate (APR) for a farm based on daily rewards and the total value locked (TVL) in the liquidity pool. It highlights that APR is influenced by reward amounts, token prices, and liquidity levels. ```text ($500 rewards per day/$100,000 in liquidity)*365 days = 183% APR ``` -------------------------------- ### LaunchLab TypeScript SDK for Token Creation Source: https://docs.raydium.io/raydium/getting-started/spl-wallets/bridging-assets Information on the LaunchLab TypeScript SDK, which is used for creating tokens and managing associated functionalities like referral fees and creator fee shares within the Raydium ecosystem. -------------------------------- ### Raydium Pool Creation - Confirm and Initialize Source: https://docs.raydium.io/raydium/updates/archive/creating-an-openbook-amm-pool Describes the process of confirming and initializing a liquidity pool on Raydium after creating the OpenBook market. This involves inputting the Market ID, setting the starting price, initial liquidity, and start time, followed by approving two transactions. -------------------------------- ### Create a Token with LaunchLab TypeScript SDK Source: https://docs.raydium.io/raydium/liquidity-providers This section details how to create a token using the LaunchLab TypeScript SDK, likely for launching new projects on the Raydium platform. It may involve setting up the SDK, defining token parameters, and executing the creation process. ```typescript import { LaunchLab } from '@raydium/launchlab-sdk'; async function createToken() { const sdk = new LaunchLab({ // SDK initialization options }); const tokenDetails = { name: 'MyToken', symbol: 'MTK', supply: 1000000, // other token parameters }; try { const tx = await sdk.createToken(tokenDetails); console.log('Token creation transaction:', tx); } catch (error) { console.error('Error creating token:', error); } } ``` -------------------------------- ### APR Calculation Example Source: https://docs.raydium.io/raydium/pool-creation/creating-a-standard-amm-pool/creating-an-ecosystem-farm This snippet provides an example of how to calculate the Annual Percentage Rate (APR) for a farm. APR is calculated by dividing the total value of rewards distributed over a period by the total value of liquidity in the pool, and then annualizing the result. Changes in liquidity or reward token price will affect the APR. ```text APR Calculation Example: ($500 rewards per day / $100,000 in liquidity) * 365 days = 183% APR ``` -------------------------------- ### LaunchLab TypeScript SDK for Raydium Source: https://docs.raydium.io/raydium/liquidity-providers/liquidity-pools This section details the LaunchLab TypeScript SDK, a tool for developers to integrate with Raydium's ecosystem, likely for creating new tokens or managing launchpad events. ```TypeScript // Example usage of LaunchLab TypeScript SDK (conceptual) // import { RaydiumLaunchpad } from '@raydium/launchpad-sdk'; // async function createTokenOffering() { // const sdk = new RaydiumLaunchpad({ // apiKey: 'YOUR_API_KEY', // network: 'mainnet' // }); // const offeringDetails = { // tokenName: 'MyNewToken', // symbol: 'MNT', // supply: 1000000, // // ... other offering parameters // }; // await sdk.createOffering(offeringDetails); // console.log('Token offering created successfully!'); // } ``` -------------------------------- ### APR Calculation Example Source: https://docs.raydium.io/raydium/pool-creation/creating-a-constant-product-pool/creating-an-ecosystem-farm This snippet provides an example of how to calculate the Annual Percentage Rate (APR) for a farm. APR is calculated by dividing the total value of rewards distributed over a period by the total value of liquidity in the pool, and then annualizing the result. Changes in liquidity or reward token price will affect the APR. ```text APR Calculation Example: ($500 rewards per day / $100,000 in liquidity) * 365 days = 183% APR ``` -------------------------------- ### Standard AMM Pool Creation - CLI Source: https://docs.raydium.io/raydium/pool-creation/pool-creation-faq This describes the process of creating a Standard AMM Pool using the Command Line Interface (CLI). It highlights the use of OpenBook market IDs for market making and warns about non-refundable fees associated with market creation. ```Shell # Example CLI command for creating a Standard AMM Pool # This is a conceptual example, actual command may vary based on the CLI tool. # raydium-cli create-pool --base-token --quote-token --initial-liquidity --openbook-market-id ``` -------------------------------- ### Deserialize Transaction Data Source: https://docs.raydium.io/raydium/traders/trade-api Deserializes the transaction data received from the Raydium API into Solana Transaction or VersionedTransaction objects, preparing them for signing and execution. ```javascript const allTxBuf = swapTransactions.data.map((tx) => Buffer.from(tx.transaction, 'base64')) const allTransactions = allTxBuf.map((txBuf) => isV0Tx ? VersionedTransaction.deserialize(txBuf) : Transaction.from(txBuf) ) console.log(`total ${allTransactions.length} transactions`, swapTransactions) ``` -------------------------------- ### Create Token with JustSendit Mode - Raydium LaunchLab Source: https://docs.raydium.io/raydium/pool-creation/launchlab/create-a-token This guide explains how to launch a token using Raydium's JustSendit mode. It involves filling in basic token information, adding an image, signing with a wallet, and optionally setting an initial buy. Tokens created this way will graduate to a Raydium AMM pool when the bonding curve reaches 85 SOL. ```text 1. Fill in the Name and Ticker. A description is optional. 2. Add an image or GIF. A square image of at least 128 x 128 is suggested. File size must not exceed 5mb. Optional: Click "Socials & more" to add links to social media or a website. 3. Click "Sign-in to Create token" to sign a message and confirm your wallet as the creating wallet. Then click "Create Token". 4. **Initial buy** : After clicking "Create Token" you'll see a pop-up for an initial buy of your token. This is optional but can discourage snipers and allows you to secure the first buy. 5. Click confirm, and BOOM - your token is now live and can be traded on the bonding curve! Your token will graduate to a Raydium AMM pool when the curve reaches 85 SOL! Tip: Click the "Share" button on the token page to earn referral fees from users that trade from your link! ``` -------------------------------- ### Swap Tokens on Raydium Source: https://docs.raydium.io/raydium/traders/swapping This section details the process of swapping tokens on the Raydium platform. It guides users through connecting their wallet, selecting the 'from' and 'to' tokens, entering the desired amount, and executing the swap. It also highlights key parameters like Price Impact and Minimum Received. ```English 1. Navigate to Swap using the navigation menu at the top of the app, then connect your wallet. 2. Next, select from the drop-down the tokens you want to swap or paste the token mint address. For this example, we'll be swapping **From** SOL **To** RAY. 3. Enter the amount of tokens you want to swap or receive. Finally, click Swap! 4. Shortly after the transaction is confirmed you should be able to see your new balance, although this can sometimes take a few seconds to refresh. ``` -------------------------------- ### LaunchLab TypeScript SDK Source: https://docs.raydium.io/raydium/pool-creation Information about the LaunchLab TypeScript SDK, likely used for programmatic interaction with the LaunchLab platform for token creation and management. ```TypeScript import { LaunchLabClient } from '@raydium/launchlab-sdk'; // Example usage (conceptual) async function createToken() { const client = new LaunchLabClient('YOUR_RPC_URL'); const tokenDetails = { name: 'MyToken', symbol: 'MTK', supply: 1000000, decimals: 6 }; const tx = await client.createToken(tokenDetails); console.log('Token creation transaction:', tx); } ``` -------------------------------- ### Real-time Pool Creation Monitoring Source: https://docs.raydium.io/raydium/protocol/developers/api Example TypeScript code for monitoring new AMM pool creations in real-time using gRPC. This is recommended for development purposes over the V3 API. ```typescript https://github.com/raydium-io/raydium-sdk-V2-demo/blob/master/src/grpc/subNewAmmPool.ts ``` -------------------------------- ### Sign and Execute Transactions (Versioned) Source: https://docs.raydium.io/raydium/traders/trade-api Signs and confirms versioned Solana transactions. This method handles VersionedTransactions, signs them with the owner's keypair, sends them, and confirms their execution. ```javascript else { for (const tx of allTransactions) { idx++ const transaction = tx as VersionedTransaction transaction.sign([owner]) const txId = await connection.sendTransaction(tx as VersionedTransaction, { skipPreflight: true }) const { lastValidBlockHeight, blockhash } = await connection.getLatestBlockhash({ commitment: 'finalized', }) console.log(`${idx} transaction sending..., txId: ${txId}`) await connection.confirmTransaction( { blockhash, lastValidBlockHeight, signature: txId, }, 'confirmed' ) console.log(`${idx} transaction confirmed`) } } ```