Skip to content

Commit dfe9ab7

Browse files
Merge pull request #98 from fdundjer/master
cleanup: mutable and renounced filters
2 parents 29a9c92 + d22d45f commit dfe9ab7

File tree

4 files changed

+71
-22
lines changed

4 files changed

+71
-22
lines changed

filters/mutable.filter.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,60 @@ import { Serializer } from '@metaplex-foundation/umi/serializers';
77
import { logger } from '../helpers';
88

99
export class MutableFilter implements Filter {
10-
constructor(private readonly connection: Connection, private readonly metadataSerializer: Serializer<MetadataAccountDataArgs, MetadataAccountData>, private readonly checkMutable: boolean, private readonly checkSocials: boolean) {}
10+
private readonly errorMessage: string[] = [];
11+
12+
constructor(
13+
private readonly connection: Connection,
14+
private readonly metadataSerializer: Serializer<MetadataAccountDataArgs, MetadataAccountData>,
15+
private readonly checkMutable: boolean,
16+
private readonly checkSocials: boolean,
17+
) {
18+
if (this.checkMutable) {
19+
this.errorMessage.push('mutable');
20+
}
21+
22+
if (this.checkSocials) {
23+
this.errorMessage.push('socials');
24+
}
25+
}
1126

1227
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
13-
const errorMessage = [ this.checkMutable ? 'mutable' : undefined, this.checkSocials ? 'socials' : undefined ].filter((e) => e !== undefined);
1428
try {
1529
const metadataPDA = getPdaMetadataKey(poolKeys.baseMint);
16-
const metadataAccount = await this.connection.getAccountInfo(metadataPDA.publicKey);
30+
const metadataAccount = await this.connection.getAccountInfo(metadataPDA.publicKey, this.connection.commitment);
31+
1732
if (!metadataAccount?.data) {
1833
return { ok: false, message: 'Mutable -> Failed to fetch account data' };
1934
}
35+
2036
const deserialize = this.metadataSerializer.deserialize(metadataAccount.data);
21-
const mutable = this.checkMutable ? deserialize[0].isMutable: false;
37+
const mutable = !this.checkMutable || deserialize[0].isMutable;
38+
const hasSocials = !this.checkSocials || (await this.hasSocials(deserialize[0]));
39+
const ok = !mutable && hasSocials;
40+
const message: string[] = [];
2241

23-
const hasSocials = this.checkSocials ? (Object.values(await this.getSocials(deserialize[0])).some((value: any) => value !== null && value.length > 0)) === true: true;
42+
if (mutable) {
43+
message.push('metadata can be changed');
44+
}
2445

25-
const message = [ !mutable ? undefined : 'metadata can be changed', hasSocials ? undefined : 'has no socials' ].filter((e) => e !== undefined);
26-
const ok = !mutable && hasSocials;
46+
if (!hasSocials) {
47+
message.push('has no socials');
48+
}
2749

2850
return { ok: ok, message: ok ? undefined : `MutableSocials -> Token ${message.join(' and ')}` };
2951
} catch (e) {
30-
logger.error({ mint: poolKeys.baseMint, error: e }, `MutableSocials -> Failed to check ${errorMessage.join(' and ')}`);
31-
return { ok: false, message: `MutableSocials -> Failed to check ${errorMessage.join(' and ')}` };
52+
logger.error({ mint: poolKeys.baseMint }, `MutableSocials -> Failed to check ${this.errorMessage.join(' and ')}`);
3253
}
3354

34-
logger.error({ mint: poolKeys.baseMint }, `MutableSocials -> Failed to check ${errorMessage.join(' and ')}`);
35-
return { ok: false, message: `MutableSocials -> Failed to check ${errorMessage.join(' and ')}` };
55+
return {
56+
ok: false,
57+
message: `MutableSocials -> Failed to check ${this.errorMessage.join(' and ')}`,
58+
};
3659
}
3760

38-
async getSocials(metadata: MetadataAccountData): Promise<Object> {
61+
private async hasSocials(metadata: MetadataAccountData) {
3962
const response = await fetch(metadata.uri);
4063
const data = await response.json();
41-
return data?.extensions;
64+
return Object.values(data?.extensions ?? {}).some((value: any) => value !== null && value.length > 0);
4265
}
4366
}

filters/renounced.filter.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@ import { LiquidityPoolKeysV4 } from '@raydium-io/raydium-sdk';
55
import { logger } from '../helpers';
66

77
export class RenouncedFreezeFilter implements Filter {
8-
constructor(private readonly connection: Connection, private readonly checkRenounced: boolean, private readonly checkFreezable: boolean) {}
8+
private readonly errorMessage: string[] = [];
9+
10+
constructor(
11+
private readonly connection: Connection,
12+
private readonly checkRenounced: boolean,
13+
private readonly checkFreezable: boolean,
14+
) {
15+
if (this.checkRenounced) {
16+
this.errorMessage.push('mint');
17+
}
18+
19+
if (this.checkFreezable) {
20+
this.errorMessage.push('freeze');
21+
}
22+
}
923

1024
async execute(poolKeys: LiquidityPoolKeysV4): Promise<FilterResult> {
11-
const errorMessage = [ this.checkRenounced ? 'mint' : undefined, this.checkFreezable ? 'freeze' : undefined ].filter((e) => e !== undefined);
1225
try {
1326
const accountInfo = await this.connection.getAccountInfo(poolKeys.baseMint, this.connection.commitment);
1427
if (!accountInfo?.data) {
@@ -18,15 +31,28 @@ export class RenouncedFreezeFilter implements Filter {
1831
const deserialize = MintLayout.decode(accountInfo.data);
1932
const renounced = !this.checkRenounced || deserialize.mintAuthorityOption === 0;
2033
const freezable = !this.checkFreezable || deserialize.freezeAuthorityOption !== 0;
21-
22-
const message = [ renounced ? undefined : 'mint', !freezable ? undefined : 'freeze' ].filter((e) => e !== undefined);
2334
const ok = renounced && !freezable;
35+
const message: string[] = [];
36+
37+
if (!renounced) {
38+
message.push('mint');
39+
}
40+
41+
if (freezable) {
42+
message.push('freeze');
43+
}
2444

2545
return { ok: ok, message: ok ? undefined : `RenouncedFreeze -> Creator can ${message.join(' and ')} tokens` };
2646
} catch (e) {
27-
logger.error({ mint: poolKeys.baseMint }, `RenouncedFreeze -> Failed to check if creator can ${errorMessage.join(' and ')} tokens`);
47+
logger.error(
48+
{ mint: poolKeys.baseMint },
49+
`RenouncedFreeze -> Failed to check if creator can ${this.errorMessage.join(' and ')} tokens`,
50+
);
2851
}
2952

30-
return { ok: false, message: `RenouncedFreeze -> Failed to check if creator can ${errorMessage.join(' and ')} tokens` };
53+
return {
54+
ok: false,
55+
message: `RenouncedFreeze -> Failed to check if creator can ${this.errorMessage.join(' and ')} tokens`,
56+
};
3157
}
3258
}

transactions/jito-rpc-transaction-executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class JitoTransactionExecutor implements TransactionExecutor {
4444
transaction: VersionedTransaction,
4545
payer: Keypair,
4646
latestBlockhash: BlockhashWithExpiryBlockHeight,
47-
): Promise<{ confirmed: boolean; signature?: string }> {
47+
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
4848
logger.debug('Starting Jito transaction execution...');
4949
this.JitoFeeWallet = this.getRandomValidatorKey(); // Update wallet key each execution
5050
logger.trace(`Selected Jito fee wallet: ${this.JitoFeeWallet.toBase58()}`);

transactions/warp-transaction-executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class WarpTransactionExecutor implements TransactionExecutor {
2121
transaction: VersionedTransaction,
2222
payer: Keypair,
2323
latestBlockhash: BlockhashWithExpiryBlockHeight,
24-
): Promise<{ confirmed: boolean; signature?: string }> {
24+
): Promise<{ confirmed: boolean; signature?: string; error?: string }> {
2525
logger.debug('Executing transaction...');
2626

2727
try {
@@ -41,7 +41,7 @@ export class WarpTransactionExecutor implements TransactionExecutor {
4141
const warpFeeTx = new VersionedTransaction(warpFeeMessage);
4242
warpFeeTx.sign([payer]);
4343

44-
const response = await axios.post<{ confirmed: boolean; signature: string, error?: string }>(
44+
const response = await axios.post<{ confirmed: boolean; signature: string; error?: string }>(
4545
'https://tx.warp.id/transaction/execute',
4646
{
4747
transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],

0 commit comments

Comments
 (0)