Skip to main content

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