@posit/parser
Transaction parsing engine for Solana DEX swaps
Core IP: The parser is the moat. Quality and accuracy here is the competitive advantage.
Overview
The parser package processes Solana transactions and extracts normalized swap data from multiple DEX protocols. It handles the complexity of aggregated routes, multi-hop swaps, and protocol-specific quirks.
Installation
# Within the monorepo
pnpm add @posit/parser --filter @posit/web
Basic Usage
import { parseTransaction } from '@posit/parser';
const result = await parseTransaction(transaction, {
walletAddress: 'YOUR_WALLET_ADDRESS',
});
// Result contains normalized swap data
console.log(result.swaps);
Supported Protocols
| Protocol | Type | Status |
|---|---|---|
| Jupiter | Aggregator | Complete |
| Raydium AMM | AMM | Complete |
| Raydium CLMM | Concentrated Liquidity | Complete |
| Pump.fun | Bonding Curve | Complete |
| Meteora DLMM | Dynamic Liquidity | In Progress |
| Orca Whirlpools | Concentrated Liquidity | In Progress |
Normalizer Architecture
Each protocol has a dedicated normalizer that converts protocol-specific transaction data into a common NormalizedSwap format:
interface NormalizedSwap {
signature: string;
timestamp: number;
protocol: string;
inputMint: string;
inputAmount: bigint;
outputMint: string;
outputAmount: bigint;
fee?: bigint;
feeMint?: string;
success: boolean;
}
Jupiter Normalizer
Handles aggregated routes by flattening inner legs to net in/out amounts. Correctly processes multi-hop routes and extracts platform fees.
Pump.fun Normalizer
Handles bonding curve swaps and migration events. Properly attributes fees and handles the unique pump.fun transaction structure.
Testing
# Run parser tests
pnpm --filter @posit/parser test
# Run with coverage
pnpm --filter @posit/parser test:coverage
# Update snapshots
pnpm --filter @posit/parser test -- -u
Adding a New Normalizer
- Create
src/normalizers/{protocol}.ts - Implement the
Normalizerinterface - Add program IDs to
constants.ts - Register in
normalizers/index.ts - Add snapshot tests with real transactions
Tip: Always test with real transactions from Solscan/Birdeye. Hand-verify amounts before creating snapshots.