feat: filter cache

This commit is contained in:
Filip Dunder
2024-04-27 17:18:46 +02:00
parent cb91e04d60
commit ba11c539f6
3 changed files with 40 additions and 3 deletions

View File

@ -4,13 +4,25 @@ import { LiquidityPoolKeysV4 } from '@raydium-io/raydium-sdk';
import { logger } from '../helpers';
export class BurnFilter implements Filter {
private cachedResult: FilterResult | undefined = undefined;
constructor(private readonly connection: Connection) {}
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
if (this.cachedResult) {
return this.cachedResult;
}
try {
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" };
const result = { ok: burned, message: burned ? undefined : "Burned -> Creator didn't burn LP" };
if (result.ok) {
this.cachedResult = result;
}
return result;
} catch (e: any) {
if (e.code == -32602) {
return { ok: true };

View File

@ -8,6 +8,7 @@ import { logger } from '../helpers';
export class MutableFilter implements Filter {
private readonly errorMessage: string[] = [];
private cachedResult: FilterResult | undefined = undefined;
constructor(
private readonly connection: Connection,
@ -25,6 +26,10 @@ export class MutableFilter implements Filter {
}
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
if (this.cachedResult) {
return this.cachedResult;
}
try {
const metadataPDA = getPdaMetadataKey(poolKeys.baseMint);
const metadataAccount = await this.connection.getAccountInfo(metadataPDA.publicKey, this.connection.commitment);
@ -47,7 +52,13 @@ export class MutableFilter implements Filter {
message.push('has no socials');
}
return { ok: ok, message: ok ? undefined : `MutableSocials -> Token ${message.join(' and ')}` };
const result = { ok: ok, message: ok ? undefined : `MutableSocials -> Token ${message.join(' and ')}` };
if (!mutable) {
this.cachedResult = result;
}
return result;
} catch (e) {
logger.error({ mint: poolKeys.baseMint }, `MutableSocials -> Failed to check ${this.errorMessage.join(' and ')}`);
}

View File

@ -6,6 +6,7 @@ import { logger } from '../helpers';
export class RenouncedFreezeFilter implements Filter {
private readonly errorMessage: string[] = [];
private cachedResult: FilterResult | undefined = undefined;
constructor(
private readonly connection: Connection,
@ -22,6 +23,10 @@ export class RenouncedFreezeFilter implements Filter {
}
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
if (this.cachedResult) {
return this.cachedResult;
}
try {
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
if (!accountInfo?.data) {
@ -42,7 +47,16 @@ export class RenouncedFreezeFilter implements Filter {
message.push('freeze');
}
return { ok: ok, message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens` };
const result = {
ok: ok,
message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens`,
};
if (result.ok) {
this.cachedResult = result;
}
return result;
} catch (e) {
logger.error(
{ mint: poolKeys.baseMint },