tensor_escrow/generated/accounts/
margin_account.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! <https://github.com/kinobi-so/kinobi>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct MarginAccount {
15    pub discriminator: [u8; 8],
16    #[cfg_attr(
17        feature = "serde",
18        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
19    )]
20    pub owner: Pubkey,
21    pub name: [u8; 32],
22    pub nr: u16,
23    pub bump: [u8; 1],
24    pub pools_attached: u32,
25    #[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
26    pub reserved: [u8; 64],
27}
28
29impl MarginAccount {
30    pub const LEN: usize = 143;
31
32    /// Prefix values used to generate a PDA for this account.
33    ///
34    /// Values are positional and appear in the following order:
35    ///
36    ///   0. `MarginAccount::PREFIX`
37    ///   1. tswap (`Pubkey`)
38    ///   2. owner (`Pubkey`)
39    ///   3. margin_nr (`u16`)
40    pub const PREFIX: &'static [u8] = "margin".as_bytes();
41
42    pub fn create_pda(
43        tswap: Pubkey,
44        owner: Pubkey,
45        margin_nr: u16,
46        bump: u8,
47    ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
48        solana_program::pubkey::Pubkey::create_program_address(
49            &[
50                "margin".as_bytes(),
51                tswap.as_ref(),
52                owner.as_ref(),
53                margin_nr.to_string().as_ref(),
54                &[bump],
55            ],
56            &crate::TENSOR_ESCROW_ID,
57        )
58    }
59
60    pub fn find_pda(
61        tswap: &Pubkey,
62        owner: &Pubkey,
63        margin_nr: u16,
64    ) -> (solana_program::pubkey::Pubkey, u8) {
65        solana_program::pubkey::Pubkey::find_program_address(
66            &[
67                "margin".as_bytes(),
68                tswap.as_ref(),
69                owner.as_ref(),
70                margin_nr.to_string().as_ref(),
71            ],
72            &crate::TENSOR_ESCROW_ID,
73        )
74    }
75
76    #[inline(always)]
77    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
78        let mut data = data;
79        Self::deserialize(&mut data)
80    }
81}
82
83impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for MarginAccount {
84    type Error = std::io::Error;
85
86    fn try_from(
87        account_info: &solana_program::account_info::AccountInfo<'a>,
88    ) -> Result<Self, Self::Error> {
89        let mut data: &[u8] = &(*account_info.data).borrow();
90        Self::deserialize(&mut data)
91    }
92}
93
94#[cfg(feature = "anchor")]
95impl anchor_lang::AccountDeserialize for MarginAccount {
96    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
97        Ok(Self::deserialize(buf)?)
98    }
99}
100
101#[cfg(feature = "anchor")]
102impl anchor_lang::AccountSerialize for MarginAccount {}
103
104#[cfg(feature = "anchor")]
105impl anchor_lang::Owner for MarginAccount {
106    fn owner() -> Pubkey {
107        crate::TENSOR_ESCROW_ID
108    }
109}
110
111#[cfg(feature = "anchor-idl-build")]
112impl anchor_lang::IdlBuild for MarginAccount {}
113
114#[cfg(feature = "anchor-idl-build")]
115impl anchor_lang::Discriminator for MarginAccount {
116    const DISCRIMINATOR: [u8; 8] = [0; 8];
117}