1use crate::generated::types::FeeType;
9use crate::generated::types::PolicyData;
10use solana_pubkey::Pubkey;
11use borsh::BorshSerialize;
12use borsh::BorshDeserialize;
13
14pub const INITIALIZE_MERCHANT_OPERATOR_CONFIG_DISCRIMINATOR: u8 = 2;
15
16#[derive(Debug)]
18pub struct InitializeMerchantOperatorConfig {
19
20
21 pub payer: solana_pubkey::Pubkey,
22 pub authority: solana_pubkey::Pubkey,
27 pub merchant: solana_pubkey::Pubkey,
32 pub operator: solana_pubkey::Pubkey,
37 pub config: solana_pubkey::Pubkey,
42
43
44 pub system_program: solana_pubkey::Pubkey,
45 }
46
47impl InitializeMerchantOperatorConfig {
48 pub fn instruction(&self, args: InitializeMerchantOperatorConfigInstructionArgs) -> solana_instruction::Instruction {
49 self.instruction_with_remaining_accounts(args, &[])
50 }
51 #[allow(clippy::arithmetic_side_effects)]
52 #[allow(clippy::vec_init_then_push)]
53 pub fn instruction_with_remaining_accounts(&self, args: InitializeMerchantOperatorConfigInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
54 let mut accounts = Vec::with_capacity(6+ remaining_accounts.len());
55 accounts.push(solana_instruction::AccountMeta::new(
56 self.payer,
57 true
58 ));
59 accounts.push(solana_instruction::AccountMeta::new_readonly(
60 self.authority,
61 true
62 ));
63 accounts.push(solana_instruction::AccountMeta::new_readonly(
64 self.merchant,
65 false
66 ));
67 accounts.push(solana_instruction::AccountMeta::new_readonly(
68 self.operator,
69 false
70 ));
71 accounts.push(solana_instruction::AccountMeta::new(
72 self.config,
73 false
74 ));
75 accounts.push(solana_instruction::AccountMeta::new_readonly(
76 self.system_program,
77 false
78 ));
79 accounts.extend_from_slice(remaining_accounts);
80 let mut data = borsh::to_vec(&InitializeMerchantOperatorConfigInstructionData::new()).unwrap();
81 let mut args = borsh::to_vec(&args).unwrap();
82 data.append(&mut args);
83
84 solana_instruction::Instruction {
85 program_id: crate::COMMERCE_PROGRAM_ID,
86 accounts,
87 data,
88 }
89 }
90}
91
92#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
93#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
94 pub struct InitializeMerchantOperatorConfigInstructionData {
95 discriminator: u8,
96 }
97
98impl InitializeMerchantOperatorConfigInstructionData {
99 pub fn new() -> Self {
100 Self {
101 discriminator: 2,
102 }
103 }
104}
105
106impl Default for InitializeMerchantOperatorConfigInstructionData {
107 fn default() -> Self {
108 Self::new()
109 }
110}
111
112#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114 pub struct InitializeMerchantOperatorConfigInstructionArgs {
115 pub version: u32,
116 pub bump: u8,
117 pub operator_fee: u64,
118 pub fee_type: FeeType,
119 pub days_to_close: u16,
120 pub policies: Vec<PolicyData>,
121 pub accepted_currencies: Vec<Pubkey>,
122 }
123
124
125#[derive(Clone, Debug, Default)]
136pub struct InitializeMerchantOperatorConfigBuilder {
137 payer: Option<solana_pubkey::Pubkey>,
138 authority: Option<solana_pubkey::Pubkey>,
139 merchant: Option<solana_pubkey::Pubkey>,
140 operator: Option<solana_pubkey::Pubkey>,
141 config: Option<solana_pubkey::Pubkey>,
142 system_program: Option<solana_pubkey::Pubkey>,
143 version: Option<u32>,
144 bump: Option<u8>,
145 operator_fee: Option<u64>,
146 fee_type: Option<FeeType>,
147 days_to_close: Option<u16>,
148 policies: Option<Vec<PolicyData>>,
149 accepted_currencies: Option<Vec<Pubkey>>,
150 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
151}
152
153impl InitializeMerchantOperatorConfigBuilder {
154 pub fn new() -> Self {
155 Self::default()
156 }
157 #[inline(always)]
158 pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self {
159 self.payer = Some(payer);
160 self
161 }
162 #[inline(always)]
164 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
165 self.authority = Some(authority);
166 self
167 }
168 #[inline(always)]
170 pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self {
171 self.merchant = Some(merchant);
172 self
173 }
174 #[inline(always)]
176 pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self {
177 self.operator = Some(operator);
178 self
179 }
180 #[inline(always)]
182 pub fn config(&mut self, config: solana_pubkey::Pubkey) -> &mut Self {
183 self.config = Some(config);
184 self
185 }
186 #[inline(always)]
188 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
189 self.system_program = Some(system_program);
190 self
191 }
192 #[inline(always)]
193 pub fn version(&mut self, version: u32) -> &mut Self {
194 self.version = Some(version);
195 self
196 }
197 #[inline(always)]
198 pub fn bump(&mut self, bump: u8) -> &mut Self {
199 self.bump = Some(bump);
200 self
201 }
202 #[inline(always)]
203 pub fn operator_fee(&mut self, operator_fee: u64) -> &mut Self {
204 self.operator_fee = Some(operator_fee);
205 self
206 }
207 #[inline(always)]
208 pub fn fee_type(&mut self, fee_type: FeeType) -> &mut Self {
209 self.fee_type = Some(fee_type);
210 self
211 }
212 #[inline(always)]
213 pub fn days_to_close(&mut self, days_to_close: u16) -> &mut Self {
214 self.days_to_close = Some(days_to_close);
215 self
216 }
217 #[inline(always)]
218 pub fn policies(&mut self, policies: Vec<PolicyData>) -> &mut Self {
219 self.policies = Some(policies);
220 self
221 }
222 #[inline(always)]
223 pub fn accepted_currencies(&mut self, accepted_currencies: Vec<Pubkey>) -> &mut Self {
224 self.accepted_currencies = Some(accepted_currencies);
225 self
226 }
227 #[inline(always)]
229 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
230 self.__remaining_accounts.push(account);
231 self
232 }
233 #[inline(always)]
235 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
236 self.__remaining_accounts.extend_from_slice(accounts);
237 self
238 }
239 #[allow(clippy::clone_on_copy)]
240 pub fn instruction(&self) -> solana_instruction::Instruction {
241 let accounts = InitializeMerchantOperatorConfig {
242 payer: self.payer.expect("payer is not set"),
243 authority: self.authority.expect("authority is not set"),
244 merchant: self.merchant.expect("merchant is not set"),
245 operator: self.operator.expect("operator is not set"),
246 config: self.config.expect("config is not set"),
247 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
248 };
249 let args = InitializeMerchantOperatorConfigInstructionArgs {
250 version: self.version.clone().expect("version is not set"),
251 bump: self.bump.clone().expect("bump is not set"),
252 operator_fee: self.operator_fee.clone().expect("operator_fee is not set"),
253 fee_type: self.fee_type.clone().expect("fee_type is not set"),
254 days_to_close: self.days_to_close.clone().expect("days_to_close is not set"),
255 policies: self.policies.clone().expect("policies is not set"),
256 accepted_currencies: self.accepted_currencies.clone().expect("accepted_currencies is not set"),
257 };
258
259 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
260 }
261}
262
263 pub struct InitializeMerchantOperatorConfigCpiAccounts<'a, 'b> {
265
266
267 pub payer: &'b solana_account_info::AccountInfo<'a>,
268 pub authority: &'b solana_account_info::AccountInfo<'a>,
273 pub merchant: &'b solana_account_info::AccountInfo<'a>,
278 pub operator: &'b solana_account_info::AccountInfo<'a>,
283 pub config: &'b solana_account_info::AccountInfo<'a>,
288
289
290 pub system_program: &'b solana_account_info::AccountInfo<'a>,
291 }
292
293pub struct InitializeMerchantOperatorConfigCpi<'a, 'b> {
295 pub __program: &'b solana_account_info::AccountInfo<'a>,
297
298
299 pub payer: &'b solana_account_info::AccountInfo<'a>,
300 pub authority: &'b solana_account_info::AccountInfo<'a>,
305 pub merchant: &'b solana_account_info::AccountInfo<'a>,
310 pub operator: &'b solana_account_info::AccountInfo<'a>,
315 pub config: &'b solana_account_info::AccountInfo<'a>,
320
321
322 pub system_program: &'b solana_account_info::AccountInfo<'a>,
323 pub __args: InitializeMerchantOperatorConfigInstructionArgs,
325 }
326
327impl<'a, 'b> InitializeMerchantOperatorConfigCpi<'a, 'b> {
328 pub fn new(
329 program: &'b solana_account_info::AccountInfo<'a>,
330 accounts: InitializeMerchantOperatorConfigCpiAccounts<'a, 'b>,
331 args: InitializeMerchantOperatorConfigInstructionArgs,
332 ) -> Self {
333 Self {
334 __program: program,
335 payer: accounts.payer,
336 authority: accounts.authority,
337 merchant: accounts.merchant,
338 operator: accounts.operator,
339 config: accounts.config,
340 system_program: accounts.system_program,
341 __args: args,
342 }
343 }
344 #[inline(always)]
345 pub fn invoke(&self) -> solana_program_error::ProgramResult {
346 self.invoke_signed_with_remaining_accounts(&[], &[])
347 }
348 #[inline(always)]
349 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
350 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
351 }
352 #[inline(always)]
353 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
354 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
355 }
356 #[allow(clippy::arithmetic_side_effects)]
357 #[allow(clippy::clone_on_copy)]
358 #[allow(clippy::vec_init_then_push)]
359 pub fn invoke_signed_with_remaining_accounts(
360 &self,
361 signers_seeds: &[&[&[u8]]],
362 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
363 ) -> solana_program_error::ProgramResult {
364 let mut accounts = Vec::with_capacity(6+ remaining_accounts.len());
365 accounts.push(solana_instruction::AccountMeta::new(
366 *self.payer.key,
367 true
368 ));
369 accounts.push(solana_instruction::AccountMeta::new_readonly(
370 *self.authority.key,
371 true
372 ));
373 accounts.push(solana_instruction::AccountMeta::new_readonly(
374 *self.merchant.key,
375 false
376 ));
377 accounts.push(solana_instruction::AccountMeta::new_readonly(
378 *self.operator.key,
379 false
380 ));
381 accounts.push(solana_instruction::AccountMeta::new(
382 *self.config.key,
383 false
384 ));
385 accounts.push(solana_instruction::AccountMeta::new_readonly(
386 *self.system_program.key,
387 false
388 ));
389 remaining_accounts.iter().for_each(|remaining_account| {
390 accounts.push(solana_instruction::AccountMeta {
391 pubkey: *remaining_account.0.key,
392 is_signer: remaining_account.1,
393 is_writable: remaining_account.2,
394 })
395 });
396 let mut data = borsh::to_vec(&InitializeMerchantOperatorConfigInstructionData::new()).unwrap();
397 let mut args = borsh::to_vec(&self.__args).unwrap();
398 data.append(&mut args);
399
400 let instruction = solana_instruction::Instruction {
401 program_id: crate::COMMERCE_PROGRAM_ID,
402 accounts,
403 data,
404 };
405 let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len());
406 account_infos.push(self.__program.clone());
407 account_infos.push(self.payer.clone());
408 account_infos.push(self.authority.clone());
409 account_infos.push(self.merchant.clone());
410 account_infos.push(self.operator.clone());
411 account_infos.push(self.config.clone());
412 account_infos.push(self.system_program.clone());
413 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
414
415 if signers_seeds.is_empty() {
416 solana_cpi::invoke(&instruction, &account_infos)
417 } else {
418 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
419 }
420 }
421}
422
423#[derive(Clone, Debug)]
434pub struct InitializeMerchantOperatorConfigCpiBuilder<'a, 'b> {
435 instruction: Box<InitializeMerchantOperatorConfigCpiBuilderInstruction<'a, 'b>>,
436}
437
438impl<'a, 'b> InitializeMerchantOperatorConfigCpiBuilder<'a, 'b> {
439 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
440 let instruction = Box::new(InitializeMerchantOperatorConfigCpiBuilderInstruction {
441 __program: program,
442 payer: None,
443 authority: None,
444 merchant: None,
445 operator: None,
446 config: None,
447 system_program: None,
448 version: None,
449 bump: None,
450 operator_fee: None,
451 fee_type: None,
452 days_to_close: None,
453 policies: None,
454 accepted_currencies: None,
455 __remaining_accounts: Vec::new(),
456 });
457 Self { instruction }
458 }
459 #[inline(always)]
460 pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
461 self.instruction.payer = Some(payer);
462 self
463 }
464 #[inline(always)]
466 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
467 self.instruction.authority = Some(authority);
468 self
469 }
470 #[inline(always)]
472 pub fn merchant(&mut self, merchant: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
473 self.instruction.merchant = Some(merchant);
474 self
475 }
476 #[inline(always)]
478 pub fn operator(&mut self, operator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
479 self.instruction.operator = Some(operator);
480 self
481 }
482 #[inline(always)]
484 pub fn config(&mut self, config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
485 self.instruction.config = Some(config);
486 self
487 }
488 #[inline(always)]
489 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
490 self.instruction.system_program = Some(system_program);
491 self
492 }
493 #[inline(always)]
494 pub fn version(&mut self, version: u32) -> &mut Self {
495 self.instruction.version = Some(version);
496 self
497 }
498 #[inline(always)]
499 pub fn bump(&mut self, bump: u8) -> &mut Self {
500 self.instruction.bump = Some(bump);
501 self
502 }
503 #[inline(always)]
504 pub fn operator_fee(&mut self, operator_fee: u64) -> &mut Self {
505 self.instruction.operator_fee = Some(operator_fee);
506 self
507 }
508 #[inline(always)]
509 pub fn fee_type(&mut self, fee_type: FeeType) -> &mut Self {
510 self.instruction.fee_type = Some(fee_type);
511 self
512 }
513 #[inline(always)]
514 pub fn days_to_close(&mut self, days_to_close: u16) -> &mut Self {
515 self.instruction.days_to_close = Some(days_to_close);
516 self
517 }
518 #[inline(always)]
519 pub fn policies(&mut self, policies: Vec<PolicyData>) -> &mut Self {
520 self.instruction.policies = Some(policies);
521 self
522 }
523 #[inline(always)]
524 pub fn accepted_currencies(&mut self, accepted_currencies: Vec<Pubkey>) -> &mut Self {
525 self.instruction.accepted_currencies = Some(accepted_currencies);
526 self
527 }
528 #[inline(always)]
530 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
531 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
532 self
533 }
534 #[inline(always)]
539 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
540 self.instruction.__remaining_accounts.extend_from_slice(accounts);
541 self
542 }
543 #[inline(always)]
544 pub fn invoke(&self) -> solana_program_error::ProgramResult {
545 self.invoke_signed(&[])
546 }
547 #[allow(clippy::clone_on_copy)]
548 #[allow(clippy::vec_init_then_push)]
549 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
550 let args = InitializeMerchantOperatorConfigInstructionArgs {
551 version: self.instruction.version.clone().expect("version is not set"),
552 bump: self.instruction.bump.clone().expect("bump is not set"),
553 operator_fee: self.instruction.operator_fee.clone().expect("operator_fee is not set"),
554 fee_type: self.instruction.fee_type.clone().expect("fee_type is not set"),
555 days_to_close: self.instruction.days_to_close.clone().expect("days_to_close is not set"),
556 policies: self.instruction.policies.clone().expect("policies is not set"),
557 accepted_currencies: self.instruction.accepted_currencies.clone().expect("accepted_currencies is not set"),
558 };
559 let instruction = InitializeMerchantOperatorConfigCpi {
560 __program: self.instruction.__program,
561
562 payer: self.instruction.payer.expect("payer is not set"),
563
564 authority: self.instruction.authority.expect("authority is not set"),
565
566 merchant: self.instruction.merchant.expect("merchant is not set"),
567
568 operator: self.instruction.operator.expect("operator is not set"),
569
570 config: self.instruction.config.expect("config is not set"),
571
572 system_program: self.instruction.system_program.expect("system_program is not set"),
573 __args: args,
574 };
575 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
576 }
577}
578
579#[derive(Clone, Debug)]
580struct InitializeMerchantOperatorConfigCpiBuilderInstruction<'a, 'b> {
581 __program: &'b solana_account_info::AccountInfo<'a>,
582 payer: Option<&'b solana_account_info::AccountInfo<'a>>,
583 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
584 merchant: Option<&'b solana_account_info::AccountInfo<'a>>,
585 operator: Option<&'b solana_account_info::AccountInfo<'a>>,
586 config: Option<&'b solana_account_info::AccountInfo<'a>>,
587 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
588 version: Option<u32>,
589 bump: Option<u8>,
590 operator_fee: Option<u64>,
591 fee_type: Option<FeeType>,
592 days_to_close: Option<u16>,
593 policies: Option<Vec<PolicyData>>,
594 accepted_currencies: Option<Vec<Pubkey>>,
595 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
597}
598