Skip to main content

tensor_price_lock/generated/instructions/
create_nft_receipt.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/kinobi-so/kinobi>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct CreateNftReceipt {
13    pub payer: solana_program::pubkey::Pubkey,
14
15    pub asset: solana_program::pubkey::Pubkey,
16
17    pub order_state: solana_program::pubkey::Pubkey,
18
19    pub order_vault: solana_program::pubkey::Pubkey,
20
21    pub nft_deposit_receipt: solana_program::pubkey::Pubkey,
22
23    pub system_program: solana_program::pubkey::Pubkey,
24}
25
26impl CreateNftReceipt {
27    pub fn instruction(&self) -> solana_program::instruction::Instruction {
28        self.instruction_with_remaining_accounts(&[])
29    }
30    #[allow(clippy::vec_init_then_push)]
31    pub fn instruction_with_remaining_accounts(
32        &self,
33        remaining_accounts: &[solana_program::instruction::AccountMeta],
34    ) -> solana_program::instruction::Instruction {
35        let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
36        accounts.push(solana_program::instruction::AccountMeta::new(
37            self.payer, true,
38        ));
39        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
40            self.asset, false,
41        ));
42        accounts.push(solana_program::instruction::AccountMeta::new(
43            self.order_state,
44            false,
45        ));
46        accounts.push(solana_program::instruction::AccountMeta::new(
47            self.order_vault,
48            false,
49        ));
50        accounts.push(solana_program::instruction::AccountMeta::new(
51            self.nft_deposit_receipt,
52            false,
53        ));
54        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55            self.system_program,
56            false,
57        ));
58        accounts.extend_from_slice(remaining_accounts);
59        let data = CreateNftReceiptInstructionData::new().try_to_vec().unwrap();
60
61        solana_program::instruction::Instruction {
62            program_id: crate::TENSOR_PRICE_LOCK_ID,
63            accounts,
64            data,
65        }
66    }
67}
68
69#[derive(BorshDeserialize, BorshSerialize)]
70pub struct CreateNftReceiptInstructionData {
71    discriminator: [u8; 8],
72}
73
74impl CreateNftReceiptInstructionData {
75    pub fn new() -> Self {
76        Self {
77            discriminator: [102, 123, 79, 245, 103, 241, 107, 251],
78        }
79    }
80}
81
82impl Default for CreateNftReceiptInstructionData {
83    fn default() -> Self {
84        Self::new()
85    }
86}
87
88/// Instruction builder for `CreateNftReceipt`.
89///
90/// ### Accounts:
91///
92///   0. `[writable, signer]` payer
93///   1. `[]` asset
94///   2. `[writable]` order_state
95///   3. `[writable]` order_vault
96///   4. `[writable]` nft_deposit_receipt
97///   5. `[optional]` system_program (default to `11111111111111111111111111111111`)
98#[derive(Clone, Debug, Default)]
99pub struct CreateNftReceiptBuilder {
100    payer: Option<solana_program::pubkey::Pubkey>,
101    asset: Option<solana_program::pubkey::Pubkey>,
102    order_state: Option<solana_program::pubkey::Pubkey>,
103    order_vault: Option<solana_program::pubkey::Pubkey>,
104    nft_deposit_receipt: Option<solana_program::pubkey::Pubkey>,
105    system_program: Option<solana_program::pubkey::Pubkey>,
106    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
107}
108
109impl CreateNftReceiptBuilder {
110    pub fn new() -> Self {
111        Self::default()
112    }
113    #[inline(always)]
114    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
115        self.payer = Some(payer);
116        self
117    }
118    #[inline(always)]
119    pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
120        self.asset = Some(asset);
121        self
122    }
123    #[inline(always)]
124    pub fn order_state(&mut self, order_state: solana_program::pubkey::Pubkey) -> &mut Self {
125        self.order_state = Some(order_state);
126        self
127    }
128    #[inline(always)]
129    pub fn order_vault(&mut self, order_vault: solana_program::pubkey::Pubkey) -> &mut Self {
130        self.order_vault = Some(order_vault);
131        self
132    }
133    #[inline(always)]
134    pub fn nft_deposit_receipt(
135        &mut self,
136        nft_deposit_receipt: solana_program::pubkey::Pubkey,
137    ) -> &mut Self {
138        self.nft_deposit_receipt = Some(nft_deposit_receipt);
139        self
140    }
141    /// `[optional account, default to '11111111111111111111111111111111']`
142    #[inline(always)]
143    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
144        self.system_program = Some(system_program);
145        self
146    }
147    /// Add an aditional account to the instruction.
148    #[inline(always)]
149    pub fn add_remaining_account(
150        &mut self,
151        account: solana_program::instruction::AccountMeta,
152    ) -> &mut Self {
153        self.__remaining_accounts.push(account);
154        self
155    }
156    /// Add additional accounts to the instruction.
157    #[inline(always)]
158    pub fn add_remaining_accounts(
159        &mut self,
160        accounts: &[solana_program::instruction::AccountMeta],
161    ) -> &mut Self {
162        self.__remaining_accounts.extend_from_slice(accounts);
163        self
164    }
165    #[allow(clippy::clone_on_copy)]
166    pub fn instruction(&self) -> solana_program::instruction::Instruction {
167        let accounts = CreateNftReceipt {
168            payer: self.payer.expect("payer is not set"),
169            asset: self.asset.expect("asset is not set"),
170            order_state: self.order_state.expect("order_state is not set"),
171            order_vault: self.order_vault.expect("order_vault is not set"),
172            nft_deposit_receipt: self
173                .nft_deposit_receipt
174                .expect("nft_deposit_receipt is not set"),
175            system_program: self
176                .system_program
177                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
178        };
179
180        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
181    }
182}
183
184/// `create_nft_receipt` CPI accounts.
185pub struct CreateNftReceiptCpiAccounts<'a, 'b> {
186    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
187
188    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
189
190    pub order_state: &'b solana_program::account_info::AccountInfo<'a>,
191
192    pub order_vault: &'b solana_program::account_info::AccountInfo<'a>,
193
194    pub nft_deposit_receipt: &'b solana_program::account_info::AccountInfo<'a>,
195
196    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
197}
198
199/// `create_nft_receipt` CPI instruction.
200pub struct CreateNftReceiptCpi<'a, 'b> {
201    /// The program to invoke.
202    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
203
204    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
205
206    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
207
208    pub order_state: &'b solana_program::account_info::AccountInfo<'a>,
209
210    pub order_vault: &'b solana_program::account_info::AccountInfo<'a>,
211
212    pub nft_deposit_receipt: &'b solana_program::account_info::AccountInfo<'a>,
213
214    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
215}
216
217impl<'a, 'b> CreateNftReceiptCpi<'a, 'b> {
218    pub fn new(
219        program: &'b solana_program::account_info::AccountInfo<'a>,
220        accounts: CreateNftReceiptCpiAccounts<'a, 'b>,
221    ) -> Self {
222        Self {
223            __program: program,
224            payer: accounts.payer,
225            asset: accounts.asset,
226            order_state: accounts.order_state,
227            order_vault: accounts.order_vault,
228            nft_deposit_receipt: accounts.nft_deposit_receipt,
229            system_program: accounts.system_program,
230        }
231    }
232    #[inline(always)]
233    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
234        self.invoke_signed_with_remaining_accounts(&[], &[])
235    }
236    #[inline(always)]
237    pub fn invoke_with_remaining_accounts(
238        &self,
239        remaining_accounts: &[(
240            &'b solana_program::account_info::AccountInfo<'a>,
241            bool,
242            bool,
243        )],
244    ) -> solana_program::entrypoint::ProgramResult {
245        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
246    }
247    #[inline(always)]
248    pub fn invoke_signed(
249        &self,
250        signers_seeds: &[&[&[u8]]],
251    ) -> solana_program::entrypoint::ProgramResult {
252        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
253    }
254    #[allow(clippy::clone_on_copy)]
255    #[allow(clippy::vec_init_then_push)]
256    pub fn invoke_signed_with_remaining_accounts(
257        &self,
258        signers_seeds: &[&[&[u8]]],
259        remaining_accounts: &[(
260            &'b solana_program::account_info::AccountInfo<'a>,
261            bool,
262            bool,
263        )],
264    ) -> solana_program::entrypoint::ProgramResult {
265        let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
266        accounts.push(solana_program::instruction::AccountMeta::new(
267            *self.payer.key,
268            true,
269        ));
270        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
271            *self.asset.key,
272            false,
273        ));
274        accounts.push(solana_program::instruction::AccountMeta::new(
275            *self.order_state.key,
276            false,
277        ));
278        accounts.push(solana_program::instruction::AccountMeta::new(
279            *self.order_vault.key,
280            false,
281        ));
282        accounts.push(solana_program::instruction::AccountMeta::new(
283            *self.nft_deposit_receipt.key,
284            false,
285        ));
286        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
287            *self.system_program.key,
288            false,
289        ));
290        remaining_accounts.iter().for_each(|remaining_account| {
291            accounts.push(solana_program::instruction::AccountMeta {
292                pubkey: *remaining_account.0.key,
293                is_signer: remaining_account.1,
294                is_writable: remaining_account.2,
295            })
296        });
297        let data = CreateNftReceiptInstructionData::new().try_to_vec().unwrap();
298
299        let instruction = solana_program::instruction::Instruction {
300            program_id: crate::TENSOR_PRICE_LOCK_ID,
301            accounts,
302            data,
303        };
304        let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
305        account_infos.push(self.__program.clone());
306        account_infos.push(self.payer.clone());
307        account_infos.push(self.asset.clone());
308        account_infos.push(self.order_state.clone());
309        account_infos.push(self.order_vault.clone());
310        account_infos.push(self.nft_deposit_receipt.clone());
311        account_infos.push(self.system_program.clone());
312        remaining_accounts
313            .iter()
314            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
315
316        if signers_seeds.is_empty() {
317            solana_program::program::invoke(&instruction, &account_infos)
318        } else {
319            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
320        }
321    }
322}
323
324/// Instruction builder for `CreateNftReceipt` via CPI.
325///
326/// ### Accounts:
327///
328///   0. `[writable, signer]` payer
329///   1. `[]` asset
330///   2. `[writable]` order_state
331///   3. `[writable]` order_vault
332///   4. `[writable]` nft_deposit_receipt
333///   5. `[]` system_program
334#[derive(Clone, Debug)]
335pub struct CreateNftReceiptCpiBuilder<'a, 'b> {
336    instruction: Box<CreateNftReceiptCpiBuilderInstruction<'a, 'b>>,
337}
338
339impl<'a, 'b> CreateNftReceiptCpiBuilder<'a, 'b> {
340    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
341        let instruction = Box::new(CreateNftReceiptCpiBuilderInstruction {
342            __program: program,
343            payer: None,
344            asset: None,
345            order_state: None,
346            order_vault: None,
347            nft_deposit_receipt: None,
348            system_program: None,
349            __remaining_accounts: Vec::new(),
350        });
351        Self { instruction }
352    }
353    #[inline(always)]
354    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
355        self.instruction.payer = Some(payer);
356        self
357    }
358    #[inline(always)]
359    pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
360        self.instruction.asset = Some(asset);
361        self
362    }
363    #[inline(always)]
364    pub fn order_state(
365        &mut self,
366        order_state: &'b solana_program::account_info::AccountInfo<'a>,
367    ) -> &mut Self {
368        self.instruction.order_state = Some(order_state);
369        self
370    }
371    #[inline(always)]
372    pub fn order_vault(
373        &mut self,
374        order_vault: &'b solana_program::account_info::AccountInfo<'a>,
375    ) -> &mut Self {
376        self.instruction.order_vault = Some(order_vault);
377        self
378    }
379    #[inline(always)]
380    pub fn nft_deposit_receipt(
381        &mut self,
382        nft_deposit_receipt: &'b solana_program::account_info::AccountInfo<'a>,
383    ) -> &mut Self {
384        self.instruction.nft_deposit_receipt = Some(nft_deposit_receipt);
385        self
386    }
387    #[inline(always)]
388    pub fn system_program(
389        &mut self,
390        system_program: &'b solana_program::account_info::AccountInfo<'a>,
391    ) -> &mut Self {
392        self.instruction.system_program = Some(system_program);
393        self
394    }
395    /// Add an additional account to the instruction.
396    #[inline(always)]
397    pub fn add_remaining_account(
398        &mut self,
399        account: &'b solana_program::account_info::AccountInfo<'a>,
400        is_writable: bool,
401        is_signer: bool,
402    ) -> &mut Self {
403        self.instruction
404            .__remaining_accounts
405            .push((account, is_writable, is_signer));
406        self
407    }
408    /// Add additional accounts to the instruction.
409    ///
410    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
411    /// and a `bool` indicating whether the account is a signer or not.
412    #[inline(always)]
413    pub fn add_remaining_accounts(
414        &mut self,
415        accounts: &[(
416            &'b solana_program::account_info::AccountInfo<'a>,
417            bool,
418            bool,
419        )],
420    ) -> &mut Self {
421        self.instruction
422            .__remaining_accounts
423            .extend_from_slice(accounts);
424        self
425    }
426    #[inline(always)]
427    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
428        self.invoke_signed(&[])
429    }
430    #[allow(clippy::clone_on_copy)]
431    #[allow(clippy::vec_init_then_push)]
432    pub fn invoke_signed(
433        &self,
434        signers_seeds: &[&[&[u8]]],
435    ) -> solana_program::entrypoint::ProgramResult {
436        let instruction = CreateNftReceiptCpi {
437            __program: self.instruction.__program,
438
439            payer: self.instruction.payer.expect("payer is not set"),
440
441            asset: self.instruction.asset.expect("asset is not set"),
442
443            order_state: self
444                .instruction
445                .order_state
446                .expect("order_state is not set"),
447
448            order_vault: self
449                .instruction
450                .order_vault
451                .expect("order_vault is not set"),
452
453            nft_deposit_receipt: self
454                .instruction
455                .nft_deposit_receipt
456                .expect("nft_deposit_receipt is not set"),
457
458            system_program: self
459                .instruction
460                .system_program
461                .expect("system_program is not set"),
462        };
463        instruction.invoke_signed_with_remaining_accounts(
464            signers_seeds,
465            &self.instruction.__remaining_accounts,
466        )
467    }
468}
469
470#[derive(Clone, Debug)]
471struct CreateNftReceiptCpiBuilderInstruction<'a, 'b> {
472    __program: &'b solana_program::account_info::AccountInfo<'a>,
473    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
474    asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
475    order_state: Option<&'b solana_program::account_info::AccountInfo<'a>>,
476    order_vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
477    nft_deposit_receipt: Option<&'b solana_program::account_info::AccountInfo<'a>>,
478    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
479    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
480    __remaining_accounts: Vec<(
481        &'b solana_program::account_info::AccountInfo<'a>,
482        bool,
483        bool,
484    )>,
485}