Struct TunaPosition

Source
pub struct TunaPosition {
Show 27 fields pub discriminator: [u8; 8], pub version: u16, pub bump: [u8; 1], pub authority: Pubkey, pub pool: Pubkey, pub mint_a: Pubkey, pub mint_b: Pubkey, pub position_mint: Pubkey, pub liquidity: u128, pub tick_lower_index: i32, pub tick_upper_index: i32, pub loan_shares_a: u64, pub loan_shares_b: u64, pub loan_funds_a: u64, pub loan_funds_b: u64, pub leftovers_a: u64, pub leftovers_b: u64, pub tick_entry_index: i32, pub tick_stop_loss_index: i32, pub tick_take_profit_index: i32, pub state: TunaPositionState, pub swap_to_token_on_limit_order: u8, pub compounded_yield_a: u64, pub compounded_yield_b: u64, pub flags: u32, pub market_maker: MarketMaker, pub reserved: [u8; 61],
}

Fields§

§discriminator: [u8; 8]§version: u16

Struct version

§bump: [u8; 1]

Bump seed for the tuna position account

§authority: Pubkey

The authority address used for managing the position

§pool: Pubkey

Liquidity pool address this position belongs to

§mint_a: Pubkey

The mint address for token A

§mint_b: Pubkey

The mint address for token B

§position_mint: Pubkey

The mint address for the position token (minted and used in Orca/Fusion)

§liquidity: u128

Total minted liquidity

§tick_lower_index: i32

Position lower tick

§tick_upper_index: i32

Position upper tick

§loan_shares_a: u64

The amount of shares borrowed by user from vault A.

§loan_shares_b: u64

The amount of shares borrowed by user from vault B.

§loan_funds_a: u64

The amount of funds borrowed by user from vault A. Doesn’t include accrued interest.

§loan_funds_b: u64

The amount of funds borrowed by user from vault B. Doesn’t include accrued interest.

§leftovers_a: u64

The leftovers are funds that couldn’t be added to a pool as liquidity. They remain in the position token account.

§leftovers_b: u64

The leftovers are funds that couldn’t be added to a pool as liquidity. They remain in the position token account.

§tick_entry_index: i32

Position entry tick index.

§tick_stop_loss_index: i32

Position stop loss tick index.

§tick_take_profit_index: i32

Position stop loss tick index.

§state: TunaPositionState

Position state: normal, liquidated, closed by limit order

§swap_to_token_on_limit_order: u8

OBSOLETE: Which token to swap collateral to when a limit order is executed. Used for position ver 4 or older. bits 0..1: Stop loss swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B bits 2..3: Take profit swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B

§compounded_yield_a: u64

Yield amount in token A that has already been collected and compounded into the position.

§compounded_yield_b: u64

Yield amount in token B that has already been collected and compounded into the position.

§flags: u32

Position options. Bits 0..1: Stop loss swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B Bits 2..3: Take profit swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B Bits 4..5: Yield auto compounding. 0 - don’t compound, 1 - compound yield, 2 - compound yield with leverage

§market_maker: MarketMaker

Market maker (Orca, Fusion)

§reserved: [u8; 61]

Reserved

Implementations§

Source§

impl TunaPosition

Source

pub fn get_total_balance( &self, sqrt_price: u128, ) -> Result<(u64, u64), ErrorCode>

Returns the total position balance.

Source

pub fn compute_total_and_debt( &self, sqrt_price: u128, vault_a: &Vault, vault_b: &Vault, ) -> Result<(u64, u64), ErrorCode>

Returns the current position total and debt size.

Source

pub fn is_healthy( &self, sqrt_price: u128, market: &Market, vault_a: &Vault, vault_b: &Vault, ) -> Result<(bool, u32), ErrorCode>

Returns if the position is healthy or not. Vaults must be passed with accrued interest.

Source

pub fn is_liquidated(&self) -> bool

Source

pub fn is_limit_order_reached(&self, sqrt_price: u128) -> bool

Source

pub fn compute_leverage( &self, sqrt_price: u128, vault_a: &Vault, vault_b: &Vault, ) -> Result<Fixed128, ErrorCode>

Returns the current leverage of a position. Vaults must be passed with accrued interest.

Source

pub fn get_pool_key(&self) -> String

Source§

impl TunaPosition

Source

pub const LEN: usize = 339usize

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, Error>

Trait Implementations§

Source§

impl BorshDeserialize for TunaPosition

Source§

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

Source§

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.
Source§

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

Deserialize this instance from a slice of bytes.
Source§

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

Source§

impl BorshSerialize for TunaPosition

Source§

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

Source§

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

Serialize this instance into a vector of bytes.
Source§

impl Clone for TunaPosition

Source§

fn clone(&self) -> TunaPosition

Returns a duplicate 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 TunaPosition

Source§

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

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

impl Display for TunaPosition

Source§

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

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

impl PartialEq for TunaPosition

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&AccountInfo<'a>> for TunaPosition

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(account_info: &AccountInfo<'a>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for TunaPosition

Source§

impl StructuralPartialEq for TunaPosition

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

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

Source§

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

Source§

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) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where 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.
Source§

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

Source§

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

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

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 T
where U: From<T>,

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where 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 Dst
where Src: OverflowingCast<Dst>,

Source§

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

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

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

Casts the value.
Source§

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

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
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) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

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

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

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) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

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

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ErasedDestructor for T
where T: 'static,