#[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.

§price_premium_rate: f64

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

source

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.

source

pub fn set_is_configured(&mut self, is_configured: bool)

source

pub fn tcs_type(&self) -> TokenConditionalSwapType

source

pub fn is_expired(&self, now_ts: u64) -> bool

source

pub fn passed_start(&self, now_ts: u64) -> bool

source

pub fn is_startable_type(&self) -> bool

Does this tcs type support an explicit tcs_start instruction call?

source

pub fn allow_creating_deposits(&self) -> bool

source

pub fn allow_creating_borrows(&self) -> bool

source

pub fn remaining_buy(&self) -> u64

source

pub fn remaining_sell(&self) -> u64

source

pub fn premium_price(&self, base_price: f64, now_ts: u64) -> f64

Base price adjusted for the premium

Base price is the amount of sell_token to pay for one buy_token.

source

pub fn maker_price(&self, premium_price: f64) -> f64

Premium price adjusted for the maker fee

source

pub fn taker_price(&self, premium_price: f64) -> f64

Premium price adjusted for the taker fee

source

pub fn maker_fee(&self, base_sell_amount: I80F48) -> u64

source

pub fn taker_fee(&self, base_sell_amount: I80F48) -> u64

source

pub fn check_startable(&self, price: f64, now_ts: u64) -> Result<()>

Do the current conditions and tcs type allow starting?

source

pub fn is_startable(&self, price: f64, now_ts: u64) -> bool

source

pub fn check_triggerable(&self, price: f64, now_ts: u64) -> Result<()>

source

pub fn is_triggerable(&self, price: f64, now_ts: u64) -> bool

source

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.

source

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,

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
§

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,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

§

fn try_to_vec(&self) -> Result<Vec<u8, Global>, Error>

Serialize this instance into a vector of bytes.
source§

impl Clone for TokenConditionalSwap

source§

fn clone(&self) -> TokenConditionalSwap

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TokenConditionalSwap

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TokenConditionalSwap

source§

fn default() -> Self

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

impl PartialEq<TokenConditionalSwap> for TokenConditionalSwap

source§

fn eq(&self, other: &TokenConditionalSwap) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Zeroable for TokenConditionalSwap

§

fn zeroed() -> Self

source§

impl Copy for TokenConditionalSwap

source§

impl Pod for TokenConditionalSwap

source§

impl StructuralPartialEq for TokenConditionalSwap

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
§

impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,

§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> AnyBitPattern for Twhere T: Pod,

§

impl<T> NoUninit for Twhere T: Pod,