mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2026-06-22 04:11:27 +10:00
feat: complete rewrite
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { Filter, FilterResult } from './pool-filters';
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { LiquidityStateV4 } from '@raydium-io/raydium-sdk';
|
||||
import { logger } from '../helpers';
|
||||
|
||||
export class BurnFilter implements Filter {
|
||||
constructor(private readonly connection: Connection) {}
|
||||
|
||||
async execute(poolState: LiquidityStateV4): Promise<FilterResult> {
|
||||
try {
|
||||
const amount = await this.connection.getTokenSupply(poolState.lpMint, this.connection.commitment);
|
||||
const burned = amount.value.uiAmount === 0;
|
||||
return { ok: burned, message: burned ? undefined : "Burned -> Creator didn't burn LP" };
|
||||
} catch (e: any) {
|
||||
if (e.code == -32602) {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
logger.error({ mint: poolState.baseMint }, `Failed to check if LP is burned`);
|
||||
}
|
||||
|
||||
return { ok: false, message: 'Failed to check if LP is burned' };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './burn.filter';
|
||||
export * from './pool-filters';
|
||||
export * from './pool-size.filter';
|
||||
export * from './renounced.filter';
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
|
||||
import { BurnFilter } from './burn.filter';
|
||||
import { RenouncedFilter } from './renounced.filter';
|
||||
import { PoolSizeFilter } from './pool-size.filter';
|
||||
import { CHECK_IF_BURNED, CHECK_IF_MINT_IS_RENOUNCED, logger } from '../helpers';
|
||||
|
||||
export interface Filter {
|
||||
execute(poolState: LiquidityStateV4): Promise<FilterResult>;
|
||||
}
|
||||
|
||||
export interface FilterResult {
|
||||
ok: boolean;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface PoolFilterArgs {
|
||||
minPoolSize: TokenAmount;
|
||||
maxPoolSize: TokenAmount;
|
||||
quoteToken: Token;
|
||||
}
|
||||
|
||||
export class PoolFilters {
|
||||
private readonly filters: Filter[] = [];
|
||||
|
||||
constructor(
|
||||
readonly connection: Connection,
|
||||
readonly args: PoolFilterArgs,
|
||||
) {
|
||||
if (CHECK_IF_BURNED) {
|
||||
this.filters.push(new BurnFilter(connection));
|
||||
}
|
||||
|
||||
if (CHECK_IF_MINT_IS_RENOUNCED) {
|
||||
this.filters.push(new RenouncedFilter(connection));
|
||||
}
|
||||
|
||||
if (!args.minPoolSize.isZero() || !args.maxPoolSize.isZero()) {
|
||||
this.filters.push(new PoolSizeFilter(connection, args.quoteToken, args.minPoolSize, args.maxPoolSize));
|
||||
}
|
||||
}
|
||||
|
||||
public async execute(poolState: LiquidityStateV4): Promise<boolean> {
|
||||
if (this.filters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const result = await Promise.all(this.filters.map((f) => f.execute(poolState)));
|
||||
const pass = result.every((r) => r.ok);
|
||||
|
||||
if (pass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const filterResult of result.filter((r) => !r.ok)) {
|
||||
logger.info(filterResult.message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Filter, FilterResult } from './pool-filters';
|
||||
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
|
||||
import { Connection } from '@solana/web3.js';
|
||||
|
||||
export class PoolSizeFilter implements Filter {
|
||||
constructor(
|
||||
private readonly connection: Connection,
|
||||
private readonly quoteToken: Token,
|
||||
private readonly minPoolSize: TokenAmount,
|
||||
private readonly maxPoolSize: TokenAmount,
|
||||
) {}
|
||||
|
||||
async execute(poolState: LiquidityStateV4): Promise<FilterResult> {
|
||||
const response = await this.connection.getTokenAccountBalance(poolState.quoteVault, this.connection.commitment);
|
||||
const poolSize = new TokenAmount(this.quoteToken, response.value.amount, true);
|
||||
let inRange = true;
|
||||
|
||||
if (!this.maxPoolSize?.isZero()) {
|
||||
inRange = poolSize.lt(this.maxPoolSize);
|
||||
|
||||
if (!inRange) {
|
||||
return { ok: false, message: `PoolSize -> Pool size ${poolSize.toFixed()} > ${this.maxPoolSize.toFixed()}` };
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.minPoolSize?.isZero()) {
|
||||
inRange = poolSize.gt(this.minPoolSize);
|
||||
|
||||
if (!inRange) {
|
||||
return { ok: false, message: `PoolSize -> Pool size ${poolSize.toFixed()} < ${this.minPoolSize.toFixed()}` };
|
||||
}
|
||||
}
|
||||
|
||||
return { ok: inRange };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Filter, FilterResult } from './pool-filters';
|
||||
import { MintLayout } from '@solana/spl-token';
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { LiquidityStateV4 } from '@raydium-io/raydium-sdk';
|
||||
import { logger } from '../helpers';
|
||||
|
||||
export class RenouncedFilter implements Filter {
|
||||
constructor(private readonly connection: Connection) {}
|
||||
|
||||
async execute(poolState: LiquidityStateV4): Promise<FilterResult> {
|
||||
try {
|
||||
const accountInfo = await this.connection.getAccountInfo(poolState.baseMint, this.connection.commitment);
|
||||
if (!accountInfo?.data) {
|
||||
return { ok: false, message: 'Renounced -> Failed to fetch account data' };
|
||||
}
|
||||
|
||||
const deserialize = MintLayout.decode(accountInfo.data);
|
||||
const renounced = deserialize.mintAuthorityOption === 0;
|
||||
return { ok: renounced, message: renounced ? undefined : 'Renounced -> Creator can mint more tokens' };
|
||||
} catch (e) {
|
||||
logger.error({ mint: poolState.baseMint }, `Failed to check if mint is renounced`);
|
||||
}
|
||||
|
||||
return { ok: false, message: 'Renounced -> Failed to check if mint is renounced' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user