Package Exports
- solana-dex-parser
- solana-dex-parser/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (solana-dex-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Solana Dex Transaction Parser
A TypeScript library for parsing Solana DEX swap transactions. Supports multiple DEX protocols including Jupiter, Raydium, Meteora, PumpFun, and Moonshot.
Features
- Parse swap transactions from multiple DEX protocols
- Support for transfer and transfer-check instructions
- Detailed swap information extraction
- Built-in error handling and validation
- TypeScript type definitions
- Comprehensive test coverage
Supported DEX Protocols
- Jupiter
- Raydium
- Meteora
- PumpFun
- Moonshot
- Orca
- Phoenix
- OKX Dex
Supported Trading Bot Programs
- Banana gun
- Mintech
- Bloom
- Maestro
- Nova
Installation
npm install solana-dex-parserUsage
Configuration Options
The DexParser class doesn't require any configuration. It automatically detects the DEX protocol used in the transaction and applies the appropriate parsing logic.
Basic Usage
import { Connection } from '@solana/web3.js';
import { DexParser } from 'solana-dex-parser';
async function parseSwap() {
// Setup connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
// Get transaction
const signature = 'your-transaction-signature';
const parser = new DexParser(connection);
// case 1, by signature
const trades = await parser.parseTransaction(signature);
console.log("Trades:", trades);
// case 2, by tx object
const tx = await this.connection.getParsedTransaction(signature, {
commitment: "confirmed",
maxSupportedTransactionVersion: 0,
});
const trades2 = await parser.parseTrades(tx);
console.log("trades2:", trades);
}
Common Use Cases
- Analyzing DEX trading activity:
const signatures = ['sig1', 'sig2', 'sig3'];
const allTrades = [];
for (const signature of signatures) {
const parsedTransaction = await connection.getParsedTransaction(signature);
const trades = dexParser.parseTransaction(parsedTransaction);
allTrades.push(...trades);
}
console.log(`Total trades: ${allTrades.length}`);- Extracting token transfer information:
import { TransferParser } from 'solana-dex-parser';
// Setup connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
// Get transaction
const signature = 'your-transaction-signature';
const tx = await this.connection.getParsedTransaction(signature, {
maxSupportedTransactionVersion: 0,
});
const transferParser = new TransferParser();
const transfers = transferParser.parseTransfers(tx);
console.log(transfers);- Extracting Pumpfun events (create/trade/complete):
import { PumpfunEventParser } from 'solana-dex-parser';
// Setup connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
// Get transaction
const signature = 'your-transaction-signature';
const tx = await this.connection.getParsedTransaction(signature, {
maxSupportedTransactionVersion: 0,
});
const eventParser = new PumpfunEventParser(tx);
const events = eventParser.processEvents(); // PumpfunEvent[]
console.log(events);
export interface PumpfunEvent {
type: "TRADE" | "CREATE" | "COMPLETE";
data: PumpfunTradeEvent | PumpfunCreateEvent | PumpfunCompleteEvent;
slot: number;
timestamp: number;
signature: string;
}Development
Prerequisites
- Node.js >= 16
- npm >= 7
Setup
- Clone the repository
git clone https://github.com/cxcx-ai/solana-dex-parser.git
cd solana-dex-parser- Install dependencies
npm install- Build the project
npm run buildTesting
Run the test suite:
npm testRun tests with coverage:
npm run test:coverageContributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This project is a TypeScript port of the original Go implementation solana-swap-go.