소스 검색

feat: use token amount instead of BN

Filip Dunder 1 년 전
부모
커밋
c53a5062dd
3개의 변경된 파일29개의 추가작업 그리고 22개의 파일을 삭제
  1. 2 0
      README.md
  2. 24 21
      buy.ts
  3. 3 1
      constants/constants.ts

+ 2 - 0
README.md

@@ -23,6 +23,8 @@ To run the script you need to:
   - USE_SNIPE_LIST (buy only tokens listed in snipe-list.txt)
   - SNIPE_LIST_REFRESH_INTERVAL (how often snipe list should be refreshed in milliseconds)
   - CHECK_IF_MINT_IS_RENOUNCED (script will buy only if mint is renounced)
+  - MIN_POOL_SIZE (script will buy only if pool size is greater than specified amount)
+    - set to 0 to disable pool size check
 - Install dependencies by typing: `npm install`
 - Run the script by typing: `npm run buy` in terminal
 

+ 24 - 21
buy.ts

@@ -30,7 +30,6 @@ import { logger } from './utils';
 import { getMinimalMarketV3, MinimalMarketLayoutV3 } from './market';
 import { MintLayout } from './types';
 import bs58 from 'bs58';
-import BN from 'bn.js';
 import * as fs from 'fs';
 import * as path from 'path';
 import {
@@ -60,7 +59,7 @@ export interface MinimalTokenAccountData {
   address: PublicKey;
   poolKeys?: LiquidityPoolKeys;
   market?: MinimalMarketLayoutV3;
-};
+}
 
 const existingLiquidityPools: Set<string> = new Set<string>();
 const existingOpenBookMarkets: Set<string> = new Set<string>();
@@ -70,6 +69,7 @@ let wallet: Keypair;
 let quoteToken: Token;
 let quoteTokenAssociatedAddress: PublicKey;
 let quoteAmount: TokenAmount;
+let quoteMinPoolSizeAmount: TokenAmount;
 
 let snipeList: string[] = [];
 
@@ -85,6 +85,7 @@ async function init(): Promise<void> {
     case 'WSOL': {
       quoteToken = Token.WSOL;
       quoteAmount = new TokenAmount(Token.WSOL, QUOTE_AMOUNT, false);
+      quoteMinPoolSizeAmount = new TokenAmount(quoteToken, MIN_POOL_SIZE, false);
       break;
     }
     case 'USDC': {
@@ -96,6 +97,7 @@ async function init(): Promise<void> {
         'USDC',
       );
       quoteAmount = new TokenAmount(quoteToken, QUOTE_AMOUNT, false);
+      quoteMinPoolSizeAmount = new TokenAmount(quoteToken, MIN_POOL_SIZE, false);
       break;
     }
     default: {
@@ -103,9 +105,14 @@ async function init(): Promise<void> {
     }
   }
 
+  logger.info(`Snipe list: ${USE_SNIPE_LIST}`);
+  logger.info(`Check mint renounced: ${CHECK_IF_MINT_IS_RENOUNCED}`);
   logger.info(
-    `Script will buy all new tokens using ${QUOTE_MINT}. Amount that will be used to buy each token is: ${quoteAmount.toFixed().toString()}`,
+    `Min pool size: ${quoteMinPoolSizeAmount.isZero() ? 'false' : quoteMinPoolSizeAmount.toFixed()} ${quoteToken.symbol}`,
   );
+  logger.info(`Buy amount: ${quoteAmount.toFixed()} ${quoteToken.symbol}`);
+  logger.info(`Auto sell: ${AUTO_SELL}`);
+  logger.info(`Sell delay: ${AUTO_SELL_DELAY === 0 ? 'false' : AUTO_SELL_DELAY}`);
 
   // check existing wallet for associated token account of quote mint
   const tokenAccounts = await getTokenAccounts(solanaConnection, wallet.publicKey, COMMITMENT_LEVEL);
@@ -149,25 +156,21 @@ export async function processRaydiumPool(id: PublicKey, poolState: LiquidityStat
     return;
   }
 
-  let poolSize = new BN(poolState.swapQuoteInAmount);
-
-  poolSize = poolSize.div(new BN(10 ** quoteToken.decimals));
-
+  if (!quoteMinPoolSizeAmount.isZero()) {
+    const poolSize = new TokenAmount(quoteToken, poolState.swapQuoteInAmount, true);
+    logger.info(`Processing pool: ${id.toString()} with ${poolSize.toFixed()} ${quoteToken.symbol} in liquidity`);
 
-  logger.info(
-    `Processing pool: ${id.toString()} with ${poolSize.toString()} ${quoteToken.symbol} in liquidity`,
-  );
-
-  if (poolSize.lt(new BN(MIN_POOL_SIZE))) {
-    logger.warn(
-      {
-        mint: poolState.baseMint,
-        pooled: poolSize.toString() + ' ' + quoteToken.symbol,
-      },
-      `Skipping pool, smaller than ${MIN_POOL_SIZE} ${quoteToken.symbol}`,
-      `Swap quote in amount: ${poolSize.toString()}`
-    );
-    return;
+    if (poolSize.lt(quoteMinPoolSizeAmount)) {
+      logger.warn(
+        {
+          mint: poolState.baseMint,
+          pooled: `${poolSize.toFixed()} ${quoteToken.symbol}`,
+        },
+        `Skipping pool, smaller than ${quoteMinPoolSizeAmount.toFixed()} ${quoteToken.symbol}`,
+        `Swap quote in amount: ${poolSize.toFixed()}`,
+      );
+      return;
+    }
   }
 
   if (CHECK_IF_MINT_IS_RENOUNCED) {

+ 3 - 1
constants/constants.ts

@@ -14,4 +14,6 @@ export const MAX_SELL_RETRIES = Number(retrieveEnvVariable('MAX_SELL_RETRIES', l
 export const AUTO_SELL_DELAY = Number(retrieveEnvVariable('AUTO_SELL_DELAY', logger));
 export const PRIVATE_KEY = retrieveEnvVariable('PRIVATE_KEY', logger);
 export const QUOTE_MINT = retrieveEnvVariable('QUOTE_MINT', logger);
-export const QUOTE_AMOUNT = retrieveEnvVariable('QUOTE_AMOUNT', logger);
+export const QUOTE_AMOUNT = retrieveEnvVariable('QUOTE_AMOUNT', logger);
+export const MIN_POOL_SIZE = retrieveEnvVariable('MIN_POOL_SIZE', logger);
+