Struct stable_swap::curve::StableSwap [−][src]
pub struct StableSwap { /* fields omitted */ }
Expand description
The StableSwap invariant calculator.
This is primarily used to calculate two quantities:
D
, the swap invariant, andY
, the amount of tokens swapped in an instruction.
This calculator also contains several helper utilities for computing swap, withdraw, and deposit amounts.
Resources:
Implementations
Constructs a new StableSwap from a SwapInfo.
Constructs a new StableSwap invariant calculator.
Compute the amplification coefficient (A).
The amplification coefficient is used to determine the slippage incurred when performing swaps. The lower it is, the closer the invariant is to the constant product1.
The amplication coefficient linearly increases with respect to time,
based on the SwapInfo::start_ramp_ts
and SwapInfo::stop_ramp_ts
parameters.
Computes the Stable Swap invariant (D).
The invariant is defined as follows:
A * sum(x_i) * n**n + D = A * D * n**n + D**(n+1) / (n**n * prod(x_i))
Arguments
amount_a
- The amount of token A owned by the LP pool. (i.e. token A reserves)amount_b
- The amount of token B owned by the LP pool. (i.e. token B reserves)
For more info on reserves, see stable_swap_client::state::SwapTokenInfo::reserves.
Computes the amount of pool tokens to mint after a deposit.
Compute the swap amount y
in proportion to x
.
Solve for y
:
y**2 + y * (sum' - (A*n**n - 1) * D / (A * n**n)) = D ** (n + 1) / (n ** (2 * n) * prod' * A)
y**2 + b*y = c
Computes the swap amount y
in proportion to x
.
Calculates the withdrawal amount when withdrawing only one type of token.
Calculation:
- Get current D
- Solve Eqn against
y_i
forD - _token_amount
Trait Implementations
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
type Error = ProgramError
type Error = ProgramError
The type returned in the event of a conversion error.
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for StableSwap
impl Send for StableSwap
impl Sync for StableSwap
impl Unpin for StableSwap
impl UnwindSafe for StableSwap
Blanket Implementations
pub default fn example() -> T
Mutably borrows from an owned value. Read more