lighthouse_sdk/generated/instructions/
memory_close.rs

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