8: Best practices

For SDK Users

circle-check

βœ… 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

βœ… Monitor fundraising progress


For Direct Integration

circle-check

βœ… 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

βœ… 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


Security Considerations

circle-exclamation

πŸ”’ 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

circle-info

⚑ Tips to improve performance and reduce latency / RPC cost.

⚑ 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