1#![allow(clippy::too_many_arguments)]
2#![allow(unexpected_cfgs)]
3pub mod errors;
4pub mod instructions;
5pub use instructions::*;
6pub mod state;
7pub use state::*;
8pub mod processor;
9pub mod utils;
10pub use processor::*;
11pub mod sdk;
12use anchor_lang::prelude::*;
13
14declare_id!("compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq");
15
16#[cfg(not(feature = "no-entrypoint"))]
17solana_security_txt::security_txt! {
18 name: "account-compression",
19 project_url: "lightprotocol.com",
20 contacts: "email:security@lightprotocol.com",
21 policy: "https://github.com/Lightprotocol/light-protocol/blob/main/SECURITY.md",
22 source_code: "https://github.com/Lightprotocol/light-protocol"
23}
24
25#[program]
26pub mod account_compression {
27
28 use errors::AccountCompressionErrorCode;
29
30 use self::{
31 initialize_state_merkle_tree_and_nullifier_queue::process_initialize_state_merkle_tree_and_nullifier_queue,
32 insert_into_queues::{process_insert_into_queues, InsertIntoQueues},
33 };
34
35 use super::*;
36
37 pub fn initialize_address_merkle_tree_and_queue<'info>(
38 ctx: Context<'_, '_, '_, 'info, InitializeAddressMerkleTreeAndQueue<'info>>,
39 index: u64,
40 program_owner: Option<Pubkey>,
41 forester: Option<Pubkey>,
42 address_merkle_tree_config: AddressMerkleTreeConfig,
43 address_queue_config: AddressQueueConfig,
44 ) -> Result<()> {
45 process_initialize_address_merkle_tree_and_queue(
46 ctx,
47 index,
48 program_owner,
49 forester,
50 address_merkle_tree_config,
51 address_queue_config,
52 )
53 }
54
55 pub fn insert_addresses<'a, 'b, 'c: 'info, 'info>(
56 ctx: Context<'a, 'b, 'c, 'info, InsertIntoQueues<'info>>,
57 addresses: Vec<[u8; 32]>,
58 ) -> Result<()> {
59 process_insert_into_queues::<AddressMerkleTreeAccount>(
60 ctx,
61 addresses.as_slice(),
62 QueueType::AddressQueue,
63 )
64 }
65
66 pub fn update_address_merkle_tree<'info>(
68 ctx: Context<'_, '_, '_, 'info, UpdateAddressMerkleTree<'info>>,
69 changelog_index: u16,
71 indexed_changelog_index: u16,
72 value: u16,
74 low_address_index: u64,
76 low_address_value: [u8; 32],
77 low_address_next_index: u64,
78 low_address_next_value: [u8; 32],
80 low_address_proof: [[u8; 32]; 16],
82 ) -> Result<()> {
83 process_update_address_merkle_tree(
84 ctx,
85 changelog_index,
86 indexed_changelog_index,
87 value,
88 low_address_value,
89 low_address_next_index,
90 low_address_next_value,
91 low_address_index,
92 low_address_proof,
93 )
94 }
95
96 pub fn rollover_address_merkle_tree_and_queue<'a, 'b, 'c: 'info, 'info>(
97 ctx: Context<'a, 'b, 'c, 'info, RolloverAddressMerkleTreeAndQueue<'info>>,
98 ) -> Result<()> {
99 process_rollover_address_merkle_tree_and_queue(ctx)
100 }
101
102 pub fn initialize_group_authority<'info>(
105 ctx: Context<'_, '_, '_, 'info, InitializeGroupAuthority<'info>>,
106 authority: Pubkey,
107 ) -> Result<()> {
108 let seed_pubkey = ctx.accounts.seed.key();
109 set_group_authority(
110 &mut ctx.accounts.group_authority,
111 authority,
112 Some(seed_pubkey),
113 )?;
114 Ok(())
115 }
116
117 pub fn update_group_authority<'info>(
118 ctx: Context<'_, '_, '_, 'info, UpdateGroupAuthority<'info>>,
119 authority: Pubkey,
120 ) -> Result<()> {
121 set_group_authority(&mut ctx.accounts.group_authority, authority, None)
122 }
123
124 pub fn register_program_to_group<'info>(
125 ctx: Context<'_, '_, '_, 'info, RegisterProgramToGroup<'info>>,
126 ) -> Result<()> {
127 process_register_program(ctx)
128 }
129
130 pub fn deregister_program(_ctx: Context<DeregisterProgram>) -> Result<()> {
131 Ok(())
132 }
133
134 pub fn initialize_state_merkle_tree_and_nullifier_queue<'info>(
137 ctx: Context<'_, '_, '_, 'info, InitializeStateMerkleTreeAndNullifierQueue<'info>>,
138 index: u64,
139 program_owner: Option<Pubkey>,
140 forester: Option<Pubkey>,
141 state_merkle_tree_config: StateMerkleTreeConfig,
142 nullifier_queue_config: NullifierQueueConfig,
143 additional_bytes: u64,
146 ) -> Result<()> {
147 if additional_bytes != 0 {
148 msg!("additional_bytes is not supported yet");
149 return err!(AccountCompressionErrorCode::UnsupportedAdditionalBytes);
150 }
151 process_initialize_state_merkle_tree_and_nullifier_queue(
152 ctx,
153 index,
154 program_owner,
155 forester,
156 state_merkle_tree_config,
157 nullifier_queue_config,
158 additional_bytes,
159 )
160 }
161
162 pub fn append_leaves_to_merkle_trees<'a, 'b, 'c: 'info, 'info>(
163 ctx: Context<'a, 'b, 'c, 'info, AppendLeaves<'info>>,
164 leaves: Vec<(u8, [u8; 32])>,
165 ) -> Result<()> {
166 process_append_leaves_to_merkle_trees(ctx, leaves)
167 }
168
169 pub fn nullify_leaves<'a, 'b, 'c: 'info, 'info>(
170 ctx: Context<'a, 'b, 'c, 'info, NullifyLeaves<'info>>,
171 change_log_indices: Vec<u64>,
172 leaves_queue_indices: Vec<u16>,
173 leaf_indices: Vec<u64>,
174 proofs: Vec<Vec<[u8; 32]>>,
175 ) -> Result<()> {
176 process_nullify_leaves(
177 &ctx,
178 &change_log_indices,
179 &leaves_queue_indices,
180 &leaf_indices,
181 &proofs,
182 )
183 }
184
185 pub fn insert_into_nullifier_queues<'a, 'b, 'c: 'info, 'info>(
186 ctx: Context<'a, 'b, 'c, 'info, InsertIntoQueues<'info>>,
187 nullifiers: Vec<[u8; 32]>,
188 ) -> Result<()> {
189 process_insert_into_queues::<StateMerkleTreeAccount>(
190 ctx,
191 &nullifiers,
192 QueueType::NullifierQueue,
193 )
194 }
195
196 pub fn rollover_state_merkle_tree_and_nullifier_queue<'a, 'b, 'c: 'info, 'info>(
197 ctx: Context<'a, 'b, 'c, 'info, RolloverStateMerkleTreeAndNullifierQueue<'info>>,
198 ) -> Result<()> {
199 process_rollover_state_merkle_tree_nullifier_queue_pair(ctx)
200 }
201}