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/// Reserved
80#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
81pub reserved: [u8; 61],
82}
83
84
85impl TunaPosition {
86      pub const LEN: usize = 339;
87  
88  
89  
90  #[inline(always)]
91  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
92    let mut data = data;
93    Self::deserialize(&mut data)
94  }
95}
96
97impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for TunaPosition {
98  type Error = std::io::Error;
99
100  fn try_from(account_info: &solana_program::account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
101      let mut data: &[u8] = &(*account_info.data).borrow();
102      Self::deserialize(&mut data)
103  }
104}
105
106#[cfg(feature = "fetch")]
107pub fn fetch_tuna_position(
108  rpc: &solana_client::rpc_client::RpcClient,
109  address: &solana_program::pubkey::Pubkey,
110) -> Result<crate::shared::DecodedAccount<TunaPosition>, std::io::Error> {
111  let accounts = fetch_all_tuna_position(rpc, &[*address])?;
112  Ok(accounts[0].clone())
113}
114
115#[cfg(feature = "fetch")]
116pub fn fetch_all_tuna_position(
117  rpc: &solana_client::rpc_client::RpcClient,
118  addresses: &[solana_program::pubkey::Pubkey],
119) -> Result<Vec<crate::shared::DecodedAccount<TunaPosition>>, std::io::Error> {
120    let accounts = rpc.get_multiple_accounts(addresses)
121      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
122    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<TunaPosition>> = Vec::new();
123    for i in 0..addresses.len() {
124      let address = addresses[i];
125      let account = accounts[i].as_ref()
126        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
127      let data = TunaPosition::from_bytes(&account.data)?;
128      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
129    }
130    Ok(decoded_accounts)
131}
132
133#[cfg(feature = "fetch")]
134pub fn fetch_maybe_tuna_position(
135  rpc: &solana_client::rpc_client::RpcClient,
136  address: &solana_program::pubkey::Pubkey,
137) -> Result<crate::shared::MaybeAccount<TunaPosition>, std::io::Error> {
138    let accounts = fetch_all_maybe_tuna_position(rpc, &[*address])?;
139    Ok(accounts[0].clone())
140}
141
142#[cfg(feature = "fetch")]
143pub fn fetch_all_maybe_tuna_position(
144  rpc: &solana_client::rpc_client::RpcClient,
145  addresses: &[solana_program::pubkey::Pubkey],
146) -> Result<Vec<crate::shared::MaybeAccount<TunaPosition>>, std::io::Error> {
147    let accounts = rpc.get_multiple_accounts(addresses)
148      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
149    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<TunaPosition>> = Vec::new();
150    for i in 0..addresses.len() {
151      let address = addresses[i];
152      if let Some(account) = accounts[i].as_ref() {
153        let data = TunaPosition::from_bytes(&account.data)?;
154        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
155      } else {
156        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
157      }
158    }
159  Ok(decoded_accounts)
160}
161
162  #[cfg(feature = "anchor")]
163  impl anchor_lang::AccountDeserialize for TunaPosition {
164      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
165        Ok(Self::deserialize(buf)?)
166      }
167  }
168
169  #[cfg(feature = "anchor")]
170  impl anchor_lang::AccountSerialize for TunaPosition {}
171
172  #[cfg(feature = "anchor")]
173  impl anchor_lang::Owner for TunaPosition {
174      fn owner() -> Pubkey {
175        crate::TUNA_ID
176      }
177  }
178
179  #[cfg(feature = "anchor-idl-build")]
180  impl anchor_lang::IdlBuild for TunaPosition {}
181
182  
183  #[cfg(feature = "anchor-idl-build")]
184  impl anchor_lang::Discriminator for TunaPosition {
185    const DISCRIMINATOR: [u8; 8] = [0; 8];
186  }
187