https://github.com/casatrick/solana-swap-decoder
Rust library for decoding swap transactions on Solana from unprocessed data - before on-chain confirmation
https://github.com/casatrick/solana-swap-decoder
decoder dex mev parser rust solana swap
Last synced: 9 days ago
JSON representation
Rust library for decoding swap transactions on Solana from unprocessed data - before on-chain confirmation
- Host: GitHub
- URL: https://github.com/casatrick/solana-swap-decoder
- Owner: casatrick
- Created: 2026-01-29T05:54:03.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-02-04T06:13:13.000Z (5 months ago)
- Last Synced: 2026-06-19T07:36:50.743Z (10 days ago)
- Topics: decoder, dex, mev, parser, rust, solana, swap
- Language: Rust
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Solana Swap Transaction Decoder
Rust library for decoding swap transactions on Solana from unprocessed transactions. Works with raw instruction data before on-chain confirmation.
## Features
- Decode unprocessed transactions
- Multi-DEX support (Pumpswap, Meteora DLMM, Orca Whirlpools)
- Zero-copy parsing for performance
- Exact-in and exact-out swap support
- MEV detection
- Utility functions for price calc and slippage
## Supported DEXes
| DEX | Program ID | Swap Types |
|-----|-----------|------------|
| Pumpswap | `6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P` | Exact In, Exact Out |
| Meteora DLMM | `LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo` | Exact In |
| Orca Whirlpools | `whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc` | Exact In, Exact Out, Two-Hop |
## Usage
Add to `Cargo.toml`:
```toml
[dependencies]
solana-swap-decoder = { path = "." }
```
Basic example:
```rust
use solana_sdk::message::Message;
use swap_decoder::decode_transaction_swaps;
fn decode_swap(message: &Message) {
let swaps = decode_transaction_swaps(message);
for swap_result in swaps {
if let Ok(swap_info) = swap_result {
println!("DEX: {:?}", swap_info.dex);
println!("User: {}", swap_info.user);
if swap_info.is_exact_in {
println!("Amount In: {:?}", swap_info.amount_in);
println!("Min Out: {:?}", swap_info.min_amount_out);
} else {
println!("Max In: {:?}", swap_info.max_amount_in);
println!("Amount Out: {:?}", swap_info.amount_out);
}
}
}
}
```
## Examples
```bash
cargo run --example simple_decode
cargo run --example decode_from_bytes
cargo run --example decode_unprocessed_tx
cargo run --example monitor_mempool --features cli
```
## Installation
```bash
cargo build --lib --release
cargo build --release --features cli # with CLI tools
```
## Use Cases
### MEV Bot
```rust
use swap_decoder::{decode_transaction_swaps, detect_mev_opportunity};
let swaps = decode_transaction_swaps(&message);
let valid_swaps: Vec<_> = swaps.into_iter().filter_map(Result::ok).collect();
if let Some(opportunity) = detect_mev_opportunity(&valid_swaps) {
println!("MEV opportunity: {:?}", opportunity);
}
```
### Monitoring
```rust
for swap in decode_transaction_swaps(&message) {
if let Ok(info) = swap {
if info.amount_in.unwrap_or(0) > 1_000_000_000 {
alert_large_swap(info);
}
}
}
```
## Testing
```bash
cargo test
cargo test test_decode_pumpswap
cargo test -- --nocapture
```
## License
MIT