pool-filters.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Connection } from '@solana/web3.js';
  2. import { LiquidityPoolKeysV4, Token, TokenAmount } from '@raydium-io/raydium-sdk';
  3. import { BurnFilter } from './burn.filter';
  4. import { MutableFilter } from './mutable.filter';
  5. import { RenouncedFreezeFilter } from './renounced.filter';
  6. import { PoolSizeFilter } from './pool-size.filter';
  7. import { CHECK_IF_BURNED, CHECK_IF_FREEZABLE, CHECK_IF_MINT_IS_RENOUNCED, CHECK_IF_MUTABLE, logger } from '../helpers';
  8. export interface Filter {
  9. execute(poolKeysV4: LiquidityPoolKeysV4): Promise<FilterResult>;
  10. }
  11. export interface FilterResult {
  12. ok: boolean;
  13. message?: string;
  14. }
  15. export interface PoolFilterArgs {
  16. minPoolSize: TokenAmount;
  17. maxPoolSize: TokenAmount;
  18. quoteToken: Token;
  19. }
  20. export class PoolFilters {
  21. private readonly filters: Filter[] = [];
  22. constructor(
  23. readonly connection: Connection,
  24. readonly args: PoolFilterArgs,
  25. ) {
  26. if (CHECK_IF_BURNED) {
  27. this.filters.push(new BurnFilter(connection));
  28. }
  29. if (CHECK_IF_MINT_IS_RENOUNCED || CHECK_IF_FREEZABLE) {
  30. this.filters.push(new RenouncedFreezeFilter(connection, CHECK_IF_MINT_IS_RENOUNCED, CHECK_IF_FREEZABLE));
  31. }
  32. if (CHECK_IF_MUTABLE) {
  33. this.filters.push(new MutableFilter(connection));
  34. }
  35. if (!args.minPoolSize.isZero() || !args.maxPoolSize.isZero()) {
  36. this.filters.push(new PoolSizeFilter(connection, args.quoteToken, args.minPoolSize, args.maxPoolSize));
  37. }
  38. }
  39. public async execute(poolKeys: LiquidityPoolKeysV4): Promise<boolean> {
  40. if (this.filters.length === 0) {
  41. return true;
  42. }
  43. const result = await Promise.all(this.filters.map((f) => f.execute(poolKeys)));
  44. const pass = result.every((r) => r.ok);
  45. if (pass) {
  46. return true;
  47. }
  48. for (const filterResult of result.filter((r) => !r.ok)) {
  49. logger.trace(filterResult.message);
  50. }
  51. return false;
  52. }
  53. }