lighthouse_sol/instructions/
memory_close.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct MemoryClose {
14    /// Lighthouse program
15    pub program_id: solana_pubkey::Pubkey,
16    /// Payer account
17    pub payer: solana_pubkey::Pubkey,
18    /// Memory account
19    pub memory: solana_pubkey::Pubkey,
20}
21
22impl MemoryClose {
23    pub fn instruction(&self, args: MemoryCloseInstructionArgs) -> solana_instruction::Instruction {
24        self.instruction_with_remaining_accounts(args, &[])
25    }
26    #[allow(clippy::arithmetic_side_effects)]
27    #[allow(clippy::vec_init_then_push)]
28    pub fn instruction_with_remaining_accounts(
29        &self,
30        args: MemoryCloseInstructionArgs,
31        remaining_accounts: &[solana_instruction::AccountMeta],
32    ) -> solana_instruction::Instruction {
33        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
34        accounts.push(solana_instruction::AccountMeta::new_readonly(
35            self.program_id,
36            false,
37        ));
38        accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
39        accounts.push(solana_instruction::AccountMeta::new(self.memory, false));
40        accounts.extend_from_slice(remaining_accounts);
41        let mut data = borsh::to_vec(&MemoryCloseInstructionData::new()).unwrap();
42        let mut args = borsh::to_vec(&args).unwrap();
43        data.append(&mut args);
44
45        solana_instruction::Instruction {
46            program_id: crate::LIGHTHOUSE_ID,
47            accounts,
48            data,
49        }
50    }
51}
52
53#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
54#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
55pub struct MemoryCloseInstructionData {
56    discriminator: u8,
57}
58
59impl MemoryCloseInstructionData {
60    pub fn new() -> Self {
61        Self { discriminator: 1 }
62    }
63}
64
65impl Default for MemoryCloseInstructionData {
66    fn default() -> Self {
67        Self::new()
68    }
69}
70
71#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73pub struct MemoryCloseInstructionArgs {
74    pub memory_id: u8,
75    pub memory_bump: u8,
76}
77
78/// Instruction builder for `MemoryClose`.
79///
80/// ### Accounts:
81///
82///   0. `[]` program_id
83///   1. `[writable, signer]` payer
84///   2. `[writable]` memory
85#[derive(Clone, Debug, Default)]
86pub struct MemoryCloseBuilder {
87    program_id: Option<solana_pubkey::Pubkey>,
88    payer: Option<solana_pubkey::Pubkey>,
89    memory: Option<solana_pubkey::Pubkey>,
90    memory_id: Option<u8>,
91    memory_bump: Option<u8>,
92    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
93}
94
95impl MemoryCloseBuilder {
96    pub fn new() -> Self {
97        Self::default()
98    }
99    /// Lighthouse program
100    #[inline(always)]
101    pub fn program_id(&mut self, program_id: solana_pubkey::Pubkey) -> &mut Self {
102        self.program_id = Some(program_id);
103        self
104    }
105    /// Payer account
106    #[inline(always)]
107    pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self {
108        self.payer = Some(payer);
109        self
110    }
111    /// Memory account
112    #[inline(always)]
113    pub fn memory(&mut self, memory: solana_pubkey::Pubkey) -> &mut Self {
114        self.memory = Some(memory);
115        self
116    }
117    #[inline(always)]
118    pub fn memory_id(&mut self, memory_id: u8) -> &mut Self {
119        self.memory_id = Some(memory_id);
120        self
121    }
122    #[inline(always)]
123    pub fn memory_bump(&mut self, memory_bump: u8) -> &mut Self {
124        self.memory_bump = Some(memory_bump);
125        self
126    }
127    /// Add an additional account to the instruction.
128    #[inline(always)]
129    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
130        self.__remaining_accounts.push(account);
131        self
132    }
133    /// Add additional accounts to the instruction.
134    #[inline(always)]
135    pub fn add_remaining_accounts(
136        &mut self,
137        accounts: &[solana_instruction::AccountMeta],
138    ) -> &mut Self {
139        self.__remaining_accounts.extend_from_slice(accounts);
140        self
141    }
142    #[allow(clippy::clone_on_copy)]
143    pub fn instruction(&self) -> solana_instruction::Instruction {
144        let accounts = MemoryClose {
145            program_id: self.program_id.expect("program_id is not set"),
146            payer: self.payer.expect("payer is not set"),
147            memory: self.memory.expect("memory is not set"),
148        };
149        let args = MemoryCloseInstructionArgs {
150            memory_id: self.memory_id.clone().expect("memory_id is not set"),
151            memory_bump: self.memory_bump.clone().expect("memory_bump is not set"),
152        };
153
154        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
155    }
156}
157
158/// `memory_close` CPI accounts.
159pub struct MemoryCloseCpiAccounts<'a, 'b> {
160    /// Lighthouse program
161    pub program_id: &'b solana_account_info::AccountInfo<'a>,
162    /// Payer account
163    pub payer: &'b solana_account_info::AccountInfo<'a>,
164    /// Memory account
165    pub memory: &'b solana_account_info::AccountInfo<'a>,
166}
167
168/// `memory_close` CPI instruction.
169pub struct MemoryCloseCpi<'a, 'b> {
170    /// The program to invoke.
171    pub __program: &'b solana_account_info::AccountInfo<'a>,
172    /// Lighthouse program
173    pub program_id: &'b solana_account_info::AccountInfo<'a>,
174    /// Payer account
175    pub payer: &'b solana_account_info::AccountInfo<'a>,
176    /// Memory account
177    pub memory: &'b solana_account_info::AccountInfo<'a>,
178    /// The arguments for the instruction.
179    pub __args: MemoryCloseInstructionArgs,
180}
181
182impl<'a, 'b> MemoryCloseCpi<'a, 'b> {
183    pub fn new(
184        program: &'b solana_account_info::AccountInfo<'a>,
185        accounts: MemoryCloseCpiAccounts<'a, 'b>,
186        args: MemoryCloseInstructionArgs,
187    ) -> Self {
188        Self {
189            __program: program,
190            program_id: accounts.program_id,
191            payer: accounts.payer,
192            memory: accounts.memory,
193            __args: args,
194        }
195    }
196    #[inline(always)]
197    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
198        self.invoke_signed_with_remaining_accounts(&[], &[])
199    }
200    #[inline(always)]
201    pub fn invoke_with_remaining_accounts(
202        &self,
203        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
204    ) -> solana_program_entrypoint::ProgramResult {
205        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
206    }
207    #[inline(always)]
208    pub fn invoke_signed(
209        &self,
210        signers_seeds: &[&[&[u8]]],
211    ) -> solana_program_entrypoint::ProgramResult {
212        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
213    }
214    #[allow(clippy::arithmetic_side_effects)]
215    #[allow(clippy::clone_on_copy)]
216    #[allow(clippy::vec_init_then_push)]
217    pub fn invoke_signed_with_remaining_accounts(
218        &self,
219        signers_seeds: &[&[&[u8]]],
220        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
221    ) -> solana_program_entrypoint::ProgramResult {
222        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
223        accounts.push(solana_instruction::AccountMeta::new_readonly(
224            *self.program_id.key,
225            false,
226        ));
227        accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true));
228        accounts.push(solana_instruction::AccountMeta::new(
229            *self.memory.key,
230            false,
231        ));
232        remaining_accounts.iter().for_each(|remaining_account| {
233            accounts.push(solana_instruction::AccountMeta {
234                pubkey: *remaining_account.0.key,
235                is_signer: remaining_account.1,
236                is_writable: remaining_account.2,
237            })
238        });
239        let mut data = borsh::to_vec(&MemoryCloseInstructionData::new()).unwrap();
240        let mut args = borsh::to_vec(&self.__args).unwrap();
241        data.append(&mut args);
242
243        let instruction = solana_instruction::Instruction {
244            program_id: crate::LIGHTHOUSE_ID,
245            accounts,
246            data,
247        };
248        let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
249        account_infos.push(self.__program.clone());
250        account_infos.push(self.program_id.clone());
251        account_infos.push(self.payer.clone());
252        account_infos.push(self.memory.clone());
253        remaining_accounts
254            .iter()
255            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
256
257        if signers_seeds.is_empty() {
258            solana_cpi::invoke(&instruction, &account_infos)
259        } else {
260            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
261        }
262    }
263}
264
265/// Instruction builder for `MemoryClose` via CPI.
266///
267/// ### Accounts:
268///
269///   0. `[]` program_id
270///   1. `[writable, signer]` payer
271///   2. `[writable]` memory
272#[derive(Clone, Debug)]
273pub struct MemoryCloseCpiBuilder<'a, 'b> {
274    instruction: Box<MemoryCloseCpiBuilderInstruction<'a, 'b>>,
275}
276
277impl<'a, 'b> MemoryCloseCpiBuilder<'a, 'b> {
278    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
279        let instruction = Box::new(MemoryCloseCpiBuilderInstruction {
280            __program: program,
281            program_id: None,
282            payer: None,
283            memory: None,
284            memory_id: None,
285            memory_bump: None,
286            __remaining_accounts: Vec::new(),
287        });
288        Self { instruction }
289    }
290    /// Lighthouse program
291    #[inline(always)]
292    pub fn program_id(
293        &mut self,
294        program_id: &'b solana_account_info::AccountInfo<'a>,
295    ) -> &mut Self {
296        self.instruction.program_id = Some(program_id);
297        self
298    }
299    /// Payer account
300    #[inline(always)]
301    pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
302        self.instruction.payer = Some(payer);
303        self
304    }
305    /// Memory account
306    #[inline(always)]
307    pub fn memory(&mut self, memory: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
308        self.instruction.memory = Some(memory);
309        self
310    }
311    #[inline(always)]
312    pub fn memory_id(&mut self, memory_id: u8) -> &mut Self {
313        self.instruction.memory_id = Some(memory_id);
314        self
315    }
316    #[inline(always)]
317    pub fn memory_bump(&mut self, memory_bump: u8) -> &mut Self {
318        self.instruction.memory_bump = Some(memory_bump);
319        self
320    }
321    /// Add an additional account to the instruction.
322    #[inline(always)]
323    pub fn add_remaining_account(
324        &mut self,
325        account: &'b solana_account_info::AccountInfo<'a>,
326        is_writable: bool,
327        is_signer: bool,
328    ) -> &mut Self {
329        self.instruction
330            .__remaining_accounts
331            .push((account, is_writable, is_signer));
332        self
333    }
334    /// Add additional accounts to the instruction.
335    ///
336    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
337    /// and a `bool` indicating whether the account is a signer or not.
338    #[inline(always)]
339    pub fn add_remaining_accounts(
340        &mut self,
341        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
342    ) -> &mut Self {
343        self.instruction
344            .__remaining_accounts
345            .extend_from_slice(accounts);
346        self
347    }
348    #[inline(always)]
349    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
350        self.invoke_signed(&[])
351    }
352    #[allow(clippy::clone_on_copy)]
353    #[allow(clippy::vec_init_then_push)]
354    pub fn invoke_signed(
355        &self,
356        signers_seeds: &[&[&[u8]]],
357    ) -> solana_program_entrypoint::ProgramResult {
358        let args = MemoryCloseInstructionArgs {
359            memory_id: self
360                .instruction
361                .memory_id
362                .clone()
363                .expect("memory_id is not set"),
364            memory_bump: self
365                .instruction
366                .memory_bump
367                .clone()
368                .expect("memory_bump is not set"),
369        };
370        let instruction = MemoryCloseCpi {
371            __program: self.instruction.__program,
372
373            program_id: self.instruction.program_id.expect("program_id is not set"),
374
375            payer: self.instruction.payer.expect("payer is not set"),
376
377            memory: self.instruction.memory.expect("memory is not set"),
378            __args: args,
379        };
380        instruction.invoke_signed_with_remaining_accounts(
381            signers_seeds,
382            &self.instruction.__remaining_accounts,
383        )
384    }
385}
386
387#[derive(Clone, Debug)]
388struct MemoryCloseCpiBuilderInstruction<'a, 'b> {
389    __program: &'b solana_account_info::AccountInfo<'a>,
390    program_id: Option<&'b solana_account_info::AccountInfo<'a>>,
391    payer: Option<&'b solana_account_info::AccountInfo<'a>>,
392    memory: Option<&'b solana_account_info::AccountInfo<'a>>,
393    memory_id: Option<u8>,
394    memory_bump: Option<u8>,
395    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
396    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
397}