defituna_client/generated/accounts/
market.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 crate::generated::types::MarketMaker;
9use solana_program::pubkey::Pubkey;
10use borsh::BorshSerialize;
11use borsh::BorshDeserialize;
12
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct Market {
17pub discriminator: [u8; 8],
18/// Struct version
19pub version: u16,
20/// Bump seed for the market account
21pub bump: [u8; 1],
22/// Market maker: Orca, Fusion, Raydium, etc...
23pub market_maker: MarketMaker,
24/// Liquidity pool address
25#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
26pub pool: Pubkey,
27/// Address Lookup Table address for this market
28#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
29pub address_lookup_table: Pubkey,
30/// Maximum allowed leverage for this market
31pub max_leverage: u32,
32/// Protocol fee denominated in hundredths of a bip. (Value of 100 is equal to 0.01%)
33pub protocol_fee: u16,
34/// Protocol fee on collateral (funds provided by a user) denominated in hundredths of a bip. (Value of 100 is equal to 0.01%)
35pub protocol_fee_on_collateral: u16,
36/// Liquidation fee denominated in hundredths of a bip. (Value of 100 is equal to 0.01%)
37pub liquidation_fee: u32,
38/// Liquidation threshold. The position is treated as unhealthy if debt > balance * (liquidation_threshold / HUNDRED_PERCENT).
39pub liquidation_threshold: u32,
40/// Limit order execution fee denominated in hundredths of a bip. (Value of 100 is equal to 0.01%)
41pub limit_order_execution_fee: u32,
42/// Oracle price deviation threshold in percent. If it's set to zero, the default value from the global config is used.
43pub oracle_price_deviation_threshold: u32,
44/// True if the market is disabled (no more position can be opened).
45pub disabled: bool,
46/// Total borrowed shares of token A.
47pub borrowed_shares_a: u64,
48/// Total borrowed shares of token B.
49pub borrowed_shares_b: u64,
50/// Total borrow limit for this market in token A.
51pub borrow_limit_a: u64,
52/// Total borrow limit for this market in token B.
53pub borrow_limit_b: u64,
54/// Maximum allowed swap slippage percentage. If it's set to zero, the default value from the global config is used.
55pub max_swap_slippage: u32,
56/// Reserved
57#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
58pub reserved: [u8; 211],
59}
60
61
62impl Market {
63      pub const LEN: usize = 348;
64  
65  
66  
67  #[inline(always)]
68  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
69    let mut data = data;
70    Self::deserialize(&mut data)
71  }
72}
73
74impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Market {
75  type Error = std::io::Error;
76
77  fn try_from(account_info: &solana_program::account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
78      let mut data: &[u8] = &(*account_info.data).borrow();
79      Self::deserialize(&mut data)
80  }
81}
82
83#[cfg(feature = "fetch")]
84pub fn fetch_market(
85  rpc: &solana_client::rpc_client::RpcClient,
86  address: &solana_program::pubkey::Pubkey,
87) -> Result<crate::shared::DecodedAccount<Market>, std::io::Error> {
88  let accounts = fetch_all_market(rpc, &[*address])?;
89  Ok(accounts[0].clone())
90}
91
92#[cfg(feature = "fetch")]
93pub fn fetch_all_market(
94  rpc: &solana_client::rpc_client::RpcClient,
95  addresses: &[solana_program::pubkey::Pubkey],
96) -> Result<Vec<crate::shared::DecodedAccount<Market>>, std::io::Error> {
97    let accounts = rpc.get_multiple_accounts(addresses)
98      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
99    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Market>> = Vec::new();
100    for i in 0..addresses.len() {
101      let address = addresses[i];
102      let account = accounts[i].as_ref()
103        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
104      let data = Market::from_bytes(&account.data)?;
105      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
106    }
107    Ok(decoded_accounts)
108}
109
110#[cfg(feature = "fetch")]
111pub fn fetch_maybe_market(
112  rpc: &solana_client::rpc_client::RpcClient,
113  address: &solana_program::pubkey::Pubkey,
114) -> Result<crate::shared::MaybeAccount<Market>, std::io::Error> {
115    let accounts = fetch_all_maybe_market(rpc, &[*address])?;
116    Ok(accounts[0].clone())
117}
118
119#[cfg(feature = "fetch")]
120pub fn fetch_all_maybe_market(
121  rpc: &solana_client::rpc_client::RpcClient,
122  addresses: &[solana_program::pubkey::Pubkey],
123) -> Result<Vec<crate::shared::MaybeAccount<Market>>, std::io::Error> {
124    let accounts = rpc.get_multiple_accounts(addresses)
125      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
126    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Market>> = Vec::new();
127    for i in 0..addresses.len() {
128      let address = addresses[i];
129      if let Some(account) = accounts[i].as_ref() {
130        let data = Market::from_bytes(&account.data)?;
131        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
132      } else {
133        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
134      }
135    }
136  Ok(decoded_accounts)
137}
138
139  #[cfg(feature = "anchor")]
140  impl anchor_lang::AccountDeserialize for Market {
141      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
142        Ok(Self::deserialize(buf)?)
143      }
144  }
145
146  #[cfg(feature = "anchor")]
147  impl anchor_lang::AccountSerialize for Market {}
148
149  #[cfg(feature = "anchor")]
150  impl anchor_lang::Owner for Market {
151      fn owner() -> Pubkey {
152        crate::TUNA_ID
153      }
154  }
155
156  #[cfg(feature = "anchor-idl-build")]
157  impl anchor_lang::IdlBuild for Market {}
158
159  
160  #[cfg(feature = "anchor-idl-build")]
161  impl anchor_lang::Discriminator for Market {
162    const DISCRIMINATOR: [u8; 8] = [0; 8];
163  }
164