Skip to main content

orca_sol/instructions/
initialize_token_badge.rs

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