8: Best practices
For SDK Users
✅ Always follow these checks and protections when using the SDK.
✅ Always check pool status before trading
const poolState = await wendev.getPoolState(tokenMint);
if (poolState.status !== 0) {
throw new Error('Pool not in funding phase');
}✅ Use appropriate slippage tolerance
// High volume/volatile tokens: 2-5%
const slippage = 200; // 2%
// Low volume/stable tokens: 0.5-1%
const slippage = 50; // 0.5%✅ Handle transaction failures gracefully
try {
const signature = await connection.sendRawTransaction(tx.serialize());
await connection.confirmTransaction(signature, 'confirmed');
} catch (error) {
if (error.message.includes('ExceededSlippage')) {
console.error('Price moved too much. Try increasing slippage.');
} else {
console.error('Transaction failed:', error);
}
}✅ Calculate expected output before trading
const expectedTokens = await wendev.getTokensForLamports(tokenMint, amountIn);
console.log('You will receive approximately:', expectedTokens.toString());✅ Monitor fundraising progress
const progress = (poolState.real_quote.toNumber() /
poolState.total_quote_fund_raising.toNumber()) * 100;
if (progress >= 95) {
console.warn('Pool almost fully funded! Migration imminent.');
}For Direct Integration
✅ Recommended checks and practices when integrating directly with the program.
✅ Always derive PDAs correctly - Wrong PDAs cause transaction failures
✅ Verify account ownership - Ensure accounts belong to the correct program
✅ Use idempotent ATA creation - Prevents failures if account exists
createAssociatedTokenAccountIdempotentInstruction(...)✅ Validate pool state - Check status, reserves, and fees before constructing transactions
✅ Test on devnet first - Always test with devnet before mainnet
✅ Handle account size - Pool state is ~500 bytes, ensure sufficient rent
✅ Use transaction simulation - Test transactions before sending
const simulation = await connection.simulateTransaction(transaction);
if (simulation.value.err) {
console.error('Simulation failed:', simulation.value.err);
}Security Considerations
🔒 Security best practices to reduce risk of loss, frontrunning, and misconfiguration.
🔒 Slippage Protection - Always set minAmountOut to prevent frontrunning
🔒 Verify Token Mint - Check token mint matches expected value
🔒 Check Pool Legitimacy - Verify pool creator and configuration
🔒 Private Key Security - Never expose private keys in client-side code
Performance Optimization
⚡ Batch RPC Calls - Use getMultipleAccounts for multiple pool states
⚡ Use WebSockets - Subscribe to account changes instead of polling
⚡ Optimize Commitment Level - Use 'confirmed' for better speed vs. 'finalized'
⚡ Preflight Skip (Carefully) - Skip preflight for faster sends (only if validated)
Last updated
