defituna_client/generated/instructions/
set_limit_orders.rs1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11#[derive(Debug)]
13pub struct SetLimitOrders {
14
15
16 pub authority: solana_program::pubkey::Pubkey,
17
18
19 pub tuna_position: solana_program::pubkey::Pubkey,
20 }
21
22impl SetLimitOrders {
23 pub fn instruction(&self, args: SetLimitOrdersInstructionArgs) -> solana_program::instruction::Instruction {
24 self.instruction_with_remaining_accounts(args, &[])
25 }
26 #[allow(clippy::arithmetic_side_effects)]
27 #[allow(clippy::vec_init_then_push)]
28 pub fn instruction_with_remaining_accounts(&self, args: SetLimitOrdersInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
29 let mut accounts = Vec::with_capacity(2+ remaining_accounts.len());
30 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
31 self.authority,
32 true
33 ));
34 accounts.push(solana_program::instruction::AccountMeta::new(
35 self.tuna_position,
36 false
37 ));
38 accounts.extend_from_slice(remaining_accounts);
39 let mut data = borsh::to_vec(&SetLimitOrdersInstructionData::new()).unwrap();
40 let mut args = borsh::to_vec(&args).unwrap();
41 data.append(&mut args);
42
43 solana_program::instruction::Instruction {
44 program_id: crate::TUNA_ID,
45 accounts,
46 data,
47 }
48 }
49}
50
51#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
52#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53 pub struct SetLimitOrdersInstructionData {
54 discriminator: [u8; 8],
55 }
56
57impl SetLimitOrdersInstructionData {
58 pub fn new() -> Self {
59 Self {
60 discriminator: [65, 128, 90, 161, 171, 133, 122, 255],
61 }
62 }
63}
64
65impl Default for SetLimitOrdersInstructionData {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73 pub struct SetLimitOrdersInstructionArgs {
74 pub tick_stop_loss_index: i32,
75 pub tick_take_profit_index: i32,
76 pub swap_to_token_on_limit_order: u8,
77 }
78
79
80#[derive(Clone, Debug, Default)]
87pub struct SetLimitOrdersBuilder {
88 authority: Option<solana_program::pubkey::Pubkey>,
89 tuna_position: Option<solana_program::pubkey::Pubkey>,
90 tick_stop_loss_index: Option<i32>,
91 tick_take_profit_index: Option<i32>,
92 swap_to_token_on_limit_order: Option<u8>,
93 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
94}
95
96impl SetLimitOrdersBuilder {
97 pub fn new() -> Self {
98 Self::default()
99 }
100 #[inline(always)]
101 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
102 self.authority = Some(authority);
103 self
104 }
105 #[inline(always)]
106 pub fn tuna_position(&mut self, tuna_position: solana_program::pubkey::Pubkey) -> &mut Self {
107 self.tuna_position = Some(tuna_position);
108 self
109 }
110 #[inline(always)]
111 pub fn tick_stop_loss_index(&mut self, tick_stop_loss_index: i32) -> &mut Self {
112 self.tick_stop_loss_index = Some(tick_stop_loss_index);
113 self
114 }
115 #[inline(always)]
116 pub fn tick_take_profit_index(&mut self, tick_take_profit_index: i32) -> &mut Self {
117 self.tick_take_profit_index = Some(tick_take_profit_index);
118 self
119 }
120 #[inline(always)]
121 pub fn swap_to_token_on_limit_order(&mut self, swap_to_token_on_limit_order: u8) -> &mut Self {
122 self.swap_to_token_on_limit_order = Some(swap_to_token_on_limit_order);
123 self
124 }
125 #[inline(always)]
127 pub fn add_remaining_account(&mut self, account: solana_program::instruction::AccountMeta) -> &mut Self {
128 self.__remaining_accounts.push(account);
129 self
130 }
131 #[inline(always)]
133 pub fn add_remaining_accounts(&mut self, accounts: &[solana_program::instruction::AccountMeta]) -> &mut Self {
134 self.__remaining_accounts.extend_from_slice(accounts);
135 self
136 }
137 #[allow(clippy::clone_on_copy)]
138 pub fn instruction(&self) -> solana_program::instruction::Instruction {
139 let accounts = SetLimitOrders {
140 authority: self.authority.expect("authority is not set"),
141 tuna_position: self.tuna_position.expect("tuna_position is not set"),
142 };
143 let args = SetLimitOrdersInstructionArgs {
144 tick_stop_loss_index: self.tick_stop_loss_index.clone().expect("tick_stop_loss_index is not set"),
145 tick_take_profit_index: self.tick_take_profit_index.clone().expect("tick_take_profit_index is not set"),
146 swap_to_token_on_limit_order: self.swap_to_token_on_limit_order.clone().expect("swap_to_token_on_limit_order is not set"),
147 };
148
149 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
150 }
151}
152
153 pub struct SetLimitOrdersCpiAccounts<'a, 'b> {
155
156
157 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
158
159
160 pub tuna_position: &'b solana_program::account_info::AccountInfo<'a>,
161 }
162
163pub struct SetLimitOrdersCpi<'a, 'b> {
165 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
167
168
169 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
170
171
172 pub tuna_position: &'b solana_program::account_info::AccountInfo<'a>,
173 pub __args: SetLimitOrdersInstructionArgs,
175 }
176
177impl<'a, 'b> SetLimitOrdersCpi<'a, 'b> {
178 pub fn new(
179 program: &'b solana_program::account_info::AccountInfo<'a>,
180 accounts: SetLimitOrdersCpiAccounts<'a, 'b>,
181 args: SetLimitOrdersInstructionArgs,
182 ) -> Self {
183 Self {
184 __program: program,
185 authority: accounts.authority,
186 tuna_position: accounts.tuna_position,
187 __args: args,
188 }
189 }
190 #[inline(always)]
191 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
192 self.invoke_signed_with_remaining_accounts(&[], &[])
193 }
194 #[inline(always)]
195 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> solana_program::entrypoint::ProgramResult {
196 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
197 }
198 #[inline(always)]
199 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
200 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
201 }
202 #[allow(clippy::arithmetic_side_effects)]
203 #[allow(clippy::clone_on_copy)]
204 #[allow(clippy::vec_init_then_push)]
205 pub fn invoke_signed_with_remaining_accounts(
206 &self,
207 signers_seeds: &[&[&[u8]]],
208 remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]
209 ) -> solana_program::entrypoint::ProgramResult {
210 let mut accounts = Vec::with_capacity(2+ remaining_accounts.len());
211 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
212 *self.authority.key,
213 true
214 ));
215 accounts.push(solana_program::instruction::AccountMeta::new(
216 *self.tuna_position.key,
217 false
218 ));
219 remaining_accounts.iter().for_each(|remaining_account| {
220 accounts.push(solana_program::instruction::AccountMeta {
221 pubkey: *remaining_account.0.key,
222 is_signer: remaining_account.1,
223 is_writable: remaining_account.2,
224 })
225 });
226 let mut data = borsh::to_vec(&SetLimitOrdersInstructionData::new()).unwrap();
227 let mut args = borsh::to_vec(&self.__args).unwrap();
228 data.append(&mut args);
229
230 let instruction = solana_program::instruction::Instruction {
231 program_id: crate::TUNA_ID,
232 accounts,
233 data,
234 };
235 let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
236 account_infos.push(self.__program.clone());
237 account_infos.push(self.authority.clone());
238 account_infos.push(self.tuna_position.clone());
239 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
240
241 if signers_seeds.is_empty() {
242 solana_program::program::invoke(&instruction, &account_infos)
243 } else {
244 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
245 }
246 }
247}
248
249#[derive(Clone, Debug)]
256pub struct SetLimitOrdersCpiBuilder<'a, 'b> {
257 instruction: Box<SetLimitOrdersCpiBuilderInstruction<'a, 'b>>,
258}
259
260impl<'a, 'b> SetLimitOrdersCpiBuilder<'a, 'b> {
261 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
262 let instruction = Box::new(SetLimitOrdersCpiBuilderInstruction {
263 __program: program,
264 authority: None,
265 tuna_position: None,
266 tick_stop_loss_index: None,
267 tick_take_profit_index: None,
268 swap_to_token_on_limit_order: None,
269 __remaining_accounts: Vec::new(),
270 });
271 Self { instruction }
272 }
273 #[inline(always)]
274 pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
275 self.instruction.authority = Some(authority);
276 self
277 }
278 #[inline(always)]
279 pub fn tuna_position(&mut self, tuna_position: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
280 self.instruction.tuna_position = Some(tuna_position);
281 self
282 }
283 #[inline(always)]
284 pub fn tick_stop_loss_index(&mut self, tick_stop_loss_index: i32) -> &mut Self {
285 self.instruction.tick_stop_loss_index = Some(tick_stop_loss_index);
286 self
287 }
288 #[inline(always)]
289 pub fn tick_take_profit_index(&mut self, tick_take_profit_index: i32) -> &mut Self {
290 self.instruction.tick_take_profit_index = Some(tick_take_profit_index);
291 self
292 }
293 #[inline(always)]
294 pub fn swap_to_token_on_limit_order(&mut self, swap_to_token_on_limit_order: u8) -> &mut Self {
295 self.instruction.swap_to_token_on_limit_order = Some(swap_to_token_on_limit_order);
296 self
297 }
298 #[inline(always)]
300 pub fn add_remaining_account(&mut self, account: &'b solana_program::account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
301 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
302 self
303 }
304 #[inline(always)]
309 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
310 self.instruction.__remaining_accounts.extend_from_slice(accounts);
311 self
312 }
313 #[inline(always)]
314 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
315 self.invoke_signed(&[])
316 }
317 #[allow(clippy::clone_on_copy)]
318 #[allow(clippy::vec_init_then_push)]
319 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
320 let args = SetLimitOrdersInstructionArgs {
321 tick_stop_loss_index: self.instruction.tick_stop_loss_index.clone().expect("tick_stop_loss_index is not set"),
322 tick_take_profit_index: self.instruction.tick_take_profit_index.clone().expect("tick_take_profit_index is not set"),
323 swap_to_token_on_limit_order: self.instruction.swap_to_token_on_limit_order.clone().expect("swap_to_token_on_limit_order is not set"),
324 };
325 let instruction = SetLimitOrdersCpi {
326 __program: self.instruction.__program,
327
328 authority: self.instruction.authority.expect("authority is not set"),
329
330 tuna_position: self.instruction.tuna_position.expect("tuna_position is not set"),
331 __args: args,
332 };
333 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
334 }
335}
336
337#[derive(Clone, Debug)]
338struct SetLimitOrdersCpiBuilderInstruction<'a, 'b> {
339 __program: &'b solana_program::account_info::AccountInfo<'a>,
340 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
341 tuna_position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
342 tick_stop_loss_index: Option<i32>,
343 tick_take_profit_index: Option<i32>,
344 swap_to_token_on_limit_order: Option<u8>,
345 __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
347}
348