mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2026-06-22 04:11:27 +10:00
Merge pull request #98 from fdundjer/master
cleanup: mutable and renounced filters
This commit is contained in:
+37
-14
@@ -7,37 +7,60 @@ import { Serializer } from '@metaplex-foundation/umi/serializers';
|
|||||||
import { logger } from '../helpers';
|
import { logger } from '../helpers';
|
||||||
|
|
||||||
export class MutableFilter implements Filter {
|
export class MutableFilter implements Filter {
|
||||||
constructor(private readonly connection: Connection, private readonly metadataSerializer: Serializer<MetadataAccountDataArgs, MetadataAccountData>, private readonly checkMutable: boolean, private readonly checkSocials: boolean) {}
|
private readonly errorMessage: string[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly connection: Connection,
|
||||||
|
private readonly metadataSerializer: Serializer<MetadataAccountDataArgs, MetadataAccountData>,
|
||||||
|
private readonly checkMutable: boolean,
|
||||||
|
private readonly checkSocials: boolean,
|
||||||
|
) {
|
||||||
|
if (this.checkMutable) {
|
||||||
|
this.errorMessage.push('mutable');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.checkSocials) {
|
||||||
|
this.errorMessage.push('socials');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
||||||
const errorMessage = [ this.checkMutable ? 'mutable' : undefined, this.checkSocials ? 'socials' : undefined ].filter((e) => e !== undefined);
|
|
||||||
try {
|
try {
|
||||||
const metadataPDA = getPdaMetadataKey(poolKeys.baseMint);
|
const metadataPDA = getPdaMetadataKey(poolKeys.baseMint);
|
||||||
const metadataAccount = await this.connection.getAccountInfo(metadataPDA.publicKey);
|
const metadataAccount = await this.connection.getAccountInfo(metadataPDA.publicKey, this.connection.commitment);
|
||||||
|
|
||||||
if (!metadataAccount?.data) {
|
if (!metadataAccount?.data) {
|
||||||
return { ok: false, message: 'Mutable -> Failed to fetch account data' };
|
return { ok: false, message: 'Mutable -> Failed to fetch account data' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const deserialize = this.metadataSerializer.deserialize(metadataAccount.data);
|
const deserialize = this.metadataSerializer.deserialize(metadataAccount.data);
|
||||||
const mutable = this.checkMutable ? deserialize[0].isMutable: false;
|
const mutable = !this.checkMutable || deserialize[0].isMutable;
|
||||||
|
const hasSocials = !this.checkSocials || (await this.hasSocials(deserialize[0]));
|
||||||
const hasSocials = this.checkSocials ? (Object.values(await this.getSocials(deserialize[0])).some((value: any) => value !== null && value.length > 0)) === true: true;
|
|
||||||
|
|
||||||
const message = [ !mutable ? undefined : 'metadata can be changed', hasSocials ? undefined : 'has no socials' ].filter((e) => e !== undefined);
|
|
||||||
const ok = !mutable && hasSocials;
|
const ok = !mutable && hasSocials;
|
||||||
|
const message: string[] = [];
|
||||||
|
|
||||||
|
if (mutable) {
|
||||||
|
message.push('metadata can be changed');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSocials) {
|
||||||
|
message.push('has no socials');
|
||||||
|
}
|
||||||
|
|
||||||
return { ok: ok, message: ok ? undefined : `MutableSocials -> Token ${message.join(' and ')}` };
|
return { ok: ok, message: ok ? undefined : `MutableSocials -> Token ${message.join(' and ')}` };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error({ mint: poolKeys.baseMint, error: e }, `MutableSocials -> Failed to check ${errorMessage.join(' and ')}`);
|
logger.error({ mint: poolKeys.baseMint }, `MutableSocials -> Failed to check ${this.errorMessage.join(' and ')}`);
|
||||||
return { ok: false, message: `MutableSocials -> Failed to check ${errorMessage.join(' and ')}` };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error({ mint: poolKeys.baseMint }, `MutableSocials -> Failed to check ${errorMessage.join(' and ')}`);
|
return {
|
||||||
return { ok: false, message: `MutableSocials -> Failed to check ${errorMessage.join(' and ')}` };
|
ok: false,
|
||||||
|
message: `MutableSocials -> Failed to check ${this.errorMessage.join(' and ')}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSocials(metadata: MetadataAccountData): Promise<Object> {
|
private async hasSocials(metadata: MetadataAccountData) {
|
||||||
const response = await fetch(metadata.uri);
|
const response = await fetch(metadata.uri);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data?.extensions;
|
return Object.values(data?.extensions ?? {}).some((value: any) => value !== null && value.length > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,23 @@ import { LiquidityPoolKeysV4 } from '@raydium-io/raydium-sdk';
|
|||||||
import { logger } from '../helpers';
|
import { logger } from '../helpers';
|
||||||
|
|
||||||
export class RenouncedFreezeFilter implements Filter {
|
export class RenouncedFreezeFilter implements Filter {
|
||||||
constructor(private readonly connection: Connection, private readonly checkRenounced: boolean, private readonly checkFreezable: boolean) {}
|
private readonly errorMessage: string[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly connection: Connection,
|
||||||
|
private readonly checkRenounced: boolean,
|
||||||
|
private readonly checkFreezable: boolean,
|
||||||
|
) {
|
||||||
|
if (this.checkRenounced) {
|
||||||
|
this.errorMessage.push('mint');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.checkFreezable) {
|
||||||
|
this.errorMessage.push('freeze');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
|
||||||
const errorMessage = [ this.checkRenounced ? 'mint' : undefined, this.checkFreezable ? 'freeze' : undefined ].filter((e) => e !== undefined);
|
|
||||||
try {
|
try {
|
||||||
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
|
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
|
||||||
if (!accountInfo?.data) {
|
if (!accountInfo?.data) {
|
||||||
@@ -18,15 +31,28 @@ export class RenouncedFreezeFilter implements Filter {
|
|||||||
const deserialize = MintLayout.decode(accountInfo.data);
|
const deserialize = MintLayout.decode(accountInfo.data);
|
||||||
const renounced = !this.checkRenounced || deserialize.mintAuthorityOption === 0;
|
const renounced = !this.checkRenounced || deserialize.mintAuthorityOption === 0;
|
||||||
const freezable = !this.checkFreezable || deserialize.freezeAuthorityOption !== 0;
|
const freezable = !this.checkFreezable || deserialize.freezeAuthorityOption !== 0;
|
||||||
|
|
||||||
const message = [ renounced ? undefined : 'mint', !freezable ? undefined : 'freeze' ].filter((e) => e !== undefined);
|
|
||||||
const ok = renounced && !freezable;
|
const ok = renounced && !freezable;
|
||||||
|
const message: string[] = [];
|
||||||
|
|
||||||
|
if (!renounced) {
|
||||||
|
message.push('mint');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (freezable) {
|
||||||
|
message.push('freeze');
|
||||||
|
}
|
||||||
|
|
||||||
return { ok: ok, message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens` };
|
return { ok: ok, message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens` };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error({ mint: poolKeys.baseMint }, `RenouncedFreeze -> Failed to check if creator can ${errorMessage.join(' and ')} tokens`);
|
logger.error(
|
||||||
|
{ mint: poolKeys.baseMint },
|
||||||
|
`RenouncedFreeze -> Failed to check if creator can ${this.errorMessage.join(' and ')} tokens`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ok: false, message: `RenouncedFreeze -> Failed to check if creator can ${errorMessage.join(' and ')} tokens` };
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: `RenouncedFreeze -> Failed to check if creator can ${this.errorMessage.join(' and ')} tokens`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class JitoTransactionExecutor implements TransactionExecutor {
|
|||||||
transaction: VersionedTransaction,
|
transaction: VersionedTransaction,
|
||||||
payer: Keypair,
|
payer: Keypair,
|
||||||
latestBlockhash: BlockhashWithExpiryBlockHeight,
|
latestBlockhash: BlockhashWithExpiryBlockHeight,
|
||||||
): Promise<{ confirmed: boolean; signature?: string }> {
|
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
|
||||||
logger.debug('Starting Jito transaction execution...');
|
logger.debug('Starting Jito transaction execution...');
|
||||||
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
|
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
|
||||||
logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);
|
logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class WarpTransactionExecutor implements TransactionExecutor {
|
|||||||
transaction: VersionedTransaction,
|
transaction: VersionedTransaction,
|
||||||
payer: Keypair,
|
payer: Keypair,
|
||||||
latestBlockhash: BlockhashWithExpiryBlockHeight,
|
latestBlockhash: BlockhashWithExpiryBlockHeight,
|
||||||
): Promise<{ confirmed: boolean; signature?: string }> {
|
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
|
||||||
logger.debug('Executing transaction...');
|
logger.debug('Executing transaction...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -41,7 +41,7 @@ export class WarpTransactionExecutor implements TransactionExecutor {
|
|||||||
const warpFeeTx = new VersionedTransaction(warpFeeMessage);
|
const warpFeeTx = new VersionedTransaction(warpFeeMessage);
|
||||||
warpFeeTx.sign([payer]);
|
warpFeeTx.sign([payer]);
|
||||||
|
|
||||||
const response = await axios.post<{ confirmed: boolean; signature: string, error?: string }>(
|
const response = await axios.post<{ confirmed: boolean; signature: string; error?: string }>(
|
||||||
'https://tx.warp.id/transaction/execute',
|
'https://tx.warp.id/transaction/execute',
|
||||||
{
|
{
|
||||||
transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],
|
transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],
|
||||||
|
|||||||
Reference in New Issue
Block a user