Files
sol-trade-sdk/src/common/types.rs
T

78 lines
2.3 KiB
Rust
Raw Normal View History

2025-04-02 13:39:59 +08:00
use std::sync::Arc;
use solana_client::rpc_client::RpcClient;
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature::Keypair};
2025-04-02 13:39:59 +08:00
use serde::Deserialize;
use crate::{constants::trade::trade::{DEFAULT_BUY_TIP_FEE, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_RPC_UNIT_LIMIT, DEFAULT_RPC_UNIT_PRICE, DEFAULT_SELL_TIP_FEE}, swqos::{SwqosClient, SwqosConfig}};
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,
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(
rpc_url: String,
2025-07-06 23:36:18 +08:00
swqos_configs: Vec<SwqosConfig>,
2025-04-02 13:39:59 +08:00
priority_fee: PriorityFee,
commitment: CommitmentConfig,
lookup_table_key: Option<Pubkey>,
2025-04-02 13:39:59 +08:00
) -> Self {
Self {
rpc_url,
2025-07-06 23:36:18 +08:00
swqos_configs,
2025-04-02 13:39:59 +08:00
priority_fee,
commitment,
lookup_table_key,
2025-04-02 13:39:59 +08:00
}
}
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
2025-04-02 13:39:59 +08:00
pub struct PriorityFee {
pub unit_limit: u32,
pub unit_price: u64,
pub rpc_unit_limit: u32,
pub rpc_unit_price: u64,
2025-04-02 13:39:59 +08:00
pub buy_tip_fee: f64,
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 {
Self {
unit_limit: DEFAULT_COMPUTE_UNIT_LIMIT,
unit_price: DEFAULT_COMPUTE_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-04-02 13:39:59 +08:00
buy_tip_fee: DEFAULT_BUY_TIP_FEE,
buy_tip_fees: vec![],
2025-06-19 22:30:04 +08:00
smart_buy_tip_fee: 0.0,
2025-04-02 13:39:59 +08:00
sell_tip_fee: DEFAULT_SELL_TIP_FEE
}
}
}
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-07-06 22:06:44 +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 }
}
}
pub type AnyResult<T> = anyhow::Result<T>;