Skip to content

wxyz-git/spark-coding-challenge2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana Raydium Swap CLI

A CLI tool for interacting with the Raydium DEX protocol on Solana. This tool allows you to:

  1. Get quotes for token swaps against SOL/wSOL pairs
  2. Execute swaps with customizable slippage protection
  3. View detailed transaction reports after execution

Features

  • 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

Prerequisites

  • Rust and Cargo installed
  • A Solana RPC endpoint
  • A funded Solana wallet

Setup

  1. Clone the repository:

    git clone [repository-url]
    cd spark-coding-challenge2
    
  2. 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
    
  3. Build the project:

    cargo build --release
    

Usage

Run the application:

cargo run --release

Workflow:

  1. Enter the token address for the token you want to swap
  2. Specify whether you want to buy or sell
  3. Enter the quantity (in SOL for buy, or in tokens for sell)
  4. Review the quote
  5. Accept or reject the quote
  6. If accepted, specify your desired slippage tolerance (0.1-100%)
  7. The transaction will be executed and a detailed report will be displayed

Example

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
==================

Assumptions and Limitations

  1. 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.

  2. 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.

  3. 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.

  4. Token Support: Only tokens with Original Standart (Not Token-2022) existing Raydium liquidity pools against SOL/wSOL are supported.

  5. Error Handling: Basic error handling is implemented, but some edge cases may not be fully covered.

  6. Gas Specifications: Compute Unit Price/Limit and Account Size Data Limit are stablished with default numbers

Technical Details

  • 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

AI usage

  • 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

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages