Skip to main content

carbon_stake_program_decoder/instructions/
withdraw.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
5pub struct Withdraw {
6    pub args: u64,
7}
8
9#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct WithdrawInstructionAccounts {
12    pub stake: solana_pubkey::Pubkey,
13    pub recipient: solana_pubkey::Pubkey,
14    pub clock_sysvar: solana_pubkey::Pubkey,
15    pub stake_history: solana_pubkey::Pubkey,
16    pub withdraw_authority: solana_pubkey::Pubkey,
17    pub lockup_authority: Option<solana_pubkey::Pubkey>,
18    pub remaining: Vec<solana_instruction::AccountMeta>,
19}
20
21impl Withdraw {
22    pub fn decode(data: &[u8]) -> Option<Self> {
23        if data.is_empty() {
24            return None;
25        }
26        let discriminator = &data[0..1];
27        if discriminator != [4] {
28            return None;
29        }
30
31        let mut data_slice = data;
32
33        data_slice = &data_slice[1..];
34
35        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
36    }
37}
38
39impl ArrangeAccounts for Withdraw {
40    type ArrangedAccounts = WithdrawInstructionAccounts;
41
42    fn arrange_accounts(
43        accounts: &[solana_instruction::AccountMeta],
44    ) -> Option<Self::ArrangedAccounts> {
45        let mut iter = accounts.iter();
46
47        let stake = next_account(&mut iter)?;
48        let recipient = next_account(&mut iter)?;
49        let clock_sysvar = next_account(&mut iter)?;
50        let stake_history = next_account(&mut iter)?;
51        let withdraw_authority = next_account(&mut iter)?;
52        let lockup_authority = next_account(&mut iter);
53
54        let remaining = iter.as_slice();
55
56        Some(WithdrawInstructionAccounts {
57            stake,
58            recipient,
59            clock_sysvar,
60            stake_history,
61            withdraw_authority,
62            lockup_authority,
63            remaining: remaining.to_vec(),
64        })
65    }
66}