1use serde::{Deserialize, Serialize};
2use serde_with::serde_as;
3
4use crate::lend::Instruction;
5
6
7
8
9
10#[derive(Debug, Deserialize, Serialize)]
11#[serde(rename_all = "camelCase")]
12#[serde_as]
13pub enum SwapMode {
14 ExactIn,
15 ExactOut,
16}
17
18
19
20#[derive(Debug, Deserialize, Serialize)]
21#[serde(rename_all = "camelCase")]
22#[serde_as]
23pub struct SwapQuoteReq {
24 pub input_mint: String,
25 pub output_mint: String,
26 pub amount: String,
27 pub slippage_bps: u16,
28 pub swap_mode: SwapMode,
29 pub dexes: Vec<String>,
30 pub exclude_dexes: Vec<String>,
31 pub restrict_intermediate_tokens: bool,
32 pub only_direct_routes: bool,
33 pub as_legacy_transaction: bool,
34 pub platform_fee_bps: u16,
35 pub max_accounts: u64,
36 pub dynamic_slippage: bool,
37
38}
39
40#[derive(Debug, Deserialize, Serialize)]
41#[serde(rename_all = "camelCase")]
42#[serde_as]
43pub struct SwapQuoteRes {
44 pub input_mint: String,
45 pub in_amount: String,
46 pub output_mint: String,
47 pub out_amount: String,
48 pub other_amount_threshold: String,
49 pub swap_mode: SwapMode,
50 pub slippage_bps: u16,
51 pub platform_fee: PlatformFee,
52 pub price_impact_pct: String,
53 pub route_plan: Vec<RoutePlan>,
54 pub context_slot: u64,
55 pub time_taken: String,
56}
57
58#[derive(Debug, Deserialize, Serialize)]
59#[serde(rename_all = "camelCase")]
60#[serde_as]
61pub struct PlatformFee {
62 pub amount: String,
63 pub fee_bps: u16,
64}
65
66#[derive(Debug, Deserialize, Serialize)]
67#[serde(rename_all = "camelCase")]
68#[serde_as]
69pub struct RoutePlan {
70 pub swap_info: SwapInfo,
71 pub percent: u8,
72 pub bps: u16,
73}
74
75#[derive(Debug, Deserialize, Serialize)]
76#[serde(rename_all = "camelCase")]
77#[serde_as]
78pub struct SwapInfo {
79 pub amm_key: String,
80 pub label: String,
81 pub input_mint: String,
82 pub output_mint: String,
83 pub in_amount: String,
84 pub out_amount: String,
85 pub fee_amount: String,
86 pub fee_mint: String,
87}
88
89#[derive(Debug, Deserialize, Serialize)]
90#[serde(rename_all = "camelCase")]
91#[serde_as]
92pub struct SwapReq {
93 pub user_public_key: String,
94 pub payer: String,
95 pub wrap_and_unwrap_sol: bool,
96 pub use_shared_accounts: bool,
97 pub fee_account: Option<String>,
98 pub tracking_account: Option<String>,
99 pub prioritization_fee_lamports: PrioritizationFeeLamports,
100 pub as_legacy_transaction: bool,
101 pub destination_token_account: String,
102 pub dynamic_compute_unit_limit: bool,
103 pub skip_user_accounts_rpc_calls: bool,
104 pub dynamic_slippage: bool,
105 pub compute_unit_price_micro_lamports: u64,
106 pub blockhash_slots_to_expiry: u64,
107 pub quote_response: SwapQuoteRes,
108}
109
110#[derive(Debug, Deserialize, Serialize)]
111#[serde(rename_all = "camelCase")]
112#[serde_as]
113pub struct SwapRes {
114
115}
116
117#[derive(Debug, Deserialize, Serialize)]
118#[serde(rename_all = "camelCase")]
119#[serde_as]
120pub struct PrioritizationFeeLamports {
121 pub priority_level_with_max_lamports: PriorityLevelWithMaxLamports,
122 pub jito_tip_lamports: u64,
123}
124
125#[derive(Debug, Deserialize, Serialize)]
126#[serde(rename_all = "camelCase")]
127#[serde_as]
128pub struct PriorityLevelWithMaxLamports {
129 pub priority_level: String,
130 pub max_lamports: u64,
131}
132
133#[derive(Debug, Deserialize, Serialize)]
134#[serde(rename_all = "camelCase")]
135#[serde_as]
136pub struct SwapInstructionsRes {
137 pub other_instructions: Vec<Instruction>,
138 pub compute_budget_instructions: Vec<Instruction>,
139 pub setup_instructions: Vec<Instruction>,
140 pub swap_instruction: Instruction,
141 pub cleanup_instruction: Instruction,
142 pub address_lookup_table_addresses: Vec<String>,
143}