#[repr(C)]pub struct SwapCurve {
pub curve_type: CurveType,
pub calculator: Arc<dyn CurveCalculator + Sync + Send>,
}
Expand description
Concrete struct to wrap around the trait object which performs calculation.
Fields
curve_type: CurveType
The type of curve contained in the calculator, helpful for outside queries
calculator: Arc<dyn CurveCalculator + Sync + Send>
The actual calculator, represented as a trait object to allow for many different types of curves
Implementations
sourceimpl SwapCurve
impl SwapCurve
sourcepub fn swap(
&self,
source_amount: u128,
swap_source_amount: u128,
swap_destination_amount: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<SwapResult>
pub fn swap(
&self,
source_amount: u128,
swap_source_amount: u128,
swap_destination_amount: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<SwapResult>
Subtract fees and calculate how much destination token will be provided given an amount of source token.
sourcepub fn deposit_single_token_type(
&self,
source_amount: u128,
swap_token_a_amount: u128,
swap_token_b_amount: u128,
pool_supply: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<u128>
pub fn deposit_single_token_type(
&self,
source_amount: u128,
swap_token_a_amount: u128,
swap_token_b_amount: u128,
pool_supply: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<u128>
Get the amount of pool tokens for the deposited amount of token A or B
sourcepub fn withdraw_single_token_type_exact_out(
&self,
source_amount: u128,
swap_token_a_amount: u128,
swap_token_b_amount: u128,
pool_supply: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<u128>
pub fn withdraw_single_token_type_exact_out(
&self,
source_amount: u128,
swap_token_a_amount: u128,
swap_token_b_amount: u128,
pool_supply: u128,
trade_direction: TradeDirection,
fees: &Fees
) -> Option<u128>
Get the amount of pool tokens for the withdrawn amount of token A or B
Trait Implementations
sourceimpl Default for SwapCurve
impl Default for SwapCurve
Default implementation for SwapCurve cannot be derived because of the contained Arc.
sourceimpl Pack for SwapCurve
impl Pack for SwapCurve
sourceconst LEN: usize = 33usize
const LEN: usize = 33usize
Size of encoding of all curve parameters, which include fees and any other constants used to calculate swaps, deposits, and withdrawals. This includes 1 byte for the type, and 72 for the calculator to use as it needs. Some calculators may be smaller than 72 bytes.
sourcefn get_packed_len() -> usize
fn get_packed_len() -> usize
Get the packed length
sourcefn unpack(input: &[u8]) -> Result<Self, ProgramError> where
Self: IsInitialized,
fn unpack(input: &[u8]) -> Result<Self, ProgramError> where
Self: IsInitialized,
Unpack from slice and check if initialized
sourcefn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
Unpack from slice without checking if initialized
sourceimpl PartialEq<SwapCurve> for SwapCurve
impl PartialEq<SwapCurve> for SwapCurve
Simple implementation for PartialEq which assumes that the output of
Pack
is enough to guarantee equality
impl Sealed for SwapCurve
Auto Trait Implementations
impl !RefUnwindSafe for SwapCurve
impl Send for SwapCurve
impl Sync for SwapCurve
impl Unpin for SwapCurve
impl !UnwindSafe for SwapCurve
Blanket Implementations
impl<T> AbiExample for T
impl<T> AbiExample for T
default fn example() -> T
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more