Add freezable filter

Check if owner can freeze tokens
This commit is contained in:
Theo Brigitte
2024-04-19 23:00:32 +02:00
parent df38d332a0
commit 508e521433
6 changed files with 22 additions and 11 deletions

View File

@ -4,23 +4,28 @@ import { Connection } from '@solana/web3.js';
import { LiquidityPoolKeysV4 } from '@raydium-io/raydium-sdk';
import { logger } from '../helpers';
export class RenouncedFilter implements Filter {
constructor(private readonly connection: Connection) {}
export class RenouncedFreezeFilter implements Filter {
constructor(private readonly connection: Connection, private readonly checkRenounced: boolean, private readonly checkFreezable: boolean) {}
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
try {
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
if (!accountInfo?.data) {
return { ok: false, message: 'Renounced -> Failed to fetch account data' };
return { ok: false, message: 'Failed to fetch account data' };
}
const deserialize = MintLayout.decode(accountInfo.data);
const renounced = deserialize.mintAuthorityOption === 0;
return { ok: renounced, message: renounced ? undefined : 'Renounced -> Creator can mint more tokens' };
const renounced = !this.checkRenounced || deserialize.mintAuthorityOption === 0;
const freezable = !this.checkFreezable || deserialize.freezeAuthorityOption !== 0;
const message = [ renounced ? undefined : 'mint', !freezable ? undefined : 'freeze' ].filter((e) => e !== undefined);
const ok = renounced && !freezable;
return { ok: ok, message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens` };
} catch (e) {
logger.error({ mint: poolKeys.baseMint }, `Failed to check if mint is renounced`);
logger.error({ mint: poolKeys.baseMint }, `Failed to check if mint is renounced and freezable`);
}
return { ok: false, message: 'Renounced -> Failed to check if mint is renounced' };
return { ok: false, message: 'Renounced -> Failed to check if mint is renounced and freezable' };
}
}