pub struct SwapQuote {Show 13 fields
pub instrument_id: InstrumentId,
pub amount0: I256,
pub amount1: I256,
pub sqrt_price_before_x96: U160,
pub sqrt_price_after_x96: U160,
pub tick_before: i32,
pub tick_after: i32,
pub liquidity_after: u128,
pub fee_growth_global_after: U256,
pub lp_fee: U256,
pub protocol_fee: U256,
pub crossed_ticks: Vec<CrossedTick>,
pub trade_info: Option<SwapTradeInfo>,
}Expand description
Comprehensive swap quote containing profiling metrics for a hypothetical swap.
This structure provides detailed analysis of what would happen if a swap were executed, including price impact, fees, slippage, and execution details, without actually modifying the pool state.
Fields§
§instrument_id: InstrumentIdInstrument identifier ……
amount0: I256Amount of token0 that would be swapped (positive = in, negative = out).
amount1: I256Amount of token1 that would be swapped (positive = in, negative = out).
sqrt_price_before_x96: U160Square root price before the swap (Q96 format).
sqrt_price_after_x96: U160Square root price after the swap (Q96 format).
tick_before: i32Tick position before the swap.
tick_after: i32Tick position after the swap.
liquidity_after: u128Active liquidity after the swap.
fee_growth_global_after: U256Fee growth global for target token after the swap (Q128.128 format).
lp_fee: U256Total fees paid to liquidity providers.
protocol_fee: U256Total fees paid to the protocol.
crossed_ticks: Vec<CrossedTick>List of tick boundaries crossed during the swap, in order of crossing.
trade_info: Option<SwapTradeInfo>Computed swap trade information in market-oriented format.
Implementations§
Source§impl SwapQuote
impl SwapQuote
Sourcepub fn new(
instrument_id: InstrumentId,
amount0: I256,
amount1: I256,
sqrt_price_before_x96: U160,
sqrt_price_after_x96: U160,
tick_before: i32,
tick_after: i32,
liquidity_after: u128,
fee_growth_global_after: U256,
lp_fee: U256,
protocol_fee: U256,
crossed_ticks: Vec<CrossedTick>,
) -> Self
pub fn new( instrument_id: InstrumentId, amount0: I256, amount1: I256, sqrt_price_before_x96: U160, sqrt_price_after_x96: U160, tick_before: i32, tick_after: i32, liquidity_after: u128, fee_growth_global_after: U256, lp_fee: U256, protocol_fee: U256, crossed_ticks: Vec<CrossedTick>, ) -> Self
Creates a SwapQuote instance with comprehensive swap simulation results.
The trade_info field is initialized to None and must be populated by calling
calculate_trade_info() or will be lazily computed
when accessing price impact or slippage methods.
Sourcepub fn calculate_trade_info(
&mut self,
token0: &Token,
token1: &Token,
) -> Result<()>
pub fn calculate_trade_info( &mut self, token0: &Token, token1: &Token, ) -> Result<()>
Calculates and populates the trade_info field with market-oriented trade data.
This method transforms the raw swap quote data (token0/token1 amounts, sqrt prices)
into standard trading terminology (base/quote, order side, execution price).
The computation uses the sqrt_price_before_x96 to calculate price impact and slippage.
§Errors
Returns an error if trade info computation or price calculations fail.
Sourcepub fn zero_for_one(&self) -> bool
pub fn zero_for_one(&self) -> bool
Determines swap direction from amount signs.
Returns true if swapping token0 for token1 (zero_for_one).
Sourcepub fn total_fee(&self) -> U256
pub fn total_fee(&self) -> U256
Returns the total fees paid in input token(LP fees + protocol fees).
Sourcepub fn get_effective_fee_bps(&self) -> u32
pub fn get_effective_fee_bps(&self) -> u32
Gets the effective fee rate in basis points based on actual fees charged
Sourcepub fn total_crossed_ticks(&self) -> u32
pub fn total_crossed_ticks(&self) -> u32
Returns the number of tick boundaries crossed during this swap.
This equals the length of the crossed_ticks vector and indicates
how much liquidity the swap traversed.
Sourcepub fn get_output_amount(&self) -> U256
pub fn get_output_amount(&self) -> U256
Gets the output amount for the given swap direction.
Sourcepub fn get_input_amount(&self) -> U256
pub fn get_input_amount(&self) -> U256
Gets the input amount for the given swap direction.
Sourcepub fn get_price_impact_bps(&mut self) -> Result<u32>
pub fn get_price_impact_bps(&mut self) -> Result<u32>
Calculates price impact in basis points (requires token references for decimal adjustment).
Price impact measures the market movement caused by the swap size, excluding fees. This is the percentage change in spot price from before to after the swap.
§Returns
Price impact in basis points (10000 = 100%)
§Errors
Returns error if price calculations fail
Sourcepub fn get_slippage_bps(&mut self) -> Result<u32>
pub fn get_slippage_bps(&mut self) -> Result<u32>
Calculates slippage in basis points (requires token references for decimal adjustment).
Slippage includes both price impact and fees, representing the total deviation from the spot price before the swap. This measures the total cost to the trader.
§Returns
Total slippage in basis points (10000 = 100%)
§Errors
Returns error if price calculations fail
Sourcepub fn validate_slippage_tolerance(
&mut self,
max_slippage_bps: u32,
) -> Result<()>
pub fn validate_slippage_tolerance( &mut self, max_slippage_bps: u32, ) -> Result<()>
§Errors
Returns an error if the actual slippage exceeds the maximum slippage tolerance.
Sourcepub fn validate_exact_output(&self, amount_out_requested: U256) -> Result<()>
pub fn validate_exact_output(&self, amount_out_requested: U256) -> Result<()>
Validates that the quote satisfied an exact output request.
§Errors
Returns error if the actual output is less than the requested amount.
Sourcepub fn to_swap_event(
&self,
chain: SharedChain,
dex: SharedDex,
pool_identifier: PoolIdentifier,
block: BlockPosition,
sender: Address,
recipient: Address,
) -> PoolSwap
pub fn to_swap_event( &self, chain: SharedChain, dex: SharedDex, pool_identifier: PoolIdentifier, block: BlockPosition, sender: Address, recipient: Address, ) -> PoolSwap
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for SwapQuote
impl<'py> IntoPyObject<'py> for SwapQuote
Source§impl PyClassImpl for SwapQuote
impl PyClassImpl for SwapQuote
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Comprehensive swap quote containing profiling metrics for a hypothetical swap.
///
/// This structure provides detailed analysis of what would happen if a swap were executed,
/// including price impact, fees, slippage, and execution details, without actually
/// modifying the pool state.
const RAW_DOC: &'static CStr = /// Comprehensive swap quote containing profiling metrics for a hypothetical swap. /// /// This structure provides detailed analysis of what would happen if a swap were executed, /// including price impact, fees, slippage, and execution details, without actually /// modifying the pool state.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<SwapQuote>
type ThreadChecker = SendablePyClass<SwapQuote>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyMethods<SwapQuote> for PyClassImplCollector<SwapQuote>
impl PyMethods<SwapQuote> for PyClassImplCollector<SwapQuote>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for SwapQuote
impl PyTypeInfo for SwapQuote
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for SwapQuote
impl ExtractPyClassWithClone for SwapQuote
Auto Trait Implementations§
impl Freeze for SwapQuote
impl RefUnwindSafe for SwapQuote
impl Send for SwapQuote
impl Sync for SwapQuote
impl Unpin for SwapQuote
impl UnwindSafe for SwapQuote
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
Source§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more