index.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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('- Snipe list -');
  102. logger.info(`Snipe list: ${botConfig.useSnipeList}`);
  103. logger.info(`Snipe list refresh interval: ${SNIPE_LIST_REFRESH_INTERVAL} ms`);
  104. if (botConfig.useSnipeList) {
  105. logger.info('- Filters -');
  106. logger.info(`Filters are disabled when snipe list is on`);
  107. } else {
  108. logger.info('- Filters -');
  109. logger.info(`Filter check interval: ${botConfig.filterCheckInterval} ms`);
  110. logger.info(`Filter check duration: ${botConfig.filterCheckDuration} ms`);
  111. logger.info(`Consecutive filter matches: ${botConfig.consecutiveMatchCount}`);
  112. logger.info(`Check renounced: ${botConfig.checkRenounced}`);
  113. logger.info(`Check freezable: ${botConfig.checkFreezable}`);
  114. logger.info(`Check burned: ${botConfig.checkBurned}`);
  115. logger.info(`Min pool size: ${botConfig.minPoolSize.toFixed()}`);
  116. logger.info(`Max pool size: ${botConfig.maxPoolSize.toFixed()}`);
  117. }
  118. logger.info('------- CONFIGURATION END -------');
  119. logger.info('Bot is running! Press CTRL + C to stop it.');
  120. }
  121. const runListener = async () => {
  122. logger.level = LOG_LEVEL;
  123. logger.info('Bot is starting...');
  124. const marketCache = new MarketCache(connection);
  125. const poolCache = new PoolCache();
  126. let txExecutor: TransactionExecutor;
  127. switch (TRANSACTION_EXECUTOR) {
  128. case 'warp': {
  129. txExecutor = new WarpTransactionExecutor(WARP_FEE);
  130. break;
  131. }
  132. default: {
  133. txExecutor = new DefaultTransactionExecutor(connection);
  134. break;
  135. }
  136. }
  137. const wallet = getWallet(PRIVATE_KEY.trim());
  138. const quoteToken = getToken(QUOTE_MINT);
  139. const botConfig = <BotConfig>{
  140. wallet,
  141. quoteAta: getAssociatedTokenAddressSync(quoteToken.mint, wallet.publicKey),
  142. checkRenounced: CHECK_IF_MINT_IS_RENOUNCED,
  143. checkFreezable: CHECK_IF_FREEZABLE,
  144. checkBurned: CHECK_IF_BURNED,
  145. minPoolSize: new TokenAmount(quoteToken, MIN_POOL_SIZE, false),
  146. maxPoolSize: new TokenAmount(quoteToken, MAX_POOL_SIZE, false),
  147. quoteToken,
  148. quoteAmount: new TokenAmount(quoteToken, QUOTE_AMOUNT, false),
  149. oneTokenAtATime: ONE_TOKEN_AT_A_TIME,
  150. useSnipeList: USE_SNIPE_LIST,
  151. autoSell: AUTO_SELL,
  152. autoSellDelay: AUTO_SELL_DELAY,
  153. maxSellRetries: MAX_SELL_RETRIES,
  154. autoBuyDelay: AUTO_BUY_DELAY,
  155. maxBuyRetries: MAX_BUY_RETRIES,
  156. unitLimit: COMPUTE_UNIT_LIMIT,
  157. unitPrice: COMPUTE_UNIT_PRICE,
  158. takeProfit: TAKE_PROFIT,
  159. stopLoss: STOP_LOSS,
  160. buySlippage: BUY_SLIPPAGE,
  161. sellSlippage: SELL_SLIPPAGE,
  162. priceCheckInterval: PRICE_CHECK_INTERVAL,
  163. priceCheckDuration: PRICE_CHECK_DURATION,
  164. filterCheckInterval: FILTER_CHECK_INTERVAL,
  165. filterCheckDuration: FILTER_CHECK_DURATION,
  166. consecutiveMatchCount: CONSECUTIVE_FILTER_MATCHES,
  167. };
  168. const bot = new Bot(connection, marketCache, poolCache, txExecutor, botConfig);
  169. const valid = await bot.validate();
  170. if (!valid) {
  171. logger.info('Bot is exiting...');
  172. process.exit(1);
  173. }
  174. if (PRE_LOAD_EXISTING_MARKETS) {
  175. await marketCache.init({ quoteToken });
  176. }
  177. const runTimestamp = Math.floor(new Date().getTime() / 1000);
  178. const listeners = new Listeners(connection);
  179. await listeners.start({
  180. walletPublicKey: wallet.publicKey,
  181. quoteToken,
  182. autoSell: AUTO_SELL,
  183. cacheNewMarkets: CACHE_NEW_MARKETS,
  184. });
  185. listeners.on('market', (updatedAccountInfo: KeyedAccountInfo) => {
  186. const marketState = MARKET_STATE_LAYOUT_V3.decode(updatedAccountInfo.accountInfo.data);
  187. marketCache.save(updatedAccountInfo.accountId.toString(), marketState);
  188. });
  189. listeners.on('pool', async (updatedAccountInfo: KeyedAccountInfo) => {
  190. const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(updatedAccountInfo.accountInfo.data);
  191. const poolOpenTime = parseInt(poolState.poolOpenTime.toString());
  192. const exists = await poolCache.get(poolState.baseMint.toString());
  193. if (!exists && poolOpenTime > runTimestamp) {
  194. poolCache.save(updatedAccountInfo.accountId.toString(), poolState);
  195. await bot.buy(updatedAccountInfo.accountId, poolState);
  196. }
  197. });
  198. listeners.on('wallet', async (updatedAccountInfo: KeyedAccountInfo) => {
  199. const accountData = AccountLayout.decode(updatedAccountInfo.accountInfo.data);
  200. if (accountData.mint.equals(quoteToken.mint)) {
  201. return;
  202. }
  203. await bot.sell(updatedAccountInfo.accountId, accountData);
  204. });
  205. printDetails(wallet, quoteToken, bot);
  206. };
  207. runListener();