feat: add Meteora DAMM V2 support and bump to v3.0.1

Add Meteora DAMM V2 trading protocol with instruction builder, type definitions, and fixed_output_token_amount parameter for precise output control. Update all examples and documentation.
This commit is contained in:
ysq
2025-10-05 22:27:04 +08:00
parent 30a7d570fa
commit 2f5a63ed55
33 changed files with 719 additions and 59 deletions
+1
View File
@@ -168,6 +168,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
+2
View File
@@ -163,6 +163,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -205,6 +206,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
durable_nonce: None,
create_output_token_ata: false,
close_output_token_ata: false,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
+2
View File
@@ -133,6 +133,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -168,6 +169,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
open_seed_optimize: false,
with_tip: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
+10
View File
@@ -629,6 +629,7 @@ async fn handle_buy_pumpfun(
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.buy(buy_params).await {
Ok((_, signature)) => {
@@ -678,6 +679,7 @@ async fn handle_buy_pumpswap(
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.buy(buy_params).await {
Ok((_, signature)) => {
@@ -726,6 +728,7 @@ async fn handle_buy_bonk(
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.buy(buy_params).await {
Ok((_, signature)) => {
@@ -778,6 +781,7 @@ async fn handle_buy_raydium_v4(
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.buy(buy_params).await {
Ok((_, signature)) => {
@@ -830,6 +834,7 @@ async fn handle_buy_raydium_cpmm(
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.buy(buy_params).await {
Ok((_, signature)) => {
@@ -992,6 +997,7 @@ async fn handle_sell_pumpfun(
close_output_token_ata: false,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.sell(sell_params).await {
@@ -1044,6 +1050,7 @@ async fn handle_sell_pumpswap(
close_output_token_ata: false,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.sell(sell_params).await {
Ok((_, signature)) => {
@@ -1095,6 +1102,7 @@ async fn handle_sell_bonk(
close_output_token_ata: false,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.sell(sell_params).await {
Ok((_, signature)) => {
@@ -1149,6 +1157,7 @@ async fn handle_sell_raydium_v4(
close_output_token_ata: false,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.sell(sell_params).await {
Ok((_, signature)) => {
@@ -1203,6 +1212,7 @@ async fn handle_sell_raydium_cpmm(
close_output_token_ata: false,
open_seed_optimize: use_seed,
durable_nonce: None,
fixed_output_token_amount: None,
};
match client.sell(sell_params).await {
Ok((_, signature)) => {
@@ -0,0 +1,12 @@
[package]
name = "meteora_damm_v2_direct_trading"
version = "0.1.0"
edition = "2021"
[dependencies]
sol-trade-sdk = { path = "../.." }
solana-streamer-sdk = "0.5.0"
solana-sdk = "3.0.0"
solana-commitment-config = { version = "3.0.0", features = ["serde"] }
tokio = { version = "1", features = ["full"] }
spl-token-2022 = { version = "8.0.0", features = ["no-entrypoint"] }
@@ -0,0 +1,98 @@
use sol_trade_sdk::{
common::{
spl_associated_token_account::get_associated_token_address_with_program_id, AnyResult,
TradeConfig,
},
swqos::SwqosConfig,
trading::{core::params::MeteoraDammV2Params, factory::DexType},
SolanaTrade, TradeTokenType,
};
use solana_commitment_config::CommitmentConfig;
use solana_sdk::signature::Keypair;
use solana_sdk::{pubkey::Pubkey, signer::Signer};
use std::{str::FromStr, sync::Arc};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Testing Metaora Damm V2 trading...");
let client = create_solana_trade_client().await?;
let slippage_basis_points = Some(100);
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let pool = Pubkey::from_str("35EFyWd9cH8pdHxVgXHF68L1oZxSWd1FfJASSNTUtoTC").unwrap();
let mint_pubkey = Pubkey::from_str("FhTRoy63ZiLcjLEVCMCTLc5Cu5ozrzouNg6cDp1ASZMC").unwrap();
// Buy tokens
println!("Buying tokens from Metaora Damm V2...");
let buy_sol_amount = 100_000;
let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::MeteoraDammV2,
input_token_type: TradeTokenType::WSOL,
mint: mint_pubkey,
input_token_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(
MeteoraDammV2Params::from_pool_address_by_rpc(&client.rpc, &pool).await?,
),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_input_token_ata: true,
close_input_token_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: Some(1),
};
client.buy(buy_params).await?;
// Sell tokens
println!("Selling tokens from Metaora Damm V2...");
let rpc = client.rpc.clone();
let payer = client.payer.pubkey();
let program_id = sol_trade_sdk::constants::TOKEN_PROGRAM;
let account = get_associated_token_address_with_program_id(&payer, &mint_pubkey, &program_id);
let balance = rpc.get_token_account_balance(&account).await?;
let amount_token = balance.amount.parse::<u64>().unwrap();
println!("Token balance: {}", amount_token);
let sell_params = sol_trade_sdk::TradeSellParams {
dex_type: DexType::MeteoraDammV2,
output_token_type: TradeTokenType::WSOL,
mint: mint_pubkey,
input_token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(
MeteoraDammV2Params::from_pool_address_by_rpc(&client.rpc, &pool).await?,
),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_output_token_ata: true,
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: Some(1),
};
client.sell(sell_params).await?;
tokio::signal::ctrl_c().await?;
Ok(())
}
/// Create SolanaTrade client
/// Initializes a new SolanaTrade client with configuration
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
println!("🚀 Initializing SolanaTrade client...");
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
let rpc_url = "https://api.mainnet-beta.solana.com".to_string();
let commitment = CommitmentConfig::confirmed();
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
// set global strategy
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
println!("✅ SolanaTrade client initialized successfully!");
Ok(solana_trade)
}
+1
View File
@@ -99,6 +99,7 @@ async fn test_middleware() -> AnyResult<()> {
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
println!("tip: This transaction will not succeed because we're using a test account. You can modify the code to initialize the payer with your own private key");
+1
View File
@@ -155,6 +155,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: Some(durable_nonce),
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -151,6 +151,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -191,6 +192,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
close_output_token_ata: false,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
@@ -117,6 +117,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -146,6 +147,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
@@ -42,6 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -71,6 +72,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
+2
View File
@@ -201,6 +201,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -232,6 +233,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
@@ -157,6 +157,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -187,6 +188,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
@@ -148,6 +148,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -180,6 +181,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
close_output_token_ata: true,
open_seed_optimize: false,
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;
+2
View File
@@ -41,6 +41,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
create_mint_ata: true,
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
durable_nonce: None,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;
@@ -78,6 +79,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
close_output_token_ata: true,
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
durable_nonce: None,
fixed_output_token_amount: None,
};
client.sell(sell_params).await?;