index.ts 8.0 KB

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