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