Browse Source

Merge pull request #65 from fdundjer/feat/improvements

feat: improvements
Filip Dunđer 1 year ago
parent
commit
95baa36072
3 changed files with 26 additions and 21 deletions
  1. 3 1
      .env.copy
  2. 6 1
      README.md
  3. 17 19
      buy.ts

+ 3 - 1
.env.copy

@@ -8,4 +8,6 @@ USE_SNIPE_LIST=false
 SNIPE_LIST_REFRESH_INTERVAL=30000
 SNIPE_LIST_REFRESH_INTERVAL=30000
 CHECK_IF_MINT_IS_RENOUNCED=false
 CHECK_IF_MINT_IS_RENOUNCED=false
 AUTO_SELL=true
 AUTO_SELL=true
-MAX_SELL_RETRIES=5
+MAX_SELL_RETRIES=5
+SELL_DELAY=1000
+LOG_LEVEL=info

+ 6 - 1
README.md

@@ -47,11 +47,16 @@ It will buy only when new pool is open for trading. If you want to buy token tha
 By default, auto sell is enabled. If you want to disable it, you need to:
 By default, auto sell is enabled. If you want to disable it, you need to:
 - Change variable `AUTO_SELL` to `false`
 - Change variable `AUTO_SELL` to `false`
 - Update `MAX_SELL_RETRIES` to set the maximum number of retries for selling token
 - Update `MAX_SELL_RETRIES` to set the maximum number of retries for selling token
+- Update `SELL_DELAY` to the number of milliseconds you want to wait before selling the token
+  - This will sell the token after the specified delay. (+- RPC node speed)
 
 
-Token will be sold immediately after it is bought.
+If you set SELL_DELAY to 0, token will be sold immediately after it is bought.
+
+There is no guarantee that the token will be sold at a profit or even sold at all. The developer is not responsible for any losses incurred by using this feature.
 
 
 ## Common issues
 ## Common issues
 If you have an error which is not listed here, please create a new issue in this repository.
 If you have an error which is not listed here, please create a new issue in this repository.
+To collect more information on an issue, please change `LOG_LEVEL` to `debug`.
 
 
 ### Empty transaction
 ### Empty transaction
 - If you see empty transactions on SolScan most likely fix is to change commitment level to `finalized`.
 - If you see empty transactions on SolScan most likely fix is to change commitment level to `finalized`.

+ 17 - 19
buy.ts

@@ -36,21 +36,7 @@ import * as fs from 'fs';
 import * as path from 'path';
 import * as path from 'path';
 
 
 const transport = pino.transport({
 const transport = pino.transport({
-  targets: [
-    // {
-    //   level: 'trace',
-    //   target: 'pino/file',
-    //   options: {
-    //     destination: 'buy.log',
-    //   },
-    // },
-
-    {
-      level: 'info',
-      target: 'pino-pretty',
-      options: {},
-    },
-  ],
+  target: 'pino-pretty',
 });
 });
 
 
 export const logger = pino(
 export const logger = pino(
@@ -68,6 +54,7 @@ export const logger = pino(
 const network = 'mainnet-beta';
 const network = 'mainnet-beta';
 const RPC_ENDPOINT = retrieveEnvVariable('RPC_ENDPOINT', logger);
 const RPC_ENDPOINT = retrieveEnvVariable('RPC_ENDPOINT', logger);
 const RPC_WEBSOCKET_ENDPOINT = retrieveEnvVariable('RPC_WEBSOCKET_ENDPOINT', logger);
 const RPC_WEBSOCKET_ENDPOINT = retrieveEnvVariable('RPC_WEBSOCKET_ENDPOINT', logger);
+const LOG_LEVEL = retrieveEnvVariable('LOG_LEVEL', logger);
 
 
 const solanaConnection = new Connection(RPC_ENDPOINT, {
 const solanaConnection = new Connection(RPC_ENDPOINT, {
   wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
   wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
@@ -95,10 +82,13 @@ const USE_SNIPE_LIST = retrieveEnvVariable('USE_SNIPE_LIST', logger) === 'true';
 const SNIPE_LIST_REFRESH_INTERVAL = Number(retrieveEnvVariable('SNIPE_LIST_REFRESH_INTERVAL', logger));
 const SNIPE_LIST_REFRESH_INTERVAL = Number(retrieveEnvVariable('SNIPE_LIST_REFRESH_INTERVAL', logger));
 const AUTO_SELL = retrieveEnvVariable('AUTO_SELL', logger) === 'true';
 const AUTO_SELL = retrieveEnvVariable('AUTO_SELL', logger) === 'true';
 const MAX_SELL_RETRIES = Number(retrieveEnvVariable('MAX_SELL_RETRIES', logger));
 const MAX_SELL_RETRIES = Number(retrieveEnvVariable('MAX_SELL_RETRIES', logger));
+const AUTO_SELL_DELAY = Number(retrieveEnvVariable('AUTO_SELL_DELAY', logger));
 
 
 let snipeList: string[] = [];
 let snipeList: string[] = [];
 
 
 async function init(): Promise<void> {
 async function init(): Promise<void> {
+  logger.level = LOG_LEVEL;
+
   // get wallet
   // get wallet
   const PRIVATE_KEY = retrieveEnvVariable('PRIVATE_KEY', logger);
   const PRIVATE_KEY = retrieveEnvVariable('PRIVATE_KEY', logger);
   wallet = Keypair.fromSecretKey(bs58.decode(PRIVATE_KEY));
   wallet = Keypair.fromSecretKey(bs58.decode(PRIVATE_KEY));
@@ -298,6 +288,10 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
   let sold = false;
   let sold = false;
   let retries = 0;
   let retries = 0;
 
 
+  if (AUTO_SELL_DELAY > 0) {
+    await new Promise((resolve) => setTimeout(resolve, AUTO_SELL_DELAY));
+  }
+
   do {
   do {
     try {
     try {
       const tokenAccount = existingTokenAccounts.get(mint.toString());
       const tokenAccount = existingTokenAccounts.get(mint.toString());
@@ -308,7 +302,7 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
 
 
       if (!tokenAccount.poolKeys) {
       if (!tokenAccount.poolKeys) {
         logger.warn({ mint }, 'No pool keys found');
         logger.warn({ mint }, 'No pool keys found');
-        continue;
+        return;
       }
       }
 
 
       if (amount === 0) {
       if (amount === 0) {
@@ -369,9 +363,13 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
       }
       }
 
 
       logger.info(
       logger.info(
-        { mint, signature, url: `https://solscan.io/tx/${signature}?cluster=${network}` },
-        `Confirmed sell tx,
-        \x1b[35mhttps://dexscreener.com/solana/${mint}?maker=${wallet.publicKey}\x1b[0m`,
+        {
+          dex: `https://dexscreener.com/solana/${mint}?maker=${wallet.publicKey}`,
+          mint,
+          signature,
+          url: `https://solscan.io/tx/${signature}?cluster=${network}`,
+        },
+        `Confirmed sell tx`,
       );
       );
       sold = true;
       sold = true;
     } catch (e: any) {
     } catch (e: any) {