light_token_interface/instructions/mint_action/
cpi_context.rs

1use light_compressed_account::instruction_data::zero_copy_set::CompressedCpiContextTrait;
2use light_zero_copy::{ZeroCopy, ZeroCopyMut};
3
4use crate::{AnchorDeserialize, AnchorSerialize, MINT_ADDRESS_TREE};
5
6#[repr(C)]
7#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy, ZeroCopyMut, PartialEq)]
8pub struct CpiContext {
9    pub set_context: bool,
10    pub first_set_context: bool,
11    // Used as address tree index if create mint
12    pub in_tree_index: u8,
13    pub in_queue_index: u8,
14    pub out_queue_index: u8,
15    pub token_out_queue_index: u8,
16    // Index of the compressed account that should receive the new address (0 = mint, 1+ = token accounts)
17    pub assigned_account_index: u8,
18    /// Placeholder to enable mints in multiple address trees.
19    /// Currently set to 0.
20    pub read_only_address_trees: [u8; 4],
21    pub address_tree_pubkey: [u8; 32],
22}
23
24impl Default for CpiContext {
25    fn default() -> Self {
26        Self {
27            set_context: false,
28            first_set_context: false,
29            in_tree_index: 0,
30            in_queue_index: 0,
31            out_queue_index: 0,
32            token_out_queue_index: 0,
33            assigned_account_index: 0,
34            read_only_address_trees: [0; 4],
35            address_tree_pubkey: MINT_ADDRESS_TREE,
36        }
37    }
38}
39
40impl CompressedCpiContextTrait for ZCpiContext<'_> {
41    fn first_set_context(&self) -> u8 {
42        if self.first_set_context == 0 {
43            0
44        } else {
45            1
46        }
47    }
48
49    fn set_context(&self) -> u8 {
50        if self.set_context == 0 {
51            0
52        } else {
53            1
54        }
55    }
56}