1use anyhow::anyhow;
2
3#[derive(Copy, Clone, Debug, PartialEq)]
4pub enum Side {
5 Bid,
6 Ask,
7}
8
9#[derive(Clone, PartialEq, Debug)]
10pub enum Swap {
11 Saber,
12 SaberAddDecimalsDeposit,
13 SaberAddDecimalsWithdraw,
14 TokenSwap,
15 Raydium,
16 Crema {
17 a_to_b: bool,
18 },
19 Mercurial,
20 Aldrin {
21 side: Side,
22 },
23 AldrinV2 {
24 side: Side,
25 },
26 Whirlpool {
27 a_to_b: bool,
28 },
29 Invariant {
30 x_to_y: bool,
31 },
32 Meteora,
33 MarcoPolo {
34 x_to_y: bool,
35 },
36 LifinityV2,
37 RaydiumClmm,
38 Phoenix {
39 side: Side,
40 },
41 TokenSwapV2,
42 HeliumTreasuryManagementRedeemV0,
43 StakeDexStakeWrappedSol,
44 MeteoraDlmm,
45 OpenBookV2 {
46 side: Side,
47 },
48 RaydiumClmmV2,
49 StakeDexPrefundWithdrawStakeAndDepositStake {
50 bridge_stake_seed: u32,
51 },
52 SanctumS {
53 src_lst_value_calc_accs: u8,
54 dst_lst_value_calc_accs: u8,
55 src_lst_index: u32,
56 dst_lst_index: u32,
57 },
58 SanctumSAddLiquidity {
59 lst_value_calc_accs: u8,
60 lst_index: u32,
61 },
62 SanctumSRemoveLiquidity {
63 lst_value_calc_accs: u8,
64 lst_index: u32,
65 },
66 RaydiumCP,
67 WhirlpoolSwapV2 {
68 a_to_b: bool,
69 remaining_accounts_info: Option<RemainingAccountsInfo>,
70 },
71 OneIntro,
72 PerpsV2,
73 PerpsV2AddLiquidity,
74 PerpsV2RemoveLiquidity,
75 MoonshotWrappedBuy,
76 MoonshotWrappedSell,
77 StabbleStableSwap,
78 StabbleWeightedSwap,
79 Obric {
80 x_to_y: bool,
81 },
82 SolFi {
83 is_quote_to_base: bool,
84 },
85 SolayerDelegateNoInit,
86 SolayerUndelegateNoInit,
87 ZeroFi,
88 StakeDexWithdrawWrappedSol,
89 VirtualsBuy,
90 VirtualsSell,
91 Perena {
92 in_index: u8,
93 out_index: u8,
94 },
95 Gamma,
96 MeteoraDlmmSwapV2 {
97 remaining_accounts_info: RemainingAccountsInfo,
98 },
99 Woofi,
100 MeteoraDammV2,
101 StabbleStableSwapV2,
102 StabbleWeightedSwapV2,
103 RaydiumLaunchlabBuy {
104 share_fee_rate: u64,
105 },
106 RaydiumLaunchlabSell {
107 share_fee_rate: u64,
108 },
109 BoopdotfunWrappedBuy,
110 BoopdotfunWrappedSell,
111 Plasma {
112 side: Side,
113 },
114 GoonFi {
115 is_bid: bool,
116 blacklist_bump: u8,
117 },
118 HumidiFi {
119 swap_id: u64,
120 is_base_to_quote: bool,
121 },
122 MeteoraDynamicBondingCurveSwapWithRemainingAccounts,
123 TesseraV {
124 side: Side,
125 },
126 Heaven {
127 a_to_b: bool,
128 },
129 SolFiV2 {
130 is_quote_to_base: bool,
131 },
132 Aquifer,
133 PumpWrappedBuyV3,
134 PumpWrappedSellV3,
135 PumpSwapBuyV3,
136 PumpSwapSellV3,
137 JupiterLendDeposit,
138 JupiterLendRedeem,
139 DefiTuna {
140 a_to_b: bool,
141 remaining_accounts_info: Option<RemainingAccountsInfo>,
142 },
143 AlphaQ {
144 a_to_b: bool,
145 },
146 RaydiumV2,
147 SarosDlmm {
148 swap_for_y: bool,
149 },
150 Futarchy {
151 side: Side,
152 },
153 MeteoraDammV2WithRemainingAccounts,
154 Obsidian,
155 WhaleStreet {
156 side: Side,
157 },
158 DynamicV1 {
159 candidate_swaps: Vec<CandidateSwap>,
160 },
161 PumpWrappedBuyV4,
162 PumpWrappedSellV4,
163 CarrotIssue,
164 CarrotRedeem,
165 Manifest {
166 side: Side,
167 },
168 BisonFi {
169 a_to_b: bool,
170 },
171 HumidiFiV2 {
172 swap_id: u64,
173 is_base_to_quote: bool,
174 },
175 PerenaStar {
176 is_mint: bool,
177 },
178 GoonFiV2 {
179 is_bid: bool,
180 },
181}
182
183#[derive(Clone, PartialEq, Eq, Debug)]
184pub enum AccountsType {
185 TransferHookA,
186 TransferHookB,
187 TickArray,
192 }
195
196#[derive(Clone, Debug, PartialEq)]
197pub struct RemainingAccountsSlice {
198 pub accounts_type: AccountsType,
199 pub length: u8,
200}
201
202#[derive(Clone, Debug, PartialEq)]
203pub struct RemainingAccountsInfo {
204 pub slices: Vec<RemainingAccountsSlice>,
205}
206
207#[derive(Clone, PartialEq, Debug)]
208pub enum CandidateSwap {
209 HumidiFi {
210 swap_id: u64,
211 is_base_to_quote: bool,
212 },
213 TesseraV {
214 side: Side,
215 },
216 HumidiFiV2 {
217 swap_id: u64,
218 is_base_to_quote: bool,
219 },
220}
221
222impl TryInto<CandidateSwap> for Swap {
223 type Error = anyhow::Error;
224
225 fn try_into(self) -> Result<CandidateSwap, Self::Error> {
226 let candidate_swap = match self {
227 Swap::HumidiFi {
228 swap_id,
229 is_base_to_quote,
230 } => CandidateSwap::HumidiFi {
231 swap_id,
232 is_base_to_quote,
233 },
234 Swap::TesseraV { side } => CandidateSwap::TesseraV { side },
235 Swap::HumidiFiV2 {
236 swap_id,
237 is_base_to_quote,
238 } => CandidateSwap::HumidiFiV2 {
239 swap_id,
240 is_base_to_quote,
241 },
242 _ => return Err(anyhow!("Swap {self:?} is not a valid candidate swap")),
243 };
244 Ok(candidate_swap)
245 }
246}