carbon_tcomp_decoder/instructions/
bid.rs

1//! This code was AUTOGENERATED using the Codama library.
2use crate::types::Field;
3use crate::types::Target;
4use carbon_core::CarbonDeserialize;
5use carbon_core::account_utils::next_account;
6use carbon_core::borsh;
7use carbon_core::deserialize::ArrangeAccounts;
8use carbon_core::deserialize::CarbonDeserialize;
9use solana_pubkey::Pubkey;
10
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq, Eq, Hash)]
13pub struct Bid {
14    pub bid_id: Pubkey,
15    pub target: Target,
16    pub target_id: Pubkey,
17    pub field: Option<Field>,
18    pub field_id: Option<Pubkey>,
19    pub amount: u64,
20    pub quantity: u32,
21    pub expire_in_sec: Option<u64>,
22    pub currency: Option<Pubkey>,
23    pub private_taker: Option<Pubkey>,
24    pub maker_broker: Option<Pubkey>,
25}
26
27#[derive(Debug, Clone, PartialEq)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub struct BidInstructionAccounts {
30    pub system_program: solana_pubkey::Pubkey,
31    pub tcomp_program: solana_pubkey::Pubkey,
32    pub bid_state: solana_pubkey::Pubkey,
33    pub owner: solana_pubkey::Pubkey,
34    pub margin_account: solana_pubkey::Pubkey,
35    pub cosigner: solana_pubkey::Pubkey,
36    pub rent_payer: solana_pubkey::Pubkey,
37    pub remaining: Vec<solana_instruction::AccountMeta>,
38}
39
40impl Bid {
41    pub fn decode(data: &[u8]) -> Option<Self> {
42        if data.len() < 8 {
43            return None;
44        }
45        let discriminator = &data[0..8];
46        if discriminator != &[199, 56, 85, 38, 146, 243, 37, 158] {
47            return None;
48        }
49
50        let data_slice = data;
51
52        let data_slice = &data_slice[8..];
53
54        Self::deserialize(data_slice)
55    }
56}
57
58impl ArrangeAccounts for Bid {
59    type ArrangedAccounts = BidInstructionAccounts;
60
61    fn arrange_accounts(
62        accounts: &[solana_instruction::AccountMeta],
63    ) -> Option<Self::ArrangedAccounts> {
64        let mut iter = accounts.iter();
65
66        let system_program = next_account(&mut iter)?;
67        let tcomp_program = next_account(&mut iter)?;
68        let bid_state = next_account(&mut iter)?;
69        let owner = next_account(&mut iter)?;
70        let margin_account = next_account(&mut iter)?;
71        let cosigner = next_account(&mut iter)?;
72        let rent_payer = next_account(&mut iter)?;
73
74        let remaining = iter.as_slice();
75
76        Some(BidInstructionAccounts {
77            system_program,
78            tcomp_program,
79            bid_state,
80            owner,
81            margin_account,
82            cosigner,
83            rent_payer,
84            remaining: remaining.to_vec(),
85        })
86    }
87}