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