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