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