defituna_client/generated/accounts/
tuna_config.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 borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct TunaConfig {
16pub discriminator: [u8; 8],
17/// Struct version.
18pub version: u16,
19/// Bump seed for the vaults config account.
20pub bump: u8,
21/// Current update authority address for both the tunaConfig and the Vault PDAs themselves - can be updated.
22#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
23pub admin_authority: Pubkey,
24/// Fee recipient address.
25#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
26pub fee_recipient: Pubkey,
27/// Owner of the program. Can change ownership and set the admin of the program.
28#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
29pub owner_authority: Pubkey,
30/// Maximum allowed swap slippage percentage.
31pub max_swap_slippage: u32,
32/// Maximum allowed percentage of leftovers.
33pub max_percentage_of_leftovers: u32,
34/// Suspends lending deposits in case of emergency.
35pub suspend_lending_deposits: bool,
36/// Suspends lending withdrawals in case of emergency.
37pub suspend_lending_withdrawals: bool,
38/// Suspends adding liquidity to positions in case of emergency.
39pub suspend_add_liquidity: bool,
40/// Suspends removing liquidity, claiming fees and closing positions in case of emergency.
41pub suspend_remove_liquidity: bool,
42/// Liquidation bot wallet.
43#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
44pub liquidator_authority: Pubkey,
45/// Maximum allowed oracle price deviation in percent.
46pub oracle_price_deviation_threshold: u32,
47/// Reserved
48#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
49pub reserved: [u8; 176],
50}
51
52
53impl TunaConfig {
54      pub const LEN: usize = 331;
55  
56  
57  
58  #[inline(always)]
59  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
60    let mut data = data;
61    Self::deserialize(&mut data)
62  }
63}
64
65impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for TunaConfig {
66  type Error = std::io::Error;
67
68  fn try_from(account_info: &solana_program::account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
69      let mut data: &[u8] = &(*account_info.data).borrow();
70      Self::deserialize(&mut data)
71  }
72}
73
74#[cfg(feature = "fetch")]
75pub fn fetch_tuna_config(
76  rpc: &solana_client::rpc_client::RpcClient,
77  address: &solana_program::pubkey::Pubkey,
78) -> Result<crate::shared::DecodedAccount<TunaConfig>, std::io::Error> {
79  let accounts = fetch_all_tuna_config(rpc, &[*address])?;
80  Ok(accounts[0].clone())
81}
82
83#[cfg(feature = "fetch")]
84pub fn fetch_all_tuna_config(
85  rpc: &solana_client::rpc_client::RpcClient,
86  addresses: &[solana_program::pubkey::Pubkey],
87) -> Result<Vec<crate::shared::DecodedAccount<TunaConfig>>, std::io::Error> {
88    let accounts = rpc.get_multiple_accounts(addresses)
89      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
90    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<TunaConfig>> = Vec::new();
91    for i in 0..addresses.len() {
92      let address = addresses[i];
93      let account = accounts[i].as_ref()
94        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
95      let data = TunaConfig::from_bytes(&account.data)?;
96      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
97    }
98    Ok(decoded_accounts)
99}
100
101#[cfg(feature = "fetch")]
102pub fn fetch_maybe_tuna_config(
103  rpc: &solana_client::rpc_client::RpcClient,
104  address: &solana_program::pubkey::Pubkey,
105) -> Result<crate::shared::MaybeAccount<TunaConfig>, std::io::Error> {
106    let accounts = fetch_all_maybe_tuna_config(rpc, &[*address])?;
107    Ok(accounts[0].clone())
108}
109
110#[cfg(feature = "fetch")]
111pub fn fetch_all_maybe_tuna_config(
112  rpc: &solana_client::rpc_client::RpcClient,
113  addresses: &[solana_program::pubkey::Pubkey],
114) -> Result<Vec<crate::shared::MaybeAccount<TunaConfig>>, std::io::Error> {
115    let accounts = rpc.get_multiple_accounts(addresses)
116      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
117    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<TunaConfig>> = Vec::new();
118    for i in 0..addresses.len() {
119      let address = addresses[i];
120      if let Some(account) = accounts[i].as_ref() {
121        let data = TunaConfig::from_bytes(&account.data)?;
122        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
123      } else {
124        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
125      }
126    }
127  Ok(decoded_accounts)
128}
129
130  #[cfg(feature = "anchor")]
131  impl anchor_lang::AccountDeserialize for TunaConfig {
132      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
133        Ok(Self::deserialize(buf)?)
134      }
135  }
136
137  #[cfg(feature = "anchor")]
138  impl anchor_lang::AccountSerialize for TunaConfig {}
139
140  #[cfg(feature = "anchor")]
141  impl anchor_lang::Owner for TunaConfig {
142      fn owner() -> Pubkey {
143        crate::TUNA_ID
144      }
145  }
146
147  #[cfg(feature = "anchor-idl-build")]
148  impl anchor_lang::IdlBuild for TunaConfig {}
149
150  
151  #[cfg(feature = "anchor-idl-build")]
152  impl anchor_lang::Discriminator for TunaConfig {
153    const DISCRIMINATOR: [u8; 8] = [0; 8];
154  }
155