1use crate::generated::types::UpdateRateArgs;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub const UPDATE_RATE_ACCOUNT_DISCRIMINATOR: u8 = 14;
13
14#[derive(Debug)]
16pub struct UpdateRateAccount {
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 rate_account: solana_pubkey::Pubkey,
24
25 pub mint_from: solana_pubkey::Pubkey,
26
27 pub mint_to: solana_pubkey::Pubkey,
28}
29
30impl UpdateRateAccount {
31 pub fn instruction(
32 &self,
33 args: UpdateRateAccountInstructionArgs,
34 ) -> solana_instruction::Instruction {
35 self.instruction_with_remaining_accounts(args, &[])
36 }
37 #[allow(clippy::arithmetic_side_effects)]
38 #[allow(clippy::vec_init_then_push)]
39 pub fn instruction_with_remaining_accounts(
40 &self,
41 args: UpdateRateAccountInstructionArgs,
42 remaining_accounts: &[solana_instruction::AccountMeta],
43 ) -> solana_instruction::Instruction {
44 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
45 accounts.push(solana_instruction::AccountMeta::new_readonly(
46 self.mint, false,
47 ));
48 accounts.push(solana_instruction::AccountMeta::new_readonly(
49 self.verification_config_or_mint_authority,
50 false,
51 ));
52 accounts.push(solana_instruction::AccountMeta::new_readonly(
53 self.instructions_sysvar_or_creator,
54 false,
55 ));
56 accounts.push(solana_instruction::AccountMeta::new(
57 self.rate_account,
58 false,
59 ));
60 accounts.push(solana_instruction::AccountMeta::new_readonly(
61 self.mint_from,
62 false,
63 ));
64 accounts.push(solana_instruction::AccountMeta::new_readonly(
65 self.mint_to,
66 false,
67 ));
68 accounts.extend_from_slice(remaining_accounts);
69 let mut data = borsh::to_vec(&UpdateRateAccountInstructionData::new()).unwrap();
70 let mut args = borsh::to_vec(&args).unwrap();
71 data.append(&mut args);
72
73 solana_instruction::Instruction {
74 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
75 accounts,
76 data,
77 }
78 }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub struct UpdateRateAccountInstructionData {
84 discriminator: u8,
85}
86
87impl UpdateRateAccountInstructionData {
88 pub fn new() -> Self {
89 Self { discriminator: 14 }
90 }
91}
92
93impl Default for UpdateRateAccountInstructionData {
94 fn default() -> Self {
95 Self::new()
96 }
97}
98
99#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
100#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
101pub struct UpdateRateAccountInstructionArgs {
102 pub update_rate_args: UpdateRateArgs,
103}
104
105#[derive(Clone, Debug, Default)]
116pub struct UpdateRateAccountBuilder {
117 mint: Option<solana_pubkey::Pubkey>,
118 verification_config_or_mint_authority: Option<solana_pubkey::Pubkey>,
119 instructions_sysvar_or_creator: Option<solana_pubkey::Pubkey>,
120 rate_account: Option<solana_pubkey::Pubkey>,
121 mint_from: Option<solana_pubkey::Pubkey>,
122 mint_to: Option<solana_pubkey::Pubkey>,
123 update_rate_args: Option<UpdateRateArgs>,
124 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
125}
126
127impl UpdateRateAccountBuilder {
128 pub fn new() -> Self {
129 Self::default()
130 }
131 #[inline(always)]
132 pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
133 self.mint = Some(mint);
134 self
135 }
136 #[inline(always)]
137 pub fn verification_config_or_mint_authority(
138 &mut self,
139 verification_config_or_mint_authority: solana_pubkey::Pubkey,
140 ) -> &mut Self {
141 self.verification_config_or_mint_authority = Some(verification_config_or_mint_authority);
142 self
143 }
144 #[inline(always)]
145 pub fn instructions_sysvar_or_creator(
146 &mut self,
147 instructions_sysvar_or_creator: solana_pubkey::Pubkey,
148 ) -> &mut Self {
149 self.instructions_sysvar_or_creator = Some(instructions_sysvar_or_creator);
150 self
151 }
152 #[inline(always)]
153 pub fn rate_account(&mut self, rate_account: solana_pubkey::Pubkey) -> &mut Self {
154 self.rate_account = Some(rate_account);
155 self
156 }
157 #[inline(always)]
158 pub fn mint_from(&mut self, mint_from: solana_pubkey::Pubkey) -> &mut Self {
159 self.mint_from = Some(mint_from);
160 self
161 }
162 #[inline(always)]
163 pub fn mint_to(&mut self, mint_to: solana_pubkey::Pubkey) -> &mut Self {
164 self.mint_to = Some(mint_to);
165 self
166 }
167 #[inline(always)]
168 pub fn update_rate_args(&mut self, update_rate_args: UpdateRateArgs) -> &mut Self {
169 self.update_rate_args = Some(update_rate_args);
170 self
171 }
172 #[inline(always)]
174 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
175 self.__remaining_accounts.push(account);
176 self
177 }
178 #[inline(always)]
180 pub fn add_remaining_accounts(
181 &mut self,
182 accounts: &[solana_instruction::AccountMeta],
183 ) -> &mut Self {
184 self.__remaining_accounts.extend_from_slice(accounts);
185 self
186 }
187 #[allow(clippy::clone_on_copy)]
188 pub fn instruction(&self) -> solana_instruction::Instruction {
189 let accounts = UpdateRateAccount {
190 mint: self.mint.expect("mint is not set"),
191 verification_config_or_mint_authority: self
192 .verification_config_or_mint_authority
193 .expect("verification_config_or_mint_authority is not set"),
194 instructions_sysvar_or_creator: self
195 .instructions_sysvar_or_creator
196 .expect("instructions_sysvar_or_creator is not set"),
197 rate_account: self.rate_account.expect("rate_account is not set"),
198 mint_from: self.mint_from.expect("mint_from is not set"),
199 mint_to: self.mint_to.expect("mint_to is not set"),
200 };
201 let args = UpdateRateAccountInstructionArgs {
202 update_rate_args: self
203 .update_rate_args
204 .clone()
205 .expect("update_rate_args is not set"),
206 };
207
208 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
209 }
210}
211
212pub struct UpdateRateAccountCpiAccounts<'a, 'b> {
214 pub mint: &'b solana_account_info::AccountInfo<'a>,
215
216 pub verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
217
218 pub instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
219
220 pub rate_account: &'b solana_account_info::AccountInfo<'a>,
221
222 pub mint_from: &'b solana_account_info::AccountInfo<'a>,
223
224 pub mint_to: &'b solana_account_info::AccountInfo<'a>,
225}
226
227pub struct UpdateRateAccountCpi<'a, 'b> {
229 pub __program: &'b solana_account_info::AccountInfo<'a>,
231
232 pub mint: &'b solana_account_info::AccountInfo<'a>,
233
234 pub verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
235
236 pub instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
237
238 pub rate_account: &'b solana_account_info::AccountInfo<'a>,
239
240 pub mint_from: &'b solana_account_info::AccountInfo<'a>,
241
242 pub mint_to: &'b solana_account_info::AccountInfo<'a>,
243 pub __args: UpdateRateAccountInstructionArgs,
245}
246
247impl<'a, 'b> UpdateRateAccountCpi<'a, 'b> {
248 pub fn new(
249 program: &'b solana_account_info::AccountInfo<'a>,
250 accounts: UpdateRateAccountCpiAccounts<'a, 'b>,
251 args: UpdateRateAccountInstructionArgs,
252 ) -> Self {
253 Self {
254 __program: program,
255 mint: accounts.mint,
256 verification_config_or_mint_authority: accounts.verification_config_or_mint_authority,
257 instructions_sysvar_or_creator: accounts.instructions_sysvar_or_creator,
258 rate_account: accounts.rate_account,
259 mint_from: accounts.mint_from,
260 mint_to: accounts.mint_to,
261 __args: args,
262 }
263 }
264 #[inline(always)]
265 pub fn invoke(&self) -> solana_program_error::ProgramResult {
266 self.invoke_signed_with_remaining_accounts(&[], &[])
267 }
268 #[inline(always)]
269 pub fn invoke_with_remaining_accounts(
270 &self,
271 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
272 ) -> solana_program_error::ProgramResult {
273 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
274 }
275 #[inline(always)]
276 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
277 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
278 }
279 #[allow(clippy::arithmetic_side_effects)]
280 #[allow(clippy::clone_on_copy)]
281 #[allow(clippy::vec_init_then_push)]
282 pub fn invoke_signed_with_remaining_accounts(
283 &self,
284 signers_seeds: &[&[&[u8]]],
285 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
286 ) -> solana_program_error::ProgramResult {
287 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
288 accounts.push(solana_instruction::AccountMeta::new_readonly(
289 *self.mint.key,
290 false,
291 ));
292 accounts.push(solana_instruction::AccountMeta::new_readonly(
293 *self.verification_config_or_mint_authority.key,
294 false,
295 ));
296 accounts.push(solana_instruction::AccountMeta::new_readonly(
297 *self.instructions_sysvar_or_creator.key,
298 false,
299 ));
300 accounts.push(solana_instruction::AccountMeta::new(
301 *self.rate_account.key,
302 false,
303 ));
304 accounts.push(solana_instruction::AccountMeta::new_readonly(
305 *self.mint_from.key,
306 false,
307 ));
308 accounts.push(solana_instruction::AccountMeta::new_readonly(
309 *self.mint_to.key,
310 false,
311 ));
312 remaining_accounts.iter().for_each(|remaining_account| {
313 accounts.push(solana_instruction::AccountMeta {
314 pubkey: *remaining_account.0.key,
315 is_signer: remaining_account.1,
316 is_writable: remaining_account.2,
317 })
318 });
319 let mut data = borsh::to_vec(&UpdateRateAccountInstructionData::new()).unwrap();
320 let mut args = borsh::to_vec(&self.__args).unwrap();
321 data.append(&mut args);
322
323 let instruction = solana_instruction::Instruction {
324 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
325 accounts,
326 data,
327 };
328 let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len());
329 account_infos.push(self.__program.clone());
330 account_infos.push(self.mint.clone());
331 account_infos.push(self.verification_config_or_mint_authority.clone());
332 account_infos.push(self.instructions_sysvar_or_creator.clone());
333 account_infos.push(self.rate_account.clone());
334 account_infos.push(self.mint_from.clone());
335 account_infos.push(self.mint_to.clone());
336 remaining_accounts
337 .iter()
338 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
339
340 if signers_seeds.is_empty() {
341 solana_cpi::invoke(&instruction, &account_infos)
342 } else {
343 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
344 }
345 }
346}
347
348#[derive(Clone, Debug)]
359pub struct UpdateRateAccountCpiBuilder<'a, 'b> {
360 instruction: Box<UpdateRateAccountCpiBuilderInstruction<'a, 'b>>,
361}
362
363impl<'a, 'b> UpdateRateAccountCpiBuilder<'a, 'b> {
364 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
365 let instruction = Box::new(UpdateRateAccountCpiBuilderInstruction {
366 __program: program,
367 mint: None,
368 verification_config_or_mint_authority: None,
369 instructions_sysvar_or_creator: None,
370 rate_account: None,
371 mint_from: None,
372 mint_to: None,
373 update_rate_args: None,
374 __remaining_accounts: Vec::new(),
375 });
376 Self { instruction }
377 }
378 #[inline(always)]
379 pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
380 self.instruction.mint = Some(mint);
381 self
382 }
383 #[inline(always)]
384 pub fn verification_config_or_mint_authority(
385 &mut self,
386 verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
387 ) -> &mut Self {
388 self.instruction.verification_config_or_mint_authority =
389 Some(verification_config_or_mint_authority);
390 self
391 }
392 #[inline(always)]
393 pub fn instructions_sysvar_or_creator(
394 &mut self,
395 instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
396 ) -> &mut Self {
397 self.instruction.instructions_sysvar_or_creator = Some(instructions_sysvar_or_creator);
398 self
399 }
400 #[inline(always)]
401 pub fn rate_account(
402 &mut self,
403 rate_account: &'b solana_account_info::AccountInfo<'a>,
404 ) -> &mut Self {
405 self.instruction.rate_account = Some(rate_account);
406 self
407 }
408 #[inline(always)]
409 pub fn mint_from(&mut self, mint_from: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
410 self.instruction.mint_from = Some(mint_from);
411 self
412 }
413 #[inline(always)]
414 pub fn mint_to(&mut self, mint_to: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
415 self.instruction.mint_to = Some(mint_to);
416 self
417 }
418 #[inline(always)]
419 pub fn update_rate_args(&mut self, update_rate_args: UpdateRateArgs) -> &mut Self {
420 self.instruction.update_rate_args = Some(update_rate_args);
421 self
422 }
423 #[inline(always)]
425 pub fn add_remaining_account(
426 &mut self,
427 account: &'b solana_account_info::AccountInfo<'a>,
428 is_writable: bool,
429 is_signer: bool,
430 ) -> &mut Self {
431 self.instruction
432 .__remaining_accounts
433 .push((account, is_writable, is_signer));
434 self
435 }
436 #[inline(always)]
441 pub fn add_remaining_accounts(
442 &mut self,
443 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
444 ) -> &mut Self {
445 self.instruction
446 .__remaining_accounts
447 .extend_from_slice(accounts);
448 self
449 }
450 #[inline(always)]
451 pub fn invoke(&self) -> solana_program_error::ProgramResult {
452 self.invoke_signed(&[])
453 }
454 #[allow(clippy::clone_on_copy)]
455 #[allow(clippy::vec_init_then_push)]
456 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
457 let args = UpdateRateAccountInstructionArgs {
458 update_rate_args: self
459 .instruction
460 .update_rate_args
461 .clone()
462 .expect("update_rate_args is not set"),
463 };
464 let instruction = UpdateRateAccountCpi {
465 __program: self.instruction.__program,
466
467 mint: self.instruction.mint.expect("mint is not set"),
468
469 verification_config_or_mint_authority: self
470 .instruction
471 .verification_config_or_mint_authority
472 .expect("verification_config_or_mint_authority is not set"),
473
474 instructions_sysvar_or_creator: self
475 .instruction
476 .instructions_sysvar_or_creator
477 .expect("instructions_sysvar_or_creator is not set"),
478
479 rate_account: self
480 .instruction
481 .rate_account
482 .expect("rate_account is not set"),
483
484 mint_from: self.instruction.mint_from.expect("mint_from is not set"),
485
486 mint_to: self.instruction.mint_to.expect("mint_to is not set"),
487 __args: args,
488 };
489 instruction.invoke_signed_with_remaining_accounts(
490 signers_seeds,
491 &self.instruction.__remaining_accounts,
492 )
493 }
494}
495
496#[derive(Clone, Debug)]
497struct UpdateRateAccountCpiBuilderInstruction<'a, 'b> {
498 __program: &'b solana_account_info::AccountInfo<'a>,
499 mint: Option<&'b solana_account_info::AccountInfo<'a>>,
500 verification_config_or_mint_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
501 instructions_sysvar_or_creator: Option<&'b solana_account_info::AccountInfo<'a>>,
502 rate_account: Option<&'b solana_account_info::AccountInfo<'a>>,
503 mint_from: Option<&'b solana_account_info::AccountInfo<'a>>,
504 mint_to: Option<&'b solana_account_info::AccountInfo<'a>>,
505 update_rate_args: Option<UpdateRateArgs>,
506 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
508}