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