index.ts 7.4 KB

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