Skip to main content

nautilus_model/python/defi/
quote.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use pyo3::prelude::*;
17
18use crate::defi::pool_analysis::quote::SwapQuote;
19
20#[pymethods]
21#[pyo3_stub_gen::derive::gen_stub_pymethods]
22impl SwapQuote {
23    #[getter]
24    #[pyo3(name = "amount0")]
25    fn py_amount0(&self) -> String {
26        self.amount0.to_string()
27    }
28
29    #[getter]
30    #[pyo3(name = "amount1")]
31    fn py_amount1(&self) -> String {
32        self.amount1.to_string()
33    }
34
35    #[getter]
36    #[pyo3(name = "sqrt_price_before_x96")]
37    fn py_sqrt_price_before_x96(&self) -> String {
38        self.sqrt_price_before_x96.to_string()
39    }
40
41    #[getter]
42    #[pyo3(name = "sqrt_price_after_x96")]
43    fn py_sqrt_price_after_x96(&self) -> String {
44        self.sqrt_price_after_x96.to_string()
45    }
46
47    #[getter]
48    #[pyo3(name = "tick_before")]
49    fn py_tick_before(&self) -> i32 {
50        self.tick_before
51    }
52
53    #[getter]
54    #[pyo3(name = "tick_after")]
55    fn py_tick_after(&self) -> i32 {
56        self.tick_after
57    }
58
59    #[getter]
60    #[pyo3(name = "liquidity_after")]
61    fn py_liquidity_after(&self) -> u128 {
62        self.liquidity_after
63    }
64
65    #[getter]
66    #[pyo3(name = "fee_growth_global_after")]
67    fn py_fee_growth_global_after(&self) -> String {
68        self.fee_growth_global_after.to_string()
69    }
70
71    #[getter]
72    #[pyo3(name = "lp_fee")]
73    fn py_lp_fee(&self) -> String {
74        self.lp_fee.to_string()
75    }
76
77    #[getter]
78    #[pyo3(name = "protocol_fee")]
79    fn py_protocol_fee(&self) -> String {
80        self.protocol_fee.to_string()
81    }
82
83    #[getter]
84    #[pyo3(name = "crossed_ticks_count")]
85    fn py_crossed_ticks_count(&self) -> usize {
86        self.crossed_ticks.len()
87    }
88
89    /// Determines swap direction from amount signs.
90    ///
91    /// Returns `true` if swapping token0 for token1 (`zero_for_one`).
92    #[pyo3(name = "zero_for_one")]
93    fn py_zero_for_one(&self) -> bool {
94        self.zero_for_one()
95    }
96
97    /// Returns the total fees paid in input token(LP fees + protocol fees).
98    #[pyo3(name = "total_fee")]
99    fn py_total_fee(&self) -> String {
100        self.total_fee().to_string()
101    }
102
103    /// Returns the number of tick boundaries crossed during this swap.
104    ///
105    /// This equals the length of the `crossed_ticks` vector and indicates
106    /// how much liquidity the swap traversed.
107    #[pyo3(name = "total_crossed_ticks")]
108    fn py_total_crossed_ticks(&self) -> u32 {
109        self.total_crossed_ticks()
110    }
111
112    /// Gets the output amount for the given swap direction.
113    #[pyo3(name = "get_output_amount")]
114    fn py_get_output_amount(&self) -> String {
115        self.get_output_amount().to_string()
116    }
117
118    fn __str__(&self) -> String {
119        format!(
120            "SwapQuote(amount0={}, amount1={}, tick_before={}, tick_after={}, liquidity_after={}, total_fee={})",
121            self.amount0,
122            self.amount1,
123            self.tick_before,
124            self.tick_after,
125            self.liquidity_after,
126            self.total_fee()
127        )
128    }
129
130    fn __repr__(&self) -> String {
131        format!("{self:?}")
132    }
133}