index.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { MarketCache, PoolCache } from './cache';
  2. import { Listeners } from './listeners';
  3. import { Connection, KeyedAccountInfo, Keypair } from '@solana/web3.js';
  4. import { LIQUIDITY_STATE_LAYOUT_V4, MARKET_STATE_LAYOUT_V3, Token, TokenAmount } from '@raydium-io/raydium-sdk';
  5. import { AccountLayout, getAssociatedTokenAddressSync } from '@solana/spl-token';
  6. import { Bot, BotConfig } from './bot';
  7. import { DefaultTransactionExecutor } from './transactions';
  8. import {
  9. getToken,
  10. getWallet,
  11. logger,
  12. COMMITMENT_LEVEL,
  13. RPC_ENDPOINT,
  14. RPC_WEBSOCKET_ENDPOINT,
  15. PRE_LOAD_EXISTING_MARKETS,
  16. LOG_LEVEL,
  17. CHECK_IF_MINT_IS_RENOUNCED,
  18. CHECK_IF_BURNED,
  19. QUOTE_MINT,
  20. MAX_POOL_SIZE,
  21. MIN_POOL_SIZE,
  22. QUOTE_AMOUNT,
  23. PRIVATE_KEY,
  24. USE_SNIPE_LIST,
  25. ONE_TOKEN_AT_A_TIME,
  26. AUTO_SELL_DELAY,
  27. MAX_SELL_RETRIES,
  28. AUTO_SELL,
  29. MAX_BUY_RETRIES,
  30. AUTO_BUY_DELAY,
  31. COMPUTE_UNIT_LIMIT,
  32. COMPUTE_UNIT_PRICE,
  33. CACHE_NEW_MARKETS,
  34. TAKE_PROFIT,
  35. STOP_LOSS,
  36. BUY_SLIPPAGE,
  37. SELL_SLIPPAGE,
  38. PRICE_CHECK_DURATION,
  39. PRICE_CHECK_INTERVAL, SNIPE_LIST_REFRESH_INTERVAL,
  40. } from './helpers';
  41. import { version } from './package.json';
  42. const connection = new Connection(RPC_ENDPOINT, {
  43. wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
  44. commitment: COMMITMENT_LEVEL,
  45. });
  46. function printDetails(wallet: Keypair, quoteToken: Token, botConfig: BotConfig) {
  47. logger.info(`
  48. .. :-===++++-
  49. .-==+++++++- =+++++++++-
  50. ..:::--===+=.=: .+++++++++++:=+++++++++:
  51. .==+++++++++++++++=:+++: .+++++++++++.=++++++++-.
  52. .-+++++++++++++++=:=++++- .+++++++++=:.=+++++-::-.
  53. -:+++++++++++++=:+++++++- .++++++++-:- =+++++=-:
  54. -:++++++=++++=:++++=++++= .++++++++++- =+++++:
  55. -:++++-:=++=:++++=:-+++++:+++++====--:::::::.
  56. ::=+-:::==:=+++=::-:--::::::::::---------::.
  57. ::-: .::::::::. --------:::..
  58. :- .:.-:::.
  59. WARP DRIVE ACTIVATED 🚀🐟
  60. Made with ❤️ by humans.
  61. Version: ${version}
  62. `);
  63. logger.info('------- CONFIGURATION START -------');
  64. logger.info(`Wallet: ${wallet.publicKey.toString()}`);
  65. logger.info('- Bot -');
  66. logger.info(`Compute Unit limit: ${botConfig.unitLimit}`);
  67. logger.info(`Compute Unit price (micro lamports): ${botConfig.unitPrice}`);
  68. logger.info(`Single token at the time: ${botConfig.oneTokenAtATime}`);
  69. logger.info(`Pre load existing markets: ${PRE_LOAD_EXISTING_MARKETS}`);
  70. logger.info(`Cache new markets: ${CACHE_NEW_MARKETS}`);
  71. logger.info(`Log level: ${LOG_LEVEL}`);
  72. logger.info('- Buy -');
  73. logger.info(`Buy amount: ${botConfig.quoteAmount.toFixed()} ${botConfig.quoteToken.name}`);
  74. logger.info(`Auto buy delay: ${botConfig.autoBuyDelay} ms`);
  75. logger.info(`Max buy retries: ${botConfig.maxBuyRetries}`);
  76. logger.info(`Buy amount (${quoteToken.symbol}): ${botConfig.quoteAmount.toFixed()}`);
  77. logger.info(`Buy slippage: ${botConfig.buySlippage}%`);
  78. logger.info('- Sell -');
  79. logger.info(`Auto sell: ${AUTO_SELL}`);
  80. logger.info(`Auto sell delay: ${botConfig.autoSellDelay} ms`);
  81. logger.info(`Max sell retries: ${botConfig.maxSellRetries}`);
  82. logger.info(`Sell slippage: ${botConfig.sellSlippage}%`);
  83. logger.info(`Price check interval: ${botConfig.priceCheckInterval} ms`);
  84. logger.info(`Price check duration: ${botConfig.priceCheckDuration} ms`);
  85. logger.info(`Take profit: ${botConfig.takeProfit}%`);
  86. logger.info(`Stop loss: ${botConfig.stopLoss}%`);
  87. logger.info('- Filters -');
  88. logger.info(`Snipe list: ${botConfig.useSnipeList}`);
  89. logger.info(`Snipe list refresh interval: ${SNIPE_LIST_REFRESH_INTERVAL} ms`);
  90. logger.info(`Check renounced: ${botConfig.checkRenounced}`);
  91. logger.info(`Check burned: ${botConfig.checkBurned}`);
  92. logger.info(`Min pool size: ${botConfig.minPoolSize.toFixed()}`);
  93. logger.info(`Max pool size: ${botConfig.maxPoolSize.toFixed()}`);
  94. logger.info('------- CONFIGURATION END -------');
  95. logger.info('Bot is running! Press CTRL + C to stop it.');
  96. }
  97. const runListener = async () => {
  98. logger.level = LOG_LEVEL;
  99. logger.info('Bot is starting...');
  100. const marketCache = new MarketCache(connection);
  101. const poolCache = new PoolCache();
  102. const txExecutor = new DefaultTransactionExecutor(connection);
  103. const wallet = getWallet(PRIVATE_KEY.trim());
  104. const quoteToken = getToken(QUOTE_MINT);
  105. const botConfig = <BotConfig>{
  106. wallet,
  107. quoteAta: getAssociatedTokenAddressSync(quoteToken.mint, wallet.publicKey),
  108. checkRenounced: CHECK_IF_MINT_IS_RENOUNCED,
  109. checkBurned: CHECK_IF_BURNED,
  110. minPoolSize: new TokenAmount(quoteToken, MIN_POOL_SIZE, false),
  111. maxPoolSize: new TokenAmount(quoteToken, MAX_POOL_SIZE, false),
  112. quoteToken,
  113. quoteAmount: new TokenAmount(quoteToken, QUOTE_AMOUNT, false),
  114. oneTokenAtATime: ONE_TOKEN_AT_A_TIME,
  115. useSnipeList: USE_SNIPE_LIST,
  116. autoSellDelay: AUTO_SELL_DELAY,
  117. maxSellRetries: MAX_SELL_RETRIES,
  118. autoBuyDelay: AUTO_BUY_DELAY,
  119. maxBuyRetries: MAX_BUY_RETRIES,
  120. unitLimit: COMPUTE_UNIT_LIMIT,
  121. unitPrice: COMPUTE_UNIT_PRICE,
  122. takeProfit: TAKE_PROFIT,
  123. stopLoss: STOP_LOSS,
  124. buySlippage: BUY_SLIPPAGE,
  125. sellSlippage: SELL_SLIPPAGE,
  126. priceCheckInterval: PRICE_CHECK_INTERVAL,
  127. priceCheckDuration: PRICE_CHECK_DURATION,
  128. };
  129. const bot = new Bot(connection, marketCache, poolCache, txExecutor, botConfig);
  130. const valid = await bot.validate();
  131. if (!valid) {
  132. logger.info('Bot is exiting...');
  133. process.exit(1);
  134. }
  135. if (PRE_LOAD_EXISTING_MARKETS) {
  136. await marketCache.init({ quoteToken });
  137. }
  138. const runTimestamp = Math.floor(new Date().getTime() / 1000);
  139. const listeners = new Listeners(connection);
  140. await listeners.start({
  141. walletPublicKey: wallet.publicKey,
  142. quoteToken,
  143. autoSell: AUTO_SELL,
  144. cacheNewMarkets: CACHE_NEW_MARKETS,
  145. });
  146. listeners.on('market', (updatedAccountInfo: KeyedAccountInfo) => {
  147. const marketState = MARKET_STATE_LAYOUT_V3.decode(updatedAccountInfo.accountInfo.data);
  148. marketCache.save(updatedAccountInfo.accountId.toString(), marketState);
  149. });
  150. listeners.on('pool', async (updatedAccountInfo: KeyedAccountInfo) => {
  151. const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(updatedAccountInfo.accountInfo.data);
  152. const poolOpenTime = parseInt(poolState.poolOpenTime.toString());
  153. const exists = await poolCache.get(poolState.baseMint.toString());
  154. if (!exists && poolOpenTime > runTimestamp) {
  155. poolCache.save(updatedAccountInfo.accountId.toString(), poolState);
  156. await bot.buy(updatedAccountInfo.accountId, poolState);
  157. }
  158. });
  159. listeners.on('wallet', async (updatedAccountInfo: KeyedAccountInfo) => {
  160. const accountData = AccountLayout.decode(updatedAccountInfo.accountInfo.data);
  161. if (accountData.mint.equals(quoteToken.mint)) {
  162. return;
  163. }
  164. await bot.sell(updatedAccountInfo.accountId, accountData);
  165. });
  166. printDetails(wallet, quoteToken, botConfig);
  167. };
  168. runListener();