Skip to main content

carbon_token_program_decoder/accounts/
token.rs

1//! This code was AUTOGENERATED using the Codama library.
2use {crate::types::AccountState, solana_pubkey::Pubkey};
3
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
6pub struct Token {
7    /// The mint associated with this account.
8    pub mint: Pubkey,
9    /// The owner of this account.
10    pub owner: Pubkey,
11    /// The amount of tokens this account holds.
12    pub amount: u64,
13    /// If `delegate` is `Some` then `delegated_amount` represents
14    /// the amount authorized by the delegate.
15    pub delegate: Option<Pubkey>,
16    /// The account's state.
17    pub state: AccountState,
18    /// If is_native.is_some, this is a native token, and the value logs the
19    /// rent-exempt reserve. An Account is required to be rent-exempt, so
20    /// the value is used by the Processor to ensure that wrapped SOL
21    /// accounts do not drop below this threshold.
22    pub is_native: Option<u64>,
23    /// The amount delegated.
24    pub delegated_amount: u64,
25    /// Optional authority to close the account.
26    pub close_authority: Option<Pubkey>,
27}
28
29impl From<spl_token_interface::state::Account> for Token {
30    fn from(value: spl_token_interface::state::Account) -> Self {
31        Token {
32            mint: value.mint,
33            owner: value.owner,
34            amount: value.amount,
35            delegate: value.delegate.into(),
36            state: match value.state {
37                spl_token_interface::state::AccountState::Uninitialized => {
38                    crate::types::AccountState::Uninitialized
39                }
40                spl_token_interface::state::AccountState::Initialized => {
41                    crate::types::AccountState::Initialized
42                }
43                spl_token_interface::state::AccountState::Frozen => {
44                    crate::types::AccountState::Frozen
45                }
46            },
47            is_native: value.is_native.into(),
48            delegated_amount: value.delegated_amount,
49            close_authority: value.close_authority.into(),
50        }
51    }
52}