Skip to main content

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