Struct mango_v4::state::TokenConditionalSwap
source · #[repr(C)]pub struct TokenConditionalSwap {Show 23 fields
pub id: u64,
pub max_buy: u64,
pub max_sell: u64,
pub bought: u64,
pub sold: u64,
pub expiry_timestamp: u64,
pub price_lower_limit: f64,
pub price_upper_limit: f64,
pub price_premium_rate: f64,
pub taker_fee_rate: f32,
pub maker_fee_rate: f32,
pub buy_token_index: TokenIndex,
pub sell_token_index: TokenIndex,
pub is_configured: u8,
pub allow_creating_deposits: u8,
pub allow_creating_borrows: u8,
pub display_price_style: u8,
pub intention: u8,
pub tcs_type: u8,
pub padding: [u8; 6],
pub start_timestamp: u64,
pub duration_seconds: u64,
pub reserved: [u8; 88],
}
Fields§
§id: u64
§max_buy: u64
maximum amount of native tokens to buy or sell
max_sell: u64
§bought: u64
how many native tokens were already bought/sold
sold: u64
§expiry_timestamp: u64
timestamp until which the conditional swap is valid
price_lower_limit: f64
The lower or starting price:
- For FixedPremium or PremiumAuctions, it’s the lower end of the price range: the tcs can only be triggered if the oracle price exceeds this value.
- For LinearAuctions it’s the starting price that’s offered at start_timestamp.
The price is always in “sell_token per buy_token” units, which can be computed by dividing the buy token price by the sell token price.
For FixedPremium or PremiumAuctions:
The price must exceed this threshold to allow execution.
This threshold is compared to the “sell_token per buy_token” oracle price. If that price is >= lower_limit and <= upper_limit the tcs may be executable.
Example: Stop loss to get out of a SOL long: The user bought SOL at 20 USDC/SOL and wants to stop loss at 18 USDC/SOL. They’d set buy_token=USDC, sell_token=SOL so the reference price is in SOL/USDC units. Set price_lower_limit=toNative(1/18) and price_upper_limit=toNative(1/10). Also set allow_borrows=false.
Example: Want to buy SOL with USDC if the price falls below 22 USDC/SOL. buy_token=SOL, sell_token=USDC, reference price is in USDC/SOL units. Set price_upper_limit=toNative(22), price_lower_limit=0.
price_upper_limit: f64
Parallel to price_lower_limit, but an upper limit / auction end price.
The premium to pay over oracle price to incentivize execution.
taker_fee_rate: f32
The taker receives only premium_price * (1 - taker_fee_rate)
maker_fee_rate: f32
The maker has to pay premium_price * (1 + maker_fee_rate)
buy_token_index: TokenIndex
indexes of tokens for the swap
sell_token_index: TokenIndex
§is_configured: u8
If this struct is in use. (tcs are stored in a static-length array)
allow_creating_deposits: u8
may token purchases create deposits? (often users just want to get out of a borrow)
allow_creating_borrows: u8
may token selling create borrows? (often users just want to get out of a long)
display_price_style: u8
The stored prices are always “sell token per buy token”, but if the user used “buy token per sell token” when creating the tcs order, we should continue to show them prices in that way.
Stores a TokenConditionalSwapDisplayPriceStyle enum value
intention: u8
The intention the user had when placing this order, display-only
Stores a TokenConditionalSwapIntention enum value
tcs_type: u8
Stores a TokenConditionalSwapType enum value
padding: [u8; 6]
§start_timestamp: u64
In seconds since epoch. 0 means not-started.
FixedPremium: Time of first trigger call. No other effect. PremiumAuction: Time of start or first trigger call. Can continue to trigger once started. LinearAuction: Set during creation, auction starts with price_lower_limit at this timestamp.
duration_seconds: u64
Duration of the auction mechanism
FixedPremium: ignored PremiumAuction: time after start that the premium needs to scale to price_premium_rate LinearAuction: time after start to go from price_lower_limit to price_upper_limit
reserved: [u8; 88]
Implementations§
source§impl TokenConditionalSwap
impl TokenConditionalSwap
sourcepub fn is_configured(&self) -> bool
pub fn is_configured(&self) -> bool
Whether the entry is in use
Note that it’s possible for an entry to be configured but expired. Or to be configured but not started yet.
pub fn set_is_configured(&mut self, is_configured: bool)
pub fn tcs_type(&self) -> TokenConditionalSwapType
pub fn is_expired(&self, now_ts: u64) -> bool
pub fn passed_start(&self, now_ts: u64) -> bool
sourcepub fn is_startable_type(&self) -> bool
pub fn is_startable_type(&self) -> bool
Does this tcs type support an explicit tcs_start instruction call?
pub fn allow_creating_deposits(&self) -> bool
pub fn allow_creating_borrows(&self) -> bool
pub fn remaining_buy(&self) -> u64
pub fn remaining_sell(&self) -> u64
Base price adjusted for the premium
Base price is the amount of sell_token to pay for one buy_token.
sourcepub fn maker_price(&self, premium_price: f64) -> f64
pub fn maker_price(&self, premium_price: f64) -> f64
Premium price adjusted for the maker fee
sourcepub fn taker_price(&self, premium_price: f64) -> f64
pub fn taker_price(&self, premium_price: f64) -> f64
Premium price adjusted for the taker fee
pub fn maker_fee(&self, base_sell_amount: I80F48) -> u64
pub fn taker_fee(&self, base_sell_amount: I80F48) -> u64
sourcepub fn check_startable(&self, price: f64, now_ts: u64) -> Result<()>
pub fn check_startable(&self, price: f64, now_ts: u64) -> Result<()>
Do the current conditions and tcs type allow starting?
pub fn is_startable(&self, price: f64, now_ts: u64) -> bool
pub fn check_triggerable(&self, price: f64, now_ts: u64) -> Result<()>
pub fn is_triggerable(&self, price: f64, now_ts: u64) -> bool
sourcepub fn max_buy_for_position(&self, buy_position: I80F48, buy_bank: &Bank) -> u64
pub fn max_buy_for_position(&self, buy_position: I80F48, buy_bank: &Bank) -> u64
The remaining buy amount, taking the current buy token position and buy bank’s reduce-only status into account.
Note that the account health might further restrict execution.
sourcepub fn max_sell_for_position(
&self,
sell_position: I80F48,
sell_bank: &Bank
) -> u64
pub fn max_sell_for_position( &self, sell_position: I80F48, sell_bank: &Bank ) -> u64
The remaining sell amount, taking the current sell token position and sell bank’s reduce-only status into account.
Note that the account health might further restrict execution.
Trait Implementations§
source§impl BorshDeserialize for TokenConditionalSwapwhere
u64: BorshDeserialize,
f64: BorshDeserialize,
f32: BorshDeserialize,
TokenIndex: BorshDeserialize,
u8: BorshDeserialize,
[u8; 6]: BorshDeserialize,
[u8; 88]: BorshDeserialize,
impl BorshDeserialize for TokenConditionalSwapwhere u64: BorshDeserialize, f64: BorshDeserialize, f32: BorshDeserialize, TokenIndex: BorshDeserialize, u8: BorshDeserialize, [u8; 6]: BorshDeserialize, [u8; 88]: BorshDeserialize,
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where R: Read,
source§impl BorshSerialize for TokenConditionalSwapwhere
u64: BorshSerialize,
f64: BorshSerialize,
f32: BorshSerialize,
TokenIndex: BorshSerialize,
u8: BorshSerialize,
[u8; 6]: BorshSerialize,
[u8; 88]: BorshSerialize,
impl BorshSerialize for TokenConditionalSwapwhere u64: BorshSerialize, f64: BorshSerialize, f32: BorshSerialize, TokenIndex: BorshSerialize, u8: BorshSerialize, [u8; 6]: BorshSerialize, [u8; 88]: BorshSerialize,
source§impl Clone for TokenConditionalSwap
impl Clone for TokenConditionalSwap
source§fn clone(&self) -> TokenConditionalSwap
fn clone(&self) -> TokenConditionalSwap
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TokenConditionalSwap
impl Debug for TokenConditionalSwap
source§impl Default for TokenConditionalSwap
impl Default for TokenConditionalSwap
source§impl PartialEq<TokenConditionalSwap> for TokenConditionalSwap
impl PartialEq<TokenConditionalSwap> for TokenConditionalSwap
source§fn eq(&self, other: &TokenConditionalSwap) -> bool
fn eq(&self, other: &TokenConditionalSwap) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for TokenConditionalSwap
impl Pod for TokenConditionalSwap
impl StructuralPartialEq for TokenConditionalSwap
Auto Trait Implementations§
impl RefUnwindSafe for TokenConditionalSwap
impl Send for TokenConditionalSwap
impl Sync for TokenConditionalSwap
impl Unpin for TokenConditionalSwap
impl UnwindSafe for TokenConditionalSwap
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,
§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.