Skip to main content

light_compressible/
registry_instructions.rs

1//! Client-side instruction builders for Light Registry operations
2//!
3//! This module provides instruction data structures and account meta builders
4//! for creating compressible configs via the Light Registry program.
5
6// Use Anchor's Pubkey when anchor feature is enabled, otherwise use solana-pubkey
7#[cfg(feature = "anchor")]
8use anchor_lang::prelude::Pubkey;
9#[cfg(not(feature = "anchor"))]
10use solana_pubkey::Pubkey;
11
12use crate::{rent::RentConfig, AnchorDeserialize, AnchorSerialize};
13
14/// Discriminator for CreateConfigCounter instruction
15pub const CREATE_CONFIG_COUNTER_DISCRIMINATOR: [u8; 8] = [221, 9, 219, 187, 215, 138, 209, 87];
16
17/// Discriminator for CreateCompressibleConfig instruction
18pub const CREATE_COMPRESSIBLE_CONFIG_DISCRIMINATOR: [u8; 8] = [13, 182, 188, 82, 224, 82, 11, 174];
19
20/// Instruction data for CreateConfigCounter
21///
22/// Creates the config counter PDA that tracks the number of compressible configs.
23#[derive(AnchorSerialize, AnchorDeserialize, Debug, Clone)]
24pub struct CreateConfigCounter {}
25
26impl CreateConfigCounter {
27    /// Get the instruction discriminator
28    pub const fn discriminator() -> [u8; 8] {
29        CREATE_CONFIG_COUNTER_DISCRIMINATOR
30    }
31
32    /// Serialize instruction data including discriminator
33    pub fn data(&self) -> Vec<u8> {
34        let mut data = Self::discriminator().to_vec();
35        data.extend_from_slice(&borsh::to_vec(self).unwrap());
36        data
37    }
38}
39
40/// Instruction data for CreateCompressibleConfig
41///
42/// Creates a new compressible config with the specified parameters.
43#[derive(AnchorSerialize, AnchorDeserialize, Debug, Clone)]
44pub struct CreateCompressibleConfig {
45    pub rent_config: RentConfig,
46    pub update_authority: Pubkey,
47    pub withdrawal_authority: Pubkey,
48    pub active: bool,
49}
50
51impl CreateCompressibleConfig {
52    /// Get the instruction discriminator
53    pub const fn discriminator() -> [u8; 8] {
54        CREATE_COMPRESSIBLE_CONFIG_DISCRIMINATOR
55    }
56
57    /// Serialize instruction data including discriminator
58    pub fn data(&self) -> Vec<u8> {
59        let mut data = Self::discriminator().to_vec();
60        data.extend_from_slice(&AnchorSerialize::try_to_vec(self).unwrap());
61        data
62    }
63}
64
65/// Account metas for CreateCompressibleConfig instruction
66#[derive(Debug, Clone)]
67pub struct CreateCompressibleConfigAccounts {
68    pub fee_payer: Pubkey,
69    pub authority: Pubkey,
70    pub protocol_config_pda: Pubkey,
71    pub config_counter: Pubkey,
72    pub compressible_config: Pubkey,
73    pub system_program: Pubkey,
74}
75
76/// Utility functions for Light Registry PDAs
77pub mod utils {
78    use solana_pubkey::Pubkey;
79
80    /// Light Registry program ID
81    pub const LIGHT_REGISTRY_ID: Pubkey =
82        solana_pubkey::pubkey!("Lighton6oQpVkeewmo2mcPTQQp7kYHr4fWpAgJyEmDX");
83
84    /// Protocol config PDA seed
85    pub const PROTOCOL_CONFIG_PDA_SEED: &[u8] = b"protocol_config";
86
87    /// Get the protocol config PDA address
88    pub fn get_protocol_config_pda_address() -> (Pubkey, u8) {
89        Pubkey::find_program_address(&[PROTOCOL_CONFIG_PDA_SEED], &LIGHT_REGISTRY_ID)
90    }
91}