carbon_token_2022_decoder/instructions/
ui_amount_to_amount.rs

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