carbon_stake_program_decoder/instructions/
delegate_stake.rs1use 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 DelegateStake {}
6
7#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct DelegateStakeInstructionAccounts {
10 pub stake: solana_pubkey::Pubkey,
11 pub vote: solana_pubkey::Pubkey,
12 pub clock_sysvar: solana_pubkey::Pubkey,
13 pub stake_history: solana_pubkey::Pubkey,
14 pub unused: solana_pubkey::Pubkey,
15 pub stake_authority: solana_pubkey::Pubkey,
16 pub remaining: Vec<solana_instruction::AccountMeta>,
17}
18
19impl DelegateStake {
20 pub fn decode(data: &[u8]) -> Option<Self> {
21 if data.is_empty() {
22 return None;
23 }
24 let discriminator = &data[0..1];
25 if discriminator != [2] {
26 return None;
27 }
28
29 let mut data_slice = data;
30
31 data_slice = &data_slice[1..];
32
33 borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
34 }
35}
36
37impl ArrangeAccounts for DelegateStake {
38 type ArrangedAccounts = DelegateStakeInstructionAccounts;
39
40 fn arrange_accounts(
41 accounts: &[solana_instruction::AccountMeta],
42 ) -> Option<Self::ArrangedAccounts> {
43 let mut iter = accounts.iter();
44
45 let stake = next_account(&mut iter)?;
46 let vote = next_account(&mut iter)?;
47 let clock_sysvar = next_account(&mut iter)?;
48 let stake_history = next_account(&mut iter)?;
49 let unused = next_account(&mut iter)?;
50 let stake_authority = next_account(&mut iter)?;
51
52 let remaining = iter.as_slice();
53
54 Some(DelegateStakeInstructionAccounts {
55 stake,
56 vote,
57 clock_sysvar,
58 stake_history,
59 unused,
60 stake_authority,
61 remaining: remaining.to_vec(),
62 })
63 }
64}