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.

See StableSwap::compute_amp_factor.

target_amp_factor: u64

Target amp factor, or A.

See StableSwap::compute_amp_factor.

current_ts: i64

Current timestmap.

start_ramp_ts: i64

Start ramp timestamp for calculating the amp factor, or A.

See StableSwap::compute_amp_factor.

stop_ramp_ts: i64

Stop ramp timestamp for calculating the amp factor, or A.

See StableSwap::compute_amp_factor.

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

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.

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

Computes D, which is the virtual price times the total supply of the pool.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.