Skip to main content

light_system_program/instructions/
invoke.rs

1use account_compression::program::AccountCompression;
2use anchor_lang::prelude::*;
3
4use crate::{
5    account_traits::{InvokeAccounts, SignerAccounts},
6    constants::SOL_POOL_PDA_SEED,
7};
8
9/// These are the base accounts additionally Merkle tree and queue accounts are required.
10/// These additional accounts are passed as remaining accounts.
11/// 1 Merkle tree for each input compressed account one queue and Merkle tree account each for each output compressed account.
12#[derive(Accounts)]
13pub struct InvokeInstruction<'info> {
14    /// Fee payer needs to be mutable to pay rollover and protocol fees.
15    #[account(mut)]
16    pub fee_payer: Signer<'info>,
17    pub authority: Signer<'info>,
18    /// CHECK: this account
19    pub registered_program_pda: AccountInfo<'info>,
20    /// CHECK: is checked when emitting the event.
21    pub noop_program: UncheckedAccount<'info>,
22    /// CHECK: this account in account compression program.
23    /// This pda is used to invoke the account compression program.
24    pub account_compression_authority: UncheckedAccount<'info>,
25    /// CHECK: Account compression program is used to update state and address
26    /// Merkle trees.
27    pub account_compression_program: Program<'info, AccountCompression>,
28    /// Sol pool pda is used to store the native sol that has been compressed.
29    /// It's only required when compressing or decompressing sol.
30    #[account(
31        mut,
32        seeds = [SOL_POOL_PDA_SEED], bump
33    )]
34    pub sol_pool_pda: Option<AccountInfo<'info>>,
35    /// Only needs to be provided for decompression as a recipient for the
36    /// decompressed sol.
37    /// Compressed sol originate from authority.
38    #[account(mut)]
39    pub decompression_recipient: Option<AccountInfo<'info>>,
40    pub system_program: Program<'info, System>,
41}
42
43impl<'info> SignerAccounts<'info> for InvokeInstruction<'info> {
44    fn get_fee_payer(&self) -> &Signer<'info> {
45        &self.fee_payer
46    }
47
48    fn get_authority(&self) -> &Signer<'info> {
49        &self.authority
50    }
51}
52
53impl<'info> InvokeAccounts<'info> for InvokeInstruction<'info> {
54    fn get_registered_program_pda(&self) -> &AccountInfo<'info> {
55        &self.registered_program_pda
56    }
57
58    fn get_noop_program(&self) -> &UncheckedAccount<'info> {
59        &self.noop_program
60    }
61
62    fn get_account_compression_authority(&self) -> &UncheckedAccount<'info> {
63        &self.account_compression_authority
64    }
65
66    fn get_account_compression_program(&self) -> &Program<'info, AccountCompression> {
67        &self.account_compression_program
68    }
69
70    fn get_system_program(&self) -> &Program<'info, System> {
71        &self.system_program
72    }
73
74    fn get_sol_pool_pda(&self) -> Option<&AccountInfo<'info>> {
75        self.sol_pool_pda.as_ref()
76    }
77
78    fn get_decompression_recipient(&self) -> Option<&AccountInfo<'info>> {
79        self.decompression_recipient.as_ref()
80    }
81}