Skip to main content

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