tensor_eigen/formatting/
raydium.rs

1use super::{pad_label, CustomFormat};
2use crate::types::{
3    raydium_clmm::{PoolState as ClmmPoolState, RewardInfo},
4    raydium_cp::PoolState as CpPoolState,
5    raydium_v4::{AmmInfo, StateData},
6};
7use console::Style;
8
9const AMM_LABEL_LENGTH: usize = 25;
10const STATE_LABEL_LENGTH: usize = AMM_LABEL_LENGTH - 2;
11const LINE_BREAK: &str = "-------------------------";
12
13impl CustomFormat for AmmInfo {
14    fn custom_format(&self) -> String {
15        let color = Style::new();
16
17        format!(
18            "{}
19{}: {}
20{}: {}
21{}: {}
22{}: {}
23{}: {}
24{}: {}
25{}: {}
26{}: {}
27{}: {}
28{}: {}
29{}: {}
30{}: {}
31{}: {}
32{}: {}
33{}
34{}: {}
35{}: {}
36{}: {}
37{}: {}
38{}: {}
39{}: {}
40{}: {}
41{}: {}
42{}: {}
43{}: {}",
44            color.apply_to("Raydium AMM Info---------"),
45            pad_label("status", AMM_LABEL_LENGTH),
46            color.apply_to(self.status),
47            pad_label("nonce", AMM_LABEL_LENGTH),
48            color.apply_to(self.nonce),
49            pad_label("order_num", AMM_LABEL_LENGTH),
50            color.apply_to(self.order_num),
51            pad_label("depth", AMM_LABEL_LENGTH),
52            color.apply_to(self.depth),
53            pad_label("coin_decimals", AMM_LABEL_LENGTH),
54            color.apply_to(self.coin_decimals),
55            pad_label("pc_decimals", AMM_LABEL_LENGTH),
56            color.apply_to(self.pc_decimals),
57            pad_label("state", AMM_LABEL_LENGTH),
58            color.apply_to(self.state),
59            pad_label("reset_flag", AMM_LABEL_LENGTH),
60            color.apply_to(self.reset_flag),
61            pad_label("min_size", AMM_LABEL_LENGTH),
62            color.apply_to(self.min_size),
63            pad_label("coin_lot_size", AMM_LABEL_LENGTH),
64            color.apply_to(self.coin_lot_size),
65            pad_label("pc_lot_size", AMM_LABEL_LENGTH),
66            color.apply_to(self.pc_lot_size),
67            pad_label("min_price_multiplier", AMM_LABEL_LENGTH),
68            color.apply_to(self.min_price_multiplier),
69            pad_label("max_price_multiplier", AMM_LABEL_LENGTH),
70            color.apply_to(self.max_price_multiplier),
71            self.state_data.custom_format(),
72            pad_label("coin_vault", AMM_LABEL_LENGTH),
73            color.apply_to(self.coin_vault),
74            pad_label("pc_vault", AMM_LABEL_LENGTH),
75            color.apply_to(self.pc_vault),
76            pad_label("coin_vault_mint", AMM_LABEL_LENGTH),
77            color.apply_to(self.coin_vault_mint),
78            pad_label("pc_vault_mint", AMM_LABEL_LENGTH),
79            color.apply_to(self.pc_vault_mint),
80            pad_label("lp_mint", AMM_LABEL_LENGTH),
81            color.apply_to(self.lp_mint),
82            pad_label("open_orders", AMM_LABEL_LENGTH),
83            color.apply_to(self.open_orders),
84            pad_label("market", AMM_LABEL_LENGTH),
85            color.apply_to(self.market),
86            pad_label("market_program", AMM_LABEL_LENGTH),
87            color.apply_to(self.market_program),
88            pad_label("target_orders", AMM_LABEL_LENGTH),
89            color.apply_to(self.target_orders),
90            pad_label("amm_owner", AMM_LABEL_LENGTH),
91            color.apply_to(self.amm_owner),
92            pad_label("lp_amount", AMM_LABEL_LENGTH),
93            color.apply_to(self.lp_amount)
94        )
95    }
96}
97
98impl CustomFormat for StateData {
99    fn custom_format(&self) -> String {
100        let color = Style::new();
101        format!(
102            "{}
103  {}: {}
104  {}: {}
105  {}: {}
106  {}: {}
107  {}: {}
108  {}: {}
109  {}: {}
110  {}: {}
111{}",
112            color.apply_to("--State Data-------------"),
113            pad_label("need_take_pnl_coin", STATE_LABEL_LENGTH),
114            color.apply_to(self.need_take_pnl_coin),
115            pad_label("need_take_pnl_pc", STATE_LABEL_LENGTH),
116            color.apply_to(self.need_take_pnl_pc),
117            pad_label("total_pnl_pc", STATE_LABEL_LENGTH),
118            color.apply_to(self.total_pnl_pc),
119            pad_label("total_pnl_coin", STATE_LABEL_LENGTH),
120            color.apply_to(self.total_pnl_coin),
121            pad_label("pool_open_time", STATE_LABEL_LENGTH),
122            color.apply_to(self.pool_open_time),
123            pad_label("swap_coin_in_amount", STATE_LABEL_LENGTH),
124            color.apply_to(self.swap_coin_in_amount),
125            pad_label("swap_pc_out_amount", STATE_LABEL_LENGTH),
126            color.apply_to(self.swap_pc_out_amount),
127            pad_label("swap_acc_pc_fee", STATE_LABEL_LENGTH),
128            color.apply_to(self.swap_acc_pc_fee),
129            color.apply_to(LINE_BREAK)
130        )
131    }
132}
133
134impl CustomFormat for RewardInfo {
135    fn custom_format(&self) -> String {
136        let color = Style::new();
137
138        format!(
139            "{}
140  {}: {}
141  {}: {}
142  {}: {}
143  {}: {}
144  {}: {}
145  {}: {}
146  {}: {}
147  {}: {}
148  {}: {}
149  {}: {}",
150            color.apply_to("--Reward Info-------------"),
151            pad_label("reward_state", STATE_LABEL_LENGTH),
152            color.apply_to(self.reward_state),
153            pad_label("open_time", STATE_LABEL_LENGTH),
154            color.apply_to(self.open_time),
155            pad_label("end_time", STATE_LABEL_LENGTH),
156            color.apply_to(self.end_time),
157            pad_label("last_update_time", STATE_LABEL_LENGTH),
158            color.apply_to(self.last_update_time),
159            pad_label("emissions_per_second", STATE_LABEL_LENGTH),
160            color.apply_to(self.emissions_per_second_x64),
161            pad_label("total_emissioned", STATE_LABEL_LENGTH),
162            color.apply_to(self.reward_total_emissioned),
163            pad_label("reward_claimed", STATE_LABEL_LENGTH),
164            color.apply_to(self.reward_claimed),
165            pad_label("token_mint", STATE_LABEL_LENGTH),
166            color.apply_to(self.token_mint),
167            pad_label("token_vault", STATE_LABEL_LENGTH),
168            color.apply_to(self.token_vault),
169            pad_label("authority", STATE_LABEL_LENGTH),
170            color.apply_to(self.authority)
171        )
172    }
173}
174
175impl CustomFormat for ClmmPoolState {
176    fn custom_format(&self) -> String {
177        let color = Style::new();
178
179        let mut output = format!(
180            "{}
181{}: {}
182{}: {}
183{}: {}
184{}: {}
185{}: {}
186{}: {}
187{}: {}
188{}: {}
189{}: {}
190{}: {}
191{}: {}
192{}: {}
193{}: {}
194{}: {}
195{}: {}",
196            color.apply_to("--CLMM Pool State---------"),
197            pad_label("amm_config", AMM_LABEL_LENGTH),
198            color.apply_to(self.amm_config),
199            pad_label("owner", AMM_LABEL_LENGTH),
200            color.apply_to(self.owner),
201            pad_label("token_mint_0", AMM_LABEL_LENGTH),
202            color.apply_to(self.token_mint_0),
203            pad_label("token_mint_1", AMM_LABEL_LENGTH),
204            color.apply_to(self.token_mint_1),
205            pad_label("token_vault_0", AMM_LABEL_LENGTH),
206            color.apply_to(self.token_vault_0),
207            pad_label("token_vault_1", AMM_LABEL_LENGTH),
208            color.apply_to(self.token_vault_1),
209            pad_label("tick_spacing", AMM_LABEL_LENGTH),
210            color.apply_to(self.tick_spacing),
211            pad_label("liquidity", AMM_LABEL_LENGTH),
212            color.apply_to(self.liquidity),
213            pad_label("sqrt_price_x64", AMM_LABEL_LENGTH),
214            color.apply_to(self.sqrt_price_x64),
215            pad_label("tick_current", AMM_LABEL_LENGTH),
216            color.apply_to(self.tick_current),
217            pad_label("protocol_fees_0", AMM_LABEL_LENGTH),
218            color.apply_to(self.protocol_fees_token_0),
219            pad_label("protocol_fees_1", AMM_LABEL_LENGTH),
220            color.apply_to(self.protocol_fees_token_1),
221            pad_label("status", AMM_LABEL_LENGTH),
222            color.apply_to(self.status),
223            pad_label("open_time", AMM_LABEL_LENGTH),
224            color.apply_to(self.open_time),
225            pad_label("recent_epoch", AMM_LABEL_LENGTH),
226            color.apply_to(self.recent_epoch)
227        );
228
229        // Add reward info formatting
230        for (i, reward_info) in self.reward_infos.iter().enumerate() {
231            if reward_info.initialized() {
232                output.push_str(&format!(
233                    "\n{}",
234                    color.apply_to(format!("--Reward #{}--------------", i + 1))
235                ));
236                output.push_str(&format!("\n{}", reward_info.custom_format()));
237            }
238        }
239
240        output.push_str(&format!("\n{}", color.apply_to(LINE_BREAK)));
241        output
242    }
243}
244
245impl CustomFormat for CpPoolState {
246    fn custom_format(&self) -> String {
247        let color = Style::new();
248
249        format!(
250            "{}
251{}: {}
252{}: {}
253{}: {}
254{}: {}
255{}: {}
256{}: {}
257{}: {}
258{}: {}
259{}: {}
260{}: {}
261{}: {}
262{}: {}
263{}: {}
264{}: {}
265{}: {}
266{}: {}
267{}: {}
268{}: {}
269{}",
270            color.apply_to("--CPSwap Pool State-------"),
271            pad_label("amm_config", AMM_LABEL_LENGTH),
272            color.apply_to(self.amm_config),
273            pad_label("pool_creator", AMM_LABEL_LENGTH),
274            color.apply_to(self.pool_creator),
275            pad_label("token_0_vault", AMM_LABEL_LENGTH),
276            color.apply_to(self.token_0_vault),
277            pad_label("token_1_vault", AMM_LABEL_LENGTH),
278            color.apply_to(self.token_1_vault),
279            pad_label("lp_mint", AMM_LABEL_LENGTH),
280            color.apply_to(self.lp_mint),
281            pad_label("token_0_mint", AMM_LABEL_LENGTH),
282            color.apply_to(self.token_0_mint),
283            pad_label("token_1_mint", AMM_LABEL_LENGTH),
284            color.apply_to(self.token_1_mint),
285            pad_label("token_0_program", AMM_LABEL_LENGTH),
286            color.apply_to(self.token_0_program),
287            pad_label("token_1_program", AMM_LABEL_LENGTH),
288            color.apply_to(self.token_1_program),
289            pad_label("observation_key", AMM_LABEL_LENGTH),
290            color.apply_to(self.observation_key),
291            pad_label("status", AMM_LABEL_LENGTH),
292            color.apply_to(self.status),
293            pad_label("lp_supply", AMM_LABEL_LENGTH),
294            color.apply_to(self.lp_supply),
295            pad_label("protocol_fees_0", AMM_LABEL_LENGTH),
296            color.apply_to(self.protocol_fees_token_0),
297            pad_label("protocol_fees_1", AMM_LABEL_LENGTH),
298            color.apply_to(self.protocol_fees_token_1),
299            pad_label("fund_fees_0", AMM_LABEL_LENGTH),
300            color.apply_to(self.fund_fees_token_0),
301            pad_label("fund_fees_1", AMM_LABEL_LENGTH),
302            color.apply_to(self.fund_fees_token_1),
303            pad_label("open_time", AMM_LABEL_LENGTH),
304            color.apply_to(self.open_time),
305            pad_label("recent_epoch", AMM_LABEL_LENGTH),
306            color.apply_to(self.recent_epoch),
307            color.apply_to(LINE_BREAK)
308        )
309    }
310}