1use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const CREATE_TUNA_CONFIG_DISCRIMINATOR: [u8; 8] = [79, 78, 175, 62, 234, 68, 202, 241];
13
14#[derive(Debug)]
16pub struct CreateTunaConfig {
17
18
19 pub authority: solana_pubkey::Pubkey,
20
21
22 pub tuna_config: solana_pubkey::Pubkey,
23
24
25 pub system_program: solana_pubkey::Pubkey,
26
27
28 pub rent: solana_pubkey::Pubkey,
29 }
30
31impl CreateTunaConfig {
32 pub fn instruction(&self, args: CreateTunaConfigInstructionArgs) -> solana_instruction::Instruction {
33 self.instruction_with_remaining_accounts(args, &[])
34 }
35 #[allow(clippy::arithmetic_side_effects)]
36 #[allow(clippy::vec_init_then_push)]
37 pub fn instruction_with_remaining_accounts(&self, args: CreateTunaConfigInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
38 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
39 accounts.push(solana_instruction::AccountMeta::new(
40 self.authority,
41 true
42 ));
43 accounts.push(solana_instruction::AccountMeta::new(
44 self.tuna_config,
45 false
46 ));
47 accounts.push(solana_instruction::AccountMeta::new_readonly(
48 self.system_program,
49 false
50 ));
51 accounts.push(solana_instruction::AccountMeta::new_readonly(
52 self.rent,
53 false
54 ));
55 accounts.extend_from_slice(remaining_accounts);
56 let mut data = borsh::to_vec(&CreateTunaConfigInstructionData::new()).unwrap();
57 let mut args = borsh::to_vec(&args).unwrap();
58 data.append(&mut args);
59
60 solana_instruction::Instruction {
61 program_id: crate::TUNA_ID,
62 accounts,
63 data,
64 }
65 }
66}
67
68#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
69#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
70 pub struct CreateTunaConfigInstructionData {
71 discriminator: [u8; 8],
72 }
73
74impl CreateTunaConfigInstructionData {
75 pub fn new() -> Self {
76 Self {
77 discriminator: [79, 78, 175, 62, 234, 68, 202, 241],
78 }
79 }
80}
81
82impl Default for CreateTunaConfigInstructionData {
83 fn default() -> Self {
84 Self::new()
85 }
86}
87
88#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
89#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
90 pub struct CreateTunaConfigInstructionArgs {
91 pub owner_authority: Pubkey,
92 pub admin_authority: Pubkey,
93 pub liquidator_authority: Pubkey,
94 pub fee_recipient: Pubkey,
95 }
96
97
98#[derive(Clone, Debug, Default)]
107pub struct CreateTunaConfigBuilder {
108 authority: Option<solana_pubkey::Pubkey>,
109 tuna_config: Option<solana_pubkey::Pubkey>,
110 system_program: Option<solana_pubkey::Pubkey>,
111 rent: Option<solana_pubkey::Pubkey>,
112 owner_authority: Option<Pubkey>,
113 admin_authority: Option<Pubkey>,
114 liquidator_authority: Option<Pubkey>,
115 fee_recipient: Option<Pubkey>,
116 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
117}
118
119impl CreateTunaConfigBuilder {
120 pub fn new() -> Self {
121 Self::default()
122 }
123 #[inline(always)]
124 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
125 self.authority = Some(authority);
126 self
127 }
128 #[inline(always)]
129 pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
130 self.tuna_config = Some(tuna_config);
131 self
132 }
133 #[inline(always)]
135 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
136 self.system_program = Some(system_program);
137 self
138 }
139 #[inline(always)]
141 pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
142 self.rent = Some(rent);
143 self
144 }
145 #[inline(always)]
146 pub fn owner_authority(&mut self, owner_authority: Pubkey) -> &mut Self {
147 self.owner_authority = Some(owner_authority);
148 self
149 }
150 #[inline(always)]
151 pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
152 self.admin_authority = Some(admin_authority);
153 self
154 }
155 #[inline(always)]
156 pub fn liquidator_authority(&mut self, liquidator_authority: Pubkey) -> &mut Self {
157 self.liquidator_authority = Some(liquidator_authority);
158 self
159 }
160 #[inline(always)]
161 pub fn fee_recipient(&mut self, fee_recipient: Pubkey) -> &mut Self {
162 self.fee_recipient = Some(fee_recipient);
163 self
164 }
165 #[inline(always)]
167 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
168 self.__remaining_accounts.push(account);
169 self
170 }
171 #[inline(always)]
173 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
174 self.__remaining_accounts.extend_from_slice(accounts);
175 self
176 }
177 #[allow(clippy::clone_on_copy)]
178 pub fn instruction(&self) -> solana_instruction::Instruction {
179 let accounts = CreateTunaConfig {
180 authority: self.authority.expect("authority is not set"),
181 tuna_config: self.tuna_config.expect("tuna_config is not set"),
182 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
183 rent: self.rent.unwrap_or(solana_pubkey::pubkey!("SysvarRent111111111111111111111111111111111")),
184 };
185 let args = CreateTunaConfigInstructionArgs {
186 owner_authority: self.owner_authority.clone().expect("owner_authority is not set"),
187 admin_authority: self.admin_authority.clone().expect("admin_authority is not set"),
188 liquidator_authority: self.liquidator_authority.clone().expect("liquidator_authority is not set"),
189 fee_recipient: self.fee_recipient.clone().expect("fee_recipient is not set"),
190 };
191
192 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
193 }
194}
195
196 pub struct CreateTunaConfigCpiAccounts<'a, 'b> {
198
199
200 pub authority: &'b solana_account_info::AccountInfo<'a>,
201
202
203 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
204
205
206 pub system_program: &'b solana_account_info::AccountInfo<'a>,
207
208
209 pub rent: &'b solana_account_info::AccountInfo<'a>,
210 }
211
212pub struct CreateTunaConfigCpi<'a, 'b> {
214 pub __program: &'b solana_account_info::AccountInfo<'a>,
216
217
218 pub authority: &'b solana_account_info::AccountInfo<'a>,
219
220
221 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
222
223
224 pub system_program: &'b solana_account_info::AccountInfo<'a>,
225
226
227 pub rent: &'b solana_account_info::AccountInfo<'a>,
228 pub __args: CreateTunaConfigInstructionArgs,
230 }
231
232impl<'a, 'b> CreateTunaConfigCpi<'a, 'b> {
233 pub fn new(
234 program: &'b solana_account_info::AccountInfo<'a>,
235 accounts: CreateTunaConfigCpiAccounts<'a, 'b>,
236 args: CreateTunaConfigInstructionArgs,
237 ) -> Self {
238 Self {
239 __program: program,
240 authority: accounts.authority,
241 tuna_config: accounts.tuna_config,
242 system_program: accounts.system_program,
243 rent: accounts.rent,
244 __args: args,
245 }
246 }
247 #[inline(always)]
248 pub fn invoke(&self) -> solana_program_error::ProgramResult {
249 self.invoke_signed_with_remaining_accounts(&[], &[])
250 }
251 #[inline(always)]
252 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
253 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
254 }
255 #[inline(always)]
256 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
257 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
258 }
259 #[allow(clippy::arithmetic_side_effects)]
260 #[allow(clippy::clone_on_copy)]
261 #[allow(clippy::vec_init_then_push)]
262 pub fn invoke_signed_with_remaining_accounts(
263 &self,
264 signers_seeds: &[&[&[u8]]],
265 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
266 ) -> solana_program_error::ProgramResult {
267 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
268 accounts.push(solana_instruction::AccountMeta::new(
269 *self.authority.key,
270 true
271 ));
272 accounts.push(solana_instruction::AccountMeta::new(
273 *self.tuna_config.key,
274 false
275 ));
276 accounts.push(solana_instruction::AccountMeta::new_readonly(
277 *self.system_program.key,
278 false
279 ));
280 accounts.push(solana_instruction::AccountMeta::new_readonly(
281 *self.rent.key,
282 false
283 ));
284 remaining_accounts.iter().for_each(|remaining_account| {
285 accounts.push(solana_instruction::AccountMeta {
286 pubkey: *remaining_account.0.key,
287 is_signer: remaining_account.1,
288 is_writable: remaining_account.2,
289 })
290 });
291 let mut data = borsh::to_vec(&CreateTunaConfigInstructionData::new()).unwrap();
292 let mut args = borsh::to_vec(&self.__args).unwrap();
293 data.append(&mut args);
294
295 let instruction = solana_instruction::Instruction {
296 program_id: crate::TUNA_ID,
297 accounts,
298 data,
299 };
300 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
301 account_infos.push(self.__program.clone());
302 account_infos.push(self.authority.clone());
303 account_infos.push(self.tuna_config.clone());
304 account_infos.push(self.system_program.clone());
305 account_infos.push(self.rent.clone());
306 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
307
308 if signers_seeds.is_empty() {
309 solana_cpi::invoke(&instruction, &account_infos)
310 } else {
311 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
312 }
313 }
314}
315
316#[derive(Clone, Debug)]
325pub struct CreateTunaConfigCpiBuilder<'a, 'b> {
326 instruction: Box<CreateTunaConfigCpiBuilderInstruction<'a, 'b>>,
327}
328
329impl<'a, 'b> CreateTunaConfigCpiBuilder<'a, 'b> {
330 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
331 let instruction = Box::new(CreateTunaConfigCpiBuilderInstruction {
332 __program: program,
333 authority: None,
334 tuna_config: None,
335 system_program: None,
336 rent: None,
337 owner_authority: None,
338 admin_authority: None,
339 liquidator_authority: None,
340 fee_recipient: None,
341 __remaining_accounts: Vec::new(),
342 });
343 Self { instruction }
344 }
345 #[inline(always)]
346 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
347 self.instruction.authority = Some(authority);
348 self
349 }
350 #[inline(always)]
351 pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
352 self.instruction.tuna_config = Some(tuna_config);
353 self
354 }
355 #[inline(always)]
356 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
357 self.instruction.system_program = Some(system_program);
358 self
359 }
360 #[inline(always)]
361 pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
362 self.instruction.rent = Some(rent);
363 self
364 }
365 #[inline(always)]
366 pub fn owner_authority(&mut self, owner_authority: Pubkey) -> &mut Self {
367 self.instruction.owner_authority = Some(owner_authority);
368 self
369 }
370 #[inline(always)]
371 pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
372 self.instruction.admin_authority = Some(admin_authority);
373 self
374 }
375 #[inline(always)]
376 pub fn liquidator_authority(&mut self, liquidator_authority: Pubkey) -> &mut Self {
377 self.instruction.liquidator_authority = Some(liquidator_authority);
378 self
379 }
380 #[inline(always)]
381 pub fn fee_recipient(&mut self, fee_recipient: Pubkey) -> &mut Self {
382 self.instruction.fee_recipient = Some(fee_recipient);
383 self
384 }
385 #[inline(always)]
387 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
388 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
389 self
390 }
391 #[inline(always)]
396 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
397 self.instruction.__remaining_accounts.extend_from_slice(accounts);
398 self
399 }
400 #[inline(always)]
401 pub fn invoke(&self) -> solana_program_error::ProgramResult {
402 self.invoke_signed(&[])
403 }
404 #[allow(clippy::clone_on_copy)]
405 #[allow(clippy::vec_init_then_push)]
406 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
407 let args = CreateTunaConfigInstructionArgs {
408 owner_authority: self.instruction.owner_authority.clone().expect("owner_authority is not set"),
409 admin_authority: self.instruction.admin_authority.clone().expect("admin_authority is not set"),
410 liquidator_authority: self.instruction.liquidator_authority.clone().expect("liquidator_authority is not set"),
411 fee_recipient: self.instruction.fee_recipient.clone().expect("fee_recipient is not set"),
412 };
413 let instruction = CreateTunaConfigCpi {
414 __program: self.instruction.__program,
415
416 authority: self.instruction.authority.expect("authority is not set"),
417
418 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
419
420 system_program: self.instruction.system_program.expect("system_program is not set"),
421
422 rent: self.instruction.rent.expect("rent is not set"),
423 __args: args,
424 };
425 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
426 }
427}
428
429#[derive(Clone, Debug)]
430struct CreateTunaConfigCpiBuilderInstruction<'a, 'b> {
431 __program: &'b solana_account_info::AccountInfo<'a>,
432 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
433 tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
434 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
435 rent: Option<&'b solana_account_info::AccountInfo<'a>>,
436 owner_authority: Option<Pubkey>,
437 admin_authority: Option<Pubkey>,
438 liquidator_authority: Option<Pubkey>,
439 fee_recipient: Option<Pubkey>,
440 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
442}
443