fix: update pool size filter

This commit is contained in:
Filip Dunder
2024-04-15 15:45:35 +02:00
parent d17dc6000e
commit 0c5786ca1c

View File

@ -1,6 +1,7 @@
import { Filter, FilterResult } from './pool-filters';
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
import { Connection } from '@solana/web3.js';
import { logger } from '../helpers';
export class PoolSizeFilter implements Filter {
constructor(
@ -11,26 +12,32 @@ export class PoolSizeFilter implements Filter {
) {}
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;
try {
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 (!this.maxPoolSize?.isZero()) {
inRange = poolSize.lt(this.maxPoolSize);
if (!inRange) {
return { ok: false, message: `PoolSize -> Pool size ${poolSize.toFixed()} > ${this.maxPoolSize.toFixed()}` };
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 };
} catch (error) {
logger.error({ mint: poolState.baseMint }, `Failed to check pool size`);
}
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 };
return { ok: false, message: 'PoolSize -> Failed to check pool size' };
}
}