pub enum SwapConstraint {
#[non_exhaustive] TradeLimitPrice {
limit: Price,
tolerance: f64,
min_amount_in: Option<BigUint>,
max_amount_in: Option<BigUint>,
},
#[non_exhaustive] PoolTargetPrice {
target: Price,
tolerance: f64,
min_amount_in: Option<BigUint>,
max_amount_in: Option<BigUint>,
},
}Expand description
Defines constraints for advanced quote calculations.
These constraints allow sophisticated trading strategies by limiting swaps based on price thresholds or targeting specific pool states.
Variants§
#[non_exhaustive]TradeLimitPrice
This mode will calculate the maximum trade that this pool can execute while respecting a trade limit price.
Fields
This variant is marked as non-exhaustive
limit: PriceThe minimum acceptable price for the resulting trade, as a Price struct. The resulting amount_out / amount_in must be >= trade_limit_price
#[non_exhaustive]PoolTargetPrice
This mode will calculate the amount of token_in required to move the pool’s marginal price down to a target price, and the amount of token_out received.
§Edge Cases and Limitations
Computing the exact amount to move a pool’s marginal price to a target has several challenges:
- The definition of marginal price varies between protocols. It is usually not an attribute of the pool but a consequence of its liquidity distribution and current state.
- For protocols with concentrated liquidity, the marginal price is discrete, meaning we can’t always find an exact trade amount to reach the target price.
- Not all protocols support analytical solutions for this problem, requiring numerical methods.
Fields
This variant is marked as non-exhaustive
target: PriceThe marginal price we want the pool to be after the trade, as a Price struct. The pool’s price will move down to this level as token_in is sold into it
Implementations§
Source§impl SwapConstraint
impl SwapConstraint
Sourcepub fn trade_limit_price(limit: Price, tolerance: f64) -> Self
pub fn trade_limit_price(limit: Price, tolerance: f64) -> Self
Creates a trade limit price constraint.
This constraint finds the maximum trade size while respecting a minimum price
threshold. See SwapConstraint::TradeLimitPrice for details.
§Arguments
limit- The minimum acceptable price for the tradetolerance- Additional tolerance as a fraction to loosen the constraint
Sourcepub fn pool_target_price(target: Price, tolerance: f64) -> Self
pub fn pool_target_price(target: Price, tolerance: f64) -> Self
Creates a pool target price constraint.
This constraint calculates the trade needed to move the pool’s price to a
target level. See SwapConstraint::PoolTargetPrice for details.`
§Arguments
target- The desired final marginal price of the pooltolerance- Acceptable variance from the target price as a fraction
Sourcepub fn with_lower_bound(self, lower: BigUint) -> SimulationResult<Self>
pub fn with_lower_bound(self, lower: BigUint) -> SimulationResult<Self>
Sourcepub fn with_upper_bound(self, upper: BigUint) -> SimulationResult<Self>
pub fn with_upper_bound(self, upper: BigUint) -> SimulationResult<Self>
Trait Implementations§
Source§impl Clone for SwapConstraint
impl Clone for SwapConstraint
Source§fn clone(&self) -> SwapConstraint
fn clone(&self) -> SwapConstraint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SwapConstraint
impl Debug for SwapConstraint
Source§impl PartialEq for SwapConstraint
impl PartialEq for SwapConstraint
Source§fn eq(&self, other: &SwapConstraint) -> bool
fn eq(&self, other: &SwapConstraint) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SwapConstraint
Auto Trait Implementations§
impl Freeze for SwapConstraint
impl RefUnwindSafe for SwapConstraint
impl Send for SwapConstraint
impl Sync for SwapConstraint
impl Unpin for SwapConstraint
impl UnsafeUnpin for SwapConstraint
impl UnwindSafe for SwapConstraint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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