1use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const UPDATE_MARKET_DISCRIMINATOR: [u8; 8] = [153, 39, 2, 197, 179, 50, 199, 217];
13
14#[derive(Debug)]
16pub struct UpdateMarket {
17
18
19 pub authority: solana_pubkey::Pubkey,
20
21
22 pub tuna_config: solana_pubkey::Pubkey,
23
24
25 pub market: solana_pubkey::Pubkey,
26 }
27
28impl UpdateMarket {
29 pub fn instruction(&self, args: UpdateMarketInstructionArgs) -> solana_instruction::Instruction {
30 self.instruction_with_remaining_accounts(args, &[])
31 }
32 #[allow(clippy::arithmetic_side_effects)]
33 #[allow(clippy::vec_init_then_push)]
34 pub fn instruction_with_remaining_accounts(&self, args: UpdateMarketInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
35 let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
36 accounts.push(solana_instruction::AccountMeta::new(
37 self.authority,
38 true
39 ));
40 accounts.push(solana_instruction::AccountMeta::new_readonly(
41 self.tuna_config,
42 false
43 ));
44 accounts.push(solana_instruction::AccountMeta::new(
45 self.market,
46 false
47 ));
48 accounts.extend_from_slice(remaining_accounts);
49 let mut data = borsh::to_vec(&UpdateMarketInstructionData::new()).unwrap();
50 let mut args = borsh::to_vec(&args).unwrap();
51 data.append(&mut args);
52
53 solana_instruction::Instruction {
54 program_id: crate::TUNA_ID,
55 accounts,
56 data,
57 }
58 }
59}
60
61#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63 pub struct UpdateMarketInstructionData {
64 discriminator: [u8; 8],
65 }
66
67impl UpdateMarketInstructionData {
68 pub fn new() -> Self {
69 Self {
70 discriminator: [153, 39, 2, 197, 179, 50, 199, 217],
71 }
72 }
73}
74
75impl Default for UpdateMarketInstructionData {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83 pub struct UpdateMarketInstructionArgs {
84 pub address_lookup_table: Pubkey,
85 pub max_leverage: u32,
86 pub protocol_fee: u16,
87 pub protocol_fee_on_collateral: u16,
88 pub liquidation_fee: u32,
89 pub liquidation_threshold: u32,
90 pub oracle_price_deviation_threshold: u32,
91 pub disabled: bool,
92 pub borrow_limit_a: u64,
93 pub borrow_limit_b: u64,
94 pub max_swap_slippage: u32,
95 pub rebalance_protocol_fee: u32,
96 pub spot_position_size_limit_a: u64,
97 pub spot_position_size_limit_b: u64,
98 }
99
100
101#[derive(Clone, Debug, Default)]
109pub struct UpdateMarketBuilder {
110 authority: Option<solana_pubkey::Pubkey>,
111 tuna_config: Option<solana_pubkey::Pubkey>,
112 market: Option<solana_pubkey::Pubkey>,
113 address_lookup_table: Option<Pubkey>,
114 max_leverage: Option<u32>,
115 protocol_fee: Option<u16>,
116 protocol_fee_on_collateral: Option<u16>,
117 liquidation_fee: Option<u32>,
118 liquidation_threshold: Option<u32>,
119 oracle_price_deviation_threshold: Option<u32>,
120 disabled: Option<bool>,
121 borrow_limit_a: Option<u64>,
122 borrow_limit_b: Option<u64>,
123 max_swap_slippage: Option<u32>,
124 rebalance_protocol_fee: Option<u32>,
125 spot_position_size_limit_a: Option<u64>,
126 spot_position_size_limit_b: Option<u64>,
127 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
128}
129
130impl UpdateMarketBuilder {
131 pub fn new() -> Self {
132 Self::default()
133 }
134 #[inline(always)]
135 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
136 self.authority = Some(authority);
137 self
138 }
139 #[inline(always)]
140 pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
141 self.tuna_config = Some(tuna_config);
142 self
143 }
144 #[inline(always)]
145 pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
146 self.market = Some(market);
147 self
148 }
149 #[inline(always)]
150 pub fn address_lookup_table(&mut self, address_lookup_table: Pubkey) -> &mut Self {
151 self.address_lookup_table = Some(address_lookup_table);
152 self
153 }
154 #[inline(always)]
155 pub fn max_leverage(&mut self, max_leverage: u32) -> &mut Self {
156 self.max_leverage = Some(max_leverage);
157 self
158 }
159 #[inline(always)]
160 pub fn protocol_fee(&mut self, protocol_fee: u16) -> &mut Self {
161 self.protocol_fee = Some(protocol_fee);
162 self
163 }
164 #[inline(always)]
165 pub fn protocol_fee_on_collateral(&mut self, protocol_fee_on_collateral: u16) -> &mut Self {
166 self.protocol_fee_on_collateral = Some(protocol_fee_on_collateral);
167 self
168 }
169 #[inline(always)]
170 pub fn liquidation_fee(&mut self, liquidation_fee: u32) -> &mut Self {
171 self.liquidation_fee = Some(liquidation_fee);
172 self
173 }
174 #[inline(always)]
175 pub fn liquidation_threshold(&mut self, liquidation_threshold: u32) -> &mut Self {
176 self.liquidation_threshold = Some(liquidation_threshold);
177 self
178 }
179 #[inline(always)]
180 pub fn oracle_price_deviation_threshold(&mut self, oracle_price_deviation_threshold: u32) -> &mut Self {
181 self.oracle_price_deviation_threshold = Some(oracle_price_deviation_threshold);
182 self
183 }
184 #[inline(always)]
185 pub fn disabled(&mut self, disabled: bool) -> &mut Self {
186 self.disabled = Some(disabled);
187 self
188 }
189 #[inline(always)]
190 pub fn borrow_limit_a(&mut self, borrow_limit_a: u64) -> &mut Self {
191 self.borrow_limit_a = Some(borrow_limit_a);
192 self
193 }
194 #[inline(always)]
195 pub fn borrow_limit_b(&mut self, borrow_limit_b: u64) -> &mut Self {
196 self.borrow_limit_b = Some(borrow_limit_b);
197 self
198 }
199 #[inline(always)]
200 pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
201 self.max_swap_slippage = Some(max_swap_slippage);
202 self
203 }
204 #[inline(always)]
205 pub fn rebalance_protocol_fee(&mut self, rebalance_protocol_fee: u32) -> &mut Self {
206 self.rebalance_protocol_fee = Some(rebalance_protocol_fee);
207 self
208 }
209 #[inline(always)]
210 pub fn spot_position_size_limit_a(&mut self, spot_position_size_limit_a: u64) -> &mut Self {
211 self.spot_position_size_limit_a = Some(spot_position_size_limit_a);
212 self
213 }
214 #[inline(always)]
215 pub fn spot_position_size_limit_b(&mut self, spot_position_size_limit_b: u64) -> &mut Self {
216 self.spot_position_size_limit_b = Some(spot_position_size_limit_b);
217 self
218 }
219 #[inline(always)]
221 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
222 self.__remaining_accounts.push(account);
223 self
224 }
225 #[inline(always)]
227 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
228 self.__remaining_accounts.extend_from_slice(accounts);
229 self
230 }
231 #[allow(clippy::clone_on_copy)]
232 pub fn instruction(&self) -> solana_instruction::Instruction {
233 let accounts = UpdateMarket {
234 authority: self.authority.expect("authority is not set"),
235 tuna_config: self.tuna_config.expect("tuna_config is not set"),
236 market: self.market.expect("market is not set"),
237 };
238 let args = UpdateMarketInstructionArgs {
239 address_lookup_table: self.address_lookup_table.clone().expect("address_lookup_table is not set"),
240 max_leverage: self.max_leverage.clone().expect("max_leverage is not set"),
241 protocol_fee: self.protocol_fee.clone().expect("protocol_fee is not set"),
242 protocol_fee_on_collateral: self.protocol_fee_on_collateral.clone().expect("protocol_fee_on_collateral is not set"),
243 liquidation_fee: self.liquidation_fee.clone().expect("liquidation_fee is not set"),
244 liquidation_threshold: self.liquidation_threshold.clone().expect("liquidation_threshold is not set"),
245 oracle_price_deviation_threshold: self.oracle_price_deviation_threshold.clone().expect("oracle_price_deviation_threshold is not set"),
246 disabled: self.disabled.clone().expect("disabled is not set"),
247 borrow_limit_a: self.borrow_limit_a.clone().expect("borrow_limit_a is not set"),
248 borrow_limit_b: self.borrow_limit_b.clone().expect("borrow_limit_b is not set"),
249 max_swap_slippage: self.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
250 rebalance_protocol_fee: self.rebalance_protocol_fee.clone().expect("rebalance_protocol_fee is not set"),
251 spot_position_size_limit_a: self.spot_position_size_limit_a.clone().expect("spot_position_size_limit_a is not set"),
252 spot_position_size_limit_b: self.spot_position_size_limit_b.clone().expect("spot_position_size_limit_b is not set"),
253 };
254
255 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
256 }
257}
258
259 pub struct UpdateMarketCpiAccounts<'a, 'b> {
261
262
263 pub authority: &'b solana_account_info::AccountInfo<'a>,
264
265
266 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
267
268
269 pub market: &'b solana_account_info::AccountInfo<'a>,
270 }
271
272pub struct UpdateMarketCpi<'a, 'b> {
274 pub __program: &'b solana_account_info::AccountInfo<'a>,
276
277
278 pub authority: &'b solana_account_info::AccountInfo<'a>,
279
280
281 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
282
283
284 pub market: &'b solana_account_info::AccountInfo<'a>,
285 pub __args: UpdateMarketInstructionArgs,
287 }
288
289impl<'a, 'b> UpdateMarketCpi<'a, 'b> {
290 pub fn new(
291 program: &'b solana_account_info::AccountInfo<'a>,
292 accounts: UpdateMarketCpiAccounts<'a, 'b>,
293 args: UpdateMarketInstructionArgs,
294 ) -> Self {
295 Self {
296 __program: program,
297 authority: accounts.authority,
298 tuna_config: accounts.tuna_config,
299 market: accounts.market,
300 __args: args,
301 }
302 }
303 #[inline(always)]
304 pub fn invoke(&self) -> solana_program_error::ProgramResult {
305 self.invoke_signed_with_remaining_accounts(&[], &[])
306 }
307 #[inline(always)]
308 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
309 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
310 }
311 #[inline(always)]
312 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
313 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
314 }
315 #[allow(clippy::arithmetic_side_effects)]
316 #[allow(clippy::clone_on_copy)]
317 #[allow(clippy::vec_init_then_push)]
318 pub fn invoke_signed_with_remaining_accounts(
319 &self,
320 signers_seeds: &[&[&[u8]]],
321 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
322 ) -> solana_program_error::ProgramResult {
323 let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
324 accounts.push(solana_instruction::AccountMeta::new(
325 *self.authority.key,
326 true
327 ));
328 accounts.push(solana_instruction::AccountMeta::new_readonly(
329 *self.tuna_config.key,
330 false
331 ));
332 accounts.push(solana_instruction::AccountMeta::new(
333 *self.market.key,
334 false
335 ));
336 remaining_accounts.iter().for_each(|remaining_account| {
337 accounts.push(solana_instruction::AccountMeta {
338 pubkey: *remaining_account.0.key,
339 is_signer: remaining_account.1,
340 is_writable: remaining_account.2,
341 })
342 });
343 let mut data = borsh::to_vec(&UpdateMarketInstructionData::new()).unwrap();
344 let mut args = borsh::to_vec(&self.__args).unwrap();
345 data.append(&mut args);
346
347 let instruction = solana_instruction::Instruction {
348 program_id: crate::TUNA_ID,
349 accounts,
350 data,
351 };
352 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
353 account_infos.push(self.__program.clone());
354 account_infos.push(self.authority.clone());
355 account_infos.push(self.tuna_config.clone());
356 account_infos.push(self.market.clone());
357 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
358
359 if signers_seeds.is_empty() {
360 solana_cpi::invoke(&instruction, &account_infos)
361 } else {
362 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
363 }
364 }
365}
366
367#[derive(Clone, Debug)]
375pub struct UpdateMarketCpiBuilder<'a, 'b> {
376 instruction: Box<UpdateMarketCpiBuilderInstruction<'a, 'b>>,
377}
378
379impl<'a, 'b> UpdateMarketCpiBuilder<'a, 'b> {
380 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
381 let instruction = Box::new(UpdateMarketCpiBuilderInstruction {
382 __program: program,
383 authority: None,
384 tuna_config: None,
385 market: None,
386 address_lookup_table: None,
387 max_leverage: None,
388 protocol_fee: None,
389 protocol_fee_on_collateral: None,
390 liquidation_fee: None,
391 liquidation_threshold: None,
392 oracle_price_deviation_threshold: None,
393 disabled: None,
394 borrow_limit_a: None,
395 borrow_limit_b: None,
396 max_swap_slippage: None,
397 rebalance_protocol_fee: None,
398 spot_position_size_limit_a: None,
399 spot_position_size_limit_b: None,
400 __remaining_accounts: Vec::new(),
401 });
402 Self { instruction }
403 }
404 #[inline(always)]
405 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
406 self.instruction.authority = Some(authority);
407 self
408 }
409 #[inline(always)]
410 pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
411 self.instruction.tuna_config = Some(tuna_config);
412 self
413 }
414 #[inline(always)]
415 pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
416 self.instruction.market = Some(market);
417 self
418 }
419 #[inline(always)]
420 pub fn address_lookup_table(&mut self, address_lookup_table: Pubkey) -> &mut Self {
421 self.instruction.address_lookup_table = Some(address_lookup_table);
422 self
423 }
424 #[inline(always)]
425 pub fn max_leverage(&mut self, max_leverage: u32) -> &mut Self {
426 self.instruction.max_leverage = Some(max_leverage);
427 self
428 }
429 #[inline(always)]
430 pub fn protocol_fee(&mut self, protocol_fee: u16) -> &mut Self {
431 self.instruction.protocol_fee = Some(protocol_fee);
432 self
433 }
434 #[inline(always)]
435 pub fn protocol_fee_on_collateral(&mut self, protocol_fee_on_collateral: u16) -> &mut Self {
436 self.instruction.protocol_fee_on_collateral = Some(protocol_fee_on_collateral);
437 self
438 }
439 #[inline(always)]
440 pub fn liquidation_fee(&mut self, liquidation_fee: u32) -> &mut Self {
441 self.instruction.liquidation_fee = Some(liquidation_fee);
442 self
443 }
444 #[inline(always)]
445 pub fn liquidation_threshold(&mut self, liquidation_threshold: u32) -> &mut Self {
446 self.instruction.liquidation_threshold = Some(liquidation_threshold);
447 self
448 }
449 #[inline(always)]
450 pub fn oracle_price_deviation_threshold(&mut self, oracle_price_deviation_threshold: u32) -> &mut Self {
451 self.instruction.oracle_price_deviation_threshold = Some(oracle_price_deviation_threshold);
452 self
453 }
454 #[inline(always)]
455 pub fn disabled(&mut self, disabled: bool) -> &mut Self {
456 self.instruction.disabled = Some(disabled);
457 self
458 }
459 #[inline(always)]
460 pub fn borrow_limit_a(&mut self, borrow_limit_a: u64) -> &mut Self {
461 self.instruction.borrow_limit_a = Some(borrow_limit_a);
462 self
463 }
464 #[inline(always)]
465 pub fn borrow_limit_b(&mut self, borrow_limit_b: u64) -> &mut Self {
466 self.instruction.borrow_limit_b = Some(borrow_limit_b);
467 self
468 }
469 #[inline(always)]
470 pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
471 self.instruction.max_swap_slippage = Some(max_swap_slippage);
472 self
473 }
474 #[inline(always)]
475 pub fn rebalance_protocol_fee(&mut self, rebalance_protocol_fee: u32) -> &mut Self {
476 self.instruction.rebalance_protocol_fee = Some(rebalance_protocol_fee);
477 self
478 }
479 #[inline(always)]
480 pub fn spot_position_size_limit_a(&mut self, spot_position_size_limit_a: u64) -> &mut Self {
481 self.instruction.spot_position_size_limit_a = Some(spot_position_size_limit_a);
482 self
483 }
484 #[inline(always)]
485 pub fn spot_position_size_limit_b(&mut self, spot_position_size_limit_b: u64) -> &mut Self {
486 self.instruction.spot_position_size_limit_b = Some(spot_position_size_limit_b);
487 self
488 }
489 #[inline(always)]
491 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
492 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
493 self
494 }
495 #[inline(always)]
500 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
501 self.instruction.__remaining_accounts.extend_from_slice(accounts);
502 self
503 }
504 #[inline(always)]
505 pub fn invoke(&self) -> solana_program_error::ProgramResult {
506 self.invoke_signed(&[])
507 }
508 #[allow(clippy::clone_on_copy)]
509 #[allow(clippy::vec_init_then_push)]
510 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
511 let args = UpdateMarketInstructionArgs {
512 address_lookup_table: self.instruction.address_lookup_table.clone().expect("address_lookup_table is not set"),
513 max_leverage: self.instruction.max_leverage.clone().expect("max_leverage is not set"),
514 protocol_fee: self.instruction.protocol_fee.clone().expect("protocol_fee is not set"),
515 protocol_fee_on_collateral: self.instruction.protocol_fee_on_collateral.clone().expect("protocol_fee_on_collateral is not set"),
516 liquidation_fee: self.instruction.liquidation_fee.clone().expect("liquidation_fee is not set"),
517 liquidation_threshold: self.instruction.liquidation_threshold.clone().expect("liquidation_threshold is not set"),
518 oracle_price_deviation_threshold: self.instruction.oracle_price_deviation_threshold.clone().expect("oracle_price_deviation_threshold is not set"),
519 disabled: self.instruction.disabled.clone().expect("disabled is not set"),
520 borrow_limit_a: self.instruction.borrow_limit_a.clone().expect("borrow_limit_a is not set"),
521 borrow_limit_b: self.instruction.borrow_limit_b.clone().expect("borrow_limit_b is not set"),
522 max_swap_slippage: self.instruction.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
523 rebalance_protocol_fee: self.instruction.rebalance_protocol_fee.clone().expect("rebalance_protocol_fee is not set"),
524 spot_position_size_limit_a: self.instruction.spot_position_size_limit_a.clone().expect("spot_position_size_limit_a is not set"),
525 spot_position_size_limit_b: self.instruction.spot_position_size_limit_b.clone().expect("spot_position_size_limit_b is not set"),
526 };
527 let instruction = UpdateMarketCpi {
528 __program: self.instruction.__program,
529
530 authority: self.instruction.authority.expect("authority is not set"),
531
532 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
533
534 market: self.instruction.market.expect("market is not set"),
535 __args: args,
536 };
537 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
538 }
539}
540
541#[derive(Clone, Debug)]
542struct UpdateMarketCpiBuilderInstruction<'a, 'b> {
543 __program: &'b solana_account_info::AccountInfo<'a>,
544 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
545 tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
546 market: Option<&'b solana_account_info::AccountInfo<'a>>,
547 address_lookup_table: Option<Pubkey>,
548 max_leverage: Option<u32>,
549 protocol_fee: Option<u16>,
550 protocol_fee_on_collateral: Option<u16>,
551 liquidation_fee: Option<u32>,
552 liquidation_threshold: Option<u32>,
553 oracle_price_deviation_threshold: Option<u32>,
554 disabled: Option<bool>,
555 borrow_limit_a: Option<u64>,
556 borrow_limit_b: Option<u64>,
557 max_swap_slippage: Option<u32>,
558 rebalance_protocol_fee: Option<u32>,
559 spot_position_size_limit_a: Option<u64>,
560 spot_position_size_limit_b: Option<u64>,
561 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
563}
564