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