mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2026-06-22 04:11:27 +10:00
feat: real time filtering
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { Filter, FilterResult } from './pool-filters';
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { LiquidityStateV4 } from '@raydium-io/raydium-sdk';
|
||||
import { LiquidityPoolKeysV4 } 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> {
|
||||
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
||||
try {
|
||||
const amount = await this.connection.getTokenSupply(poolState.lpMint, this.connection.commitment);
|
||||
const amount = await this.connection.getTokenSupply(poolKeys.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) {
|
||||
@@ -16,7 +16,7 @@ export class BurnFilter implements Filter {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
logger.error({ mint: poolState.baseMint }, `Failed to check if LP is burned`);
|
||||
logger.error({ mint: poolKeys.baseMint }, `Failed to check if LP is burned`);
|
||||
}
|
||||
|
||||
return { ok: false, message: 'Failed to check if LP is burned' };
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
|
||||
import { LiquidityPoolKeysV4, 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>;
|
||||
execute(poolKeysV4: LiquidityPoolKeysV4): Promise<FilterResult>;
|
||||
}
|
||||
|
||||
export interface FilterResult {
|
||||
@@ -40,12 +40,12 @@ export class PoolFilters {
|
||||
}
|
||||
}
|
||||
|
||||
public async execute(poolState: LiquidityStateV4): Promise<boolean> {
|
||||
public async execute(poolKeys: LiquidityPoolKeysV4): Promise<boolean> {
|
||||
if (this.filters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const result = await Promise.all(this.filters.map((f) => f.execute(poolState)));
|
||||
const result = await Promise.all(this.filters.map((f) => f.execute(poolKeys)));
|
||||
const pass = result.every((r) => r.ok);
|
||||
|
||||
if (pass) {
|
||||
@@ -53,7 +53,7 @@ export class PoolFilters {
|
||||
}
|
||||
|
||||
for (const filterResult of result.filter((r) => !r.ok)) {
|
||||
logger.info(filterResult.message);
|
||||
logger.trace(filterResult.message);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Filter, FilterResult } from './pool-filters';
|
||||
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
|
||||
import { LiquidityPoolKeysV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
|
||||
import { Connection } from '@solana/web3.js';
|
||||
import { logger } from '../helpers';
|
||||
|
||||
@@ -11,9 +11,9 @@ export class PoolSizeFilter implements Filter {
|
||||
private readonly maxPoolSize: TokenAmount,
|
||||
) {}
|
||||
|
||||
async execute(poolState: LiquidityStateV4): Promise<FilterResult> {
|
||||
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
||||
try {
|
||||
const response = await this.connection.getTokenAccountBalance(poolState.quoteVault, this.connection.commitment);
|
||||
const response = await this.connection.getTokenAccountBalance(poolKeys.quoteVault, this.connection.commitment);
|
||||
const poolSize = new TokenAmount(this.quoteToken, response.value.amount, true);
|
||||
let inRange = true;
|
||||
|
||||
@@ -35,7 +35,7 @@ export class PoolSizeFilter implements Filter {
|
||||
|
||||
return { ok: inRange };
|
||||
} catch (error) {
|
||||
logger.error({ mint: poolState.baseMint }, `Failed to check pool size`);
|
||||
logger.error({ mint: poolKeys.baseMint }, `Failed to check pool size`);
|
||||
}
|
||||
|
||||
return { ok: false, message: 'PoolSize -> Failed to check pool size' };
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
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 { LiquidityPoolKeysV4 } 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> {
|
||||
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
||||
try {
|
||||
const accountInfo = await this.connection.getAccountInfo(poolState.baseMint, this.connection.commitment);
|
||||
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
|
||||
if (!accountInfo?.data) {
|
||||
return { ok: false, message: 'Renounced -> Failed to fetch account data' };
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export class RenouncedFilter implements Filter {
|
||||
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`);
|
||||
logger.error({ mint: poolKeys.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