index.ts 8.0 KB

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