pub enum SwapConstraint {
TradeLimitPrice {
limit: Price,
tolerance: f64,
min_amount_in: Option<BigUint>,
max_amount_in: Option<BigUint>,
},
PoolTargetPrice {
target: Price,
tolerance: f64,
min_amount_in: Option<BigUint>,
max_amount_in: Option<BigUint>,
},
}Expand description
Options on how to constrain the pool swap query
Variants§
TradeLimitPrice
This mode will calculate the maximum trade that this pool can execute while respecting a trade limit price.
Fields
§
limit: PriceThe minimum acceptable price for the resulting trade, as a Price struct. The resulting amount_out / amount_in must be >= trade_limit_price
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
§
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
Trait Implementations§
Source§impl Clone for SwapConstraint
impl Clone for SwapConstraint
Source§fn clone(&self) -> SwapConstraint
fn clone(&self) -> SwapConstraint
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SwapConstraint
impl Debug for SwapConstraint
Source§impl PartialEq for SwapConstraint
impl PartialEq for SwapConstraint
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 UnwindSafe for SwapConstraint
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
Mutably borrows from an owned value. Read more
§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)
🔬This is a nightly-only experimental API. (
clone_to_uninit)