use anchor_lang::solana_program::pubkey::Pubkey; use std::ops::Deref; static IDS: [Pubkey; 2] = [spl_token::ID, spl_token_2022::ID]; #[derive(Clone, Debug, Default, PartialEq)] pub struct TokenAccount(spl_token_2022::state::Account); impl anchor_lang::AccountDeserialize for TokenAccount { fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { spl_token_2022::extension::StateWithExtensions::::unpack( buf, ) .map(|t| TokenAccount(t.base)) .map_err(Into::into) } } impl anchor_lang::AccountSerialize for TokenAccount {} impl anchor_lang::Owners for TokenAccount { fn owners() -> &'static [Pubkey] { &IDS } } impl Deref for TokenAccount { type Target = spl_token_2022::state::Account; fn deref(&self) -> &Self::Target { &self.0 } } #[derive(Clone, Debug, Default, PartialEq)] pub struct Mint(spl_token_2022::state::Mint); impl anchor_lang::AccountDeserialize for Mint { fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { spl_token_2022::extension::StateWithExtensions::::unpack(buf) .map(|t| Mint(t.base)) .map_err(Into::into) } } impl anchor_lang::AccountSerialize for Mint {} impl anchor_lang::Owners for Mint { fn owners() -> &'static [Pubkey] { &IDS } } impl Deref for Mint { type Target = spl_token_2022::state::Mint; fn deref(&self) -> &Self::Target { &self.0 } } #[derive(Clone)] pub struct TokenInterface; impl anchor_lang::Ids for TokenInterface { fn ids() -> &'static [Pubkey] { &IDS } } pub use crate::token_2022::*;