https://docs.shyft.to/ You acting like a Professional developer typescript on trading bot rayduim. You have access to all documentation Rayduim for building snipper bot . Your goal is to create the entire process skeleton logic implemented for final production script.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Ask user to input ticker like ELONSPLtokenThescriptcheckWhennewELON LP SPL token on rayduim is create inside list the first second he appears with less the 1second old created, immediately buy 0.001SOL one time quickly.(Do not use others old ticker only latest created. It's required to wait until the ticker appears and immediately buy)
Wait 2 min and Sell 100% all SPL Token acquired before.
Restart Loop to ask
Logic swap , logic quantity token , logic monitoring.Et pour un environnement de production réel, rédiger les structures nécessaires pour l'implémentation de la logique de tout les composants nécessaires, en mémoire. Maintenant remettre de l'ordre dans tes idées. Suis mon objectif final. Utilisation de toutes ta connaissance et de tout les token en ta possession . Sois calme, respiration profonde, tu es prêt pour l'écriture final de la version production en utilisant toutes les informations depuis le début.
please, elaborate complete Implementation and expand the utility functions referenced in all above. This a récapitulatif : You acting like a Professional developer typescript on trading bot rayduim. You have access to all documentation Rayduim Shyft for building snipper bot . Your goal is to create the entire process skeleton logic implemented for final production script. For example what the script do : Ask user to input ticker like ELONSPLtoken.ThescriptcheckWhennewELON LP SPL token on rayduim is create inside list the first second he appears New Pool Liquidity List with less the 1second old created, immediately buy 0.001SOL one time quickly.(Do not use others old ticker only latest created. It's required to wait until the ticker appears and immediately buy)
Wait 2 min and Sell 100% all SPL Token acquired before.
Restart Loop to ask
Logic swap , logic quantity token , logic monitoring.Et pour un environnement de production réel, rédiger les structures nécessaires pour l'implémentation de la logique de tout les composants nécessaires, en mémoire. Maintenant remettre de l'ordre dans tes idées. Suis mon objectif final. Utilisation de toutes ta connaissance et de tout les token en ta possession . Sois calme, respiration profonde, tu es prêt pour l'écriture final de la version production en utilisant toutes les informations depuis le début.
Assistant
To develop a production-ready TypeScript trading bot for Raydium that monitors newly created liquidity pools and executes trades based on user input, follow this structured approach:
1. Project Setup
Initialize the Project: Create a new TypeScript project and set up the necessary configurations.
Install Dependencies: Install essential packages such as @solana/web3.js for Solana blockchain interactions and @raydium-io/raydium-sdk-v2 for Raydium-specific functionalities.
Prompt for Token Ticker: Implement a function to prompt the user for the desired SPL token ticker (e.g., $ELON).
import * as readline from 'readline';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function getUserInput(query: string): Promise<string> {
return new Promise((resolve) => {
rl.question(query, (input) => {
resolve(input);
rl.close();
});
});
}
async function main() {
const ticker = await getUserInput('Enter the SPL token ticker (e.g., $ELON): ');
console.log(`Monitoring for new liquidity pools for ${ticker}...`);
// Proceed with monitoring and trading logic
}
main();
3. Monitoring New Liquidity Pools
Set Up a WebSocket Connection: Utilize a WebSocket to listen for new liquidity pool creations on Raydium. This ensures real-time monitoring and immediate response to new pools.
import { Connection, PublicKey } from '@solana/web3.js';
import { Raydium } from '@raydium-io/raydium-sdk-v2';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const raydium = await Raydium.load({ connection });
async function monitorNewPools(ticker: string) {
const tokenList = await raydium.api.getTokenList();
const tokenInfo = tokenList.find(token => token.symbol === ticker);
if (!tokenInfo) {
console.log(`Token ${ticker} not found.`);
return;
}
const tokenMint = new PublicKey(tokenInfo.mint);
// Subscribe to account changes for the Raydium AMM program
connection.onProgramAccountChange(
new PublicKey('AMM_PROGRAM_ID'), // Replace with actual Raydium AMM program ID
async (accountInfo) => {
// Parse accountInfo to identify new pools
// Check if the new pool involves the tokenMint
// If so, proceed to execute the buy order
},
'confirmed'
);
}
monitorNewPools('$ELON');
4. Executing Trades
Buy Tokens: Once a new liquidity pool for the specified token is detected, execute a buy order of 0.001 SOL worth of the token.
import { Keypair, Transaction, SystemProgram } from '@solana/web3.js';
import { createAssociatedTokenAccountInstruction, createTransferInstruction } from '@solana/spl-token';
async function buyToken(userKeypair: Keypair, tokenMint: PublicKey) {
const transaction = new Transaction();
// Create associated token account for the user if it doesn't exist
const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
userKeypair,
tokenMint,
userKeypair.publicKey
);
// Construct the swap instruction
const swapInstruction = createSwapInstruction(
userKeypair.publicKey,
associatedTokenAccount.address,
tokenMint,
0.001 * LAMPORTS_PER_SOL // Amount in lamports
);
transaction.add(swapInstruction);
// Sign and send the transaction
const signature = await sendAndConfirmTransaction(connection, transaction, [userKeypair]);
console.log(`Transaction successful with signature: ${signature}`);
}
Sell Tokens: After a 2-minute delay, sell all acquired tokens.
async function sellToken(userKeypair: Keypair, tokenMint: PublicKey) {
// Wait for 2 minutes
await new Promise(resolve => setTimeout(resolve, 2 * 60 * 1000));
const transaction = new Transaction();
// Fetch the user's token account balance
const tokenAccount = await getAssociatedTokenAccount(
connection,
userKeypair.publicKey,
tokenMint
);
const balance = await connection.getTokenAccountBalance(tokenAccount.address);
// Construct the swap instruction to sell the tokens
const swapInstruction = createSwapInstruction(
userKeypair.publicKey,
tokenAccount.address,
tokenMint,
balance.value.amount // Amount to sell
);
transaction.add(swapInstruction);
// Sign and send the transaction
const signature = await sendAndConfirmTransaction(connection, transaction, [userKeypair]);
console.log(`Sell transaction successful with signature: ${signature}`);
}
5. Utility Functions
Create Swap Instruction: Construct the instruction for swapping tokens on Raydium.
function createSwapInstruction(
userPublicKey: PublicKey,
userTokenAccount: PublicKey,
tokenMint: PublicKey,
amount: number
): TransactionInstruction {
// Implement the logic to create a swap instruction using Raydium SDK
// This involves specifying the pool, input/output accounts, and the amount
}
Get or Create Associated Token Account: Ensure the user has an associated token account for the specified token.
async function getOrCreateAssociatedTokenAccount(
connection: Connection,
payer: Keypair,
mint: PublicKey,
owner: PublicKey
): Promise<account> {
// Implement the logic to get or create the associated token account
}
6. Error Handling and Logging
Implement Robust Error Handling: Ensure that all asynchronous operations are wrapped in try-catch blocks to handle potential errors gracefully.
Logging: Incorporate logging mechanisms to track the bot's operations and any issues that arise.