2022-02-16 16:23:25 -08:00
|
|
|
/// Partial SPL Token declarations inlined to avoid an external dependency on the spl-token crate
|
|
|
|
use solana_sdk::pubkey::{Pubkey, PUBKEY_BYTES};
|
|
|
|
|
2020-12-31 18:06:03 -08:00
|
|
|
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
|
|
|
2022-04-28 14:43:57 -07:00
|
|
|
pub(crate) mod program_v3_4_0 {
|
|
|
|
solana_sdk::declare_id!("NToK4t5AQzxPNpUA84DkxgfXaVDbDQQjpHKCqsbY46B");
|
2021-02-09 09:16:01 -08:00
|
|
|
}
|
|
|
|
|
2020-12-31 18:06:03 -08:00
|
|
|
/*
|
|
|
|
spl_token::state::Account {
|
|
|
|
mint: Pubkey,
|
|
|
|
owner: Pubkey,
|
|
|
|
amount: u64,
|
|
|
|
delegate: COption<Pubkey>,
|
|
|
|
state: AccountState,
|
|
|
|
is_native: COption<u64>,
|
|
|
|
delegated_amount: u64,
|
|
|
|
close_authority: COption<Pubkey>,
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
pub const SPL_TOKEN_ACCOUNT_MINT_OFFSET: usize = 0;
|
|
|
|
pub const SPL_TOKEN_ACCOUNT_OWNER_OFFSET: usize = 32;
|
2022-02-16 16:23:25 -08:00
|
|
|
const SPL_TOKEN_ACCOUNT_LENGTH: usize = 165;
|
|
|
|
|
|
|
|
pub(crate) trait GenericTokenAccount {
|
|
|
|
fn valid_account_data(account_data: &[u8]) -> bool;
|
2020-12-31 18:06:03 -08:00
|
|
|
|
2022-02-16 16:23:25 -08:00
|
|
|
// Call after account length has already been verified
|
|
|
|
fn unpack_account_owner_unchecked(account_data: &[u8]) -> &Pubkey {
|
|
|
|
Self::unpack_pubkey_unchecked(account_data, SPL_TOKEN_ACCOUNT_OWNER_OFFSET)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call after account length has already been verified
|
|
|
|
fn unpack_account_mint_unchecked(account_data: &[u8]) -> &Pubkey {
|
|
|
|
Self::unpack_pubkey_unchecked(account_data, SPL_TOKEN_ACCOUNT_MINT_OFFSET)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call after account length has already been verified
|
|
|
|
fn unpack_pubkey_unchecked(account_data: &[u8], offset: usize) -> &Pubkey {
|
|
|
|
bytemuck::from_bytes(&account_data[offset..offset + PUBKEY_BYTES])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unpack_account_owner(account_data: &[u8]) -> Option<&Pubkey> {
|
|
|
|
if Self::valid_account_data(account_data) {
|
|
|
|
Some(Self::unpack_account_owner_unchecked(account_data))
|
|
|
|
} else {
|
|
|
|
None
|
2020-12-31 18:06:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-02-16 16:23:25 -08:00
|
|
|
|
|
|
|
fn unpack_account_mint(account_data: &[u8]) -> Option<&Pubkey> {
|
|
|
|
if Self::valid_account_data(account_data) {
|
|
|
|
Some(Self::unpack_account_mint_unchecked(account_data))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Account;
|
|
|
|
impl Account {
|
|
|
|
pub fn get_packed_len() -> usize {
|
|
|
|
SPL_TOKEN_ACCOUNT_LENGTH
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GenericTokenAccount for Account {
|
|
|
|
fn valid_account_data(account_data: &[u8]) -> bool {
|
|
|
|
account_data.len() == SPL_TOKEN_ACCOUNT_LENGTH
|
|
|
|
}
|
2020-12-31 18:06:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod native_mint {
|
|
|
|
solana_sdk::declare_id!("So11111111111111111111111111111111111111112");
|
|
|
|
|
|
|
|
/*
|
|
|
|
Mint {
|
|
|
|
mint_authority: COption::None,
|
|
|
|
supply: 0,
|
|
|
|
decimals: 9,
|
|
|
|
is_initialized: true,
|
|
|
|
freeze_authority: COption::None,
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
pub const ACCOUNT_DATA: [u8; 82] = [
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
];
|
|
|
|
}
|