riptide_amm/generated/accounts/
market.rs1use crate::generated::types::AccountDiscriminator;
8use borsh::{BorshDeserialize, BorshSerialize};
9use solana_address::Address;
10
11#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
12pub struct Market {
13 pub discriminator: AccountDiscriminator,
14 pub bump: [u8; 1],
15 pub cu_penalty_multiplier: u8,
16 pub max_inventory_imbalance_guard_per_cent: u8,
17 pub id: u32,
18 pub authority: Address,
19 pub updater: Address,
20 pub mint_a: Address,
21 pub mint_b: Address,
22 pub sequence: u64,
23 pub valid_until: u64,
24 pub oracle: [u8; 512],
25 pub min_spread_guard_per_m: i32,
26 pub arb_penalty_per_m: u32,
27 pub jitodontfront_penalty_per_m: u32,
28 pub padding1: [u8; 12],
29 pub min_oracle_price_guard: u128,
30 pub max_oracle_price_guard: u128,
31 pub padding2: [u8; 304],
32}
33
34pub const MARKET_DISCRIMINATOR: AccountDiscriminator = AccountDiscriminator::Market;
35
36impl Market {
37 pub const LEN: usize = 1024;
38
39 #[inline(always)]
40 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
41 let mut data = data;
42 Self::deserialize(&mut data)
43 }
44}
45
46impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Market {
47 type Error = std::io::Error;
48
49 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
50 let mut data: &[u8] = &(*account_info.data).borrow();
51 Self::deserialize(&mut data)
52 }
53}
54
55#[cfg(feature = "fetch")]
56pub fn fetch_market(
57 rpc: &solana_client::rpc_client::RpcClient,
58 address: &solana_address::Address,
59) -> Result<crate::shared::DecodedAccount<Market>, std::io::Error> {
60 let accounts = fetch_all_market(rpc, &[*address])?;
61 Ok(accounts[0].clone())
62}
63
64#[cfg(feature = "fetch")]
65pub fn fetch_all_market(
66 rpc: &solana_client::rpc_client::RpcClient,
67 addresses: &[solana_address::Address],
68) -> Result<Vec<crate::shared::DecodedAccount<Market>>, std::io::Error> {
69 let accounts = rpc
70 .get_multiple_accounts(addresses)
71 .map_err(|e| std::io::Error::other(e.to_string()))?;
72 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Market>> = Vec::new();
73 for i in 0..addresses.len() {
74 let address = addresses[i];
75 let account = accounts[i].as_ref().ok_or(std::io::Error::other(format!(
76 "Account not found: {address}"
77 )))?;
78 let data = Market::from_bytes(&account.data)?;
79 decoded_accounts.push(crate::shared::DecodedAccount {
80 address,
81 account: account.clone(),
82 data,
83 });
84 }
85 Ok(decoded_accounts)
86}
87
88#[cfg(feature = "fetch")]
89pub fn fetch_maybe_market(
90 rpc: &solana_client::rpc_client::RpcClient,
91 address: &solana_address::Address,
92) -> Result<crate::shared::MaybeAccount<Market>, std::io::Error> {
93 let accounts = fetch_all_maybe_market(rpc, &[*address])?;
94 Ok(accounts[0].clone())
95}
96
97#[cfg(feature = "fetch")]
98pub fn fetch_all_maybe_market(
99 rpc: &solana_client::rpc_client::RpcClient,
100 addresses: &[solana_address::Address],
101) -> Result<Vec<crate::shared::MaybeAccount<Market>>, std::io::Error> {
102 let accounts = rpc
103 .get_multiple_accounts(addresses)
104 .map_err(|e| std::io::Error::other(e.to_string()))?;
105 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Market>> = Vec::new();
106 for i in 0..addresses.len() {
107 let address = addresses[i];
108 if let Some(account) = accounts[i].as_ref() {
109 let data = Market::from_bytes(&account.data)?;
110 decoded_accounts.push(crate::shared::MaybeAccount::Exists(
111 crate::shared::DecodedAccount {
112 address,
113 account: account.clone(),
114 data,
115 },
116 ));
117 } else {
118 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
119 }
120 }
121 Ok(decoded_accounts)
122}
123
124#[cfg(feature = "anchor")]
125impl anchor_lang::AccountDeserialize for Market {
126 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
127 Ok(Self::deserialize(buf)?)
128 }
129}
130
131#[cfg(feature = "anchor")]
132impl anchor_lang::AccountSerialize for Market {}
133
134#[cfg(feature = "anchor")]
135impl anchor_lang::Owner for Market {
136 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
137 anchor_lang::solana_program::pubkey::Pubkey::from(crate::RIPTIDE_ID.to_bytes())
138 }
139}
140
141#[cfg(feature = "anchor-idl-build")]
142impl anchor_lang::IdlBuild for Market {}
143
144#[cfg(feature = "anchor-idl-build")]
145impl anchor_lang::Discriminator for Market {
146 const DISCRIMINATOR: &[u8] = &[0; 8];
147}