use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct WrapSol {
pub lamports: u64,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WrapSolInstructionAccounts {
pub from: solana_pubkey::Pubkey,
pub wrapped_sol_associated_token_account: solana_pubkey::Pubkey,
pub native_mint: solana_pubkey::Pubkey,
pub token_program: solana_pubkey::Pubkey,
pub associated_token_program: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl WrapSol {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [47, 62, 155, 172, 131, 205, 37, 201] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for WrapSol {
type ArrangedAccounts = WrapSolInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let from = next_account(&mut iter)?;
let wrapped_sol_associated_token_account = next_account(&mut iter)?;
let native_mint = next_account(&mut iter)?;
let token_program = next_account(&mut iter)?;
let associated_token_program = next_account(&mut iter)?;
let system_program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(WrapSolInstructionAccounts {
from,
wrapped_sol_associated_token_account,
native_mint,
token_program,
associated_token_program,
system_program,
remaining: remaining.to_vec(),
})
}
}