index.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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, TransactionExecutor } 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,
  40. SNIPE_LIST_REFRESH_INTERVAL,
  41. TRANSACTION_EXECUTOR,
  42. WARP_FEE,
  43. FILTER_CHECK_INTERVAL,
  44. FILTER_CHECK_DURATION,
  45. CONSECUTIVE_FILTER_MATCHES,
  46. } from './helpers';
  47. import { version } from './package.json';
  48. import { WarpTransactionExecutor } from './transactions/warp-transaction-executor';
  49. const connection = new Connection(RPC_ENDPOINT, {
  50. wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
  51. commitment: COMMITMENT_LEVEL,
  52. });
  53. function printDetails(wallet: Keypair, quoteToken: Token, bot: Bot) {
  54. logger.info(`
  55. .. :-===++++-
  56. .-==+++++++- =+++++++++-
  57. ..:::--===+=.=: .+++++++++++:=+++++++++:
  58. .==+++++++++++++++=:+++: .+++++++++++.=++++++++-.
  59. .-+++++++++++++++=:=++++- .+++++++++=:.=+++++-::-.
  60. -:+++++++++++++=:+++++++- .++++++++-:- =+++++=-:
  61. -:++++++=++++=:++++=++++= .++++++++++- =+++++:
  62. -:++++-:=++=:++++=:-+++++:+++++====--:::::::.
  63. ::=+-:::==:=+++=::-:--::::::::::---------::.
  64. ::-: .::::::::. --------:::..
  65. :- .:.-:::.
  66. WARP DRIVE ACTIVATED 🚀🐟
  67. Made with ❤️ by humans.
  68. Version: ${version}
  69. `);
  70. const botConfig = bot.config;
  71. logger.info('------- CONFIGURATION START -------');
  72. logger.info(`Wallet: ${wallet.publicKey.toString()}`);
  73. logger.info('- Bot -');
  74. logger.info(`Using warp: ${bot.isWarp}`);
  75. if (bot.isWarp) {
  76. logger.info(`Warp fee: ${WARP_FEE}`);
  77. } else {
  78. logger.info(`Compute Unit limit: ${botConfig.unitLimit}`);
  79. logger.info(`Compute Unit price (micro lamports): ${botConfig.unitPrice}`);
  80. }
  81. logger.info(`Single token at the time: ${botConfig.oneTokenAtATime}`);
  82. logger.info(`Pre load existing markets: ${PRE_LOAD_EXISTING_MARKETS}`);
  83. logger.info(`Cache new markets: ${CACHE_NEW_MARKETS}`);
  84. logger.info(`Log level: ${LOG_LEVEL}`);
  85. logger.info('- Buy -');
  86. logger.info(`Buy amount: ${botConfig.quoteAmount.toFixed()} ${botConfig.quoteToken.name}`);
  87. logger.info(`Auto buy delay: ${botConfig.autoBuyDelay} ms`);
  88. logger.info(`Max buy retries: ${botConfig.maxBuyRetries}`);
  89. logger.info(`Buy amount (${quoteToken.symbol}): ${botConfig.quoteAmount.toFixed()}`);
  90. logger.info(`Buy slippage: ${botConfig.buySlippage}%`);
  91. logger.info('- Sell -');
  92. logger.info(`Auto sell: ${AUTO_SELL}`);
  93. logger.info(`Auto sell delay: ${botConfig.autoSellDelay} ms`);
  94. logger.info(`Max sell retries: ${botConfig.maxSellRetries}`);
  95. logger.info(`Sell slippage: ${botConfig.sellSlippage}%`);
  96. logger.info(`Price check interval: ${botConfig.priceCheckInterval} ms`);
  97. logger.info(`Price check duration: ${botConfig.priceCheckDuration} ms`);
  98. logger.info(`Take profit: ${botConfig.takeProfit}%`);
  99. logger.info(`Stop loss: ${botConfig.stopLoss}%`);
  100. logger.info('- Filters -');
  101. logger.info(`Snipe list: ${botConfig.useSnipeList}`);
  102. logger.info(`Snipe list refresh interval: ${SNIPE_LIST_REFRESH_INTERVAL} ms`);
  103. logger.info(`Filter check interval: ${botConfig.filterCheckInterval} ms`);
  104. logger.info(`Filter check duration: ${botConfig.filterCheckDuration} ms`);
  105. logger.info(`Consecutive filter matches: ${botConfig.consecutiveMatchCount} ms`);
  106. logger.info(`Check renounced: ${botConfig.checkRenounced}`);
  107. logger.info(`Check burned: ${botConfig.checkBurned}`);
  108. logger.info(`Min pool size: ${botConfig.minPoolSize.toFixed()}`);
  109. logger.info(`Max pool size: ${botConfig.maxPoolSize.toFixed()}`);
  110. logger.info('------- CONFIGURATION END -------');
  111. logger.info('Bot is running! Press CTRL + C to stop it.');
  112. }
  113. const runListener = async () => {
  114. logger.level = LOG_LEVEL;
  115. logger.info('Bot is starting...');
  116. const marketCache = new MarketCache(connection);
  117. const poolCache = new PoolCache();
  118. let txExecutor: TransactionExecutor;
  119. switch (TRANSACTION_EXECUTOR) {
  120. case 'warp': {
  121. txExecutor = new WarpTransactionExecutor(WARP_FEE);
  122. break;
  123. }
  124. default: {
  125. txExecutor = new DefaultTransactionExecutor(connection);
  126. break;
  127. }
  128. }
  129. const wallet = getWallet(PRIVATE_KEY.trim());
  130. const quoteToken = getToken(QUOTE_MINT);
  131. const botConfig = <BotConfig>{
  132. wallet,
  133. quoteAta: getAssociatedTokenAddressSync(quoteToken.mint, wallet.publicKey),
  134. checkRenounced: CHECK_IF_MINT_IS_RENOUNCED,
  135. checkBurned: CHECK_IF_BURNED,
  136. minPoolSize: new TokenAmount(quoteToken, MIN_POOL_SIZE, false),
  137. maxPoolSize: new TokenAmount(quoteToken, MAX_POOL_SIZE, false),
  138. quoteToken,
  139. quoteAmount: new TokenAmount(quoteToken, QUOTE_AMOUNT, false),
  140. oneTokenAtATime: ONE_TOKEN_AT_A_TIME,
  141. useSnipeList: USE_SNIPE_LIST,
  142. autoSell: AUTO_SELL,
  143. autoSellDelay: AUTO_SELL_DELAY,
  144. maxSellRetries: MAX_SELL_RETRIES,
  145. autoBuyDelay: AUTO_BUY_DELAY,
  146. maxBuyRetries: MAX_BUY_RETRIES,
  147. unitLimit: COMPUTE_UNIT_LIMIT,
  148. unitPrice: COMPUTE_UNIT_PRICE,
  149. takeProfit: TAKE_PROFIT,
  150. stopLoss: STOP_LOSS,
  151. buySlippage: BUY_SLIPPAGE,
  152. sellSlippage: SELL_SLIPPAGE,
  153. priceCheckInterval: PRICE_CHECK_INTERVAL,
  154. priceCheckDuration: PRICE_CHECK_DURATION,
  155. filterCheckInterval: FILTER_CHECK_INTERVAL,
  156. filterCheckDuration: FILTER_CHECK_DURATION,
  157. consecutiveMatchCount: CONSECUTIVE_FILTER_MATCHES,
  158. };
  159. const bot = new Bot(connection, marketCache, poolCache, txExecutor, botConfig);
  160. const valid = await bot.validate();
  161. if (!valid) {
  162. logger.info('Bot is exiting...');
  163. process.exit(1);
  164. }
  165. if (PRE_LOAD_EXISTING_MARKETS) {
  166. await marketCache.init({ quoteToken });
  167. }
  168. const runTimestamp = Math.floor(new Date().getTime() / 1000);
  169. const listeners = new Listeners(connection);
  170. await listeners.start({
  171. walletPublicKey: wallet.publicKey,
  172. quoteToken,
  173. autoSell: AUTO_SELL,
  174. cacheNewMarkets: CACHE_NEW_MARKETS,
  175. });
  176. listeners.on('market', (updatedAccountInfo: KeyedAccountInfo) => {
  177. const marketState = MARKET_STATE_LAYOUT_V3.decode(updatedAccountInfo.accountInfo.data);
  178. marketCache.save(updatedAccountInfo.accountId.toString(), marketState);
  179. });
  180. listeners.on('pool', async (updatedAccountInfo: KeyedAccountInfo) => {
  181. const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(updatedAccountInfo.accountInfo.data);
  182. const poolOpenTime = parseInt(poolState.poolOpenTime.toString());
  183. const exists = await poolCache.get(poolState.baseMint.toString());
  184. if (!exists && poolOpenTime > runTimestamp) {
  185. poolCache.save(updatedAccountInfo.accountId.toString(), poolState);
  186. await bot.buy(updatedAccountInfo.accountId, poolState);
  187. }
  188. });
  189. listeners.on('wallet', async (updatedAccountInfo: KeyedAccountInfo) => {
  190. const accountData = AccountLayout.decode(updatedAccountInfo.accountInfo.data);
  191. if (accountData.mint.equals(quoteToken.mint)) {
  192. return;
  193. }
  194. await bot.sell(updatedAccountInfo.accountId, accountData);
  195. });
  196. printDetails(wallet, quoteToken, bot);
  197. };
  198. runListener();