kora_lib/token/
interface.rs1use async_trait::async_trait;
2use mockall::automock;
3use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
4use std::any::Any;
5
6pub trait TokenState: Any + Send + Sync {
7 fn mint(&self) -> Pubkey;
8 fn owner(&self) -> Pubkey;
9 fn amount(&self) -> u64;
10 fn decimals(&self) -> u8;
11
12 fn as_any(&self) -> &dyn Any;
14}
15
16pub trait TokenMint: Any + Send + Sync {
17 fn address(&self) -> Pubkey;
18 fn mint_authority(&self) -> Option<Pubkey>;
19 fn supply(&self) -> u64;
20 fn decimals(&self) -> u8;
21 fn freeze_authority(&self) -> Option<Pubkey>;
22 fn is_initialized(&self) -> bool;
23 fn get_token_program(&self) -> Box<dyn TokenInterface>;
24
25 fn as_any(&self) -> &dyn Any;
27}
28
29#[async_trait]
30#[automock]
31pub trait TokenInterface: Send + Sync {
32 fn program_id(&self) -> Pubkey;
33
34 fn unpack_token_account(
35 &self,
36 data: &[u8],
37 ) -> Result<Box<dyn TokenState + Send + Sync>, Box<dyn std::error::Error + Send + Sync>>;
38
39 fn create_initialize_account_instruction(
40 &self,
41 account: &Pubkey,
42 mint: &Pubkey,
43 owner: &Pubkey,
44 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
45
46 fn create_transfer_instruction(
47 &self,
48 source: &Pubkey,
49 destination: &Pubkey,
50 authority: &Pubkey,
51 amount: u64,
52 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
53
54 fn create_transfer_checked_instruction(
55 &self,
56 source: &Pubkey,
57 mint: &Pubkey,
58 destination: &Pubkey,
59 authority: &Pubkey,
60 amount: u64,
61 decimals: u8,
62 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
63
64 fn get_associated_token_address(&self, wallet: &Pubkey, mint: &Pubkey) -> Pubkey;
65
66 fn create_associated_token_account_instruction(
67 &self,
68 funding_account: &Pubkey,
69 wallet: &Pubkey,
70 mint: &Pubkey,
71 ) -> Instruction;
72
73 fn unpack_mint(
74 &self,
75 mint: &Pubkey,
76 mint_data: &[u8],
77 ) -> Result<Box<dyn TokenMint + Send + Sync>, Box<dyn std::error::Error + Send + Sync>>;
78}