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_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/// The default protocol fee rate.
48pub default_protocol_fee_rate: u16,
49/// The default liquidation fee rate.
50pub default_liquidation_fee_rate: u32,
51/// The default rebalance fee rate.
52pub default_rebalance_fee_rate: u32,
53/// Reserved
54#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
55pub reserved: [u8; 166],
56}
57
58
59pub const TUNA_CONFIG_DISCRIMINATOR: [u8; 8] = [124, 149, 24, 7, 195, 168, 153, 58];
60
61impl TunaConfig {
62      pub const LEN: usize = 331;
63  
64  
65  
66  #[inline(always)]
67  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
68    let mut data = data;
69    Self::deserialize(&mut data)
70  }
71}
72
73impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for TunaConfig {
74  type Error = std::io::Error;
75
76  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
77      let mut data: &[u8] = &(*account_info.data).borrow();
78      Self::deserialize(&mut data)
79  }
80}
81
82#[cfg(feature = "fetch")]
83pub fn fetch_tuna_config(
84  rpc: &solana_client::rpc_client::RpcClient,
85  address: &solana_pubkey::Pubkey,
86) -> Result<crate::shared::DecodedAccount<TunaConfig>, std::io::Error> {
87  let accounts = fetch_all_tuna_config(rpc, &[*address])?;
88  Ok(accounts[0].clone())
89}
90
91#[cfg(feature = "fetch")]
92pub fn fetch_all_tuna_config(
93  rpc: &solana_client::rpc_client::RpcClient,
94  addresses: &[solana_pubkey::Pubkey],
95) -> Result<Vec<crate::shared::DecodedAccount<TunaConfig>>, std::io::Error> {
96    let accounts = rpc.get_multiple_accounts(addresses)
97      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
98    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<TunaConfig>> = Vec::new();
99    for i in 0..addresses.len() {
100      let address = addresses[i];
101      let account = accounts[i].as_ref()
102        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
103      let data = TunaConfig::from_bytes(&account.data)?;
104      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
105    }
106    Ok(decoded_accounts)
107}
108
109#[cfg(feature = "fetch")]
110pub fn fetch_maybe_tuna_config(
111  rpc: &solana_client::rpc_client::RpcClient,
112  address: &solana_pubkey::Pubkey,
113) -> Result<crate::shared::MaybeAccount<TunaConfig>, std::io::Error> {
114    let accounts = fetch_all_maybe_tuna_config(rpc, &[*address])?;
115    Ok(accounts[0].clone())
116}
117
118#[cfg(feature = "fetch")]
119pub fn fetch_all_maybe_tuna_config(
120  rpc: &solana_client::rpc_client::RpcClient,
121  addresses: &[solana_pubkey::Pubkey],
122) -> Result<Vec<crate::shared::MaybeAccount<TunaConfig>>, 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::MaybeAccount<TunaConfig>> = Vec::new();
126    for i in 0..addresses.len() {
127      let address = addresses[i];
128      if let Some(account) = accounts[i].as_ref() {
129        let data = TunaConfig::from_bytes(&account.data)?;
130        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
131      } else {
132        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
133      }
134    }
135  Ok(decoded_accounts)
136}
137
138  #[cfg(feature = "anchor")]
139  impl anchor_lang::AccountDeserialize for TunaConfig {
140      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
141        Ok(Self::deserialize(buf)?)
142      }
143  }
144
145  #[cfg(feature = "anchor")]
146  impl anchor_lang::AccountSerialize for TunaConfig {}
147
148  #[cfg(feature = "anchor")]
149  impl anchor_lang::Owner for TunaConfig {
150      fn owner() -> Pubkey {
151        crate::TUNA_ID
152      }
153  }
154
155  #[cfg(feature = "anchor-idl-build")]
156  impl anchor_lang::IdlBuild for TunaConfig {}
157
158  
159  #[cfg(feature = "anchor-idl-build")]
160  impl anchor_lang::Discriminator for TunaConfig {
161    const DISCRIMINATOR: &[u8] = &[0; 8];
162  }
163