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.
Add the Saros Finance DLMM SDK to your Rust project's Cargo.toml
:
[dependencies]
saros-dlmm-sdk = { path = "../saros-dlmm" }
Import the necessary modules and initialize the client:
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 the DLMM client
#[tokio::main]
async fn main() -> Result<()> {
let client = DlmmClient::new("https://api.devnet.solana.com".to_string())?;
// Your code here
Ok(())
}
Before executing a swap, get a quote for the expected output:
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("e_params)?;
Use the quote data to create and execute the swap transaction:
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)?;
DlmmClient
instance connected to the Solana network.get_quote
method to calculate the expected output amount and other parameters needed for the swap.swap
method to create the transaction for the token exchange.Cargo.toml
.