light_token_interface/instructions/mint_action/
compress_and_close_mint.rs

1use light_zero_copy::ZeroCopy;
2
3use crate::{AnchorDeserialize, AnchorSerialize};
4
5/// Action to compress and close a Mint Solana account.
6/// The compressed mint state is always preserved.
7///
8/// ## Requirements
9/// - Mint must exist (mint_decompressed = true) - unless idempotent is set
10/// - is_compressible() must return true (rent expired)
11/// - Cannot be combined with DecompressMint in same instruction
12///
13/// ## Note
14/// CompressAndCloseMint is **permissionless** - anyone can compress and close a Mint
15/// provided is_compressible() returns true. All lamports are returned to rent_sponsor.
16#[repr(C)]
17#[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
18pub struct CompressAndCloseMintAction {
19    /// If non-zero, succeed silently when Mint doesn't exist or cannot be compressed.
20    /// Useful for foresters to handle already-compressed mints without failing.
21    pub idempotent: u8,
22}
23
24impl CompressAndCloseMintAction {
25    /// Returns true if this action should succeed silently when:
26    /// - Mint doesn't exist (already compressed)
27    /// - Mint cannot be compressed (rent not expired)
28    #[inline(always)]
29    pub fn is_idempotent(&self) -> bool {
30        self.idempotent != 0
31    }
32}
33
34impl ZCompressAndCloseMintAction<'_> {
35    /// Returns true if this action should succeed silently when:
36    /// - Mint doesn't exist (already compressed)
37    /// - Mint cannot be compressed (rent not expired)
38    #[inline(always)]
39    pub fn is_idempotent(&self) -> bool {
40        self.idempotent != 0
41    }
42}