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 oracle_price_update_authority: Pubkey,
95 pub fee_recipient: Pubkey,
96 }
97
98
99#[derive(Clone, Debug, Default)]
108pub struct CreateTunaConfigBuilder {
109 authority: Option<solana_pubkey::Pubkey>,
110 tuna_config: Option<solana_pubkey::Pubkey>,
111 system_program: Option<solana_pubkey::Pubkey>,
112 rent: Option<solana_pubkey::Pubkey>,
113 owner_authority: Option<Pubkey>,
114 admin_authority: Option<Pubkey>,
115 liquidator_authority: Option<Pubkey>,
116 oracle_price_update_authority: Option<Pubkey>,
117 fee_recipient: Option<Pubkey>,
118 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
119}
120
121impl CreateTunaConfigBuilder {
122 pub fn new() -> Self {
123 Self::default()
124 }
125 #[inline(always)]
126 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
127 self.authority = Some(authority);
128 self
129 }
130 #[inline(always)]
131 pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
132 self.tuna_config = Some(tuna_config);
133 self
134 }
135 #[inline(always)]
137 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
138 self.system_program = Some(system_program);
139 self
140 }
141 #[inline(always)]
143 pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
144 self.rent = Some(rent);
145 self
146 }
147 #[inline(always)]
148 pub fn owner_authority(&mut self, owner_authority: Pubkey) -> &mut Self {
149 self.owner_authority = Some(owner_authority);
150 self
151 }
152 #[inline(always)]
153 pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
154 self.admin_authority = Some(admin_authority);
155 self
156 }
157 #[inline(always)]
158 pub fn liquidator_authority(&mut self, liquidator_authority: Pubkey) -> &mut Self {
159 self.liquidator_authority = Some(liquidator_authority);
160 self
161 }
162 #[inline(always)]
163 pub fn oracle_price_update_authority(&mut self, oracle_price_update_authority: Pubkey) -> &mut Self {
164 self.oracle_price_update_authority = Some(oracle_price_update_authority);
165 self
166 }
167 #[inline(always)]
168 pub fn fee_recipient(&mut self, fee_recipient: Pubkey) -> &mut Self {
169 self.fee_recipient = Some(fee_recipient);
170 self
171 }
172 #[inline(always)]
174 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
175 self.__remaining_accounts.push(account);
176 self
177 }
178 #[inline(always)]
180 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
181 self.__remaining_accounts.extend_from_slice(accounts);
182 self
183 }
184 #[allow(clippy::clone_on_copy)]
185 pub fn instruction(&self) -> solana_instruction::Instruction {
186 let accounts = CreateTunaConfig {
187 authority: self.authority.expect("authority is not set"),
188 tuna_config: self.tuna_config.expect("tuna_config is not set"),
189 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
190 rent: self.rent.unwrap_or(solana_pubkey::pubkey!("SysvarRent111111111111111111111111111111111")),
191 };
192 let args = CreateTunaConfigInstructionArgs {
193 owner_authority: self.owner_authority.clone().expect("owner_authority is not set"),
194 admin_authority: self.admin_authority.clone().expect("admin_authority is not set"),
195 liquidator_authority: self.liquidator_authority.clone().expect("liquidator_authority is not set"),
196 oracle_price_update_authority: self.oracle_price_update_authority.clone().expect("oracle_price_update_authority is not set"),
197 fee_recipient: self.fee_recipient.clone().expect("fee_recipient is not set"),
198 };
199
200 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
201 }
202}
203
204 pub struct CreateTunaConfigCpiAccounts<'a, 'b> {
206
207
208 pub authority: &'b solana_account_info::AccountInfo<'a>,
209
210
211 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
212
213
214 pub system_program: &'b solana_account_info::AccountInfo<'a>,
215
216
217 pub rent: &'b solana_account_info::AccountInfo<'a>,
218 }
219
220pub struct CreateTunaConfigCpi<'a, 'b> {
222 pub __program: &'b solana_account_info::AccountInfo<'a>,
224
225
226 pub authority: &'b solana_account_info::AccountInfo<'a>,
227
228
229 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
230
231
232 pub system_program: &'b solana_account_info::AccountInfo<'a>,
233
234
235 pub rent: &'b solana_account_info::AccountInfo<'a>,
236 pub __args: CreateTunaConfigInstructionArgs,
238 }
239
240impl<'a, 'b> CreateTunaConfigCpi<'a, 'b> {
241 pub fn new(
242 program: &'b solana_account_info::AccountInfo<'a>,
243 accounts: CreateTunaConfigCpiAccounts<'a, 'b>,
244 args: CreateTunaConfigInstructionArgs,
245 ) -> Self {
246 Self {
247 __program: program,
248 authority: accounts.authority,
249 tuna_config: accounts.tuna_config,
250 system_program: accounts.system_program,
251 rent: accounts.rent,
252 __args: args,
253 }
254 }
255 #[inline(always)]
256 pub fn invoke(&self) -> solana_program_error::ProgramResult {
257 self.invoke_signed_with_remaining_accounts(&[], &[])
258 }
259 #[inline(always)]
260 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
261 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
262 }
263 #[inline(always)]
264 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
265 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
266 }
267 #[allow(clippy::arithmetic_side_effects)]
268 #[allow(clippy::clone_on_copy)]
269 #[allow(clippy::vec_init_then_push)]
270 pub fn invoke_signed_with_remaining_accounts(
271 &self,
272 signers_seeds: &[&[&[u8]]],
273 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
274 ) -> solana_program_error::ProgramResult {
275 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
276 accounts.push(solana_instruction::AccountMeta::new(
277 *self.authority.key,
278 true
279 ));
280 accounts.push(solana_instruction::AccountMeta::new(
281 *self.tuna_config.key,
282 false
283 ));
284 accounts.push(solana_instruction::AccountMeta::new_readonly(
285 *self.system_program.key,
286 false
287 ));
288 accounts.push(solana_instruction::AccountMeta::new_readonly(
289 *self.rent.key,
290 false
291 ));
292 remaining_accounts.iter().for_each(|remaining_account| {
293 accounts.push(solana_instruction::AccountMeta {
294 pubkey: *remaining_account.0.key,
295 is_signer: remaining_account.1,
296 is_writable: remaining_account.2,
297 })
298 });
299 let mut data = borsh::to_vec(&CreateTunaConfigInstructionData::new()).unwrap();
300 let mut args = borsh::to_vec(&self.__args).unwrap();
301 data.append(&mut args);
302
303 let instruction = solana_instruction::Instruction {
304 program_id: crate::TUNA_ID,
305 accounts,
306 data,
307 };
308 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
309 account_infos.push(self.__program.clone());
310 account_infos.push(self.authority.clone());
311 account_infos.push(self.tuna_config.clone());
312 account_infos.push(self.system_program.clone());
313 account_infos.push(self.rent.clone());
314 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
315
316 if signers_seeds.is_empty() {
317 solana_cpi::invoke(&instruction, &account_infos)
318 } else {
319 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
320 }
321 }
322}
323
324#[derive(Clone, Debug)]
333pub struct CreateTunaConfigCpiBuilder<'a, 'b> {
334 instruction: Box<CreateTunaConfigCpiBuilderInstruction<'a, 'b>>,
335}
336
337impl<'a, 'b> CreateTunaConfigCpiBuilder<'a, 'b> {
338 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
339 let instruction = Box::new(CreateTunaConfigCpiBuilderInstruction {
340 __program: program,
341 authority: None,
342 tuna_config: None,
343 system_program: None,
344 rent: None,
345 owner_authority: None,
346 admin_authority: None,
347 liquidator_authority: None,
348 oracle_price_update_authority: None,
349 fee_recipient: None,
350 __remaining_accounts: Vec::new(),
351 });
352 Self { instruction }
353 }
354 #[inline(always)]
355 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
356 self.instruction.authority = Some(authority);
357 self
358 }
359 #[inline(always)]
360 pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
361 self.instruction.tuna_config = Some(tuna_config);
362 self
363 }
364 #[inline(always)]
365 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
366 self.instruction.system_program = Some(system_program);
367 self
368 }
369 #[inline(always)]
370 pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
371 self.instruction.rent = Some(rent);
372 self
373 }
374 #[inline(always)]
375 pub fn owner_authority(&mut self, owner_authority: Pubkey) -> &mut Self {
376 self.instruction.owner_authority = Some(owner_authority);
377 self
378 }
379 #[inline(always)]
380 pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
381 self.instruction.admin_authority = Some(admin_authority);
382 self
383 }
384 #[inline(always)]
385 pub fn liquidator_authority(&mut self, liquidator_authority: Pubkey) -> &mut Self {
386 self.instruction.liquidator_authority = Some(liquidator_authority);
387 self
388 }
389 #[inline(always)]
390 pub fn oracle_price_update_authority(&mut self, oracle_price_update_authority: Pubkey) -> &mut Self {
391 self.instruction.oracle_price_update_authority = Some(oracle_price_update_authority);
392 self
393 }
394 #[inline(always)]
395 pub fn fee_recipient(&mut self, fee_recipient: Pubkey) -> &mut Self {
396 self.instruction.fee_recipient = Some(fee_recipient);
397 self
398 }
399 #[inline(always)]
401 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
402 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
403 self
404 }
405 #[inline(always)]
410 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
411 self.instruction.__remaining_accounts.extend_from_slice(accounts);
412 self
413 }
414 #[inline(always)]
415 pub fn invoke(&self) -> solana_program_error::ProgramResult {
416 self.invoke_signed(&[])
417 }
418 #[allow(clippy::clone_on_copy)]
419 #[allow(clippy::vec_init_then_push)]
420 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
421 let args = CreateTunaConfigInstructionArgs {
422 owner_authority: self.instruction.owner_authority.clone().expect("owner_authority is not set"),
423 admin_authority: self.instruction.admin_authority.clone().expect("admin_authority is not set"),
424 liquidator_authority: self.instruction.liquidator_authority.clone().expect("liquidator_authority is not set"),
425 oracle_price_update_authority: self.instruction.oracle_price_update_authority.clone().expect("oracle_price_update_authority is not set"),
426 fee_recipient: self.instruction.fee_recipient.clone().expect("fee_recipient is not set"),
427 };
428 let instruction = CreateTunaConfigCpi {
429 __program: self.instruction.__program,
430
431 authority: self.instruction.authority.expect("authority is not set"),
432
433 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
434
435 system_program: self.instruction.system_program.expect("system_program is not set"),
436
437 rent: self.instruction.rent.expect("rent is not set"),
438 __args: args,
439 };
440 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
441 }
442}
443
444#[derive(Clone, Debug)]
445struct CreateTunaConfigCpiBuilderInstruction<'a, 'b> {
446 __program: &'b solana_account_info::AccountInfo<'a>,
447 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
448 tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
449 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
450 rent: Option<&'b solana_account_info::AccountInfo<'a>>,
451 owner_authority: Option<Pubkey>,
452 admin_authority: Option<Pubkey>,
453 liquidator_authority: Option<Pubkey>,
454 oracle_price_update_authority: Option<Pubkey>,
455 fee_recipient: Option<Pubkey>,
456 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
458}
459