A CLI tool for interacting with the Raydium DEX protocol on Solana. This tool allows you to:
- Get quotes for token swaps against SOL/wSOL pairs
- Execute swaps with customizable slippage protection
- View detailed transaction reports after execution
- Query real-time quotes from Raydium liquidity pools
- Support for both buy and sell operations
- Customizable slippage tolerance
- Automatic token account creation for new tokens
- Detailed transaction reporting including executed price and slippage metrics
- Rust and Cargo installed
- A Solana RPC endpoint
- A funded Solana wallet
-
Clone the repository:
git clone [repository-url] cd spark-coding-challenge2
-
Create a
.env
file in the project root with the following variables:PRIVATE_KEY=your_base58_encoded_private_key RPC=your_solana_rpc_endpoint WSOL_ADDRESS=your_wsol_address
-
Build the project:
cargo build --release
Run the application:
cargo run --release
- Enter the token address for the token you want to swap
- Specify whether you want to buy or sell
- Enter the quantity (in SOL for buy, or in tokens for sell)
- Review the quote
- Accept or reject the quote
- If accepted, specify your desired slippage tolerance (0.1-100%)
- The transaction will be executed and a detailed report will be displayed
Enter the token address: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
Enter the side (buy/sell): buy
Enter the quantity in SOL: 0.1
Quote: 1.0234 USDC
Do you accept the quote? (yes/no): yes
Enter the desired slippage (0.1-100): 1
Tx signature: 4zDSPVG3Q3Ycu9UKiFHHGL5VidhbJpGmZJ5HvkgFErGkLee6ktPkGwYcwrL1YHcNTST2wUZiH7yKmNEvD4dpKQAW
=== Raydium Swap ===
Type: BUY
Amount In: 0.1
Amount Out: 1.0231
There was a -0.98% difference between the slippage you requested and the slippage that was executed.
Executed Price: 0.097741177 Token/SOL
==================
-
wSOL Account: The application assumes you have a wSOL account at a specific address. If you don't have one, you may need to create one using the Solana CLI or a wallet interface.
-
RPC Provider: The application requires a reliable RPC provider with good performance. Some operations may fail if the RPC provider has rate limits or high latency.
-
Pool Selection: For simplicity, the application selects the pool with the highest liquidity for a given token and standart type, which may not always provide the best price.
-
Token Support: Only tokens with Original Standart (Not Token-2022) existing Raydium liquidity pools against SOL/wSOL are supported.
-
Error Handling: Basic error handling is implemented, but some edge cases may not be fully covered.
-
Gas Specifications: Compute Unit Price/Limit and Account Size Data Limit are stablished with default numbers
- Protocol: This application uses the Raydium DEX protocol for swapping tokens
- Transaction Construction: Directly constructs and signs Raydium swap transactions
- Quotation: Calculates quotes based on the current pool reserves, in case there are Limit orders on the Pool the quote might not be correct
- Slippage Protection: Implements minimum output calculation based on user-defined slippage tolerance
- IDE: This project has being developed in Cursor, using his tab function
- Documentation: All the comments and documentation has being written with the help of Claude 4
MIT