tensor_marketplace/generated/accounts/
bid_state.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 crate::generated::types::Field;
9use crate::generated::types::Target;
10use crate::hooked::NullableAddress;
11use borsh::BorshDeserialize;
12use borsh::BorshSerialize;
13use solana_program::pubkey::Pubkey;
14
15#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct BidState {
18    pub discriminator: [u8; 8],
19    pub version: u8,
20    pub bump: [u8; 1],
21    #[cfg_attr(
22        feature = "serde",
23        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
24    )]
25    pub owner: Pubkey,
26    /// Randomly picked pubkey used in bid seeds. To avoid dangling bids can use assetId here.
27    #[cfg_attr(
28        feature = "serde",
29        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
30    )]
31    pub bid_id: Pubkey,
32    pub target: Target,
33    #[cfg_attr(
34        feature = "serde",
35        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
36    )]
37    pub target_id: Pubkey,
38    pub field: Option<Field>,
39    pub field_id: Option<Pubkey>,
40    pub quantity: u32,
41    pub filled_quantity: u32,
42    pub amount: u64,
43    pub currency: Option<Pubkey>,
44    pub expiry: i64,
45    pub private_taker: Option<Pubkey>,
46    pub maker_broker: Option<Pubkey>,
47    pub margin: Option<Pubkey>,
48    pub updated_at: i64,
49    /// Cosigner
50    /// Default Pubkey represents a None value.
51    pub cosigner: NullableAddress,
52    /// Owner is the rent payer when this is None.
53    /// Default Pubkey represents a None value.
54    pub rent_payer: NullableAddress,
55    pub reserved: [u8; 8],
56    pub reserved1: [u8; 16],
57    pub reserved2: [u8; 32],
58}
59
60impl BidState {
61    /// Prefix values used to generate a PDA for this account.
62    ///
63    /// Values are positional and appear in the following order:
64    ///
65    ///   0. `BidState::PREFIX`
66    ///   1. owner (`Pubkey`)
67    ///   2. bid_id (`Pubkey`)
68    pub const PREFIX: &'static [u8] = "bid_state".as_bytes();
69
70    pub fn create_pda(
71        owner: Pubkey,
72        bid_id: Pubkey,
73        bump: u8,
74    ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
75        solana_program::pubkey::Pubkey::create_program_address(
76            &[
77                "bid_state".as_bytes(),
78                owner.as_ref(),
79                bid_id.as_ref(),
80                &[bump],
81            ],
82            &crate::TENSOR_MARKETPLACE_ID,
83        )
84    }
85
86    pub fn find_pda(owner: &Pubkey, bid_id: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) {
87        solana_program::pubkey::Pubkey::find_program_address(
88            &["bid_state".as_bytes(), owner.as_ref(), bid_id.as_ref()],
89            &crate::TENSOR_MARKETPLACE_ID,
90        )
91    }
92
93    #[inline(always)]
94    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
95        let mut data = data;
96        Self::deserialize(&mut data)
97    }
98}
99
100impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for BidState {
101    type Error = std::io::Error;
102
103    fn try_from(
104        account_info: &solana_program::account_info::AccountInfo<'a>,
105    ) -> Result<Self, Self::Error> {
106        let mut data: &[u8] = &(*account_info.data).borrow();
107        Self::deserialize(&mut data)
108    }
109}
110
111#[cfg(feature = "anchor")]
112impl anchor_lang::AccountDeserialize for BidState {
113    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
114        Ok(Self::deserialize(buf)?)
115    }
116}
117
118#[cfg(feature = "anchor")]
119impl anchor_lang::AccountSerialize for BidState {}
120
121#[cfg(feature = "anchor")]
122impl anchor_lang::Owner for BidState {
123    fn owner() -> Pubkey {
124        crate::TENSOR_MARKETPLACE_ID
125    }
126}
127
128#[cfg(feature = "anchor-idl-build")]
129impl anchor_lang::IdlBuild for BidState {}
130
131#[cfg(feature = "anchor-idl-build")]
132impl anchor_lang::Discriminator for BidState {
133    const DISCRIMINATOR: [u8; 8] = [0; 8];
134}