defituna_client/generated/accounts/
tuna_position.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use solana_program::pubkey::Pubkey;
9use crate::generated::types::TunaPositionState;
10use crate::generated::types::MarketMaker;
11use borsh::BorshSerialize;
12use borsh::BorshDeserialize;
13
14
15#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct TunaPosition {
18pub discriminator: [u8; 8],
19/// Struct version
20pub version: u16,
21/// Bump seed for the tuna position account
22pub bump: [u8; 1],
23/// The authority address used for managing the position
24#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
25pub authority: Pubkey,
26/// Liquidity pool address this position belongs to
27#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
28pub pool: Pubkey,
29/// The mint address for token A
30#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
31pub mint_a: Pubkey,
32/// The mint address for token B
33#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
34pub mint_b: Pubkey,
35/// The mint address for the position token (minted and used in Orca/Fusion)
36#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
37pub position_mint: Pubkey,
38/// Total minted liquidity
39pub liquidity: u128,
40/// Position lower tick
41pub tick_lower_index: i32,
42/// Position upper tick
43pub tick_upper_index: i32,
44/// The amount of shares borrowed by user from vault A.
45pub loan_shares_a: u64,
46/// The amount of shares borrowed by user from vault B.
47pub loan_shares_b: u64,
48/// The amount of funds borrowed by user from vault A. Doesn't include accrued interest.
49pub loan_funds_a: u64,
50/// The amount of funds borrowed by user from vault B. Doesn't include accrued interest.
51pub loan_funds_b: u64,
52/// The leftovers are funds that couldn't be added to a pool as liquidity. They remain in the position token account.
53pub leftovers_a: u64,
54/// The leftovers are funds that couldn't be added to a pool as liquidity. They remain in the position token account.
55pub leftovers_b: u64,
56/// Position entry tick index.
57pub tick_entry_index: i32,
58/// Position stop loss tick index.
59pub tick_stop_loss_index: i32,
60/// Position stop loss tick index.
61pub tick_take_profit_index: i32,
62/// Position state: normal, liquidated, closed by limit order
63pub state: TunaPositionState,
64/// OBSOLETE: Which token to swap collateral to when a limit order is executed. Used for position ver 4 or older.
65/// bits 0..1: Stop loss swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B
66/// bits 2..3: Take profit swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B
67pub swap_to_token_on_limit_order: u8,
68/// Yield amount in token A that has already been collected and compounded into the position.
69pub compounded_yield_a: u64,
70/// Yield amount in token B that has already been collected and compounded into the position.
71pub compounded_yield_b: u64,
72/// Position options.
73/// Bits 0..1: Stop loss swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B
74/// Bits 2..3: Take profit swap. 0 - no swap, 1 - swap to token A, 2 - swap to token B
75/// Bits 4..5: Yield auto compounding. 0 - don't compound, 1 - compound yield, 2 - compound yield with leverage
76pub flags: u32,
77/// Market maker (Orca, Fusion)
78pub market_maker: MarketMaker,
79/// The position might be re-balanced if the current tick is lower than tick_lower_index or
80/// higher than tick_higher_index by a threshold value.
81pub rebalance_threshold_ticks: u32,
82/// Reserved
83#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
84pub reserved: [u8; 57],
85}
86
87
88impl TunaPosition {
89      pub const LEN: usize = 339;
90  
91  
92  
93  #[inline(always)]
94  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
95    let mut data = data;
96    Self::deserialize(&mut data)
97  }
98}
99
100impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for TunaPosition {
101  type Error = std::io::Error;
102
103  fn try_from(account_info: &solana_program::account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
104      let mut data: &[u8] = &(*account_info.data).borrow();
105      Self::deserialize(&mut data)
106  }
107}
108
109#[cfg(feature = "fetch")]
110pub fn fetch_tuna_position(
111  rpc: &solana_client::rpc_client::RpcClient,
112  address: &solana_program::pubkey::Pubkey,
113) -> Result<crate::shared::DecodedAccount<TunaPosition>, std::io::Error> {
114  let accounts = fetch_all_tuna_position(rpc, &[*address])?;
115  Ok(accounts[0].clone())
116}
117
118#[cfg(feature = "fetch")]
119pub fn fetch_all_tuna_position(
120  rpc: &solana_client::rpc_client::RpcClient,
121  addresses: &[solana_program::pubkey::Pubkey],
122) -> Result<Vec<crate::shared::DecodedAccount<TunaPosition>>, std::io::Error> {
123    let accounts = rpc.get_multiple_accounts(addresses)
124      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
125    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<TunaPosition>> = Vec::new();
126    for i in 0..addresses.len() {
127      let address = addresses[i];
128      let account = accounts[i].as_ref()
129        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
130      let data = TunaPosition::from_bytes(&account.data)?;
131      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
132    }
133    Ok(decoded_accounts)
134}
135
136#[cfg(feature = "fetch")]
137pub fn fetch_maybe_tuna_position(
138  rpc: &solana_client::rpc_client::RpcClient,
139  address: &solana_program::pubkey::Pubkey,
140) -> Result<crate::shared::MaybeAccount<TunaPosition>, std::io::Error> {
141    let accounts = fetch_all_maybe_tuna_position(rpc, &[*address])?;
142    Ok(accounts[0].clone())
143}
144
145#[cfg(feature = "fetch")]
146pub fn fetch_all_maybe_tuna_position(
147  rpc: &solana_client::rpc_client::RpcClient,
148  addresses: &[solana_program::pubkey::Pubkey],
149) -> Result<Vec<crate::shared::MaybeAccount<TunaPosition>>, std::io::Error> {
150    let accounts = rpc.get_multiple_accounts(addresses)
151      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
152    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<TunaPosition>> = Vec::new();
153    for i in 0..addresses.len() {
154      let address = addresses[i];
155      if let Some(account) = accounts[i].as_ref() {
156        let data = TunaPosition::from_bytes(&account.data)?;
157        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
158      } else {
159        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
160      }
161    }
162  Ok(decoded_accounts)
163}
164
165  #[cfg(feature = "anchor")]
166  impl anchor_lang::AccountDeserialize for TunaPosition {
167      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
168        Ok(Self::deserialize(buf)?)
169      }
170  }
171
172  #[cfg(feature = "anchor")]
173  impl anchor_lang::AccountSerialize for TunaPosition {}
174
175  #[cfg(feature = "anchor")]
176  impl anchor_lang::Owner for TunaPosition {
177      fn owner() -> Pubkey {
178        crate::TUNA_ID
179      }
180  }
181
182  #[cfg(feature = "anchor-idl-build")]
183  impl anchor_lang::IdlBuild for TunaPosition {}
184
185  
186  #[cfg(feature = "anchor-idl-build")]
187  impl anchor_lang::Discriminator for TunaPosition {
188    const DISCRIMINATOR: [u8; 8] = [0; 8];
189  }
190