Merge commit 'ce1dc2b185679fbdfe8c46835ce1346e0c00904f'
This commit is contained in:
@@ -19,20 +19,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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();
|
||||
let pool = Pubkey::from_str("7dVri3qjYD3uobSZL3Zth8vSCgU6r6R2nvFsh7uVfDte").unwrap();
|
||||
let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap();
|
||||
|
||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Metaora Damm V2...");
|
||||
let buy_sol_amount = 100_000;
|
||||
let input_token_amount = 100_000;
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::MeteoraDammV2,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
input_token_type: TradeTokenType::USDC, // or USDC
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: buy_sol_amount,
|
||||
input_token_amount: input_token_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(
|
||||
@@ -40,8 +40,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: true,
|
||||
create_input_token_ata: false, //if input token is SOL/WSOL,set to true,if input token is USDC,set to false.
|
||||
close_input_token_ata: false, //if input token is SOL/WSOL,set to true,if input token is USDC,set to false.
|
||||
create_mint_ata: true,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
@@ -62,7 +62,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Token balance: {}", amount_token);
|
||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||
dex_type: DexType::MeteoraDammV2,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
output_token_type: TradeTokenType::USDC,
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: amount_token,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
@@ -73,8 +73,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: true,
|
||||
create_output_token_ata: false, //if output token is SOL/WSOL,set to true,if output token is USDC,set to false.
|
||||
close_output_token_ata: false, //if output token is SOL/WSOL,set to true,if output token is USDC,set to false.
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: Some(1),
|
||||
@@ -82,15 +82,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
tokio::signal::ctrl_c().await?;
|
||||
Ok(())
|
||||
// Exit program
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
/// 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 payer = Keypair::from_base58_string("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())];
|
||||
|
||||
@@ -46,6 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
PUMPSWAP_PROGRAM_ID.to_string(), // Listen to PumpSwap program ID
|
||||
];
|
||||
let account_exclude = vec![];
|
||||
|
||||
let account_required = vec![];
|
||||
|
||||
// Listen to transaction data
|
||||
@@ -83,31 +84,37 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
PumpSwapBuyEvent => |e: PumpSwapBuyEvent| {
|
||||
if e.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
// Test code, only test one transaction
|
||||
if !ALREADY_EXECUTED.swap(true, Ordering::SeqCst) {
|
||||
let event_clone = e.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = pumpswap_trade_with_grpc_buy_event(event_clone).await {
|
||||
eprintln!("Error in trade: {:?}", err);
|
||||
std::process::exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
let is_wsol = e.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = e.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return;
|
||||
}
|
||||
// Test code, only test one transaction
|
||||
if !ALREADY_EXECUTED.swap(true, Ordering::SeqCst) {
|
||||
let event_clone = e.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = pumpswap_trade_with_grpc_buy_event(event_clone).await {
|
||||
eprintln!("Error in trade: {:?}", err);
|
||||
std::process::exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
PumpSwapSellEvent => |e: PumpSwapSellEvent| {
|
||||
if e.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
// Test code, only test one transaction
|
||||
if !ALREADY_EXECUTED.swap(true, Ordering::SeqCst) {
|
||||
let event_clone = e.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = pumpswap_trade_with_grpc_sell_event(event_clone).await {
|
||||
eprintln!("Error in trade: {:?}", err);
|
||||
std::process::exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
let is_wsol = e.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = e.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT || e.quote_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return;
|
||||
}
|
||||
// Test code, only test one transaction
|
||||
if !ALREADY_EXECUTED.swap(true, Ordering::SeqCst) {
|
||||
let event_clone = e.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = pumpswap_trade_with_grpc_sell_event(event_clone).await {
|
||||
eprintln!("Error in trade: {:?}", err);
|
||||
std::process::exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -118,7 +125,7 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
/// 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 payer = Keypair::from_base58_string("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())];
|
||||
@@ -142,7 +149,8 @@ async fn pumpswap_trade_with_grpc_buy_event(trade_info: PumpSwapBuyEvent) -> Any
|
||||
trade_info.base_token_program,
|
||||
trade_info.quote_token_program,
|
||||
);
|
||||
let mint = if trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT
|
||||
|| trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
trade_info.quote_mint
|
||||
} else {
|
||||
trade_info.base_mint
|
||||
@@ -165,7 +173,8 @@ async fn pumpswap_trade_with_grpc_sell_event(trade_info: PumpSwapSellEvent) -> A
|
||||
trade_info.base_token_program,
|
||||
trade_info.quote_token_program,
|
||||
);
|
||||
let mint = if trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
let mint = if trade_info.base_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT
|
||||
|| trade_info.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
trade_info.quote_mint
|
||||
} else {
|
||||
trade_info.base_mint
|
||||
@@ -184,21 +193,24 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
|
||||
let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpSwap...");
|
||||
let buy_sol_amount = 100_000;
|
||||
let buy_token_amount = 300_000;
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
input_token_type: TradeTokenType::SOL,
|
||||
input_token_type: if is_sol { TradeTokenType::SOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: buy_sol_amount,
|
||||
input_token_amount: buy_token_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(params.clone()),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: true,
|
||||
create_input_token_ata: is_sol,
|
||||
close_input_token_ata: is_sol,
|
||||
create_mint_ata: true,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
@@ -222,7 +234,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
let amount_token = balance.amount.parse::<u64>().unwrap();
|
||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
output_token_type: TradeTokenType::SOL,
|
||||
output_token_type: if is_sol { TradeTokenType::SOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: amount_token,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
@@ -231,8 +243,8 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
extension_params: Box::new(params.clone()),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: true,
|
||||
create_output_token_ata: is_sol,
|
||||
close_output_token_ata: is_sol,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
|
||||
@@ -101,7 +101,7 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
/// 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 payer = Keypair::from_base58_string("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())];
|
||||
@@ -123,7 +123,8 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
let amm_info = fetch_amm_info(&client.rpc, trade_info.amm).await?;
|
||||
let (coin_reserve, pc_reserve) =
|
||||
get_multi_token_balances(&client.rpc, &amm_info.token_coin, &amm_info.token_pc).await?;
|
||||
let mint_pubkey = if amm_info.pc_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT {
|
||||
let mint_pubkey = if amm_info.pc_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| amm_info.pc_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT {
|
||||
amm_info.coin_mint
|
||||
} else {
|
||||
amm_info.pc_mint
|
||||
@@ -143,19 +144,21 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Raydium_amm_v4...");
|
||||
let buy_sol_amount = 100_000;
|
||||
let input_token_amount = 100_000;
|
||||
let is_wsol = amm_info.pc_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| amm_info.coin_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
input_token_type: if is_wsol { TradeTokenType::WSOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: buy_sol_amount,
|
||||
input_token_amount: input_token_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(params),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: true,
|
||||
create_input_token_ata: is_wsol,
|
||||
close_input_token_ata: is_wsol,
|
||||
create_mint_ata: true,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
@@ -178,7 +181,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
let params = RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, trade_info.amm).await?;
|
||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
output_token_type: if is_wsol { TradeTokenType::WSOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: amount_token,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
@@ -187,8 +190,8 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
extension_params: Box::new(params),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: true,
|
||||
create_output_token_ata: is_wsol,
|
||||
close_output_token_ata: is_wsol,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use sol_trade_sdk::common::spl_associated_token_account::get_associated_token_address;
|
||||
use sol_trade_sdk::common::{gas_fee_strategy, TradeConfig};
|
||||
use sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
use sol_trade_sdk::common::TradeConfig;
|
||||
use sol_trade_sdk::constants::{WSOL_TOKEN_ACCOUNT, USDC_TOKEN_ACCOUNT};
|
||||
use sol_trade_sdk::trading::core::params::RaydiumCpmmParams;
|
||||
use sol_trade_sdk::trading::factory::DexType;
|
||||
use sol_trade_sdk::TradeTokenType;
|
||||
@@ -79,7 +79,9 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| {
|
||||
if e.input_token_mint != WSOL_TOKEN_ACCOUNT && e.output_token_mint != WSOL_TOKEN_ACCOUNT {
|
||||
let is_wsol = e.input_token_mint == WSOL_TOKEN_ACCOUNT || e.output_token_mint == WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = e.input_token_mint == USDC_TOKEN_ACCOUNT || e.output_token_mint == USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return;
|
||||
}
|
||||
// Test code, only test one transaction
|
||||
@@ -101,7 +103,7 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
/// 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 payer = Keypair::from_base58_string("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())];
|
||||
@@ -118,6 +120,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
|
||||
let client = create_solana_trade_client().await?;
|
||||
let mint_pubkey = if trade_info.input_token_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| trade_info.input_token_mint == sol_trade_sdk::constants::USDC_TOKEN_ACCOUNT
|
||||
{
|
||||
trade_info.output_token_mint
|
||||
} else {
|
||||
@@ -131,21 +134,25 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
|
||||
let buy_params =
|
||||
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?;
|
||||
|
||||
let is_wsol = trade_info.input_token_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| trade_info.output_token_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Raydium_cpmm...");
|
||||
let buy_sol_amount = 100_000;
|
||||
let input_token_amount = 100_000;
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
input_token_type: if is_wsol { TradeTokenType::SOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: buy_sol_amount,
|
||||
input_token_amount: input_token_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
extension_params: Box::new(buy_params),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: true,
|
||||
create_input_token_ata: is_wsol,
|
||||
close_input_token_ata: is_wsol,
|
||||
create_mint_ata: true,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
@@ -170,7 +177,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
println!("Selling {} tokens", amount_token);
|
||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
output_token_type: if is_wsol { TradeTokenType::SOL } else { TradeTokenType::USDC },
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: amount_token,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
@@ -179,8 +186,8 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
extension_params: Box::new(sell_params),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_output_token_ata: true,
|
||||
close_output_token_ata: true,
|
||||
create_output_token_ata: is_wsol,
|
||||
close_output_token_ata: is_wsol,
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
|
||||
@@ -42,6 +42,16 @@ pub const USD1_TOKEN_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
// USDC (mainnet) mint and meta
|
||||
pub const USDC_TOKEN_ACCOUNT: Pubkey =
|
||||
pubkey!("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
||||
pub const USDC_TOKEN_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: USDC_TOKEN_ACCOUNT,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const RENT: Pubkey = solana_sdk::sysvar::rent::id();
|
||||
pub const RENT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta { pubkey: RENT, is_signer: false, is_writable: false };
|
||||
|
||||
@@ -29,10 +29,16 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
.downcast_ref::<MeteoraDammV2Params>()
|
||||
.ok_or_else(|| anyhow!("Invalid protocol params for RaydiumCpmm"))?;
|
||||
|
||||
let is_wsol = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_a_in = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_a_in = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let amount_in: u64 = params.input_amount.unwrap_or(0);
|
||||
let minimum_amount_out: u64 = match params.fixed_output_amount {
|
||||
Some(fixed) => fixed,
|
||||
@@ -135,10 +141,16 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
return Err(anyhow!("Token amount is not set"));
|
||||
}
|
||||
|
||||
let is_wsol = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_a_in = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_a_in = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let minimum_amount_out: u64 = match params.fixed_output_amount {
|
||||
Some(fixed) => fixed,
|
||||
None => return Err(anyhow!("fixed_output_amount must be set for MeteoraDammV2 swap")),
|
||||
|
||||
+25
-18
@@ -53,22 +53,25 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
let pool_base_token_account = protocol_params.pool_base_token_account;
|
||||
let pool_quote_token_account = protocol_params.pool_quote_token_account;
|
||||
|
||||
if base_mint != crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
&& quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
{
|
||||
return Err(anyhow!("Invalid base mint and quote mint"));
|
||||
let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT)
|
||||
|| (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT && base_mint != crate::constants::USDC_TOKEN_ACCOUNT);
|
||||
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT && quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT)
|
||||
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT && base_mint != crate::constants::WSOL_TOKEN_ACCOUNT);
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let quote_mint_is_wsol = quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let quote_is_wsol_or_usdc = quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let mut creator = Pubkey::default();
|
||||
if params_coin_creator_vault_authority != accounts::DEFAULT_COIN_CREATOR_VAULT_AUTHORITY {
|
||||
creator = params_coin_creator_vault_authority;
|
||||
}
|
||||
|
||||
let (mut token_amount, sol_amount) = if quote_mint_is_wsol {
|
||||
let (mut token_amount, sol_amount) = if quote_is_wsol_or_usdc {
|
||||
let result = buy_quote_input_internal(
|
||||
params.input_amount.unwrap_or(0),
|
||||
params.slippage_basis_points.unwrap_or(DEFAULT_SLIPPAGE),
|
||||
@@ -127,8 +130,8 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
if quote_mint_is_wsol { &base_mint } else { "e_mint },
|
||||
if quote_mint_is_wsol { &base_token_program } else { "e_token_program },
|
||||
if quote_is_wsol_or_usdc { &base_mint } else { "e_mint },
|
||||
if quote_is_wsol_or_usdc { &base_token_program } else { "e_token_program },
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
@@ -157,7 +160,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
AccountMeta::new(params_coin_creator_vault_ata, false), // coin_creator_vault_ata
|
||||
AccountMeta::new_readonly(params_coin_creator_vault_authority, false), // coin_creator_vault_authority (readonly)
|
||||
]);
|
||||
if quote_mint_is_wsol {
|
||||
if quote_is_wsol_or_usdc {
|
||||
accounts.push(accounts::GLOBAL_VOLUME_ACCUMULATOR_META);
|
||||
accounts.push(AccountMeta::new(
|
||||
get_user_volume_accumulator_pda(¶ms.payer.pubkey()).unwrap(),
|
||||
@@ -169,7 +172,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
|
||||
// Create instruction data
|
||||
let mut data = [0u8; 24];
|
||||
if quote_mint_is_wsol {
|
||||
if quote_is_wsol_or_usdc {
|
||||
data[..8].copy_from_slice(&BUY_DISCRIMINATOR);
|
||||
// base_amount_out
|
||||
data[8..16].copy_from_slice(&token_amount.to_le_bytes());
|
||||
@@ -219,11 +222,14 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
let base_token_program = protocol_params.base_token_program;
|
||||
let quote_token_program = protocol_params.quote_token_program;
|
||||
|
||||
if base_mint != crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
&& quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
{
|
||||
return Err(anyhow!("Invalid base mint and quote mint"));
|
||||
let is_wsol = (base_mint == crate::constants::WSOL_TOKEN_ACCOUNT && quote_mint != crate::constants::USDC_TOKEN_ACCOUNT)
|
||||
|| (quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT && base_mint != crate::constants::USDC_TOKEN_ACCOUNT);
|
||||
let is_usdc = (base_mint == crate::constants::USDC_TOKEN_ACCOUNT && quote_mint != crate::constants::WSOL_TOKEN_ACCOUNT)
|
||||
|| (quote_mint == crate::constants::USDC_TOKEN_ACCOUNT && base_mint != crate::constants::WSOL_TOKEN_ACCOUNT);
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
if params.input_amount.is_none() {
|
||||
return Err(anyhow!("Token amount is not set"));
|
||||
}
|
||||
@@ -231,13 +237,14 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let quote_mint_is_wsol = quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let quote_is_wsol_or_usdc = quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let mut creator = Pubkey::default();
|
||||
if params_coin_creator_vault_authority != accounts::DEFAULT_COIN_CREATOR_VAULT_AUTHORITY {
|
||||
creator = params_coin_creator_vault_authority;
|
||||
}
|
||||
|
||||
let (token_amount, mut sol_amount) = if quote_mint_is_wsol {
|
||||
let (token_amount, mut sol_amount) = if quote_is_wsol_or_usdc {
|
||||
let result = sell_base_input_internal(
|
||||
params.input_amount.unwrap(),
|
||||
params.slippage_basis_points.unwrap_or(DEFAULT_SLIPPAGE),
|
||||
@@ -313,7 +320,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
AccountMeta::new(params_coin_creator_vault_ata, false), // coin_creator_vault_ata
|
||||
AccountMeta::new_readonly(params_coin_creator_vault_authority, false), // coin_creator_vault_authority (readonly)
|
||||
]);
|
||||
if !quote_mint_is_wsol {
|
||||
if !quote_is_wsol_or_usdc {
|
||||
accounts.push(accounts::GLOBAL_VOLUME_ACCUMULATOR_META);
|
||||
accounts.push(AccountMeta::new(
|
||||
get_user_volume_accumulator_pda(¶ms.payer.pubkey()).unwrap(),
|
||||
@@ -326,7 +333,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
|
||||
// Create instruction data
|
||||
let mut data = [0u8; 24];
|
||||
if quote_mint_is_wsol {
|
||||
if quote_is_wsol_or_usdc {
|
||||
data[..8].copy_from_slice(&SELL_DISCRIMINATOR);
|
||||
// base_amount_in
|
||||
data[8..16].copy_from_slice(&token_amount.to_le_bytes());
|
||||
|
||||
@@ -31,10 +31,21 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
.downcast_ref::<RaydiumAmmV4Params>()
|
||||
.ok_or_else(|| anyhow!("Invalid protocol params for RaydiumCpmm"))?;
|
||||
|
||||
let is_wsol = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.pc_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
let is_usdc = protocol_params.coin_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.pc_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_base_in = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.coin_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let amount_in: u64 = params.input_amount.unwrap_or(0);
|
||||
let swap_result = compute_swap_amount(
|
||||
protocol_params.coin_reserve,
|
||||
@@ -51,7 +62,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
let user_source_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
@@ -139,10 +150,21 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
return Err(anyhow!("Token amount is not set"));
|
||||
}
|
||||
|
||||
let is_wsol = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.pc_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
let is_usdc = protocol_params.coin_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.pc_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.pc_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_base_in = protocol_params.pc_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.pc_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let swap_result = compute_swap_amount(
|
||||
protocol_params.coin_reserve,
|
||||
protocol_params.pc_reserve,
|
||||
@@ -165,7 +187,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
let user_destination_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
@@ -30,6 +30,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
if params.input_amount.unwrap_or(0) == 0 {
|
||||
return Err(anyhow!("Amount cannot be zero"));
|
||||
}
|
||||
|
||||
let protocol_params = params
|
||||
.protocol_params
|
||||
.as_any()
|
||||
@@ -47,10 +48,21 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
protocol_params.pool_state
|
||||
};
|
||||
|
||||
let is_wsol = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
let is_usdc = protocol_params.base_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_base_in = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.base_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let mint_token_program = if is_base_in {
|
||||
protocol_params.quote_token_program
|
||||
} else {
|
||||
@@ -70,27 +82,25 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
None => result.min_amount_out,
|
||||
};
|
||||
|
||||
let wsol_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
let input_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let mint_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
let output_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.output_mint,
|
||||
&mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let wsol_vault_account = get_vault_account(
|
||||
let input_vault_account = get_vault_account(
|
||||
&pool_state,
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
protocol_params,
|
||||
true,
|
||||
);
|
||||
let mint_vault_account =
|
||||
get_vault_account(&pool_state, ¶ms.output_mint, protocol_params, false);
|
||||
let output_vault_account = get_vault_account(&pool_state, ¶ms.output_mint, protocol_params);
|
||||
|
||||
let observation_state_account = if protocol_params.observation_state == Pubkey::default() {
|
||||
get_observation_state_pda(&pool_state).unwrap()
|
||||
@@ -126,13 +136,13 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
AccountMeta::new(protocol_params.amm_config, false), // Amm Config (readonly)
|
||||
AccountMeta::new(pool_state, false), // Pool State
|
||||
AccountMeta::new(wsol_token_account, false), // Input Token Account
|
||||
AccountMeta::new(mint_token_account, false), // Output Token Account
|
||||
AccountMeta::new(wsol_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(mint_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
crate::constants::TOKEN_PROGRAM_META, // Input Token Program (readonly)
|
||||
AccountMeta::new_readonly(mint_token_program, false), // Output Token Program (readonly)
|
||||
crate::constants::WSOL_TOKEN_ACCOUNT_META, // Input token mint (readonly)
|
||||
if is_wsol { crate::constants::WSOL_TOKEN_ACCOUNT_META } else { crate::constants::USDC_TOKEN_ACCOUNT_META }, // Input token mint (readonly)
|
||||
AccountMeta::new_readonly(params.output_mint, false), // Output token mint (readonly)
|
||||
AccountMeta::new(observation_state_account, false), // Observation State Account
|
||||
];
|
||||
@@ -181,11 +191,22 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
protocol_params.pool_state
|
||||
};
|
||||
|
||||
let is_wsol = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
|
||||
let is_usdc = protocol_params.base_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.base_mint == params.input_mint;
|
||||
let mint_token_program = if is_base_in {
|
||||
let is_quote_out = protocol_params.quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let mint_token_program = if is_quote_out {
|
||||
protocol_params.base_token_program
|
||||
} else {
|
||||
protocol_params.quote_token_program
|
||||
@@ -197,7 +218,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
compute_swap_amount(
|
||||
protocol_params.base_reserve,
|
||||
protocol_params.quote_reserve,
|
||||
is_base_in,
|
||||
is_quote_out,
|
||||
params.input_amount.unwrap_or(0),
|
||||
params.slippage_basis_points.unwrap_or(DEFAULT_SLIPPAGE),
|
||||
)
|
||||
@@ -205,27 +226,25 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
}
|
||||
};
|
||||
|
||||
let wsol_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
let output_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let mint_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
let input_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.input_mint,
|
||||
&mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let wsol_vault_account = get_vault_account(
|
||||
let output_vault_account = get_vault_account(
|
||||
&pool_state,
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
protocol_params,
|
||||
true,
|
||||
);
|
||||
let mint_vault_account =
|
||||
get_vault_account(&pool_state, ¶ms.input_mint, protocol_params, false);
|
||||
let input_vault_account = get_vault_account(&pool_state, ¶ms.input_mint, protocol_params);
|
||||
|
||||
let observation_state_account = if protocol_params.observation_state == Pubkey::default() {
|
||||
get_observation_state_pda(&pool_state).unwrap()
|
||||
@@ -248,14 +267,14 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
AccountMeta::new(protocol_params.amm_config, false), // Amm Config (readonly)
|
||||
AccountMeta::new(pool_state, false), // Pool State
|
||||
AccountMeta::new(mint_token_account, false), // Input Token Account
|
||||
AccountMeta::new(wsol_token_account, false), // Output Token Account
|
||||
AccountMeta::new(mint_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(wsol_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new_readonly(mint_token_program, false), // Input Token Program (readonly)
|
||||
crate::constants::TOKEN_PROGRAM_META, // Output Token Program (readonly)
|
||||
AccountMeta::new_readonly(params.input_mint, false), // Input token mint (readonly)
|
||||
crate::constants::WSOL_TOKEN_ACCOUNT_META, // Output token mint (readonly)
|
||||
if is_wsol { crate::constants::WSOL_TOKEN_ACCOUNT_META } else { crate::constants::USDC_TOKEN_ACCOUNT_META }, // Output token mint (readonly)
|
||||
AccountMeta::new(observation_state_account, false), // Observation State Account
|
||||
];
|
||||
// Create instruction data
|
||||
|
||||
@@ -119,47 +119,25 @@ pub async fn calculate_price(
|
||||
Ok(price)
|
||||
}
|
||||
|
||||
/// Helper function to get vault account address
|
||||
/// Helper function to get token vault account address
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `pool_state`: Pool state account address
|
||||
/// - `token_mint`: Token mint address
|
||||
/// - `protocol_params`: Protocol parameters
|
||||
/// - `is_wsol`: Whether it's a wSOL token
|
||||
///
|
||||
/// # Returns
|
||||
/// Returns the corresponding vault account address
|
||||
/// Returns the corresponding token vault account address
|
||||
pub fn get_vault_account(
|
||||
pool_state: &Pubkey,
|
||||
token_mint: &Pubkey,
|
||||
protocol_params: &RaydiumCpmmParams,
|
||||
is_wsol: bool,
|
||||
) -> Pubkey {
|
||||
if is_wsol {
|
||||
// If it's wSOL, check if it's the base mint
|
||||
if protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
&& protocol_params.base_vault != Pubkey::default()
|
||||
{
|
||||
protocol_params.base_vault
|
||||
} else if protocol_params.quote_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
&& protocol_params.quote_vault != Pubkey::default()
|
||||
{
|
||||
protocol_params.quote_vault
|
||||
} else {
|
||||
get_vault_pda(pool_state, &crate::constants::WSOL_TOKEN_ACCOUNT).unwrap()
|
||||
}
|
||||
if protocol_params.base_mint == *token_mint && protocol_params.base_vault != Pubkey::default() {
|
||||
protocol_params.base_vault
|
||||
} else if protocol_params.quote_mint == *token_mint && protocol_params.quote_vault != Pubkey::default() {
|
||||
protocol_params.quote_vault
|
||||
} else {
|
||||
// For other tokens, check if it's the base or quote mint
|
||||
if *token_mint == protocol_params.base_mint
|
||||
&& protocol_params.base_vault != Pubkey::default()
|
||||
{
|
||||
protocol_params.base_vault
|
||||
} else if *token_mint == protocol_params.quote_mint
|
||||
&& protocol_params.quote_vault != Pubkey::default()
|
||||
{
|
||||
protocol_params.quote_vault
|
||||
} else {
|
||||
get_vault_pda(pool_state, token_mint).unwrap()
|
||||
}
|
||||
get_vault_pda(pool_state, token_mint).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use crate::constants::trade::trade::DEFAULT_SLIPPAGE;
|
||||
use crate::constants::SOL_TOKEN_ACCOUNT;
|
||||
use crate::constants::USD1_TOKEN_ACCOUNT;
|
||||
use crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
use crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
use crate::swqos::SwqosClient;
|
||||
use crate::swqos::SwqosConfig;
|
||||
use crate::swqos::TradeType;
|
||||
@@ -41,6 +42,7 @@ pub enum TradeTokenType {
|
||||
SOL,
|
||||
WSOL,
|
||||
USD1,
|
||||
USDC,
|
||||
}
|
||||
|
||||
/// Main trading client for Solana DeFi protocols
|
||||
@@ -283,6 +285,8 @@ impl SolanaTrade {
|
||||
SOL_TOKEN_ACCOUNT
|
||||
} else if params.input_token_type == TradeTokenType::WSOL {
|
||||
WSOL_TOKEN_ACCOUNT
|
||||
} else if params.input_token_type == TradeTokenType::USDC {
|
||||
USDC_TOKEN_ACCOUNT
|
||||
} else {
|
||||
USD1_TOKEN_ACCOUNT
|
||||
};
|
||||
@@ -379,6 +383,8 @@ impl SolanaTrade {
|
||||
SOL_TOKEN_ACCOUNT
|
||||
} else if params.output_token_type == TradeTokenType::WSOL {
|
||||
WSOL_TOKEN_ACCOUNT
|
||||
} else if params.output_token_type == TradeTokenType::USDC {
|
||||
USDC_TOKEN_ACCOUNT
|
||||
} else {
|
||||
USD1_TOKEN_ACCOUNT
|
||||
};
|
||||
|
||||
@@ -131,7 +131,8 @@ impl ExecutionPath {
|
||||
// 分支预测: 大概率是买入
|
||||
let is_buy = input_mint == &crate::constants::SOL_TOKEN_ACCOUNT
|
||||
|| input_mint == &crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| input_mint == &crate::constants::USD1_TOKEN_ACCOUNT;
|
||||
|| input_mint == &crate::constants::USD1_TOKEN_ACCOUNT
|
||||
|| input_mint == &crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
if BranchOptimizer::likely(is_buy) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user