|
@@ -48,6 +48,7 @@ import {
|
|
SNIPE_LIST_REFRESH_INTERVAL,
|
|
SNIPE_LIST_REFRESH_INTERVAL,
|
|
USE_SNIPE_LIST,
|
|
USE_SNIPE_LIST,
|
|
MIN_POOL_SIZE,
|
|
MIN_POOL_SIZE,
|
|
|
|
+ ONE_TOKEN_AT_A_TIME,
|
|
} from './constants';
|
|
} from './constants';
|
|
|
|
|
|
const solanaConnection = new Connection(RPC_ENDPOINT, {
|
|
const solanaConnection = new Connection(RPC_ENDPOINT, {
|
|
@@ -70,6 +71,9 @@ let quoteToken: Token;
|
|
let quoteTokenAssociatedAddress: PublicKey;
|
|
let quoteTokenAssociatedAddress: PublicKey;
|
|
let quoteAmount: TokenAmount;
|
|
let quoteAmount: TokenAmount;
|
|
let quoteMinPoolSizeAmount: TokenAmount;
|
|
let quoteMinPoolSizeAmount: TokenAmount;
|
|
|
|
+let processingToken: Boolean = false;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
let snipeList: string[] = [];
|
|
let snipeList: string[] = [];
|
|
|
|
|
|
@@ -110,6 +114,7 @@ async function init(): Promise<void> {
|
|
logger.info(
|
|
logger.info(
|
|
`Min pool size: ${quoteMinPoolSizeAmount.isZero() ? 'false' : quoteMinPoolSizeAmount.toFixed()} ${quoteToken.symbol}`,
|
|
`Min pool size: ${quoteMinPoolSizeAmount.isZero() ? 'false' : quoteMinPoolSizeAmount.toFixed()} ${quoteToken.symbol}`,
|
|
);
|
|
);
|
|
|
|
+ logger.info(`One token at a time: ${ONE_TOKEN_AT_A_TIME}`);
|
|
logger.info(`Buy amount: ${quoteAmount.toFixed()} ${quoteToken.symbol}`);
|
|
logger.info(`Buy amount: ${quoteAmount.toFixed()} ${quoteToken.symbol}`);
|
|
logger.info(`Auto sell: ${AUTO_SELL}`);
|
|
logger.info(`Auto sell: ${AUTO_SELL}`);
|
|
logger.info(`Sell delay: ${AUTO_SELL_DELAY === 0 ? 'false' : AUTO_SELL_DELAY}`);
|
|
logger.info(`Sell delay: ${AUTO_SELL_DELAY === 0 ? 'false' : AUTO_SELL_DELAY}`);
|
|
@@ -265,6 +270,8 @@ async function buy(accountId: PublicKey, accountData: LiquidityStateV4): Promise
|
|
preflightCommitment: COMMITMENT_LEVEL,
|
|
preflightCommitment: COMMITMENT_LEVEL,
|
|
});
|
|
});
|
|
logger.info({ mint: accountData.baseMint, signature }, `Sent buy tx`);
|
|
logger.info({ mint: accountData.baseMint, signature }, `Sent buy tx`);
|
|
|
|
+ processingToken = true;
|
|
|
|
+
|
|
const confirmation = await solanaConnection.confirmTransaction(
|
|
const confirmation = await solanaConnection.confirmTransaction(
|
|
{
|
|
{
|
|
signature,
|
|
signature,
|
|
@@ -288,6 +295,7 @@ async function buy(accountId: PublicKey, accountData: LiquidityStateV4): Promise
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
logger.debug(e);
|
|
logger.debug(e);
|
|
|
|
+ processingToken = false;
|
|
logger.error({ mint: accountData.baseMint }, `Failed to buy token`);
|
|
logger.error({ mint: accountData.baseMint }, `Failed to buy token`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -380,6 +388,7 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
|
|
`Confirmed sell tx`,
|
|
`Confirmed sell tx`,
|
|
);
|
|
);
|
|
sold = true;
|
|
sold = true;
|
|
|
|
+ processingToken = false;
|
|
} catch (e: any) {
|
|
} catch (e: any) {
|
|
// wait for a bit before retrying
|
|
// wait for a bit before retrying
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -388,6 +397,7 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
|
|
logger.error({ mint }, `Failed to sell token, retry: ${retries}/${MAX_SELL_RETRIES}`);
|
|
logger.error({ mint }, `Failed to sell token, retry: ${retries}/${MAX_SELL_RETRIES}`);
|
|
}
|
|
}
|
|
} while (!sold && retries < MAX_SELL_RETRIES);
|
|
} while (!sold && retries < MAX_SELL_RETRIES);
|
|
|
|
+ processingToken = false;
|
|
}
|
|
}
|
|
|
|
|
|
function loadSnipeList() {
|
|
function loadSnipeList() {
|
|
@@ -408,7 +418,8 @@ function loadSnipeList() {
|
|
}
|
|
}
|
|
|
|
|
|
function shouldBuy(key: string): boolean {
|
|
function shouldBuy(key: string): boolean {
|
|
- return USE_SNIPE_LIST ? snipeList.includes(key) : true;
|
|
|
|
|
|
+ logger.info(processingToken, 'Is processing token buy')
|
|
|
|
+ return USE_SNIPE_LIST ? snipeList.includes(key) : ONE_TOKEN_AT_A_TIME ? !processingToken : true
|
|
}
|
|
}
|
|
|
|
|
|
const runListener = async () => {
|
|
const runListener = async () => {
|
|
@@ -505,6 +516,10 @@ const runListener = async () => {
|
|
logger.info(`Listening for raydium changes: ${raydiumSubscriptionId}`);
|
|
logger.info(`Listening for raydium changes: ${raydiumSubscriptionId}`);
|
|
logger.info(`Listening for open book changes: ${openBookSubscriptionId}`);
|
|
logger.info(`Listening for open book changes: ${openBookSubscriptionId}`);
|
|
|
|
|
|
|
|
+ logger.info('------------------- 🚀 ---------------------');
|
|
|
|
+ logger.info('Bot is running! Press CTRL + C to stop it.');
|
|
|
|
+ logger.info('------------------- 🚀 ---------------------');
|
|
|
|
+
|
|
if (USE_SNIPE_LIST) {
|
|
if (USE_SNIPE_LIST) {
|
|
setInterval(loadSnipeList, SNIPE_LIST_REFRESH_INTERVAL);
|
|
setInterval(loadSnipeList, SNIPE_LIST_REFRESH_INTERVAL);
|
|
}
|
|
}
|