index.ts 8.2 KB

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