saros-dlmm-sdk-rsRust

Quick Start Guide

Get up and running with the Saros Finance DLMM SDK for Rust in minutes. This guide covers installation, basic setup, and your first operations using the high-performance Rust SDK.

Prerequisites
  • • Rust and Cargo installed
  • • Basic knowledge of Rust programming
  • • Solana wallet with some SOL for transaction fees
  • • Understanding of Solana's account model (helpful but not required)

1. Installation

Add the Saros Finance DLMM SDK to your Rust project's Cargo.toml:

Cargo.toml
[dependencies]
saros-dlmm-sdk = { path = "../saros-dlmm" }

2. Import and Initialize

Import the necessary modules and initialize the client:

Import SDK
use saros_dlmm_sdk::SarosDlmm;
use jupiter_amm_interface::{Amm, AmmContext, QuoteParams, SwapParams};
use solana_sdk::pubkey::Pubkey;
use std::sync::Arc;
use std::sync::atomic::{AtomicI64, AtomicU64};

Initialize Client

Initialize DLMM Client
// Initialize the DLMM client
#[tokio::main]
async fn main() -> Result<()> {
    let client = DlmmClient::new("https://api.devnet.solana.com".to_string())?;
    // Your code here
    Ok(())
}

3. Get a Swap Quote

Before executing a swap, get a quote for the expected output:

Get Swap Quote
let quote_params = QuoteParams {
    amount: 1000000,
    input_mint: Pubkey::from_str("C98A4nkJXhpVZNAZdHUA95RpTF3T4whtQubL3YobiUX9").unwrap(),
    output_mint: Pubkey::from_str("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v").unwrap(),
    swap_mode: SwapMode::ExactIn,
};
let quote = saros_dlmm.quote(&quote_params)?;

4. Execute Swap

Use the quote data to create and execute the swap transaction:

Execute Swap
let swap_params = SwapParams {
    in_amount: 1000000,
    out_amount: quote.out_amount,
    source_mint: Pubkey::from_str("C98A4nkJXhpVZNAZdHUA95RpTF3T4whtQubL3YobiUX9").unwrap(),
    destination_mint: Pubkey::from_str("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v").unwrap(),
    source_token_account: Pubkey::from_str("YOUR_SOURCE_TOKEN_ACCOUNT").unwrap(),
    destination_token_account: Pubkey::from_str("YOUR_DESTINATION_TOKEN_ACCOUNT").unwrap(),
    token_transfer_authority: Pubkey::from_str("YOUR_WALLET_PUBLIC_KEY").unwrap(),
};
let swap_and_account_metas = saros_dlmm.get_swap_and_account_metas(&swap_params)?;
Understanding the Swap Process
1. Initialize Client: First, we create a DlmmClient instance connected to the Solana network.
2. Get Quote: We call the get_quote method to calculate the expected output amount and other parameters needed for the swap.
3. Execute Swap: Then we use the swap method to create the transaction for the token exchange.
4. Sign and Send: In a real implementation, you would sign the transaction with your wallet and send it to the network.
🎉 Congratulations!
You've successfully set up the Saros Finance DLMM SDK for Rust and performed your first operations.
Troubleshooting
Compilation Issues: Make sure you have the latest Rust toolchain installed and all dependencies are correctly specified in your Cargo.toml.
Connection Issues: Verify that the RPC endpoint URL is correct and accessible.
Transaction Failures: Ensure your wallet has sufficient SOL for transaction fees and the tokens you're trying to swap.