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 {
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
16#[async_trait]
17#[automock]
18pub trait TokenInterface: Send + Sync {
19 fn program_id(&self) -> Pubkey;
20
21 fn unpack_token_account(
22 &self,
23 data: &[u8],
24 ) -> Result<Box<dyn TokenState + Send + Sync>, Box<dyn std::error::Error + Send + Sync>>;
25
26 fn create_initialize_account_instruction(
27 &self,
28 account: &Pubkey,
29 mint: &Pubkey,
30 owner: &Pubkey,
31 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
32
33 fn create_transfer_instruction(
34 &self,
35 source: &Pubkey,
36 destination: &Pubkey,
37 authority: &Pubkey,
38 amount: u64,
39 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
40
41 fn create_transfer_checked_instruction(
42 &self,
43 source: &Pubkey,
44 mint: &Pubkey,
45 destination: &Pubkey,
46 authority: &Pubkey,
47 amount: u64,
48 decimals: u8,
49 ) -> Result<Instruction, Box<dyn std::error::Error + Send + Sync>>;
50
51 fn get_associated_token_address(&self, wallet: &Pubkey, mint: &Pubkey) -> Pubkey;
52
53 fn create_associated_token_account_instruction(
54 &self,
55 funding_account: &Pubkey,
56 wallet: &Pubkey,
57 mint: &Pubkey,
58 ) -> Instruction;
59
60 fn get_mint_decimals(
61 &self,
62 mint_data: &[u8],
63 ) -> Result<u8, Box<dyn std::error::Error + Send + Sync>>;
64
65 fn decode_transfer_instruction(
66 &self,
67 data: &[u8],
68 ) -> Result<u64, Box<dyn std::error::Error + Send + Sync>>;
69}