defituna_client/generated/accounts/
tuna_config.rs1use 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],
17pub version: u16,
19pub bump: u8,
21#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
23pub admin_authority: Pubkey,
24#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
26pub fee_recipient: Pubkey,
27#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
29pub owner_authority: Pubkey,
30pub max_swap_slippage: u32,
32pub max_percentage_of_leftovers: u32,
34pub suspend_lending_deposits: bool,
36pub suspend_lending_withdrawals: bool,
38pub suspend_add_liquidity: bool,
40pub suspend_remove_liquidity: bool,
42#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
44pub liquidator_authority: Pubkey,
45pub oracle_price_deviation_threshold: u32,
47pub default_protocol_fee_rate: u16,
49pub default_liquidation_fee_rate: u32,
51pub default_rebalance_fee_rate: u32,
53#[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