2025-04-02 13:39:59 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2025-08-23 20:37:03 +08:00
|
|
|
use crate::{
|
|
|
|
|
constants::trade::trade::{
|
|
|
|
|
DEFAULT_BUY_TIP_FEE, DEFAULT_RPC_UNIT_LIMIT, DEFAULT_RPC_UNIT_PRICE, DEFAULT_SELL_TIP_FEE,
|
|
|
|
|
DEFAULT_TIP_UNIT_LIMIT, DEFAULT_TIP_UNIT_PRICE,
|
|
|
|
|
},
|
|
|
|
|
swqos::{SwqosClient, SwqosConfig},
|
|
|
|
|
};
|
|
|
|
|
use serde::Deserialize;
|
2025-04-02 13:39:59 +08:00
|
|
|
use solana_client::rpc_client::RpcClient;
|
2025-05-29 18:53:58 +08:00
|
|
|
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature::Keypair};
|
2025-04-02 13:39:59 +08:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2025-07-06 23:36:18 +08:00
|
|
|
pub struct TradeConfig {
|
2025-04-02 13:39:59 +08:00
|
|
|
pub rpc_url: String,
|
2025-07-06 23:36:18 +08:00
|
|
|
pub swqos_configs: Vec<SwqosConfig>,
|
2025-04-02 13:39:59 +08:00
|
|
|
pub priority_fee: PriorityFee,
|
|
|
|
|
pub commitment: CommitmentConfig,
|
2025-05-29 18:53:58 +08:00
|
|
|
pub lookup_table_key: Option<Pubkey>,
|
2025-04-02 13:39:59 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-06 23:36:18 +08:00
|
|
|
impl TradeConfig {
|
2025-04-02 13:39:59 +08:00
|
|
|
pub fn new(
|
2025-08-23 20:37:03 +08:00
|
|
|
rpc_url: String,
|
2025-07-06 23:36:18 +08:00
|
|
|
swqos_configs: Vec<SwqosConfig>,
|
2025-08-23 20:37:03 +08:00
|
|
|
priority_fee: PriorityFee,
|
|
|
|
|
commitment: CommitmentConfig,
|
2025-05-29 18:53:58 +08:00
|
|
|
lookup_table_key: Option<Pubkey>,
|
2025-04-02 13:39:59 +08:00
|
|
|
) -> Self {
|
2025-08-23 20:37:03 +08:00
|
|
|
Self { rpc_url, swqos_configs, priority_fee, commitment, lookup_table_key }
|
2025-04-02 13:39:59 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-29 18:53:58 +08:00
|
|
|
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
2025-04-02 13:39:59 +08:00
|
|
|
pub struct PriorityFee {
|
2025-08-23 20:37:03 +08:00
|
|
|
pub tip_unit_limit: u32,
|
|
|
|
|
pub tip_unit_price: u64,
|
2025-05-29 18:53:58 +08:00
|
|
|
pub rpc_unit_limit: u32,
|
|
|
|
|
pub rpc_unit_price: u64,
|
2025-04-02 13:39:59 +08:00
|
|
|
pub buy_tip_fee: f64,
|
2025-05-29 18:53:58 +08:00
|
|
|
pub buy_tip_fees: Vec<f64>,
|
2025-06-19 22:30:04 +08:00
|
|
|
pub smart_buy_tip_fee: f64,
|
2025-04-02 13:39:59 +08:00
|
|
|
pub sell_tip_fee: f64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for PriorityFee {
|
|
|
|
|
fn default() -> Self {
|
2025-08-23 20:37:03 +08:00
|
|
|
Self {
|
|
|
|
|
tip_unit_limit: DEFAULT_TIP_UNIT_LIMIT,
|
|
|
|
|
tip_unit_price: DEFAULT_TIP_UNIT_PRICE,
|
2025-06-14 18:52:46 +08:00
|
|
|
rpc_unit_limit: DEFAULT_RPC_UNIT_LIMIT,
|
|
|
|
|
rpc_unit_price: DEFAULT_RPC_UNIT_PRICE,
|
2025-08-23 20:37:03 +08:00
|
|
|
buy_tip_fee: DEFAULT_BUY_TIP_FEE,
|
2025-05-29 18:53:58 +08:00
|
|
|
buy_tip_fees: vec![],
|
2025-06-19 22:30:04 +08:00
|
|
|
smart_buy_tip_fee: 0.0,
|
2025-08-23 20:37:03 +08:00
|
|
|
sell_tip_fee: DEFAULT_SELL_TIP_FEE,
|
2025-04-02 13:39:59 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SolanaRpcClient = solana_client::nonblocking::rpc_client::RpcClient;
|
|
|
|
|
|
|
|
|
|
pub struct MethodArgs {
|
|
|
|
|
pub payer: Arc<Keypair>,
|
|
|
|
|
pub rpc: Arc<RpcClient>,
|
|
|
|
|
pub nonblocking_rpc: Arc<SolanaRpcClient>,
|
2025-07-06 22:06:44 +08:00
|
|
|
pub jito_client: Arc<SwqosClient>,
|
2025-04-02 13:39:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MethodArgs {
|
2025-08-23 20:37:03 +08:00
|
|
|
pub fn new(
|
|
|
|
|
payer: Arc<Keypair>,
|
|
|
|
|
rpc: Arc<RpcClient>,
|
|
|
|
|
nonblocking_rpc: Arc<SolanaRpcClient>,
|
|
|
|
|
jito_client: Arc<SwqosClient>,
|
|
|
|
|
) -> Self {
|
2025-04-02 13:39:59 +08:00
|
|
|
Self { payer, rpc, nonblocking_rpc, jito_client }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 11:04:55 +08:00
|
|
|
pub type AnyResult<T> = anyhow::Result<T>;
|