Add MIN_POOL_SIZE environment variable and implement pool size check

This commit is contained in:
OneRobotBoii
2024-03-22 22:36:12 +07:00
parent 5d3fd39f6b
commit 9138ff3edf
3 changed files with 30 additions and 1 deletions

View File

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

3
.gitignore vendored
View File

@ -122,6 +122,9 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# PNPM
pnpm-lock.yaml
# yarn v2
.yarn/cache
.yarn/unplugged

25
buy.ts
View File

@ -34,6 +34,7 @@ import pino from 'pino';
import bs58 from 'bs58';
import * as fs from 'fs';
import * as path from 'path';
import BN from 'bn.js';
const transport = pino.transport({
target: 'pino-pretty',
@ -165,6 +166,28 @@ export async function processRaydiumPool(id: PublicKey, poolState: LiquidityStat
return;
}
let poolSize = new BN(poolState.swapQuoteInAmount);
poolSize = poolSize.div(new BN(10 ** quoteToken.decimals));
const MIN_POOL_SIZE = new BN(retrieveEnvVariable('MIN_POOL_SIZE', logger));
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 (CHECK_IF_MINT_IS_RENOUNCED) {
const mintOption = await checkMintable(poolState.baseMint);
@ -373,6 +396,8 @@ async function sell(accountId: PublicKey, mint: PublicKey, amount: BigNumberish)
);
sold = true;
} catch (e: any) {
// wait for a bit before retrying
await new Promise((resolve) => setTimeout(resolve, 100));
retries++;
logger.debug(e);
logger.error({ mint }, `Failed to sell token, retry: ${retries}/${MAX_SELL_RETRIES}`);