
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
solana-swap-parser
Advanced tools
A TypeScript library for parsing Solana DEX swap transaction results
A TypeScript library specialized in parsing Solana DEX swap transaction results. This parser extracts detailed swap information from various Solana DEX transactions, focusing on the actual swap results and token transfers.
The parser automatically detects and handles swap transactions from:
npm install solana-swap-parser
# or
yarn add solana-swap-parser
import { Connection } from '@solana/web3.js';
import { TransactionParser } from 'solana-swap-parser';
import { SwapState } from 'solana-swap-parser';
import { setDebugLogs } from 'solana-swap-parser';
// Initialize connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
// Production mode (no debug logs)
const parser = new TransactionParser(connection);
// Development mode (with debug logs)
const debugParser = new TransactionParser(connection, true);
The library provides granular control over debug logging for different components:
// 1. Parser logging
const parser = new TransactionParser(connection, true); // Enable parser logs
// 2. Token state logging
SwapState.setDebugLogs(true); // Enable token state logs
// 3. Utility function logging
setDebugLogs(true); // Enable utility logs
// 4. Retry mechanism logging
const result = await withRetry(
() => someOperation(),
{
enableDebugLogs: true,
maxAttempts: 3
}
);
When debug logging is enabled, you'll see information about:
Transaction Processing
Token Operations
Retry Mechanism
Utility Operations
For production environments, it's recommended to disable all debug logs:
const parser = new TransactionParser(connection, false);
SwapState.setDebugLogs(false);
setDebugLogs(false);
import { Connection, Commitment } from '@solana/web3.js';
import { TransactionParser } from 'solana-swap-parser';
// Configure connection with custom settings
const rpcUrl = 'your_rpc_endpoint';
const commitment: Commitment = 'confirmed';
const connection = new Connection(rpcUrl, {
commitment,
confirmTransactionInitialTimeout: 60000,
wsEndpoint: 'your_ws_endpoint' // Optional WebSocket endpoint
});
const parser = new TransactionParser(connection);
import { TransactionParser } from 'solana-swap-parser';
async function parseSwap(signature: string) {
try {
const result = await parser.parseTransaction(signature);
if (!result.success) {
switch (result.error) {
case 'TRANSACTION_NOT_FOUND':
console.error('Transaction not found or expired');
break;
case 'INVALID_SIGNATURE':
console.error('Invalid transaction signature format');
break;
case 'UNKNOWN_AMM':
console.error('Unsupported DEX protocol');
break;
case 'RATE_LIMIT':
console.error('RPC rate limit exceeded');
break;
default:
console.error('Unknown error:', result.error);
}
return;
}
// Process successful result
const {
TokenInMint,
TokenInAmount,
TokenOutMint,
TokenOutAmount,
AMMs
} = result.data;
// Your processing logic here
} catch (error) {
console.error('Failed to parse swap:', error);
}
}
import { TransactionParser } from 'solana-swap-parser';
async function parseMultipleSwaps(signatures: string[]) {
const results = await Promise.all(
signatures.map(async (sig) => {
try {
const result = await parser.parseTransaction(sig);
return {
signature: sig,
...result
};
} catch (error) {
return {
signature: sig,
success: false,
error: error.message
};
}
})
);
// Filter successful swaps
const successfulSwaps = results.filter(r => r.success);
// Process results
successfulSwaps.forEach(swap => {
console.log(`Swap ${swap.signature}:`, swap.data);
});
}
import { Connection } from '@solana/web3.js';
import { TransactionParser } from 'solana-swap-parser';
async function parseAnySwap(signature: string) {
const connection = new Connection('https://api.mainnet-beta.solana.com');
const parser = new TransactionParser(connection);
const result = await parser.parseTransaction(signature);
if (result.success) {
// The AMM type is automatically detected and included in the result
console.log('Detected AMM:', result.data.AMMs[0]); // e.g., "RAYDIUM", "ORCA", etc.
console.log('Swap details:', {
tokenIn: result.data.TokenInMint,
amountIn: result.data.TokenInAmount,
tokenOut: result.data.TokenOutMint,
amountOut: result.data.TokenOutAmount,
});
}
}
// Examples with different DEXs - same code works for all:
await parseAnySwap('raydium_swap_signature'); // Works for Raydium
await parseAnySwap('orca_swap_signature'); // Works for Orca
await parseAnySwap('jupiter_swap_signature'); // Works for Jupiter
// ... and so on for any supported DEX
# Install dependencies
yarn install
# Run tests
yarn test
# Run linter
yarn lint
# Fix lint issues
yarn lint:fix
# Format code
yarn format
# Type check
yarn check-types
The parser may return the following error codes:
TRANSACTION_NOT_FOUND: Transaction signature is invalid or transaction has expiredINVALID_SIGNATURE: Invalid transaction signature formatUNKNOWN_AMM: Unsupported DEX protocolPARSE_ERROR: Failed to parse transaction dataRATE_LIMIT: RPC rate limit exceededINVALID_TOKEN_ACCOUNT: Failed to get token account informationContributions are welcome! Please feel free to submit a Pull Request.
This project's implementation was inspired by solanaswap-go. Thanks for their great work!
If this project has saved you time, consider buying me a coffee:
SOL Address: DnqW4j7ZVtfqR1D3ZmNfHFatoLjYCpici1pzFaJmkmBd
MIT License - see LICENSE for details
FAQs
A TypeScript library for parsing Solana DEX swap transaction results
We found that solana-swap-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.