Add ONE_TOKEN_AT_A_TIME flag and update logging

This commit is contained in:
OneRobotBoii
2024-03-26 21:20:06 +07:00
parent 707e79ec21
commit e5b88a66fb
3 changed files with 19 additions and 3 deletions

View File

@ -11,4 +11,5 @@ AUTO_SELL=true
MAX_SELL_RETRIES=5
AUTO_SELL_DELAY=1000
LOG_LEVEL=info
MIN_POOL_SIZE=10
MIN_POOL_SIZE=10
ONE_TOKEN_AT_A_TIME=true

17
buy.ts
View File

@ -48,6 +48,7 @@ import {
SNIPE_LIST_REFRESH_INTERVAL,
USE_SNIPE_LIST,
MIN_POOL_SIZE,
ONE_TOKEN_AT_A_TIME,
} from './constants';
const solanaConnection = new Connection(RPC_ENDPOINT, {
@ -70,6 +71,9 @@ let quoteToken: Token;
let quoteTokenAssociatedAddress: PublicKey;
let quoteAmount: TokenAmount;
let quoteMinPoolSizeAmount: TokenAmount;
let processingToken: Boolean = false;
let snipeList: string[] = [];
@ -110,6 +114,7 @@ async function init(): Promise<void> {
logger.info(
`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(`Auto sell: ${AUTO_SELL}`);
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,
});
logger.info({ mint: accountData.baseMint, signature }, `Sent buy tx`);
processingToken = true;
const confirmation = await solanaConnection.confirmTransaction(
{
signature,
@ -288,6 +295,7 @@ async function buy(accountId: PublicKey, accountData: LiquidityStateV4): Promise
}
} catch (e) {
logger.debug(e);
processingToken = false;
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`,
);
sold = true;
processingToken = false;
} catch (e: any) {
// wait for a bit before retrying
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}`);
}
} while (!sold && retries < MAX_SELL_RETRIES);
processingToken = false;
}
function loadSnipeList() {
@ -408,7 +418,8 @@ function loadSnipeList() {
}
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 () => {
@ -505,6 +516,10 @@ const runListener = async () => {
logger.info(`Listening for raydium changes: ${raydiumSubscriptionId}`);
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) {
setInterval(loadSnipeList, SNIPE_LIST_REFRESH_INTERVAL);
}

View File

@ -16,4 +16,4 @@ 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 MIN_POOL_SIZE = retrieveEnvVariable('MIN_POOL_SIZE', logger);
export const ONE_TOKEN_AT_A_TIME = retrieveEnvVariable('ONE_TOKEN_AT_A_TIME', logger) === 'true';