jup_perps_client/instructions/
create_token_ledger.rs1use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const CREATE_TOKEN_LEDGER_DISCRIMINATOR: [u8; 8] = [232, 242, 197, 253, 240, 143, 129, 52];
11
12#[derive(Debug)]
14pub struct CreateTokenLedger {
15 pub token_ledger: solana_program::pubkey::Pubkey,
16
17 pub payer: solana_program::pubkey::Pubkey,
18
19 pub system_program: solana_program::pubkey::Pubkey,
20}
21
22impl CreateTokenLedger {
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 true,
36 ));
37 accounts.push(solana_program::instruction::AccountMeta::new(
38 self.payer, true,
39 ));
40 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
41 self.system_program,
42 false,
43 ));
44 accounts.extend_from_slice(remaining_accounts);
45 let data = borsh::to_vec(&CreateTokenLedgerInstructionData::new()).unwrap();
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 CreateTokenLedgerInstructionData {
58 discriminator: [u8; 8],
59}
60
61impl CreateTokenLedgerInstructionData {
62 pub fn new() -> Self {
63 Self {
64 discriminator: [232, 242, 197, 253, 240, 143, 129, 52],
65 }
66 }
67}
68
69impl Default for CreateTokenLedgerInstructionData {
70 fn default() -> Self {
71 Self::new()
72 }
73}
74
75#[derive(Clone, Debug, Default)]
83pub struct CreateTokenLedgerBuilder {
84 token_ledger: Option<solana_program::pubkey::Pubkey>,
85 payer: Option<solana_program::pubkey::Pubkey>,
86 system_program: Option<solana_program::pubkey::Pubkey>,
87 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
88}
89
90impl CreateTokenLedgerBuilder {
91 pub fn new() -> Self {
92 Self::default()
93 }
94 #[inline(always)]
95 pub fn token_ledger(&mut self, token_ledger: solana_program::pubkey::Pubkey) -> &mut Self {
96 self.token_ledger = Some(token_ledger);
97 self
98 }
99 #[inline(always)]
100 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
101 self.payer = Some(payer);
102 self
103 }
104 #[inline(always)]
106 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
107 self.system_program = Some(system_program);
108 self
109 }
110 #[inline(always)]
112 pub fn add_remaining_account(
113 &mut self,
114 account: solana_program::instruction::AccountMeta,
115 ) -> &mut Self {
116 self.__remaining_accounts.push(account);
117 self
118 }
119 #[inline(always)]
121 pub fn add_remaining_accounts(
122 &mut self,
123 accounts: &[solana_program::instruction::AccountMeta],
124 ) -> &mut Self {
125 self.__remaining_accounts.extend_from_slice(accounts);
126 self
127 }
128 #[allow(clippy::clone_on_copy)]
129 pub fn instruction(&self) -> solana_program::instruction::Instruction {
130 let accounts = CreateTokenLedger {
131 token_ledger: self.token_ledger.expect("token_ledger is not set"),
132 payer: self.payer.expect("payer is not set"),
133 system_program: self
134 .system_program
135 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
136 };
137
138 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
139 }
140}
141
142pub struct CreateTokenLedgerCpiAccounts<'a, 'b> {
144 pub token_ledger: &'b solana_program::account_info::AccountInfo<'a>,
145
146 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
147
148 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
149}
150
151pub struct CreateTokenLedgerCpi<'a, 'b> {
153 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
155
156 pub token_ledger: &'b solana_program::account_info::AccountInfo<'a>,
157
158 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
159
160 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
161}
162
163impl<'a, 'b> CreateTokenLedgerCpi<'a, 'b> {
164 pub fn new(
165 program: &'b solana_program::account_info::AccountInfo<'a>,
166 accounts: CreateTokenLedgerCpiAccounts<'a, 'b>,
167 ) -> Self {
168 Self {
169 __program: program,
170 token_ledger: accounts.token_ledger,
171 payer: accounts.payer,
172 system_program: accounts.system_program,
173 }
174 }
175 #[inline(always)]
176 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
177 self.invoke_signed_with_remaining_accounts(&[], &[])
178 }
179 #[inline(always)]
180 pub fn invoke_with_remaining_accounts(
181 &self,
182 remaining_accounts: &[(
183 &'b solana_program::account_info::AccountInfo<'a>,
184 bool,
185 bool,
186 )],
187 ) -> solana_program::entrypoint::ProgramResult {
188 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
189 }
190 #[inline(always)]
191 pub fn invoke_signed(
192 &self,
193 signers_seeds: &[&[&[u8]]],
194 ) -> solana_program::entrypoint::ProgramResult {
195 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
196 }
197 #[allow(clippy::arithmetic_side_effects)]
198 #[allow(clippy::clone_on_copy)]
199 #[allow(clippy::vec_init_then_push)]
200 pub fn invoke_signed_with_remaining_accounts(
201 &self,
202 signers_seeds: &[&[&[u8]]],
203 remaining_accounts: &[(
204 &'b solana_program::account_info::AccountInfo<'a>,
205 bool,
206 bool,
207 )],
208 ) -> solana_program::entrypoint::ProgramResult {
209 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
210 accounts.push(solana_program::instruction::AccountMeta::new(
211 *self.token_ledger.key,
212 true,
213 ));
214 accounts.push(solana_program::instruction::AccountMeta::new(
215 *self.payer.key,
216 true,
217 ));
218 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
219 *self.system_program.key,
220 false,
221 ));
222 remaining_accounts.iter().for_each(|remaining_account| {
223 accounts.push(solana_program::instruction::AccountMeta {
224 pubkey: *remaining_account.0.key,
225 is_signer: remaining_account.1,
226 is_writable: remaining_account.2,
227 })
228 });
229 let data = borsh::to_vec(&CreateTokenLedgerInstructionData::new()).unwrap();
230
231 let instruction = solana_program::instruction::Instruction {
232 program_id: crate::PERPETUALS_ID,
233 accounts,
234 data,
235 };
236 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
237 account_infos.push(self.__program.clone());
238 account_infos.push(self.token_ledger.clone());
239 account_infos.push(self.payer.clone());
240 account_infos.push(self.system_program.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)]
261pub struct CreateTokenLedgerCpiBuilder<'a, 'b> {
262 instruction: Box<CreateTokenLedgerCpiBuilderInstruction<'a, 'b>>,
263}
264
265impl<'a, 'b> CreateTokenLedgerCpiBuilder<'a, 'b> {
266 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
267 let instruction = Box::new(CreateTokenLedgerCpiBuilderInstruction {
268 __program: program,
269 token_ledger: None,
270 payer: None,
271 system_program: None,
272 __remaining_accounts: Vec::new(),
273 });
274 Self { instruction }
275 }
276 #[inline(always)]
277 pub fn token_ledger(
278 &mut self,
279 token_ledger: &'b solana_program::account_info::AccountInfo<'a>,
280 ) -> &mut Self {
281 self.instruction.token_ledger = Some(token_ledger);
282 self
283 }
284 #[inline(always)]
285 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
286 self.instruction.payer = Some(payer);
287 self
288 }
289 #[inline(always)]
290 pub fn system_program(
291 &mut self,
292 system_program: &'b solana_program::account_info::AccountInfo<'a>,
293 ) -> &mut Self {
294 self.instruction.system_program = Some(system_program);
295 self
296 }
297 #[inline(always)]
299 pub fn add_remaining_account(
300 &mut self,
301 account: &'b solana_program::account_info::AccountInfo<'a>,
302 is_writable: bool,
303 is_signer: bool,
304 ) -> &mut Self {
305 self.instruction
306 .__remaining_accounts
307 .push((account, is_writable, is_signer));
308 self
309 }
310 #[inline(always)]
315 pub fn add_remaining_accounts(
316 &mut self,
317 accounts: &[(
318 &'b solana_program::account_info::AccountInfo<'a>,
319 bool,
320 bool,
321 )],
322 ) -> &mut Self {
323 self.instruction
324 .__remaining_accounts
325 .extend_from_slice(accounts);
326 self
327 }
328 #[inline(always)]
329 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
330 self.invoke_signed(&[])
331 }
332 #[allow(clippy::clone_on_copy)]
333 #[allow(clippy::vec_init_then_push)]
334 pub fn invoke_signed(
335 &self,
336 signers_seeds: &[&[&[u8]]],
337 ) -> solana_program::entrypoint::ProgramResult {
338 let instruction = CreateTokenLedgerCpi {
339 __program: self.instruction.__program,
340
341 token_ledger: self
342 .instruction
343 .token_ledger
344 .expect("token_ledger is not set"),
345
346 payer: self.instruction.payer.expect("payer is not set"),
347
348 system_program: self
349 .instruction
350 .system_program
351 .expect("system_program is not set"),
352 };
353 instruction.invoke_signed_with_remaining_accounts(
354 signers_seeds,
355 &self.instruction.__remaining_accounts,
356 )
357 }
358}
359
360#[derive(Clone, Debug)]
361struct CreateTokenLedgerCpiBuilderInstruction<'a, 'b> {
362 __program: &'b solana_program::account_info::AccountInfo<'a>,
363 token_ledger: Option<&'b solana_program::account_info::AccountInfo<'a>>,
364 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
365 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
366 __remaining_accounts: Vec<(
368 &'b solana_program::account_info::AccountInfo<'a>,
369 bool,
370 bool,
371 )>,
372}