Skip to main content

carbon_token_program_decoder/instructions/
ui_amount_to_amount.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Convert a UiAmount of tokens to a little-endian `u64` raw Amount, using
4/// the given mint. In this version of the program, the mint can only
5/// specify the number of decimals.
6/// Return data can be fetched using `sol_get_return_data` and deserializing
7/// the return data as a little-endian `u64`.
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
10pub struct UiAmountToAmount {
11    /// The ui_amount of tokens to reformat.
12    pub ui_amount: String,
13}
14
15#[derive(Debug, Clone, PartialEq)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct UiAmountToAmountInstructionAccounts {
18    pub mint: solana_pubkey::Pubkey,
19    pub remaining: Vec<solana_instruction::AccountMeta>,
20}
21
22impl UiAmountToAmount {
23    pub fn decode(data: &[u8]) -> Option<Self> {
24        if data.is_empty() {
25            return None;
26        }
27        let discriminator = &data[0..1];
28        if discriminator != [24] {
29            return None;
30        }
31
32        let mut data_slice = data;
33
34        data_slice = &data_slice[1..];
35
36        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
37    }
38}
39
40impl ArrangeAccounts for UiAmountToAmount {
41    type ArrangedAccounts = UiAmountToAmountInstructionAccounts;
42
43    fn arrange_accounts(
44        accounts: &[solana_instruction::AccountMeta],
45    ) -> Option<Self::ArrangedAccounts> {
46        let mut iter = accounts.iter();
47
48        let mint = next_account(&mut iter)?;
49
50        let remaining = iter.as_slice();
51
52        Some(UiAmountToAmountInstructionAccounts {
53            mint,
54            remaining: remaining.to_vec(),
55        })
56    }
57}