Skip to main content

satrush_client/generated/instructions/
set_affiliate_rate.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::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const SET_AFFILIATE_RATE_DISCRIMINATOR: [u8; 8] = [154, 180, 87, 120, 226, 89, 33, 166];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct SetAffiliateRate {
16      
17              
18          pub authority: solana_address::Address,
19          
20              
21          pub satrush_config: solana_address::Address,
22          
23              
24          pub affiliate: solana_address::Address,
25      }
26
27impl SetAffiliateRate {
28  pub fn instruction(&self, args: SetAffiliateRateInstructionArgs) -> solana_instruction::Instruction {
29    self.instruction_with_remaining_accounts(args, &[])
30  }
31  #[allow(clippy::arithmetic_side_effects)]
32  #[allow(clippy::vec_init_then_push)]
33  pub fn instruction_with_remaining_accounts(&self, args: SetAffiliateRateInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
34    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
35                            accounts.push(solana_instruction::AccountMeta::new_readonly(
36            self.authority,
37            true
38          ));
39                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
40            self.satrush_config,
41            false
42          ));
43                                          accounts.push(solana_instruction::AccountMeta::new(
44            self.affiliate,
45            false
46          ));
47                      accounts.extend_from_slice(remaining_accounts);
48    let mut data = SetAffiliateRateInstructionData::new().try_to_vec().unwrap();
49          let mut args = args.try_to_vec().unwrap();
50      data.append(&mut args);
51    
52    solana_instruction::Instruction {
53      program_id: crate::SATRUSH_ID,
54      accounts,
55      data,
56    }
57  }
58}
59
60#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
61 pub struct SetAffiliateRateInstructionData {
62            discriminator: [u8; 8],
63            }
64
65impl SetAffiliateRateInstructionData {
66  pub fn new() -> Self {
67    Self {
68                        discriminator: [154, 180, 87, 120, 226, 89, 33, 166],
69                                }
70  }
71
72    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
73    borsh::to_vec(self)
74  }
75  }
76
77impl Default for SetAffiliateRateInstructionData {
78  fn default() -> Self {
79    Self::new()
80  }
81}
82
83#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
84 pub struct SetAffiliateRateInstructionArgs {
85                  pub rate_bps: u16,
86      }
87
88impl SetAffiliateRateInstructionArgs {
89  pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
90    borsh::to_vec(self)
91  }
92}
93
94
95/// Instruction builder for `SetAffiliateRate`.
96///
97/// ### Accounts:
98///
99                ///   0. `[signer]` authority
100          ///   1. `[]` satrush_config
101                ///   2. `[writable]` affiliate
102#[derive(Clone, Debug, Default)]
103pub struct SetAffiliateRateBuilder {
104            authority: Option<solana_address::Address>,
105                satrush_config: Option<solana_address::Address>,
106                affiliate: Option<solana_address::Address>,
107                        rate_bps: Option<u16>,
108        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
109}
110
111impl SetAffiliateRateBuilder {
112  pub fn new() -> Self {
113    Self::default()
114  }
115            #[inline(always)]
116    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
117                        self.authority = Some(authority);
118                    self
119    }
120            #[inline(always)]
121    pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
122                        self.satrush_config = Some(satrush_config);
123                    self
124    }
125            #[inline(always)]
126    pub fn affiliate(&mut self, affiliate: solana_address::Address) -> &mut Self {
127                        self.affiliate = Some(affiliate);
128                    self
129    }
130                    #[inline(always)]
131      pub fn rate_bps(&mut self, rate_bps: u16) -> &mut Self {
132        self.rate_bps = Some(rate_bps);
133        self
134      }
135        /// Add an additional account to the instruction.
136  #[inline(always)]
137  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
138    self.__remaining_accounts.push(account);
139    self
140  }
141  /// Add additional accounts to the instruction.
142  #[inline(always)]
143  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
144    self.__remaining_accounts.extend_from_slice(accounts);
145    self
146  }
147  #[allow(clippy::clone_on_copy)]
148  pub fn instruction(&self) -> solana_instruction::Instruction {
149    let accounts = SetAffiliateRate {
150                              authority: self.authority.expect("authority is not set"),
151                                        satrush_config: self.satrush_config.expect("satrush_config is not set"),
152                                        affiliate: self.affiliate.expect("affiliate is not set"),
153                      };
154          let args = SetAffiliateRateInstructionArgs {
155                                                              rate_bps: self.rate_bps.clone().expect("rate_bps is not set"),
156                                    };
157    
158    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
159  }
160}
161
162  /// `set_affiliate_rate` CPI accounts.
163  pub struct SetAffiliateRateCpiAccounts<'a, 'b> {
164          
165                    
166              pub authority: &'b solana_account_info::AccountInfo<'a>,
167                
168                    
169              pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
170                
171                    
172              pub affiliate: &'b solana_account_info::AccountInfo<'a>,
173            }
174
175/// `set_affiliate_rate` CPI instruction.
176pub struct SetAffiliateRateCpi<'a, 'b> {
177  /// The program to invoke.
178  pub __program: &'b solana_account_info::AccountInfo<'a>,
179      
180              
181          pub authority: &'b solana_account_info::AccountInfo<'a>,
182          
183              
184          pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
185          
186              
187          pub affiliate: &'b solana_account_info::AccountInfo<'a>,
188            /// The arguments for the instruction.
189    pub __args: SetAffiliateRateInstructionArgs,
190  }
191
192impl<'a, 'b> SetAffiliateRateCpi<'a, 'b> {
193  pub fn new(
194    program: &'b solana_account_info::AccountInfo<'a>,
195          accounts: SetAffiliateRateCpiAccounts<'a, 'b>,
196              args: SetAffiliateRateInstructionArgs,
197      ) -> Self {
198    Self {
199      __program: program,
200              authority: accounts.authority,
201              satrush_config: accounts.satrush_config,
202              affiliate: accounts.affiliate,
203                    __args: args,
204          }
205  }
206  #[inline(always)]
207  pub fn invoke(&self) -> solana_program_error::ProgramResult {
208    self.invoke_signed_with_remaining_accounts(&[], &[])
209  }
210  #[inline(always)]
211  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
212    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
213  }
214  #[inline(always)]
215  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
216    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
217  }
218  #[allow(clippy::arithmetic_side_effects)]
219  #[allow(clippy::clone_on_copy)]
220  #[allow(clippy::vec_init_then_push)]
221  pub fn invoke_signed_with_remaining_accounts(
222    &self,
223    signers_seeds: &[&[&[u8]]],
224    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
225  ) -> solana_program_error::ProgramResult {
226    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
227                            accounts.push(solana_instruction::AccountMeta::new_readonly(
228            *self.authority.key,
229            true
230          ));
231                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
232            *self.satrush_config.key,
233            false
234          ));
235                                          accounts.push(solana_instruction::AccountMeta::new(
236            *self.affiliate.key,
237            false
238          ));
239                      remaining_accounts.iter().for_each(|remaining_account| {
240      accounts.push(solana_instruction::AccountMeta {
241          pubkey: *remaining_account.0.key,
242          is_signer: remaining_account.1,
243          is_writable: remaining_account.2,
244      })
245    });
246    let mut data = SetAffiliateRateInstructionData::new().try_to_vec().unwrap();
247          let mut args = self.__args.try_to_vec().unwrap();
248      data.append(&mut args);
249    
250    let instruction = solana_instruction::Instruction {
251      program_id: crate::SATRUSH_ID,
252      accounts,
253      data,
254    };
255    let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
256    account_infos.push(self.__program.clone());
257                  account_infos.push(self.authority.clone());
258                        account_infos.push(self.satrush_config.clone());
259                        account_infos.push(self.affiliate.clone());
260              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
261
262    if signers_seeds.is_empty() {
263      solana_cpi::invoke(&instruction, &account_infos)
264    } else {
265      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
266    }
267  }
268}
269
270/// Instruction builder for `SetAffiliateRate` via CPI.
271///
272/// ### Accounts:
273///
274                ///   0. `[signer]` authority
275          ///   1. `[]` satrush_config
276                ///   2. `[writable]` affiliate
277#[derive(Clone, Debug)]
278pub struct SetAffiliateRateCpiBuilder<'a, 'b> {
279  instruction: Box<SetAffiliateRateCpiBuilderInstruction<'a, 'b>>,
280}
281
282impl<'a, 'b> SetAffiliateRateCpiBuilder<'a, 'b> {
283  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
284    let instruction = Box::new(SetAffiliateRateCpiBuilderInstruction {
285      __program: program,
286              authority: None,
287              satrush_config: None,
288              affiliate: None,
289                                            rate_bps: None,
290                    __remaining_accounts: Vec::new(),
291    });
292    Self { instruction }
293  }
294      #[inline(always)]
295    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
296                        self.instruction.authority = Some(authority);
297                    self
298    }
299      #[inline(always)]
300    pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
301                        self.instruction.satrush_config = Some(satrush_config);
302                    self
303    }
304      #[inline(always)]
305    pub fn affiliate(&mut self, affiliate: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
306                        self.instruction.affiliate = Some(affiliate);
307                    self
308    }
309                    #[inline(always)]
310      pub fn rate_bps(&mut self, rate_bps: u16) -> &mut Self {
311        self.instruction.rate_bps = Some(rate_bps);
312        self
313      }
314        /// Add an additional account to the instruction.
315  #[inline(always)]
316  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
317    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
318    self
319  }
320  /// Add additional accounts to the instruction.
321  ///
322  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
323  /// and a `bool` indicating whether the account is a signer or not.
324  #[inline(always)]
325  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
326    self.instruction.__remaining_accounts.extend_from_slice(accounts);
327    self
328  }
329  #[inline(always)]
330  pub fn invoke(&self) -> solana_program_error::ProgramResult {
331    self.invoke_signed(&[])
332  }
333  #[allow(clippy::clone_on_copy)]
334  #[allow(clippy::vec_init_then_push)]
335  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
336          let args = SetAffiliateRateInstructionArgs {
337                                                              rate_bps: self.instruction.rate_bps.clone().expect("rate_bps is not set"),
338                                    };
339        let instruction = SetAffiliateRateCpi {
340        __program: self.instruction.__program,
341                  
342          authority: self.instruction.authority.expect("authority is not set"),
343                  
344          satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
345                  
346          affiliate: self.instruction.affiliate.expect("affiliate is not set"),
347                          __args: args,
348            };
349    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
350  }
351}
352
353#[derive(Clone, Debug)]
354struct SetAffiliateRateCpiBuilderInstruction<'a, 'b> {
355  __program: &'b solana_account_info::AccountInfo<'a>,
356            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
357                satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
358                affiliate: Option<&'b solana_account_info::AccountInfo<'a>>,
359                        rate_bps: Option<u16>,
360        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
361  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
362}
363