defituna_client/generated/instructions/
close_market.rs1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const CLOSE_MARKET_DISCRIMINATOR: [u8; 8] = [88, 154, 248, 186, 48, 14, 123, 244];
12
13#[derive(Debug)]
15pub struct CloseMarket {
16
17
18 pub authority: solana_pubkey::Pubkey,
19
20
21 pub tuna_config: solana_pubkey::Pubkey,
22
23
24 pub market: solana_pubkey::Pubkey,
25
26
27 pub vault_a: solana_pubkey::Pubkey,
28
29
30 pub vault_b: solana_pubkey::Pubkey,
31 }
32
33impl CloseMarket {
34 pub fn instruction(&self) -> solana_instruction::Instruction {
35 self.instruction_with_remaining_accounts(&[])
36 }
37 #[allow(clippy::arithmetic_side_effects)]
38 #[allow(clippy::vec_init_then_push)]
39 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
40 let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
41 accounts.push(solana_instruction::AccountMeta::new(
42 self.authority,
43 true
44 ));
45 accounts.push(solana_instruction::AccountMeta::new_readonly(
46 self.tuna_config,
47 false
48 ));
49 accounts.push(solana_instruction::AccountMeta::new(
50 self.market,
51 false
52 ));
53 accounts.push(solana_instruction::AccountMeta::new(
54 self.vault_a,
55 false
56 ));
57 accounts.push(solana_instruction::AccountMeta::new(
58 self.vault_b,
59 false
60 ));
61 accounts.extend_from_slice(remaining_accounts);
62 let data = borsh::to_vec(&CloseMarketInstructionData::new()).unwrap();
63
64 solana_instruction::Instruction {
65 program_id: crate::TUNA_ID,
66 accounts,
67 data,
68 }
69 }
70}
71
72#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
74 pub struct CloseMarketInstructionData {
75 discriminator: [u8; 8],
76 }
77
78impl CloseMarketInstructionData {
79 pub fn new() -> Self {
80 Self {
81 discriminator: [88, 154, 248, 186, 48, 14, 123, 244],
82 }
83 }
84}
85
86impl Default for CloseMarketInstructionData {
87 fn default() -> Self {
88 Self::new()
89 }
90}
91
92
93
94#[derive(Clone, Debug, Default)]
104pub struct CloseMarketBuilder {
105 authority: Option<solana_pubkey::Pubkey>,
106 tuna_config: Option<solana_pubkey::Pubkey>,
107 market: Option<solana_pubkey::Pubkey>,
108 vault_a: Option<solana_pubkey::Pubkey>,
109 vault_b: Option<solana_pubkey::Pubkey>,
110 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
111}
112
113impl CloseMarketBuilder {
114 pub fn new() -> Self {
115 Self::default()
116 }
117 #[inline(always)]
118 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
119 self.authority = Some(authority);
120 self
121 }
122 #[inline(always)]
123 pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
124 self.tuna_config = Some(tuna_config);
125 self
126 }
127 #[inline(always)]
128 pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
129 self.market = Some(market);
130 self
131 }
132 #[inline(always)]
133 pub fn vault_a(&mut self, vault_a: solana_pubkey::Pubkey) -> &mut Self {
134 self.vault_a = Some(vault_a);
135 self
136 }
137 #[inline(always)]
138 pub fn vault_b(&mut self, vault_b: solana_pubkey::Pubkey) -> &mut Self {
139 self.vault_b = Some(vault_b);
140 self
141 }
142 #[inline(always)]
144 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
145 self.__remaining_accounts.push(account);
146 self
147 }
148 #[inline(always)]
150 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
151 self.__remaining_accounts.extend_from_slice(accounts);
152 self
153 }
154 #[allow(clippy::clone_on_copy)]
155 pub fn instruction(&self) -> solana_instruction::Instruction {
156 let accounts = CloseMarket {
157 authority: self.authority.expect("authority is not set"),
158 tuna_config: self.tuna_config.expect("tuna_config is not set"),
159 market: self.market.expect("market is not set"),
160 vault_a: self.vault_a.expect("vault_a is not set"),
161 vault_b: self.vault_b.expect("vault_b is not set"),
162 };
163
164 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
165 }
166}
167
168 pub struct CloseMarketCpiAccounts<'a, 'b> {
170
171
172 pub authority: &'b solana_account_info::AccountInfo<'a>,
173
174
175 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
176
177
178 pub market: &'b solana_account_info::AccountInfo<'a>,
179
180
181 pub vault_a: &'b solana_account_info::AccountInfo<'a>,
182
183
184 pub vault_b: &'b solana_account_info::AccountInfo<'a>,
185 }
186
187pub struct CloseMarketCpi<'a, 'b> {
189 pub __program: &'b solana_account_info::AccountInfo<'a>,
191
192
193 pub authority: &'b solana_account_info::AccountInfo<'a>,
194
195
196 pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
197
198
199 pub market: &'b solana_account_info::AccountInfo<'a>,
200
201
202 pub vault_a: &'b solana_account_info::AccountInfo<'a>,
203
204
205 pub vault_b: &'b solana_account_info::AccountInfo<'a>,
206 }
207
208impl<'a, 'b> CloseMarketCpi<'a, 'b> {
209 pub fn new(
210 program: &'b solana_account_info::AccountInfo<'a>,
211 accounts: CloseMarketCpiAccounts<'a, 'b>,
212 ) -> Self {
213 Self {
214 __program: program,
215 authority: accounts.authority,
216 tuna_config: accounts.tuna_config,
217 market: accounts.market,
218 vault_a: accounts.vault_a,
219 vault_b: accounts.vault_b,
220 }
221 }
222 #[inline(always)]
223 pub fn invoke(&self) -> solana_program_error::ProgramResult {
224 self.invoke_signed_with_remaining_accounts(&[], &[])
225 }
226 #[inline(always)]
227 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
228 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
229 }
230 #[inline(always)]
231 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
232 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
233 }
234 #[allow(clippy::arithmetic_side_effects)]
235 #[allow(clippy::clone_on_copy)]
236 #[allow(clippy::vec_init_then_push)]
237 pub fn invoke_signed_with_remaining_accounts(
238 &self,
239 signers_seeds: &[&[&[u8]]],
240 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
241 ) -> solana_program_error::ProgramResult {
242 let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
243 accounts.push(solana_instruction::AccountMeta::new(
244 *self.authority.key,
245 true
246 ));
247 accounts.push(solana_instruction::AccountMeta::new_readonly(
248 *self.tuna_config.key,
249 false
250 ));
251 accounts.push(solana_instruction::AccountMeta::new(
252 *self.market.key,
253 false
254 ));
255 accounts.push(solana_instruction::AccountMeta::new(
256 *self.vault_a.key,
257 false
258 ));
259 accounts.push(solana_instruction::AccountMeta::new(
260 *self.vault_b.key,
261 false
262 ));
263 remaining_accounts.iter().for_each(|remaining_account| {
264 accounts.push(solana_instruction::AccountMeta {
265 pubkey: *remaining_account.0.key,
266 is_signer: remaining_account.1,
267 is_writable: remaining_account.2,
268 })
269 });
270 let data = borsh::to_vec(&CloseMarketInstructionData::new()).unwrap();
271
272 let instruction = solana_instruction::Instruction {
273 program_id: crate::TUNA_ID,
274 accounts,
275 data,
276 };
277 let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
278 account_infos.push(self.__program.clone());
279 account_infos.push(self.authority.clone());
280 account_infos.push(self.tuna_config.clone());
281 account_infos.push(self.market.clone());
282 account_infos.push(self.vault_a.clone());
283 account_infos.push(self.vault_b.clone());
284 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
285
286 if signers_seeds.is_empty() {
287 solana_cpi::invoke(&instruction, &account_infos)
288 } else {
289 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
290 }
291 }
292}
293
294#[derive(Clone, Debug)]
304pub struct CloseMarketCpiBuilder<'a, 'b> {
305 instruction: Box<CloseMarketCpiBuilderInstruction<'a, 'b>>,
306}
307
308impl<'a, 'b> CloseMarketCpiBuilder<'a, 'b> {
309 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
310 let instruction = Box::new(CloseMarketCpiBuilderInstruction {
311 __program: program,
312 authority: None,
313 tuna_config: None,
314 market: None,
315 vault_a: None,
316 vault_b: None,
317 __remaining_accounts: Vec::new(),
318 });
319 Self { instruction }
320 }
321 #[inline(always)]
322 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
323 self.instruction.authority = Some(authority);
324 self
325 }
326 #[inline(always)]
327 pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
328 self.instruction.tuna_config = Some(tuna_config);
329 self
330 }
331 #[inline(always)]
332 pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
333 self.instruction.market = Some(market);
334 self
335 }
336 #[inline(always)]
337 pub fn vault_a(&mut self, vault_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
338 self.instruction.vault_a = Some(vault_a);
339 self
340 }
341 #[inline(always)]
342 pub fn vault_b(&mut self, vault_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
343 self.instruction.vault_b = Some(vault_b);
344 self
345 }
346 #[inline(always)]
348 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
349 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
350 self
351 }
352 #[inline(always)]
357 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
358 self.instruction.__remaining_accounts.extend_from_slice(accounts);
359 self
360 }
361 #[inline(always)]
362 pub fn invoke(&self) -> solana_program_error::ProgramResult {
363 self.invoke_signed(&[])
364 }
365 #[allow(clippy::clone_on_copy)]
366 #[allow(clippy::vec_init_then_push)]
367 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
368 let instruction = CloseMarketCpi {
369 __program: self.instruction.__program,
370
371 authority: self.instruction.authority.expect("authority is not set"),
372
373 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
374
375 market: self.instruction.market.expect("market is not set"),
376
377 vault_a: self.instruction.vault_a.expect("vault_a is not set"),
378
379 vault_b: self.instruction.vault_b.expect("vault_b is not set"),
380 };
381 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
382 }
383}
384
385#[derive(Clone, Debug)]
386struct CloseMarketCpiBuilderInstruction<'a, 'b> {
387 __program: &'b solana_account_info::AccountInfo<'a>,
388 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
389 tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
390 market: Option<&'b solana_account_info::AccountInfo<'a>>,
391 vault_a: Option<&'b solana_account_info::AccountInfo<'a>>,
392 vault_b: Option<&'b solana_account_info::AccountInfo<'a>>,
393 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
395}
396