fix: update pool size filter

This commit is contained in:
Filip Dunder
2024-04-15 15:45:35 +02:00
parent d17dc6000e
commit 0c5786ca1c
+23 -16
View File
@@ -1,6 +1,7 @@
import { Filter, FilterResult } from './pool-filters'; import { Filter, FilterResult } from './pool-filters';
import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk'; import { LiquidityStateV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
import { Connection } from '@solana/web3.js'; import { Connection } from '@solana/web3.js';
import { logger } from '../helpers';
export class PoolSizeFilter implements Filter { export class PoolSizeFilter implements Filter {
constructor( constructor(
@@ -11,26 +12,32 @@ export class PoolSizeFilter implements Filter {
) {} ) {}
async execute(poolState: LiquidityStateV4): Promise<FilterResult> { async execute(poolState: LiquidityStateV4): Promise<FilterResult> {
const response = await this.connection.getTokenAccountBalance(poolState.quoteVault, this.connection.commitment); try {
const poolSize = new TokenAmount(this.quoteToken, response.value.amount, true); const response = await this.connection.getTokenAccountBalance(poolState.quoteVault, this.connection.commitment);
let inRange = true; const poolSize = new TokenAmount(this.quoteToken, response.value.amount, true);
let inRange = true;
if (!this.maxPoolSize?.isZero()) { if (!this.maxPoolSize?.isZero()) {
inRange = poolSize.lt(this.maxPoolSize); inRange = poolSize.lt(this.maxPoolSize);
if (!inRange) { if (!inRange) {
return { ok: false, message: `PoolSize -> Pool size ${poolSize.toFixed()} > ${this.maxPoolSize.toFixed()}` }; 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()) { return { ok: false, message: 'PoolSize -> Failed to check pool size' };
inRange = poolSize.gt(this.minPoolSize);
if (!inRange) {
return { ok: false, message: `PoolSize -> Pool size ${poolSize.toFixed()} < ${this.minPoolSize.toFixed()}` };
}
}
return { ok: inRange };
} }
} }