Struct stable_swap_math::price::SaberSwap
source · [−]pub struct SaberSwap {
pub initial_amp_factor: u64,
pub target_amp_factor: u64,
pub current_ts: i64,
pub start_ramp_ts: i64,
pub stop_ramp_ts: i64,
pub lp_mint_supply: u64,
pub token_a_reserve: u64,
pub token_b_reserve: u64,
}
Expand description
Utilities for calculating the virtual price of a Saber LP token.
This is especially useful for if you want to use a Saber LP token as collateral.
Calculating liquidation value
To use a Saber LP token as collateral, you will need to fetch the prices of both of the tokens in the pool and get the min of the two. Then, use the SaberSwap::calculate_virtual_price_of_pool_tokens function to get the virtual price.
This virtual price is resilient to manipulations of the LP token price.
Hence, min_lp_price = min_value * virtual_price
.
Additional Reading
Fields
initial_amp_factor: u64
Initial amp factor, or A
.
target_amp_factor: u64
Target amp factor, or A
.
current_ts: i64
Current timestmap.
start_ramp_ts: i64
Start ramp timestamp for calculating the amp factor, or A
.
stop_ramp_ts: i64
Stop ramp timestamp for calculating the amp factor, or A
.
lp_mint_supply: u64
Total supply of LP tokens.
This is pool_mint.supply
, where pool_mint
is an SPL Token Mint.
token_a_reserve: u64
Amount of token A.
This is token_a.reserve.amount
, where token_a.reserve
is an SPL Token Token Account.
token_b_reserve: u64
Amount of token B.
This is token_b.reserve.amount
, where token_b.reserve
is an SPL Token Token Account.
Implementations
sourceimpl SaberSwap
impl SaberSwap
sourcepub fn calculate_pool_tokens_from_virtual_amount(
&self,
virtual_amount: u64
) -> Option<u64>
pub fn calculate_pool_tokens_from_virtual_amount(
&self,
virtual_amount: u64
) -> Option<u64>
Calculates the amount of pool tokens represented by the given amount of virtual tokens.
A virtual token is the denomination of virtual price. For example, if there is a virtual price of 1.04 on USDC-USDT LP, then 1 virtual token maps to 1/1.04 USDC-USDT LP tokens.
This is useful for building assets that are backed by LP tokens. An example of this is Cashio, which allows users to mint $CASH tokens based on the virtual price of underlying LP tokens.
Arguments
virtual_amount
- The number of “virtual” underlying tokens.
sourcepub fn calculate_virtual_price_of_pool_tokens(
&self,
pool_token_amount: u64
) -> Option<u64>
pub fn calculate_virtual_price_of_pool_tokens(
&self,
pool_token_amount: u64
) -> Option<u64>
Calculates the virtual price of the given amount of pool tokens.
The virtual price is defined as the current price of the pool LP token relative to the underlying pool assets.
The virtual price in the StableSwap algorithm is obtained through taking the invariance of the pool, which by default takes every token as valued at 1.00 of the underlying. You can get the virtual price of each pool by calling this function for it.1
Trait Implementations
sourceimpl From<&'_ SaberSwap> for StableSwap
impl From<&'_ SaberSwap> for StableSwap
impl Copy for SaberSwap
impl Eq for SaberSwap
impl StructuralEq for SaberSwap
impl StructuralPartialEq for SaberSwap
Auto Trait Implementations
impl RefUnwindSafe for SaberSwap
impl Send for SaberSwap
impl Sync for SaberSwap
impl Unpin for SaberSwap
impl UnwindSafe for SaberSwap
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
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more