tensor_amm/generated/instructions/
buy_nft.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 crate::generated::types::AuthorizationDataLocal;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13pub struct BuyNft {
14    /// The owner of the pool and the buyer/recipient of the NFT.
15    pub owner: solana_program::pubkey::Pubkey,
16    /// The taker is the user buying or selling the NFT.
17    pub taker: solana_program::pubkey::Pubkey,
18    /// The original rent payer of the pool--stored on the pool. Used to refund rent in case the pool
19    /// is auto-closed.
20    pub rent_payer: solana_program::pubkey::Pubkey,
21    /// Fee vault account owned by the TFEE program.
22    pub fee_vault: solana_program::pubkey::Pubkey,
23    /// The Pool state account that the NFT is being sold into. Stores pool state and config,
24    /// but is also the owner of any NFTs in the pool, and also escrows any SOL.
25    /// Any active pool can be specified provided it is a Token type and the NFT passes at least one
26    /// whitelist condition.
27    pub pool: solana_program::pubkey::Pubkey,
28    /// The whitelist account that the pool uses to verify the NFTs being sold into it.
29    pub whitelist: Option<solana_program::pubkey::Pubkey>,
30    /// Optional account which must be passed in if the NFT must be verified against a
31    /// merkle proof condition in the whitelist.
32    pub mint_proof: Option<solana_program::pubkey::Pubkey>,
33    /// The shared escrow account for pools that have liquidity in a shared account.
34    pub shared_escrow: Option<solana_program::pubkey::Pubkey>,
35    /// The account that receives the maker broker fee.
36    pub maker_broker: Option<solana_program::pubkey::Pubkey>,
37    /// The account that receives the taker broker fee.
38    pub taker_broker: Option<solana_program::pubkey::Pubkey>,
39    /// The optional cosigner account that must be passed in if the pool has a cosigner.
40    pub cosigner: Option<solana_program::pubkey::Pubkey>,
41    /// The AMM program account, used for self-cpi logging.
42    pub amm_program: solana_program::pubkey::Pubkey,
43    /// The escrow program account for shared liquidity pools.
44    pub escrow_program: Option<solana_program::pubkey::Pubkey>,
45
46    pub native_program: solana_program::pubkey::Pubkey,
47    /// The mint account of the NFT.
48    pub mint: solana_program::pubkey::Pubkey,
49    /// The Token Metadata metadata account of the NFT.
50    pub metadata: solana_program::pubkey::Pubkey,
51    /// The Token Metadata edition account of the NFT.
52    pub edition: solana_program::pubkey::Pubkey,
53    /// The Token Metadata source token record account of the NFT.
54    pub user_token_record: Option<solana_program::pubkey::Pubkey>,
55    /// The Token Metadata token record for the destination.
56    pub pool_token_record: Option<solana_program::pubkey::Pubkey>,
57    /// The Token Metadata program account.
58    pub token_metadata_program: Option<solana_program::pubkey::Pubkey>,
59    /// The sysvar instructions account.
60    pub sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
61    /// The Metaplex Token Authority Rules account that stores royalty enforcement rules.
62    pub authorization_rules: Option<solana_program::pubkey::Pubkey>,
63    /// The Metaplex Token Authority Rules program account.
64    pub authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
65    /// The NFT deposit receipt, which ties an NFT to the pool it was deposited to.
66    pub nft_receipt: solana_program::pubkey::Pubkey,
67    /// The TA of the buyer, where the NFT will be transferred.
68    pub taker_ta: solana_program::pubkey::Pubkey,
69    /// The TA of the pool, where the NFT is held.
70    pub pool_ta: solana_program::pubkey::Pubkey,
71    /// Either the legacy token program or token-2022.
72    pub token_program: solana_program::pubkey::Pubkey,
73    /// The SPL associated token program.
74    pub associated_token_program: solana_program::pubkey::Pubkey,
75    /// The Solana system program.
76    pub system_program: solana_program::pubkey::Pubkey,
77}
78
79impl BuyNft {
80    pub fn instruction(
81        &self,
82        args: BuyNftInstructionArgs,
83    ) -> solana_program::instruction::Instruction {
84        self.instruction_with_remaining_accounts(args, &[])
85    }
86    #[allow(clippy::vec_init_then_push)]
87    pub fn instruction_with_remaining_accounts(
88        &self,
89        args: BuyNftInstructionArgs,
90        remaining_accounts: &[solana_program::instruction::AccountMeta],
91    ) -> solana_program::instruction::Instruction {
92        let mut accounts = Vec::with_capacity(29 + remaining_accounts.len());
93        accounts.push(solana_program::instruction::AccountMeta::new(
94            self.owner, false,
95        ));
96        accounts.push(solana_program::instruction::AccountMeta::new(
97            self.taker, true,
98        ));
99        accounts.push(solana_program::instruction::AccountMeta::new(
100            self.rent_payer,
101            false,
102        ));
103        accounts.push(solana_program::instruction::AccountMeta::new(
104            self.fee_vault,
105            false,
106        ));
107        accounts.push(solana_program::instruction::AccountMeta::new(
108            self.pool, false,
109        ));
110        if let Some(whitelist) = self.whitelist {
111            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
112                whitelist, false,
113            ));
114        } else {
115            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
116                crate::TENSOR_AMM_ID,
117                false,
118            ));
119        }
120        if let Some(mint_proof) = self.mint_proof {
121            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
122                mint_proof, false,
123            ));
124        } else {
125            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
126                crate::TENSOR_AMM_ID,
127                false,
128            ));
129        }
130        if let Some(shared_escrow) = self.shared_escrow {
131            accounts.push(solana_program::instruction::AccountMeta::new(
132                shared_escrow,
133                false,
134            ));
135        } else {
136            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
137                crate::TENSOR_AMM_ID,
138                false,
139            ));
140        }
141        if let Some(maker_broker) = self.maker_broker {
142            accounts.push(solana_program::instruction::AccountMeta::new(
143                maker_broker,
144                false,
145            ));
146        } else {
147            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
148                crate::TENSOR_AMM_ID,
149                false,
150            ));
151        }
152        if let Some(taker_broker) = self.taker_broker {
153            accounts.push(solana_program::instruction::AccountMeta::new(
154                taker_broker,
155                false,
156            ));
157        } else {
158            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
159                crate::TENSOR_AMM_ID,
160                false,
161            ));
162        }
163        if let Some(cosigner) = self.cosigner {
164            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
165                cosigner, true,
166            ));
167        } else {
168            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
169                crate::TENSOR_AMM_ID,
170                false,
171            ));
172        }
173        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
174            self.amm_program,
175            false,
176        ));
177        if let Some(escrow_program) = self.escrow_program {
178            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
179                escrow_program,
180                false,
181            ));
182        } else {
183            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
184                crate::TENSOR_AMM_ID,
185                false,
186            ));
187        }
188        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
189            self.native_program,
190            false,
191        ));
192        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
193            self.mint, false,
194        ));
195        accounts.push(solana_program::instruction::AccountMeta::new(
196            self.metadata,
197            false,
198        ));
199        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
200            self.edition,
201            false,
202        ));
203        if let Some(user_token_record) = self.user_token_record {
204            accounts.push(solana_program::instruction::AccountMeta::new(
205                user_token_record,
206                false,
207            ));
208        } else {
209            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
210                crate::TENSOR_AMM_ID,
211                false,
212            ));
213        }
214        if let Some(pool_token_record) = self.pool_token_record {
215            accounts.push(solana_program::instruction::AccountMeta::new(
216                pool_token_record,
217                false,
218            ));
219        } else {
220            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
221                crate::TENSOR_AMM_ID,
222                false,
223            ));
224        }
225        if let Some(token_metadata_program) = self.token_metadata_program {
226            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
227                token_metadata_program,
228                false,
229            ));
230        } else {
231            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
232                crate::TENSOR_AMM_ID,
233                false,
234            ));
235        }
236        if let Some(sysvar_instructions) = self.sysvar_instructions {
237            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
238                sysvar_instructions,
239                false,
240            ));
241        } else {
242            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
243                crate::TENSOR_AMM_ID,
244                false,
245            ));
246        }
247        if let Some(authorization_rules) = self.authorization_rules {
248            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
249                authorization_rules,
250                false,
251            ));
252        } else {
253            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
254                crate::TENSOR_AMM_ID,
255                false,
256            ));
257        }
258        if let Some(authorization_rules_program) = self.authorization_rules_program {
259            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
260                authorization_rules_program,
261                false,
262            ));
263        } else {
264            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
265                crate::TENSOR_AMM_ID,
266                false,
267            ));
268        }
269        accounts.push(solana_program::instruction::AccountMeta::new(
270            self.nft_receipt,
271            false,
272        ));
273        accounts.push(solana_program::instruction::AccountMeta::new(
274            self.taker_ta,
275            false,
276        ));
277        accounts.push(solana_program::instruction::AccountMeta::new(
278            self.pool_ta,
279            false,
280        ));
281        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
282            self.token_program,
283            false,
284        ));
285        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
286            self.associated_token_program,
287            false,
288        ));
289        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
290            self.system_program,
291            false,
292        ));
293        accounts.extend_from_slice(remaining_accounts);
294        let mut data = BuyNftInstructionData::new().try_to_vec().unwrap();
295        let mut args = args.try_to_vec().unwrap();
296        data.append(&mut args);
297
298        solana_program::instruction::Instruction {
299            program_id: crate::TENSOR_AMM_ID,
300            accounts,
301            data,
302        }
303    }
304}
305
306#[derive(BorshDeserialize, BorshSerialize)]
307pub struct BuyNftInstructionData {
308    discriminator: [u8; 8],
309}
310
311impl BuyNftInstructionData {
312    pub fn new() -> Self {
313        Self {
314            discriminator: [96, 0, 28, 190, 49, 107, 83, 222],
315        }
316    }
317}
318
319impl Default for BuyNftInstructionData {
320    fn default() -> Self {
321        Self::new()
322    }
323}
324
325#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
326#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
327pub struct BuyNftInstructionArgs {
328    pub max_amount: u64,
329    pub authorization_data: Option<AuthorizationDataLocal>,
330    pub optional_royalty_pct: Option<u16>,
331}
332
333/// Instruction builder for `BuyNft`.
334///
335/// ### Accounts:
336///
337///   0. `[writable]` owner
338///   1. `[writable, signer]` taker
339///   2. `[writable]` rent_payer
340///   3. `[writable]` fee_vault
341///   4. `[writable]` pool
342///   5. `[optional]` whitelist
343///   6. `[optional]` mint_proof
344///   7. `[writable, optional]` shared_escrow
345///   8. `[writable, optional]` maker_broker
346///   9. `[writable, optional]` taker_broker
347///   10. `[signer, optional]` cosigner
348///   11. `[optional]` amm_program (default to `TAMM6ub33ij1mbetoMyVBLeKY5iP41i4UPUJQGkhfsg`)
349///   12. `[optional]` escrow_program
350///   13. `[optional]` native_program (default to `11111111111111111111111111111111`)
351///   14. `[]` mint
352///   15. `[writable]` metadata
353///   16. `[]` edition
354///   17. `[writable, optional]` user_token_record
355///   18. `[writable, optional]` pool_token_record
356///   19. `[optional]` token_metadata_program
357///   20. `[optional]` sysvar_instructions
358///   21. `[optional]` authorization_rules
359///   22. `[optional]` authorization_rules_program
360///   23. `[writable]` nft_receipt
361///   24. `[writable]` taker_ta
362///   25. `[writable]` pool_ta
363///   26. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
364///   27. `[optional]` associated_token_program (default to `ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`)
365///   28. `[optional]` system_program (default to `11111111111111111111111111111111`)
366#[derive(Clone, Debug, Default)]
367pub struct BuyNftBuilder {
368    owner: Option<solana_program::pubkey::Pubkey>,
369    taker: Option<solana_program::pubkey::Pubkey>,
370    rent_payer: Option<solana_program::pubkey::Pubkey>,
371    fee_vault: Option<solana_program::pubkey::Pubkey>,
372    pool: Option<solana_program::pubkey::Pubkey>,
373    whitelist: Option<solana_program::pubkey::Pubkey>,
374    mint_proof: Option<solana_program::pubkey::Pubkey>,
375    shared_escrow: Option<solana_program::pubkey::Pubkey>,
376    maker_broker: Option<solana_program::pubkey::Pubkey>,
377    taker_broker: Option<solana_program::pubkey::Pubkey>,
378    cosigner: Option<solana_program::pubkey::Pubkey>,
379    amm_program: Option<solana_program::pubkey::Pubkey>,
380    escrow_program: Option<solana_program::pubkey::Pubkey>,
381    native_program: Option<solana_program::pubkey::Pubkey>,
382    mint: Option<solana_program::pubkey::Pubkey>,
383    metadata: Option<solana_program::pubkey::Pubkey>,
384    edition: Option<solana_program::pubkey::Pubkey>,
385    user_token_record: Option<solana_program::pubkey::Pubkey>,
386    pool_token_record: Option<solana_program::pubkey::Pubkey>,
387    token_metadata_program: Option<solana_program::pubkey::Pubkey>,
388    sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
389    authorization_rules: Option<solana_program::pubkey::Pubkey>,
390    authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
391    nft_receipt: Option<solana_program::pubkey::Pubkey>,
392    taker_ta: Option<solana_program::pubkey::Pubkey>,
393    pool_ta: Option<solana_program::pubkey::Pubkey>,
394    token_program: Option<solana_program::pubkey::Pubkey>,
395    associated_token_program: Option<solana_program::pubkey::Pubkey>,
396    system_program: Option<solana_program::pubkey::Pubkey>,
397    max_amount: Option<u64>,
398    authorization_data: Option<AuthorizationDataLocal>,
399    optional_royalty_pct: Option<u16>,
400    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
401}
402
403impl BuyNftBuilder {
404    pub fn new() -> Self {
405        Self::default()
406    }
407    /// The owner of the pool and the buyer/recipient of the NFT.
408    #[inline(always)]
409    pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
410        self.owner = Some(owner);
411        self
412    }
413    /// The taker is the user buying or selling the NFT.
414    #[inline(always)]
415    pub fn taker(&mut self, taker: solana_program::pubkey::Pubkey) -> &mut Self {
416        self.taker = Some(taker);
417        self
418    }
419    /// The original rent payer of the pool--stored on the pool. Used to refund rent in case the pool
420    /// is auto-closed.
421    #[inline(always)]
422    pub fn rent_payer(&mut self, rent_payer: solana_program::pubkey::Pubkey) -> &mut Self {
423        self.rent_payer = Some(rent_payer);
424        self
425    }
426    /// Fee vault account owned by the TFEE program.
427    #[inline(always)]
428    pub fn fee_vault(&mut self, fee_vault: solana_program::pubkey::Pubkey) -> &mut Self {
429        self.fee_vault = Some(fee_vault);
430        self
431    }
432    /// The Pool state account that the NFT is being sold into. Stores pool state and config,
433    /// but is also the owner of any NFTs in the pool, and also escrows any SOL.
434    /// Any active pool can be specified provided it is a Token type and the NFT passes at least one
435    /// whitelist condition.
436    #[inline(always)]
437    pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
438        self.pool = Some(pool);
439        self
440    }
441    /// `[optional account]`
442    /// The whitelist account that the pool uses to verify the NFTs being sold into it.
443    #[inline(always)]
444    pub fn whitelist(&mut self, whitelist: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
445        self.whitelist = whitelist;
446        self
447    }
448    /// `[optional account]`
449    /// Optional account which must be passed in if the NFT must be verified against a
450    /// merkle proof condition in the whitelist.
451    #[inline(always)]
452    pub fn mint_proof(&mut self, mint_proof: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
453        self.mint_proof = mint_proof;
454        self
455    }
456    /// `[optional account]`
457    /// The shared escrow account for pools that have liquidity in a shared account.
458    #[inline(always)]
459    pub fn shared_escrow(
460        &mut self,
461        shared_escrow: Option<solana_program::pubkey::Pubkey>,
462    ) -> &mut Self {
463        self.shared_escrow = shared_escrow;
464        self
465    }
466    /// `[optional account]`
467    /// The account that receives the maker broker fee.
468    #[inline(always)]
469    pub fn maker_broker(
470        &mut self,
471        maker_broker: Option<solana_program::pubkey::Pubkey>,
472    ) -> &mut Self {
473        self.maker_broker = maker_broker;
474        self
475    }
476    /// `[optional account]`
477    /// The account that receives the taker broker fee.
478    #[inline(always)]
479    pub fn taker_broker(
480        &mut self,
481        taker_broker: Option<solana_program::pubkey::Pubkey>,
482    ) -> &mut Self {
483        self.taker_broker = taker_broker;
484        self
485    }
486    /// `[optional account]`
487    /// The optional cosigner account that must be passed in if the pool has a cosigner.
488    #[inline(always)]
489    pub fn cosigner(&mut self, cosigner: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
490        self.cosigner = cosigner;
491        self
492    }
493    /// `[optional account, default to 'TAMM6ub33ij1mbetoMyVBLeKY5iP41i4UPUJQGkhfsg']`
494    /// The AMM program account, used for self-cpi logging.
495    #[inline(always)]
496    pub fn amm_program(&mut self, amm_program: solana_program::pubkey::Pubkey) -> &mut Self {
497        self.amm_program = Some(amm_program);
498        self
499    }
500    /// `[optional account]`
501    /// The escrow program account for shared liquidity pools.
502    #[inline(always)]
503    pub fn escrow_program(
504        &mut self,
505        escrow_program: Option<solana_program::pubkey::Pubkey>,
506    ) -> &mut Self {
507        self.escrow_program = escrow_program;
508        self
509    }
510    /// `[optional account, default to '11111111111111111111111111111111']`
511    #[inline(always)]
512    pub fn native_program(&mut self, native_program: solana_program::pubkey::Pubkey) -> &mut Self {
513        self.native_program = Some(native_program);
514        self
515    }
516    /// The mint account of the NFT.
517    #[inline(always)]
518    pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
519        self.mint = Some(mint);
520        self
521    }
522    /// The Token Metadata metadata account of the NFT.
523    #[inline(always)]
524    pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
525        self.metadata = Some(metadata);
526        self
527    }
528    /// The Token Metadata edition account of the NFT.
529    #[inline(always)]
530    pub fn edition(&mut self, edition: solana_program::pubkey::Pubkey) -> &mut Self {
531        self.edition = Some(edition);
532        self
533    }
534    /// `[optional account]`
535    /// The Token Metadata source token record account of the NFT.
536    #[inline(always)]
537    pub fn user_token_record(
538        &mut self,
539        user_token_record: Option<solana_program::pubkey::Pubkey>,
540    ) -> &mut Self {
541        self.user_token_record = user_token_record;
542        self
543    }
544    /// `[optional account]`
545    /// The Token Metadata token record for the destination.
546    #[inline(always)]
547    pub fn pool_token_record(
548        &mut self,
549        pool_token_record: Option<solana_program::pubkey::Pubkey>,
550    ) -> &mut Self {
551        self.pool_token_record = pool_token_record;
552        self
553    }
554    /// `[optional account]`
555    /// The Token Metadata program account.
556    #[inline(always)]
557    pub fn token_metadata_program(
558        &mut self,
559        token_metadata_program: Option<solana_program::pubkey::Pubkey>,
560    ) -> &mut Self {
561        self.token_metadata_program = token_metadata_program;
562        self
563    }
564    /// `[optional account]`
565    /// The sysvar instructions account.
566    #[inline(always)]
567    pub fn sysvar_instructions(
568        &mut self,
569        sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
570    ) -> &mut Self {
571        self.sysvar_instructions = sysvar_instructions;
572        self
573    }
574    /// `[optional account]`
575    /// The Metaplex Token Authority Rules account that stores royalty enforcement rules.
576    #[inline(always)]
577    pub fn authorization_rules(
578        &mut self,
579        authorization_rules: Option<solana_program::pubkey::Pubkey>,
580    ) -> &mut Self {
581        self.authorization_rules = authorization_rules;
582        self
583    }
584    /// `[optional account]`
585    /// The Metaplex Token Authority Rules program account.
586    #[inline(always)]
587    pub fn authorization_rules_program(
588        &mut self,
589        authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
590    ) -> &mut Self {
591        self.authorization_rules_program = authorization_rules_program;
592        self
593    }
594    /// The NFT deposit receipt, which ties an NFT to the pool it was deposited to.
595    #[inline(always)]
596    pub fn nft_receipt(&mut self, nft_receipt: solana_program::pubkey::Pubkey) -> &mut Self {
597        self.nft_receipt = Some(nft_receipt);
598        self
599    }
600    /// The TA of the buyer, where the NFT will be transferred.
601    #[inline(always)]
602    pub fn taker_ta(&mut self, taker_ta: solana_program::pubkey::Pubkey) -> &mut Self {
603        self.taker_ta = Some(taker_ta);
604        self
605    }
606    /// The TA of the pool, where the NFT is held.
607    #[inline(always)]
608    pub fn pool_ta(&mut self, pool_ta: solana_program::pubkey::Pubkey) -> &mut Self {
609        self.pool_ta = Some(pool_ta);
610        self
611    }
612    /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']`
613    /// Either the legacy token program or token-2022.
614    #[inline(always)]
615    pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
616        self.token_program = Some(token_program);
617        self
618    }
619    /// `[optional account, default to 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL']`
620    /// The SPL associated token program.
621    #[inline(always)]
622    pub fn associated_token_program(
623        &mut self,
624        associated_token_program: solana_program::pubkey::Pubkey,
625    ) -> &mut Self {
626        self.associated_token_program = Some(associated_token_program);
627        self
628    }
629    /// `[optional account, default to '11111111111111111111111111111111']`
630    /// The Solana system program.
631    #[inline(always)]
632    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
633        self.system_program = Some(system_program);
634        self
635    }
636    #[inline(always)]
637    pub fn max_amount(&mut self, max_amount: u64) -> &mut Self {
638        self.max_amount = Some(max_amount);
639        self
640    }
641    /// `[optional argument]`
642    #[inline(always)]
643    pub fn authorization_data(&mut self, authorization_data: AuthorizationDataLocal) -> &mut Self {
644        self.authorization_data = Some(authorization_data);
645        self
646    }
647    /// `[optional argument]`
648    #[inline(always)]
649    pub fn optional_royalty_pct(&mut self, optional_royalty_pct: u16) -> &mut Self {
650        self.optional_royalty_pct = Some(optional_royalty_pct);
651        self
652    }
653    /// Add an additional account to the instruction.
654    #[inline(always)]
655    pub fn add_remaining_account(
656        &mut self,
657        account: solana_program::instruction::AccountMeta,
658    ) -> &mut Self {
659        self.__remaining_accounts.push(account);
660        self
661    }
662    /// Add additional accounts to the instruction.
663    #[inline(always)]
664    pub fn add_remaining_accounts(
665        &mut self,
666        accounts: &[solana_program::instruction::AccountMeta],
667    ) -> &mut Self {
668        self.__remaining_accounts.extend_from_slice(accounts);
669        self
670    }
671    #[allow(clippy::clone_on_copy)]
672    pub fn instruction(&self) -> solana_program::instruction::Instruction {
673        let accounts = BuyNft {
674            owner: self.owner.expect("owner is not set"),
675            taker: self.taker.expect("taker is not set"),
676            rent_payer: self.rent_payer.expect("rent_payer is not set"),
677            fee_vault: self.fee_vault.expect("fee_vault is not set"),
678            pool: self.pool.expect("pool is not set"),
679            whitelist: self.whitelist,
680            mint_proof: self.mint_proof,
681            shared_escrow: self.shared_escrow,
682            maker_broker: self.maker_broker,
683            taker_broker: self.taker_broker,
684            cosigner: self.cosigner,
685            amm_program: self.amm_program.unwrap_or(solana_program::pubkey!(
686                "TAMM6ub33ij1mbetoMyVBLeKY5iP41i4UPUJQGkhfsg"
687            )),
688            escrow_program: self.escrow_program,
689            native_program: self
690                .native_program
691                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
692            mint: self.mint.expect("mint is not set"),
693            metadata: self.metadata.expect("metadata is not set"),
694            edition: self.edition.expect("edition is not set"),
695            user_token_record: self.user_token_record,
696            pool_token_record: self.pool_token_record,
697            token_metadata_program: self.token_metadata_program,
698            sysvar_instructions: self.sysvar_instructions,
699            authorization_rules: self.authorization_rules,
700            authorization_rules_program: self.authorization_rules_program,
701            nft_receipt: self.nft_receipt.expect("nft_receipt is not set"),
702            taker_ta: self.taker_ta.expect("taker_ta is not set"),
703            pool_ta: self.pool_ta.expect("pool_ta is not set"),
704            token_program: self.token_program.unwrap_or(solana_program::pubkey!(
705                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
706            )),
707            associated_token_program: self.associated_token_program.unwrap_or(
708                solana_program::pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"),
709            ),
710            system_program: self
711                .system_program
712                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
713        };
714        let args = BuyNftInstructionArgs {
715            max_amount: self.max_amount.clone().expect("max_amount is not set"),
716            authorization_data: self.authorization_data.clone(),
717            optional_royalty_pct: self.optional_royalty_pct.clone(),
718        };
719
720        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
721    }
722}
723
724/// `buy_nft` CPI accounts.
725pub struct BuyNftCpiAccounts<'a, 'b> {
726    /// The owner of the pool and the buyer/recipient of the NFT.
727    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
728    /// The taker is the user buying or selling the NFT.
729    pub taker: &'b solana_program::account_info::AccountInfo<'a>,
730    /// The original rent payer of the pool--stored on the pool. Used to refund rent in case the pool
731    /// is auto-closed.
732    pub rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
733    /// Fee vault account owned by the TFEE program.
734    pub fee_vault: &'b solana_program::account_info::AccountInfo<'a>,
735    /// The Pool state account that the NFT is being sold into. Stores pool state and config,
736    /// but is also the owner of any NFTs in the pool, and also escrows any SOL.
737    /// Any active pool can be specified provided it is a Token type and the NFT passes at least one
738    /// whitelist condition.
739    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
740    /// The whitelist account that the pool uses to verify the NFTs being sold into it.
741    pub whitelist: Option<&'b solana_program::account_info::AccountInfo<'a>>,
742    /// Optional account which must be passed in if the NFT must be verified against a
743    /// merkle proof condition in the whitelist.
744    pub mint_proof: Option<&'b solana_program::account_info::AccountInfo<'a>>,
745    /// The shared escrow account for pools that have liquidity in a shared account.
746    pub shared_escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
747    /// The account that receives the maker broker fee.
748    pub maker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
749    /// The account that receives the taker broker fee.
750    pub taker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
751    /// The optional cosigner account that must be passed in if the pool has a cosigner.
752    pub cosigner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
753    /// The AMM program account, used for self-cpi logging.
754    pub amm_program: &'b solana_program::account_info::AccountInfo<'a>,
755    /// The escrow program account for shared liquidity pools.
756    pub escrow_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
757
758    pub native_program: &'b solana_program::account_info::AccountInfo<'a>,
759    /// The mint account of the NFT.
760    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
761    /// The Token Metadata metadata account of the NFT.
762    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
763    /// The Token Metadata edition account of the NFT.
764    pub edition: &'b solana_program::account_info::AccountInfo<'a>,
765    /// The Token Metadata source token record account of the NFT.
766    pub user_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
767    /// The Token Metadata token record for the destination.
768    pub pool_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
769    /// The Token Metadata program account.
770    pub token_metadata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
771    /// The sysvar instructions account.
772    pub sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
773    /// The Metaplex Token Authority Rules account that stores royalty enforcement rules.
774    pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
775    /// The Metaplex Token Authority Rules program account.
776    pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
777    /// The NFT deposit receipt, which ties an NFT to the pool it was deposited to.
778    pub nft_receipt: &'b solana_program::account_info::AccountInfo<'a>,
779    /// The TA of the buyer, where the NFT will be transferred.
780    pub taker_ta: &'b solana_program::account_info::AccountInfo<'a>,
781    /// The TA of the pool, where the NFT is held.
782    pub pool_ta: &'b solana_program::account_info::AccountInfo<'a>,
783    /// Either the legacy token program or token-2022.
784    pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
785    /// The SPL associated token program.
786    pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
787    /// The Solana system program.
788    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
789}
790
791/// `buy_nft` CPI instruction.
792pub struct BuyNftCpi<'a, 'b> {
793    /// The program to invoke.
794    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
795    /// The owner of the pool and the buyer/recipient of the NFT.
796    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
797    /// The taker is the user buying or selling the NFT.
798    pub taker: &'b solana_program::account_info::AccountInfo<'a>,
799    /// The original rent payer of the pool--stored on the pool. Used to refund rent in case the pool
800    /// is auto-closed.
801    pub rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
802    /// Fee vault account owned by the TFEE program.
803    pub fee_vault: &'b solana_program::account_info::AccountInfo<'a>,
804    /// The Pool state account that the NFT is being sold into. Stores pool state and config,
805    /// but is also the owner of any NFTs in the pool, and also escrows any SOL.
806    /// Any active pool can be specified provided it is a Token type and the NFT passes at least one
807    /// whitelist condition.
808    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
809    /// The whitelist account that the pool uses to verify the NFTs being sold into it.
810    pub whitelist: Option<&'b solana_program::account_info::AccountInfo<'a>>,
811    /// Optional account which must be passed in if the NFT must be verified against a
812    /// merkle proof condition in the whitelist.
813    pub mint_proof: Option<&'b solana_program::account_info::AccountInfo<'a>>,
814    /// The shared escrow account for pools that have liquidity in a shared account.
815    pub shared_escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
816    /// The account that receives the maker broker fee.
817    pub maker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
818    /// The account that receives the taker broker fee.
819    pub taker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
820    /// The optional cosigner account that must be passed in if the pool has a cosigner.
821    pub cosigner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
822    /// The AMM program account, used for self-cpi logging.
823    pub amm_program: &'b solana_program::account_info::AccountInfo<'a>,
824    /// The escrow program account for shared liquidity pools.
825    pub escrow_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
826
827    pub native_program: &'b solana_program::account_info::AccountInfo<'a>,
828    /// The mint account of the NFT.
829    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
830    /// The Token Metadata metadata account of the NFT.
831    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
832    /// The Token Metadata edition account of the NFT.
833    pub edition: &'b solana_program::account_info::AccountInfo<'a>,
834    /// The Token Metadata source token record account of the NFT.
835    pub user_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
836    /// The Token Metadata token record for the destination.
837    pub pool_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
838    /// The Token Metadata program account.
839    pub token_metadata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
840    /// The sysvar instructions account.
841    pub sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
842    /// The Metaplex Token Authority Rules account that stores royalty enforcement rules.
843    pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
844    /// The Metaplex Token Authority Rules program account.
845    pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
846    /// The NFT deposit receipt, which ties an NFT to the pool it was deposited to.
847    pub nft_receipt: &'b solana_program::account_info::AccountInfo<'a>,
848    /// The TA of the buyer, where the NFT will be transferred.
849    pub taker_ta: &'b solana_program::account_info::AccountInfo<'a>,
850    /// The TA of the pool, where the NFT is held.
851    pub pool_ta: &'b solana_program::account_info::AccountInfo<'a>,
852    /// Either the legacy token program or token-2022.
853    pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
854    /// The SPL associated token program.
855    pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
856    /// The Solana system program.
857    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
858    /// The arguments for the instruction.
859    pub __args: BuyNftInstructionArgs,
860}
861
862impl<'a, 'b> BuyNftCpi<'a, 'b> {
863    pub fn new(
864        program: &'b solana_program::account_info::AccountInfo<'a>,
865        accounts: BuyNftCpiAccounts<'a, 'b>,
866        args: BuyNftInstructionArgs,
867    ) -> Self {
868        Self {
869            __program: program,
870            owner: accounts.owner,
871            taker: accounts.taker,
872            rent_payer: accounts.rent_payer,
873            fee_vault: accounts.fee_vault,
874            pool: accounts.pool,
875            whitelist: accounts.whitelist,
876            mint_proof: accounts.mint_proof,
877            shared_escrow: accounts.shared_escrow,
878            maker_broker: accounts.maker_broker,
879            taker_broker: accounts.taker_broker,
880            cosigner: accounts.cosigner,
881            amm_program: accounts.amm_program,
882            escrow_program: accounts.escrow_program,
883            native_program: accounts.native_program,
884            mint: accounts.mint,
885            metadata: accounts.metadata,
886            edition: accounts.edition,
887            user_token_record: accounts.user_token_record,
888            pool_token_record: accounts.pool_token_record,
889            token_metadata_program: accounts.token_metadata_program,
890            sysvar_instructions: accounts.sysvar_instructions,
891            authorization_rules: accounts.authorization_rules,
892            authorization_rules_program: accounts.authorization_rules_program,
893            nft_receipt: accounts.nft_receipt,
894            taker_ta: accounts.taker_ta,
895            pool_ta: accounts.pool_ta,
896            token_program: accounts.token_program,
897            associated_token_program: accounts.associated_token_program,
898            system_program: accounts.system_program,
899            __args: args,
900        }
901    }
902    #[inline(always)]
903    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
904        self.invoke_signed_with_remaining_accounts(&[], &[])
905    }
906    #[inline(always)]
907    pub fn invoke_with_remaining_accounts(
908        &self,
909        remaining_accounts: &[(
910            &'b solana_program::account_info::AccountInfo<'a>,
911            bool,
912            bool,
913        )],
914    ) -> solana_program::entrypoint::ProgramResult {
915        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
916    }
917    #[inline(always)]
918    pub fn invoke_signed(
919        &self,
920        signers_seeds: &[&[&[u8]]],
921    ) -> solana_program::entrypoint::ProgramResult {
922        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
923    }
924    #[allow(clippy::clone_on_copy)]
925    #[allow(clippy::vec_init_then_push)]
926    pub fn invoke_signed_with_remaining_accounts(
927        &self,
928        signers_seeds: &[&[&[u8]]],
929        remaining_accounts: &[(
930            &'b solana_program::account_info::AccountInfo<'a>,
931            bool,
932            bool,
933        )],
934    ) -> solana_program::entrypoint::ProgramResult {
935        let mut accounts = Vec::with_capacity(29 + remaining_accounts.len());
936        accounts.push(solana_program::instruction::AccountMeta::new(
937            *self.owner.key,
938            false,
939        ));
940        accounts.push(solana_program::instruction::AccountMeta::new(
941            *self.taker.key,
942            true,
943        ));
944        accounts.push(solana_program::instruction::AccountMeta::new(
945            *self.rent_payer.key,
946            false,
947        ));
948        accounts.push(solana_program::instruction::AccountMeta::new(
949            *self.fee_vault.key,
950            false,
951        ));
952        accounts.push(solana_program::instruction::AccountMeta::new(
953            *self.pool.key,
954            false,
955        ));
956        if let Some(whitelist) = self.whitelist {
957            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
958                *whitelist.key,
959                false,
960            ));
961        } else {
962            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
963                crate::TENSOR_AMM_ID,
964                false,
965            ));
966        }
967        if let Some(mint_proof) = self.mint_proof {
968            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
969                *mint_proof.key,
970                false,
971            ));
972        } else {
973            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
974                crate::TENSOR_AMM_ID,
975                false,
976            ));
977        }
978        if let Some(shared_escrow) = self.shared_escrow {
979            accounts.push(solana_program::instruction::AccountMeta::new(
980                *shared_escrow.key,
981                false,
982            ));
983        } else {
984            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
985                crate::TENSOR_AMM_ID,
986                false,
987            ));
988        }
989        if let Some(maker_broker) = self.maker_broker {
990            accounts.push(solana_program::instruction::AccountMeta::new(
991                *maker_broker.key,
992                false,
993            ));
994        } else {
995            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
996                crate::TENSOR_AMM_ID,
997                false,
998            ));
999        }
1000        if let Some(taker_broker) = self.taker_broker {
1001            accounts.push(solana_program::instruction::AccountMeta::new(
1002                *taker_broker.key,
1003                false,
1004            ));
1005        } else {
1006            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1007                crate::TENSOR_AMM_ID,
1008                false,
1009            ));
1010        }
1011        if let Some(cosigner) = self.cosigner {
1012            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1013                *cosigner.key,
1014                true,
1015            ));
1016        } else {
1017            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1018                crate::TENSOR_AMM_ID,
1019                false,
1020            ));
1021        }
1022        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1023            *self.amm_program.key,
1024            false,
1025        ));
1026        if let Some(escrow_program) = self.escrow_program {
1027            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1028                *escrow_program.key,
1029                false,
1030            ));
1031        } else {
1032            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1033                crate::TENSOR_AMM_ID,
1034                false,
1035            ));
1036        }
1037        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1038            *self.native_program.key,
1039            false,
1040        ));
1041        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1042            *self.mint.key,
1043            false,
1044        ));
1045        accounts.push(solana_program::instruction::AccountMeta::new(
1046            *self.metadata.key,
1047            false,
1048        ));
1049        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1050            *self.edition.key,
1051            false,
1052        ));
1053        if let Some(user_token_record) = self.user_token_record {
1054            accounts.push(solana_program::instruction::AccountMeta::new(
1055                *user_token_record.key,
1056                false,
1057            ));
1058        } else {
1059            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1060                crate::TENSOR_AMM_ID,
1061                false,
1062            ));
1063        }
1064        if let Some(pool_token_record) = self.pool_token_record {
1065            accounts.push(solana_program::instruction::AccountMeta::new(
1066                *pool_token_record.key,
1067                false,
1068            ));
1069        } else {
1070            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1071                crate::TENSOR_AMM_ID,
1072                false,
1073            ));
1074        }
1075        if let Some(token_metadata_program) = self.token_metadata_program {
1076            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1077                *token_metadata_program.key,
1078                false,
1079            ));
1080        } else {
1081            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1082                crate::TENSOR_AMM_ID,
1083                false,
1084            ));
1085        }
1086        if let Some(sysvar_instructions) = self.sysvar_instructions {
1087            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1088                *sysvar_instructions.key,
1089                false,
1090            ));
1091        } else {
1092            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1093                crate::TENSOR_AMM_ID,
1094                false,
1095            ));
1096        }
1097        if let Some(authorization_rules) = self.authorization_rules {
1098            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1099                *authorization_rules.key,
1100                false,
1101            ));
1102        } else {
1103            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1104                crate::TENSOR_AMM_ID,
1105                false,
1106            ));
1107        }
1108        if let Some(authorization_rules_program) = self.authorization_rules_program {
1109            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1110                *authorization_rules_program.key,
1111                false,
1112            ));
1113        } else {
1114            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1115                crate::TENSOR_AMM_ID,
1116                false,
1117            ));
1118        }
1119        accounts.push(solana_program::instruction::AccountMeta::new(
1120            *self.nft_receipt.key,
1121            false,
1122        ));
1123        accounts.push(solana_program::instruction::AccountMeta::new(
1124            *self.taker_ta.key,
1125            false,
1126        ));
1127        accounts.push(solana_program::instruction::AccountMeta::new(
1128            *self.pool_ta.key,
1129            false,
1130        ));
1131        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1132            *self.token_program.key,
1133            false,
1134        ));
1135        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1136            *self.associated_token_program.key,
1137            false,
1138        ));
1139        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
1140            *self.system_program.key,
1141            false,
1142        ));
1143        remaining_accounts.iter().for_each(|remaining_account| {
1144            accounts.push(solana_program::instruction::AccountMeta {
1145                pubkey: *remaining_account.0.key,
1146                is_signer: remaining_account.1,
1147                is_writable: remaining_account.2,
1148            })
1149        });
1150        let mut data = BuyNftInstructionData::new().try_to_vec().unwrap();
1151        let mut args = self.__args.try_to_vec().unwrap();
1152        data.append(&mut args);
1153
1154        let instruction = solana_program::instruction::Instruction {
1155            program_id: crate::TENSOR_AMM_ID,
1156            accounts,
1157            data,
1158        };
1159        let mut account_infos = Vec::with_capacity(30 + remaining_accounts.len());
1160        account_infos.push(self.__program.clone());
1161        account_infos.push(self.owner.clone());
1162        account_infos.push(self.taker.clone());
1163        account_infos.push(self.rent_payer.clone());
1164        account_infos.push(self.fee_vault.clone());
1165        account_infos.push(self.pool.clone());
1166        if let Some(whitelist) = self.whitelist {
1167            account_infos.push(whitelist.clone());
1168        }
1169        if let Some(mint_proof) = self.mint_proof {
1170            account_infos.push(mint_proof.clone());
1171        }
1172        if let Some(shared_escrow) = self.shared_escrow {
1173            account_infos.push(shared_escrow.clone());
1174        }
1175        if let Some(maker_broker) = self.maker_broker {
1176            account_infos.push(maker_broker.clone());
1177        }
1178        if let Some(taker_broker) = self.taker_broker {
1179            account_infos.push(taker_broker.clone());
1180        }
1181        if let Some(cosigner) = self.cosigner {
1182            account_infos.push(cosigner.clone());
1183        }
1184        account_infos.push(self.amm_program.clone());
1185        if let Some(escrow_program) = self.escrow_program {
1186            account_infos.push(escrow_program.clone());
1187        }
1188        account_infos.push(self.native_program.clone());
1189        account_infos.push(self.mint.clone());
1190        account_infos.push(self.metadata.clone());
1191        account_infos.push(self.edition.clone());
1192        if let Some(user_token_record) = self.user_token_record {
1193            account_infos.push(user_token_record.clone());
1194        }
1195        if let Some(pool_token_record) = self.pool_token_record {
1196            account_infos.push(pool_token_record.clone());
1197        }
1198        if let Some(token_metadata_program) = self.token_metadata_program {
1199            account_infos.push(token_metadata_program.clone());
1200        }
1201        if let Some(sysvar_instructions) = self.sysvar_instructions {
1202            account_infos.push(sysvar_instructions.clone());
1203        }
1204        if let Some(authorization_rules) = self.authorization_rules {
1205            account_infos.push(authorization_rules.clone());
1206        }
1207        if let Some(authorization_rules_program) = self.authorization_rules_program {
1208            account_infos.push(authorization_rules_program.clone());
1209        }
1210        account_infos.push(self.nft_receipt.clone());
1211        account_infos.push(self.taker_ta.clone());
1212        account_infos.push(self.pool_ta.clone());
1213        account_infos.push(self.token_program.clone());
1214        account_infos.push(self.associated_token_program.clone());
1215        account_infos.push(self.system_program.clone());
1216        remaining_accounts
1217            .iter()
1218            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
1219
1220        if signers_seeds.is_empty() {
1221            solana_program::program::invoke(&instruction, &account_infos)
1222        } else {
1223            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
1224        }
1225    }
1226}
1227
1228/// Instruction builder for `BuyNft` via CPI.
1229///
1230/// ### Accounts:
1231///
1232///   0. `[writable]` owner
1233///   1. `[writable, signer]` taker
1234///   2. `[writable]` rent_payer
1235///   3. `[writable]` fee_vault
1236///   4. `[writable]` pool
1237///   5. `[optional]` whitelist
1238///   6. `[optional]` mint_proof
1239///   7. `[writable, optional]` shared_escrow
1240///   8. `[writable, optional]` maker_broker
1241///   9. `[writable, optional]` taker_broker
1242///   10. `[signer, optional]` cosigner
1243///   11. `[]` amm_program
1244///   12. `[optional]` escrow_program
1245///   13. `[]` native_program
1246///   14. `[]` mint
1247///   15. `[writable]` metadata
1248///   16. `[]` edition
1249///   17. `[writable, optional]` user_token_record
1250///   18. `[writable, optional]` pool_token_record
1251///   19. `[optional]` token_metadata_program
1252///   20. `[optional]` sysvar_instructions
1253///   21. `[optional]` authorization_rules
1254///   22. `[optional]` authorization_rules_program
1255///   23. `[writable]` nft_receipt
1256///   24. `[writable]` taker_ta
1257///   25. `[writable]` pool_ta
1258///   26. `[]` token_program
1259///   27. `[]` associated_token_program
1260///   28. `[]` system_program
1261#[derive(Clone, Debug)]
1262pub struct BuyNftCpiBuilder<'a, 'b> {
1263    instruction: Box<BuyNftCpiBuilderInstruction<'a, 'b>>,
1264}
1265
1266impl<'a, 'b> BuyNftCpiBuilder<'a, 'b> {
1267    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
1268        let instruction = Box::new(BuyNftCpiBuilderInstruction {
1269            __program: program,
1270            owner: None,
1271            taker: None,
1272            rent_payer: None,
1273            fee_vault: None,
1274            pool: None,
1275            whitelist: None,
1276            mint_proof: None,
1277            shared_escrow: None,
1278            maker_broker: None,
1279            taker_broker: None,
1280            cosigner: None,
1281            amm_program: None,
1282            escrow_program: None,
1283            native_program: None,
1284            mint: None,
1285            metadata: None,
1286            edition: None,
1287            user_token_record: None,
1288            pool_token_record: None,
1289            token_metadata_program: None,
1290            sysvar_instructions: None,
1291            authorization_rules: None,
1292            authorization_rules_program: None,
1293            nft_receipt: None,
1294            taker_ta: None,
1295            pool_ta: None,
1296            token_program: None,
1297            associated_token_program: None,
1298            system_program: None,
1299            max_amount: None,
1300            authorization_data: None,
1301            optional_royalty_pct: None,
1302            __remaining_accounts: Vec::new(),
1303        });
1304        Self { instruction }
1305    }
1306    /// The owner of the pool and the buyer/recipient of the NFT.
1307    #[inline(always)]
1308    pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
1309        self.instruction.owner = Some(owner);
1310        self
1311    }
1312    /// The taker is the user buying or selling the NFT.
1313    #[inline(always)]
1314    pub fn taker(&mut self, taker: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
1315        self.instruction.taker = Some(taker);
1316        self
1317    }
1318    /// The original rent payer of the pool--stored on the pool. Used to refund rent in case the pool
1319    /// is auto-closed.
1320    #[inline(always)]
1321    pub fn rent_payer(
1322        &mut self,
1323        rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
1324    ) -> &mut Self {
1325        self.instruction.rent_payer = Some(rent_payer);
1326        self
1327    }
1328    /// Fee vault account owned by the TFEE program.
1329    #[inline(always)]
1330    pub fn fee_vault(
1331        &mut self,
1332        fee_vault: &'b solana_program::account_info::AccountInfo<'a>,
1333    ) -> &mut Self {
1334        self.instruction.fee_vault = Some(fee_vault);
1335        self
1336    }
1337    /// The Pool state account that the NFT is being sold into. Stores pool state and config,
1338    /// but is also the owner of any NFTs in the pool, and also escrows any SOL.
1339    /// Any active pool can be specified provided it is a Token type and the NFT passes at least one
1340    /// whitelist condition.
1341    #[inline(always)]
1342    pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
1343        self.instruction.pool = Some(pool);
1344        self
1345    }
1346    /// `[optional account]`
1347    /// The whitelist account that the pool uses to verify the NFTs being sold into it.
1348    #[inline(always)]
1349    pub fn whitelist(
1350        &mut self,
1351        whitelist: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1352    ) -> &mut Self {
1353        self.instruction.whitelist = whitelist;
1354        self
1355    }
1356    /// `[optional account]`
1357    /// Optional account which must be passed in if the NFT must be verified against a
1358    /// merkle proof condition in the whitelist.
1359    #[inline(always)]
1360    pub fn mint_proof(
1361        &mut self,
1362        mint_proof: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1363    ) -> &mut Self {
1364        self.instruction.mint_proof = mint_proof;
1365        self
1366    }
1367    /// `[optional account]`
1368    /// The shared escrow account for pools that have liquidity in a shared account.
1369    #[inline(always)]
1370    pub fn shared_escrow(
1371        &mut self,
1372        shared_escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1373    ) -> &mut Self {
1374        self.instruction.shared_escrow = shared_escrow;
1375        self
1376    }
1377    /// `[optional account]`
1378    /// The account that receives the maker broker fee.
1379    #[inline(always)]
1380    pub fn maker_broker(
1381        &mut self,
1382        maker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1383    ) -> &mut Self {
1384        self.instruction.maker_broker = maker_broker;
1385        self
1386    }
1387    /// `[optional account]`
1388    /// The account that receives the taker broker fee.
1389    #[inline(always)]
1390    pub fn taker_broker(
1391        &mut self,
1392        taker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1393    ) -> &mut Self {
1394        self.instruction.taker_broker = taker_broker;
1395        self
1396    }
1397    /// `[optional account]`
1398    /// The optional cosigner account that must be passed in if the pool has a cosigner.
1399    #[inline(always)]
1400    pub fn cosigner(
1401        &mut self,
1402        cosigner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1403    ) -> &mut Self {
1404        self.instruction.cosigner = cosigner;
1405        self
1406    }
1407    /// The AMM program account, used for self-cpi logging.
1408    #[inline(always)]
1409    pub fn amm_program(
1410        &mut self,
1411        amm_program: &'b solana_program::account_info::AccountInfo<'a>,
1412    ) -> &mut Self {
1413        self.instruction.amm_program = Some(amm_program);
1414        self
1415    }
1416    /// `[optional account]`
1417    /// The escrow program account for shared liquidity pools.
1418    #[inline(always)]
1419    pub fn escrow_program(
1420        &mut self,
1421        escrow_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1422    ) -> &mut Self {
1423        self.instruction.escrow_program = escrow_program;
1424        self
1425    }
1426    #[inline(always)]
1427    pub fn native_program(
1428        &mut self,
1429        native_program: &'b solana_program::account_info::AccountInfo<'a>,
1430    ) -> &mut Self {
1431        self.instruction.native_program = Some(native_program);
1432        self
1433    }
1434    /// The mint account of the NFT.
1435    #[inline(always)]
1436    pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
1437        self.instruction.mint = Some(mint);
1438        self
1439    }
1440    /// The Token Metadata metadata account of the NFT.
1441    #[inline(always)]
1442    pub fn metadata(
1443        &mut self,
1444        metadata: &'b solana_program::account_info::AccountInfo<'a>,
1445    ) -> &mut Self {
1446        self.instruction.metadata = Some(metadata);
1447        self
1448    }
1449    /// The Token Metadata edition account of the NFT.
1450    #[inline(always)]
1451    pub fn edition(
1452        &mut self,
1453        edition: &'b solana_program::account_info::AccountInfo<'a>,
1454    ) -> &mut Self {
1455        self.instruction.edition = Some(edition);
1456        self
1457    }
1458    /// `[optional account]`
1459    /// The Token Metadata source token record account of the NFT.
1460    #[inline(always)]
1461    pub fn user_token_record(
1462        &mut self,
1463        user_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1464    ) -> &mut Self {
1465        self.instruction.user_token_record = user_token_record;
1466        self
1467    }
1468    /// `[optional account]`
1469    /// The Token Metadata token record for the destination.
1470    #[inline(always)]
1471    pub fn pool_token_record(
1472        &mut self,
1473        pool_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1474    ) -> &mut Self {
1475        self.instruction.pool_token_record = pool_token_record;
1476        self
1477    }
1478    /// `[optional account]`
1479    /// The Token Metadata program account.
1480    #[inline(always)]
1481    pub fn token_metadata_program(
1482        &mut self,
1483        token_metadata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1484    ) -> &mut Self {
1485        self.instruction.token_metadata_program = token_metadata_program;
1486        self
1487    }
1488    /// `[optional account]`
1489    /// The sysvar instructions account.
1490    #[inline(always)]
1491    pub fn sysvar_instructions(
1492        &mut self,
1493        sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1494    ) -> &mut Self {
1495        self.instruction.sysvar_instructions = sysvar_instructions;
1496        self
1497    }
1498    /// `[optional account]`
1499    /// The Metaplex Token Authority Rules account that stores royalty enforcement rules.
1500    #[inline(always)]
1501    pub fn authorization_rules(
1502        &mut self,
1503        authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1504    ) -> &mut Self {
1505        self.instruction.authorization_rules = authorization_rules;
1506        self
1507    }
1508    /// `[optional account]`
1509    /// The Metaplex Token Authority Rules program account.
1510    #[inline(always)]
1511    pub fn authorization_rules_program(
1512        &mut self,
1513        authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1514    ) -> &mut Self {
1515        self.instruction.authorization_rules_program = authorization_rules_program;
1516        self
1517    }
1518    /// The NFT deposit receipt, which ties an NFT to the pool it was deposited to.
1519    #[inline(always)]
1520    pub fn nft_receipt(
1521        &mut self,
1522        nft_receipt: &'b solana_program::account_info::AccountInfo<'a>,
1523    ) -> &mut Self {
1524        self.instruction.nft_receipt = Some(nft_receipt);
1525        self
1526    }
1527    /// The TA of the buyer, where the NFT will be transferred.
1528    #[inline(always)]
1529    pub fn taker_ta(
1530        &mut self,
1531        taker_ta: &'b solana_program::account_info::AccountInfo<'a>,
1532    ) -> &mut Self {
1533        self.instruction.taker_ta = Some(taker_ta);
1534        self
1535    }
1536    /// The TA of the pool, where the NFT is held.
1537    #[inline(always)]
1538    pub fn pool_ta(
1539        &mut self,
1540        pool_ta: &'b solana_program::account_info::AccountInfo<'a>,
1541    ) -> &mut Self {
1542        self.instruction.pool_ta = Some(pool_ta);
1543        self
1544    }
1545    /// Either the legacy token program or token-2022.
1546    #[inline(always)]
1547    pub fn token_program(
1548        &mut self,
1549        token_program: &'b solana_program::account_info::AccountInfo<'a>,
1550    ) -> &mut Self {
1551        self.instruction.token_program = Some(token_program);
1552        self
1553    }
1554    /// The SPL associated token program.
1555    #[inline(always)]
1556    pub fn associated_token_program(
1557        &mut self,
1558        associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
1559    ) -> &mut Self {
1560        self.instruction.associated_token_program = Some(associated_token_program);
1561        self
1562    }
1563    /// The Solana system program.
1564    #[inline(always)]
1565    pub fn system_program(
1566        &mut self,
1567        system_program: &'b solana_program::account_info::AccountInfo<'a>,
1568    ) -> &mut Self {
1569        self.instruction.system_program = Some(system_program);
1570        self
1571    }
1572    #[inline(always)]
1573    pub fn max_amount(&mut self, max_amount: u64) -> &mut Self {
1574        self.instruction.max_amount = Some(max_amount);
1575        self
1576    }
1577    /// `[optional argument]`
1578    #[inline(always)]
1579    pub fn authorization_data(&mut self, authorization_data: AuthorizationDataLocal) -> &mut Self {
1580        self.instruction.authorization_data = Some(authorization_data);
1581        self
1582    }
1583    /// `[optional argument]`
1584    #[inline(always)]
1585    pub fn optional_royalty_pct(&mut self, optional_royalty_pct: u16) -> &mut Self {
1586        self.instruction.optional_royalty_pct = Some(optional_royalty_pct);
1587        self
1588    }
1589    /// Add an additional account to the instruction.
1590    #[inline(always)]
1591    pub fn add_remaining_account(
1592        &mut self,
1593        account: &'b solana_program::account_info::AccountInfo<'a>,
1594        is_writable: bool,
1595        is_signer: bool,
1596    ) -> &mut Self {
1597        self.instruction
1598            .__remaining_accounts
1599            .push((account, is_writable, is_signer));
1600        self
1601    }
1602    /// Add additional accounts to the instruction.
1603    ///
1604    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
1605    /// and a `bool` indicating whether the account is a signer or not.
1606    #[inline(always)]
1607    pub fn add_remaining_accounts(
1608        &mut self,
1609        accounts: &[(
1610            &'b solana_program::account_info::AccountInfo<'a>,
1611            bool,
1612            bool,
1613        )],
1614    ) -> &mut Self {
1615        self.instruction
1616            .__remaining_accounts
1617            .extend_from_slice(accounts);
1618        self
1619    }
1620    #[inline(always)]
1621    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
1622        self.invoke_signed(&[])
1623    }
1624    #[allow(clippy::clone_on_copy)]
1625    #[allow(clippy::vec_init_then_push)]
1626    pub fn invoke_signed(
1627        &self,
1628        signers_seeds: &[&[&[u8]]],
1629    ) -> solana_program::entrypoint::ProgramResult {
1630        let args = BuyNftInstructionArgs {
1631            max_amount: self
1632                .instruction
1633                .max_amount
1634                .clone()
1635                .expect("max_amount is not set"),
1636            authorization_data: self.instruction.authorization_data.clone(),
1637            optional_royalty_pct: self.instruction.optional_royalty_pct.clone(),
1638        };
1639        let instruction = BuyNftCpi {
1640            __program: self.instruction.__program,
1641
1642            owner: self.instruction.owner.expect("owner is not set"),
1643
1644            taker: self.instruction.taker.expect("taker is not set"),
1645
1646            rent_payer: self.instruction.rent_payer.expect("rent_payer is not set"),
1647
1648            fee_vault: self.instruction.fee_vault.expect("fee_vault is not set"),
1649
1650            pool: self.instruction.pool.expect("pool is not set"),
1651
1652            whitelist: self.instruction.whitelist,
1653
1654            mint_proof: self.instruction.mint_proof,
1655
1656            shared_escrow: self.instruction.shared_escrow,
1657
1658            maker_broker: self.instruction.maker_broker,
1659
1660            taker_broker: self.instruction.taker_broker,
1661
1662            cosigner: self.instruction.cosigner,
1663
1664            amm_program: self
1665                .instruction
1666                .amm_program
1667                .expect("amm_program is not set"),
1668
1669            escrow_program: self.instruction.escrow_program,
1670
1671            native_program: self
1672                .instruction
1673                .native_program
1674                .expect("native_program is not set"),
1675
1676            mint: self.instruction.mint.expect("mint is not set"),
1677
1678            metadata: self.instruction.metadata.expect("metadata is not set"),
1679
1680            edition: self.instruction.edition.expect("edition is not set"),
1681
1682            user_token_record: self.instruction.user_token_record,
1683
1684            pool_token_record: self.instruction.pool_token_record,
1685
1686            token_metadata_program: self.instruction.token_metadata_program,
1687
1688            sysvar_instructions: self.instruction.sysvar_instructions,
1689
1690            authorization_rules: self.instruction.authorization_rules,
1691
1692            authorization_rules_program: self.instruction.authorization_rules_program,
1693
1694            nft_receipt: self
1695                .instruction
1696                .nft_receipt
1697                .expect("nft_receipt is not set"),
1698
1699            taker_ta: self.instruction.taker_ta.expect("taker_ta is not set"),
1700
1701            pool_ta: self.instruction.pool_ta.expect("pool_ta is not set"),
1702
1703            token_program: self
1704                .instruction
1705                .token_program
1706                .expect("token_program is not set"),
1707
1708            associated_token_program: self
1709                .instruction
1710                .associated_token_program
1711                .expect("associated_token_program is not set"),
1712
1713            system_program: self
1714                .instruction
1715                .system_program
1716                .expect("system_program is not set"),
1717            __args: args,
1718        };
1719        instruction.invoke_signed_with_remaining_accounts(
1720            signers_seeds,
1721            &self.instruction.__remaining_accounts,
1722        )
1723    }
1724}
1725
1726#[derive(Clone, Debug)]
1727struct BuyNftCpiBuilderInstruction<'a, 'b> {
1728    __program: &'b solana_program::account_info::AccountInfo<'a>,
1729    owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1730    taker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1731    rent_payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1732    fee_vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1733    pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1734    whitelist: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1735    mint_proof: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1736    shared_escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1737    maker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1738    taker_broker: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1739    cosigner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1740    amm_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1741    escrow_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1742    native_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1743    mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1744    metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1745    edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1746    user_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1747    pool_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1748    token_metadata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1749    sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1750    authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1751    authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1752    nft_receipt: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1753    taker_ta: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1754    pool_ta: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1755    token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1756    associated_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1757    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1758    max_amount: Option<u64>,
1759    authorization_data: Option<AuthorizationDataLocal>,
1760    optional_royalty_pct: Option<u16>,
1761    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
1762    __remaining_accounts: Vec<(
1763        &'b solana_program::account_info::AccountInfo<'a>,
1764        bool,
1765        bool,
1766    )>,
1767}