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

83 lines
2.3 KiB
Rust
Raw Normal View History

2025-04-02 13:39:59 +08:00
use std::sync::Arc;
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;
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,
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>,
priority_fee: PriorityFee,
commitment: CommitmentConfig,
lookup_table_key: Option<Pubkey>,
2025-04-02 13:39:59 +08:00
) -> Self {
Self { rpc_url, swqos_configs, 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 tip_unit_limit: u32,
pub tip_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 {
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,
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,
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 {
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>;