diff --git a/filters/pool-size.filter.ts b/filters/pool-size.filter.ts index b1377c4..02626e2 100644 --- a/filters/pool-size.filter.ts +++ b/filters/pool-size.filter.ts @@ -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 { - 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' }; } }