<<<<<<< HEAD
A comprehensive Node.js suite for automated SOL to USDC swaps on Solana mainnet using Jupiter V6 API. Features CLI tools, REST API, performance profiling, and advanced fee management.
- β Core Swap Engine: Reliable SOL β USDC swaps with configurable fees
- β CLI Interface: Simple command-line tool for quick swaps
- β REST API: HTTP endpoints for integration with web apps
- β Performance Profiling: Advanced monitoring and optimization tools
- β Priority Fee Management: Dynamic fee calculation for optimal transaction speed
- β Comprehensive Error Handling: Robust error management and retry logic
- β Security: Private key validation and secure transaction signing
-
Clone the repository:
git clone <repository-url> cd JupiterSwap
-
Install dependencies:
npm install
-
First-time setup: =======
A simple Node.js CLI tool to swap exactly 0.0000001 SOL to USDC on Solana mainnet using the Jupiter Aggregator V6 API.
- β Swaps exactly 0.0000001 SOL to USDC (safe for testing)
- β Configurable platform fee via environment variables
- β Jupiter V6 API integration
- β Automatic transaction signing and sending
- β Comprehensive error handling
- β No interactive prompts
- Clone or download the project
- Install dependencies:
npm installBefore you can use the swap bot, you need a funded Solana wallet and a valid configuration file.
- Generate a wallet and .env file automatically:
7acc588eb1356aa72443dadabda33980939b50b9
node setup.js<<<<<<< HEAD
This generates a new Solana wallet and creates a .env file with the correct configuration.
- Fund your wallet:
- After setup, the script displays your wallet address
- Send at least 0.001 SOL to this address for testing
- Use exchanges (Binance, Coinbase) or Solana faucets
- This will create a new Solana wallet and generate a
.envfile with the correct format. - Important: The private key is stored in
.env. Never share this file!
-
Fund your wallet:
- After running the setup, the script will display your new wallet address (public key).
- Send some SOL to this address (at least 0.001 SOL for testing).
- You can use exchanges (Binance, Coinbase, etc.) or a Solana faucet for devnet (for mainnet, use real SOL).
-
Check your .env file:
- Make sure the fields
PRIVATE_KEY,FEE_RECIPIENT, andFEE_BASIS_POINTSare filled in. - You can edit the fee recipient and fee percentage if needed.
- Make sure the fields
-
Security reminder:
- Never share your private key or .env file.
- Use a dedicated wallet for testing and small amounts.
- Copy the example environment file:
7acc588eb1356aa72443dadabda33980939b50b9
cp env.example .env<<<<<<< HEAD
Edit .env with your settings:
# Required: Solana wallet private key (Base58 encoded)
PRIVATE_KEY=your_base58_encoded_private_key_here
# Required: Fee recipient wallet address
FEE_RECIPIENT=your_fee_recipient_wallet_address_here
# Required: Fee in basis points (e.g., 30 = 0.3%)
FEE_BASIS_POINTS=30
# Optional: Custom RPC endpoint
RPC_ENDPOINT=https://api.mainnet-beta.solana.com| Variable | Required | Description | Default |
|---|---|---|---|
PRIVATE_KEY |
Yes | Base58-encoded Solana wallet private key | - |
FEE_RECIPIENT |
Yes | Wallet address receiving platform fees | - |
FEE_BASIS_POINTS |
Yes | Fee percentage (0-10000) | - |
RPC_ENDPOINT |
No | Custom RPC endpoint | Public Solana RPC |
Basic swap (recommended):
npm start
# or
node index.jsAlternative swap modes:
# Simple swap without priority fees
npm run swap
# Swap with dynamic priority fees
npm run swap:priorityPerformance profiling:
# View performance baseline
npm run profile:report
# Run comprehensive performance tests
npm run profile
# Generate mock baseline data
npm run profile:baselineStart the API server:
node server.jsServer runs on http://localhost:3001
API Endpoints:
Execute a SOL to USDC swap.
Request Body:
{
"privateKey": "your_base58_private_key",
"feeRecipient": "wallet_address",
"feeBps": 30,
"rpcEndpoint": "https://api.mainnet-beta.solana.com"
}Response:
{
"success": true,
"signature": "transaction_signature",
"logs": [
"π Starting Jupiter V6 SOL β USDC swap...",
"β
Environment validation passed",
"π° Wallet balance: 0.001234 SOL",
"π Getting quote from Jupiter V6...",
"β
Quote received:",
" π₯ Input: 0.0000001 SOL",
" π€ Output: 0.000123 USDC",
"π Swap completed successfully!",
"π Explorer: https://solscan.io/tx/5J7X..."
]
}=======
2. Edit .env with your configuration:
# Solana wallet private key (Base58 encoded)
PRIVATE_KEY=your_base58_encoded_private_key_here
# Fee recipient wallet address
FEE_RECIPIENT=your_fee_recipient_wallet_address_here
# Fee in basis points (e.g., 30 = 0.3%)
FEE_BASIS_POINTS=30
# Optional: RPC endpoint (defaults to public endpoint)
# RPC_ENDPOINT=https://api.mainnet-beta.solana.comRun the swap:
npm startOr directly:
node index.js| Variable | Required | Description |
|---|---|---|
PRIVATE_KEY |
Yes | Base58-encoded Solana wallet private key |
FEE_RECIPIENT |
Yes | Wallet address that will receive the platform fee |
FEE_BASIS_POINTS |
Yes | Integer representing fee in basis points (0-10000) |
RPC_ENDPOINT |
No | Custom RPC endpoint (defaults to public) |
7acc588eb1356aa72443dadabda33980939b50b9
π Starting Jupiter V6 SOL β USDC swap...
β
Environment validation passed
π° Wallet balance: 0.001234 SOL
π Getting quote from Jupiter V6...
β
Quote received:
π₯ Input: 0.0000001 SOL
π€ Output: 0.000123 USDC
π₯ Price Impact: 0.0001%
π€οΈ Route: Raydium
πΈ Platform Fee: 30 bps to 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
π¨ Creating swap transaction...
π¨ Transaction sent: 5J7X...
β³ Waiting for confirmation...
π Swap completed successfully!
π Explorer: https://solscan.io/tx/5J7X...
π Swapped: 0.0000001 SOL β 0.000123 USDC
π° Platform fee: 30 bps paid to 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
<<<<<<< HEAD
The project includes advanced performance profiling tools:
- Total Swap Time: 12.85 seconds average
- Success Rate: 80% (8/10 successful swaps)
- Compute Units: 139,782 CU average
- Transaction Cost:
0.000699 SOL ($0.07 @ $100 SOL)
# View detailed performance report
npm run profile:reportKey Metrics:
- Quote API Latency: 1.09s average
- Transaction Build: 1.53s average
- Transaction Confirmation: 12.23s average
β οΈ - RPC Latency: 59.8ms average
- Transaction Confirmation (Critical): Implement dynamic priority fees
- API Optimization (Medium): Add quote caching and request batching
- Reliability (Medium-High): Enhanced error handling and retry logic
- Status: β Active (Recommended)
- Purpose: Core swap functionality with comprehensive configuration
- Features: Priority fee management, detailed logging, error handling
QuoteService.js: Jupiter API integrationPriorityFeeService.js: Dynamic fee calculationNetworkService.js: RPC connection managementTxService.js: Transaction processing
- Purpose: HTTP endpoints for web integration
- Features: CORS support, JSON responses, comprehensive logging
The following files are maintained for backwards compatibility:
index.js- Deprecated wrapper (usecore-swap.js)jupiter-swap.js- Deprecated wrapper (usecore-swap.js)
Migration Guide:
// OLD
import JupiterSwapBot from "./index.js";
// NEW
import CoreSwap from "./core-swap.js";
const swap = new CoreSwap({
useSharedAccounts: true,
onlyDirectRoutes: false,
includeDetailedBalance: false,
});setup.js: Wallet generation and configurationdemo.js: Jupiter API testingtest.js: Environment validationdebug.js: Quote and transaction debugging
"Insufficient SOL balance"
- Fund your wallet with at least 0.001 SOL
- Check balance with:
node check-balance.js
"Invalid private key"
- Ensure private key is Base58 encoded
- Verify key length is 64 bytes
- Use
node setup.jsto generate a new wallet
"Transaction failed"
- Check network connectivity
- Verify RPC endpoint is accessible
- Ensure sufficient SOL for transaction fees
"Quote request failed"
- Check Jupiter API status
- Verify token addresses are correct
- Ensure slippage tolerance is reasonable
Slow transaction confirmation:
- Use dynamic priority fees:
npm run swap:priority - Consider premium RPC endpoints
- Monitor network congestion
High failure rate:
- Increase priority fees
- Use retry logic with exponential backoff
- Check RPC endpoint reliability
JupiterSwap/
βββ core-swap.js # Main swap engine (recommended)
βββ server.js # REST API server
βββ index.js # CLI wrapper (deprecated)
βββ services/ # Modular services
β βββ QuoteService.js # Jupiter API integration
β βββ PriorityFeeService.js # Fee calculation
β βββ NetworkService.js # RPC management
β βββ TxService.js # Transaction processing
βββ setup.js # Wallet generation
βββ demo.js # API testing
βββ test.js # Environment validation
βββ debug.js # Debugging tools
βββ performance-profiler.js # Performance monitoring
βββ baseline-report-generator.js # Baseline generation
βββ display-report.js # Report viewer
βββ check-balance.js # Balance checking
βββ check-token-accounts.js # Token account validation
βββ swap-priority.js # Priority fee swap
βββ swap-priority-minimal.js # Minimal priority swap
βββ swap-no-priority.js # No priority fee swap
βββ package.json # Dependencies and scripts
βββ env.example # Configuration template
βββ README.md # This file
βββ TECHNICAL.md # Technical documentation
βββ UPGRADE_SUMMARY.md # Recent improvements
βββ TASK_COMPLETION_SUMMARY.md # Performance audit results
βββ PERFORMANCE_PROFILING.md # Performance documentation
βββ DEPRECATION.md # Deprecated components
- Never share your private key or
.envfile - Use dedicated wallets for testing
- Start with small amounts (0.001 SOL)
- Consider using custom RPC endpoints for production
- Regularly update dependencies
# Never commit .env file
echo ".env" >> .gitignore
# Use environment-specific configurations
cp env.example .env.production
cp env.example .env.development- Fork the repository
- Create a feature branch
- Install dependencies:
npm install - Run tests:
npm test - Submit a pull request
- Use ES6+ modules
- Follow JSDoc documentation standards
- Include error handling for all async operations
- Add performance monitoring for new features
# Run all tests
npm test
# Test specific components
node test.js
node demo.jsMIT License - see LICENSE file for details.
- Jupiter API: https://docs.jup.ag/
- Solana Explorer: https://explorer.solana.com/
- Solscan: https://solscan.io/
- Solana Web3.js: https://docs.solana.com/developing/clients/javascript-api
The CLI will exit with clear error messages for:
- Missing environment variables
- Invalid private key format
- Invalid wallet addresses
- Insufficient SOL balance
- Network errors
- Transaction failures
dotenv- Environment variable management@solana/web3.js- Solana blockchain interactionaxios- HTTP requests to Jupiter APIbs58- Base58 encoding/decoding
- Never commit your
.envfile - Keep your private key secure
- Use a dedicated wallet for testing
- Consider using a custom RPC endpoint for production
MIT
7acc588eb1356aa72443dadabda33980939b50b9