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