import { subscribe, CommitmentLevel, LaserstreamConfig, SubscribeRequest } from 'helius-laserstream';
import bs58 from 'bs58';
const PUMP_PROGRAM_ID = '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P';
// Rolling stats across the session.
const stats = {
startedAt: Date.now(),
transactions: 0,
successes: 0,
failures: 0,
uniquePayers: new Set<string>(),
totalFeesLamports: 0,
accountUpdates: 0,
};
async function handleUpdate(data: any) {
if (data.transaction) {
const tx = data.transaction.transaction;
if (!tx) return;
stats.transactions++;
const failed = !!tx.meta?.err;
failed ? stats.failures++ : stats.successes++;
// tx.meta.fee is a u64 string — coerce before adding.
stats.totalFeesLamports += Number(tx.meta?.fee ?? 0);
// Fee payer is the first account in the message.
const firstKey = tx.transaction?.message?.accountKeys?.[0];
if (firstKey) {
const payer = typeof firstKey === 'string' ? firstKey : bs58.encode(firstKey);
stats.uniquePayers.add(payer);
}
// tx.signature is a Buffer in the SDK.
const sig = bs58.encode(tx.signature);
const slot = data.transaction.slot;
const flag = failed ? '❌' : '✅';
console.log(`${flag} ${sig.slice(0, 12)}… slot ${slot} fee ${tx.meta?.fee} lamports`);
}
if (data.account) {
stats.accountUpdates++;
const acct = data.account.account;
const pubkey = typeof acct.pubkey === 'string' ? acct.pubkey : bs58.encode(acct.pubkey);
console.log(`📋 account ${pubkey} ${acct.data?.length ?? 0} bytes`);
}
}
function printReport() {
const minutes = (Date.now() - stats.startedAt) / 60_000;
console.log('\n📊 Pump.fun activity report');
console.log(` Runtime: ${minutes.toFixed(1)} min`);
console.log(` Transactions: ${stats.transactions} (${stats.successes} ok, ${stats.failures} failed)`);
console.log(` Throughput: ${(stats.transactions / Math.max(minutes, 0.0001)).toFixed(1)} tx/min`);
console.log(` Unique fee payers: ${stats.uniquePayers.size}`);
console.log(` Total fees: ${(stats.totalFeesLamports / 1e9).toFixed(4)} SOL`);
console.log(` Account updates: ${stats.accountUpdates}\n`);
}
async function main() {
const config: LaserstreamConfig = {
apiKey: process.env.HELIUS_API_KEY ?? 'YOUR_API_KEY',
endpoint: 'https://laserstream-mainnet-ewr.helius-rpc.com', // pick the region closest to you
};
const subscriptionRequest: SubscribeRequest = {
accounts: {
'pump-accounts': {
account: [],
owner: [PUMP_PROGRAM_ID],
filters: [],
},
},
transactions: {
'pump-transactions': {
accountInclude: [PUMP_PROGRAM_ID],
accountExclude: [],
accountRequired: [],
vote: false,
failed: false,
},
},
commitment: CommitmentLevel.CONFIRMED,
slots: {},
transactionsStatus: {},
blocks: {},
blocksMeta: {},
entry: {},
accountsDataSlice: [],
};
console.log('🚀 Streaming Pump.fun activity. Press Ctrl+C to stop.\n');
const reportTimer = setInterval(printReport, 60_000);
process.on('SIGINT', () => {
clearInterval(reportTimer);
printReport();
process.exit(0);
});
await subscribe(config, subscriptionRequest, handleUpdate, async (error) => {
console.error('Stream error:', error);
});
}
main().catch(console.error);