Skip to main content

orca_sol/accounts/
position_bundle.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 borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_pubkey::Pubkey;
11
12#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct PositionBundle {
15    pub discriminator: [u8; 8],
16    #[cfg_attr(
17        feature = "serde",
18        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
19    )]
20    pub position_bundle_mint: Pubkey,
21    pub position_bitmap: [u8; 32],
22}
23
24impl PositionBundle {
25    pub const LEN: usize = 72;
26
27    #[inline(always)]
28    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
29        let mut data = data;
30        Self::deserialize(&mut data)
31    }
32}
33
34impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for PositionBundle {
35    type Error = std::io::Error;
36
37    fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
38        let mut data: &[u8] = &(*account_info.data).borrow();
39        Self::deserialize(&mut data)
40    }
41}
42
43#[cfg(feature = "fetch")]
44pub fn fetch_position_bundle(
45    rpc: &solana_client::rpc_client::RpcClient,
46    address: &solana_pubkey::Pubkey,
47) -> Result<crate::shared::DecodedAccount<PositionBundle>, std::io::Error> {
48    let accounts = fetch_all_position_bundle(rpc, &[*address])?;
49    Ok(accounts[0].clone())
50}
51
52#[cfg(feature = "fetch")]
53pub fn fetch_all_position_bundle(
54    rpc: &solana_client::rpc_client::RpcClient,
55    addresses: &[solana_pubkey::Pubkey],
56) -> Result<Vec<crate::shared::DecodedAccount<PositionBundle>>, std::io::Error> {
57    let accounts = rpc
58        .get_multiple_accounts(addresses)
59        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
60    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<PositionBundle>> = Vec::new();
61    for i in 0..addresses.len() {
62        let address = addresses[i];
63        let account = accounts[i].as_ref().ok_or(std::io::Error::new(
64            std::io::ErrorKind::Other,
65            format!("Account not found: {}", address),
66        ))?;
67        let data = PositionBundle::from_bytes(&account.data)?;
68        decoded_accounts.push(crate::shared::DecodedAccount {
69            address,
70            account: account.clone(),
71            data,
72        });
73    }
74    Ok(decoded_accounts)
75}
76
77#[cfg(feature = "fetch")]
78pub fn fetch_maybe_position_bundle(
79    rpc: &solana_client::rpc_client::RpcClient,
80    address: &solana_pubkey::Pubkey,
81) -> Result<crate::shared::MaybeAccount<PositionBundle>, std::io::Error> {
82    let accounts = fetch_all_maybe_position_bundle(rpc, &[*address])?;
83    Ok(accounts[0].clone())
84}
85
86#[cfg(feature = "fetch")]
87pub fn fetch_all_maybe_position_bundle(
88    rpc: &solana_client::rpc_client::RpcClient,
89    addresses: &[solana_pubkey::Pubkey],
90) -> Result<Vec<crate::shared::MaybeAccount<PositionBundle>>, std::io::Error> {
91    let accounts = rpc
92        .get_multiple_accounts(addresses)
93        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
94    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<PositionBundle>> = Vec::new();
95    for i in 0..addresses.len() {
96        let address = addresses[i];
97        if let Some(account) = accounts[i].as_ref() {
98            let data = PositionBundle::from_bytes(&account.data)?;
99            decoded_accounts.push(crate::shared::MaybeAccount::Exists(
100                crate::shared::DecodedAccount {
101                    address,
102                    account: account.clone(),
103                    data,
104                },
105            ));
106        } else {
107            decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
108        }
109    }
110    Ok(decoded_accounts)
111}
112
113#[cfg(feature = "anchor")]
114impl anchor_lang::AccountDeserialize for PositionBundle {
115    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
116        Ok(Self::deserialize(buf)?)
117    }
118}
119
120#[cfg(feature = "anchor")]
121impl anchor_lang::AccountSerialize for PositionBundle {}
122
123#[cfg(feature = "anchor")]
124impl anchor_lang::Owner for PositionBundle {
125    fn owner() -> Pubkey {
126        crate::WHIRLPOOL_ID
127    }
128}
129
130#[cfg(feature = "anchor-idl-build")]
131impl anchor_lang::IdlBuild for PositionBundle {}
132
133#[cfg(feature = "anchor-idl-build")]
134impl anchor_lang::Discriminator for PositionBundle {
135    const DISCRIMINATOR: [u8; 8] = [0; 8];
136}