1use crate::generated::types::Strategy;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub struct Resize {
14 pub asset: solana_program::pubkey::Pubkey,
16 pub authority: solana_program::pubkey::Pubkey,
18 pub payer: (solana_program::pubkey::Pubkey, bool),
20 pub system_program: Option<solana_program::pubkey::Pubkey>,
22}
23
24impl Resize {
25 pub fn instruction(
26 &self,
27 args: ResizeInstructionArgs,
28 ) -> solana_program::instruction::Instruction {
29 self.instruction_with_remaining_accounts(args, &[])
30 }
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(
33 &self,
34 args: ResizeInstructionArgs,
35 remaining_accounts: &[solana_program::instruction::AccountMeta],
36 ) -> solana_program::instruction::Instruction {
37 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
38 accounts.push(solana_program::instruction::AccountMeta::new(
39 self.asset, true,
40 ));
41 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42 self.authority,
43 true,
44 ));
45 accounts.push(solana_program::instruction::AccountMeta::new(
46 self.payer.0,
47 self.payer.1,
48 ));
49 if let Some(system_program) = self.system_program {
50 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
51 system_program,
52 false,
53 ));
54 } else {
55 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
56 crate::INTERFACE_ID,
57 false,
58 ));
59 }
60 accounts.extend_from_slice(remaining_accounts);
61 let mut data = ResizeInstructionData::new().try_to_vec().unwrap();
62 let mut args = args.try_to_vec().unwrap();
63 data.append(&mut args);
64
65 solana_program::instruction::Instruction {
66 program_id: crate::INTERFACE_ID,
67 accounts,
68 data,
69 }
70 }
71}
72
73#[derive(BorshDeserialize, BorshSerialize)]
74struct ResizeInstructionData {
75 discriminator: u8,
76}
77
78impl ResizeInstructionData {
79 fn new() -> Self {
80 Self { discriminator: 17 }
81 }
82}
83
84#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
86pub struct ResizeInstructionArgs {
87 pub strategy: Strategy,
88}
89
90#[derive(Default)]
99pub struct ResizeBuilder {
100 asset: Option<solana_program::pubkey::Pubkey>,
101 authority: Option<solana_program::pubkey::Pubkey>,
102 payer: Option<(solana_program::pubkey::Pubkey, bool)>,
103 system_program: Option<solana_program::pubkey::Pubkey>,
104 strategy: Option<Strategy>,
105 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
106}
107
108impl ResizeBuilder {
109 pub fn new() -> Self {
110 Self::default()
111 }
112 #[inline(always)]
114 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
115 self.asset = Some(asset);
116 self
117 }
118 #[inline(always)]
120 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
121 self.authority = Some(authority);
122 self
123 }
124 #[inline(always)]
126 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey, as_signer: bool) -> &mut Self {
127 self.payer = Some((payer, as_signer));
128 self
129 }
130 #[inline(always)]
133 pub fn system_program(
134 &mut self,
135 system_program: Option<solana_program::pubkey::Pubkey>,
136 ) -> &mut Self {
137 self.system_program = system_program;
138 self
139 }
140 #[inline(always)]
141 pub fn strategy(&mut self, strategy: Strategy) -> &mut Self {
142 self.strategy = Some(strategy);
143 self
144 }
145 #[inline(always)]
147 pub fn add_remaining_account(
148 &mut self,
149 account: solana_program::instruction::AccountMeta,
150 ) -> &mut Self {
151 self.__remaining_accounts.push(account);
152 self
153 }
154 #[inline(always)]
156 pub fn add_remaining_accounts(
157 &mut self,
158 accounts: &[solana_program::instruction::AccountMeta],
159 ) -> &mut Self {
160 self.__remaining_accounts.extend_from_slice(accounts);
161 self
162 }
163 #[allow(clippy::clone_on_copy)]
164 pub fn instruction(&self) -> solana_program::instruction::Instruction {
165 let accounts = Resize {
166 asset: self.asset.expect("asset is not set"),
167 authority: self.authority.expect("authority is not set"),
168 payer: self.payer.expect("payer is not set"),
169 system_program: self.system_program,
170 };
171 let args = ResizeInstructionArgs {
172 strategy: self.strategy.clone().expect("strategy is not set"),
173 };
174
175 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
176 }
177}
178
179pub struct ResizeCpiAccounts<'a, 'b> {
181 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
183 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
185 pub payer: (&'b solana_program::account_info::AccountInfo<'a>, bool),
187 pub system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
189}
190
191pub struct ResizeCpi<'a, 'b> {
193 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
195 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
197 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
199 pub payer: (&'b solana_program::account_info::AccountInfo<'a>, bool),
201 pub system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
203 pub __args: ResizeInstructionArgs,
205}
206
207impl<'a, 'b> ResizeCpi<'a, 'b> {
208 pub fn new(
209 program: &'b solana_program::account_info::AccountInfo<'a>,
210 accounts: ResizeCpiAccounts<'a, 'b>,
211 args: ResizeInstructionArgs,
212 ) -> Self {
213 Self {
214 __program: program,
215 asset: accounts.asset,
216 authority: accounts.authority,
217 payer: accounts.payer,
218 system_program: accounts.system_program,
219 __args: args,
220 }
221 }
222 #[inline(always)]
223 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
224 self.invoke_signed_with_remaining_accounts(&[], &[])
225 }
226 #[inline(always)]
227 pub fn invoke_with_remaining_accounts(
228 &self,
229 remaining_accounts: &[(
230 &'b solana_program::account_info::AccountInfo<'a>,
231 bool,
232 bool,
233 )],
234 ) -> solana_program::entrypoint::ProgramResult {
235 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
236 }
237 #[inline(always)]
238 pub fn invoke_signed(
239 &self,
240 signers_seeds: &[&[&[u8]]],
241 ) -> solana_program::entrypoint::ProgramResult {
242 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
243 }
244 #[allow(clippy::clone_on_copy)]
245 #[allow(clippy::vec_init_then_push)]
246 pub fn invoke_signed_with_remaining_accounts(
247 &self,
248 signers_seeds: &[&[&[u8]]],
249 remaining_accounts: &[(
250 &'b solana_program::account_info::AccountInfo<'a>,
251 bool,
252 bool,
253 )],
254 ) -> solana_program::entrypoint::ProgramResult {
255 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
256 accounts.push(solana_program::instruction::AccountMeta::new(
257 *self.asset.key,
258 true,
259 ));
260 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
261 *self.authority.key,
262 true,
263 ));
264 accounts.push(solana_program::instruction::AccountMeta::new(
265 *self.payer.0.key,
266 self.payer.1,
267 ));
268 if let Some(system_program) = self.system_program {
269 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
270 *system_program.key,
271 false,
272 ));
273 } else {
274 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
275 crate::INTERFACE_ID,
276 false,
277 ));
278 }
279 remaining_accounts.iter().for_each(|remaining_account| {
280 accounts.push(solana_program::instruction::AccountMeta {
281 pubkey: *remaining_account.0.key,
282 is_signer: remaining_account.1,
283 is_writable: remaining_account.2,
284 })
285 });
286 let mut data = ResizeInstructionData::new().try_to_vec().unwrap();
287 let mut args = self.__args.try_to_vec().unwrap();
288 data.append(&mut args);
289
290 let instruction = solana_program::instruction::Instruction {
291 program_id: crate::INTERFACE_ID,
292 accounts,
293 data,
294 };
295 let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
296 account_infos.push(self.__program.clone());
297 account_infos.push(self.asset.clone());
298 account_infos.push(self.authority.clone());
299 account_infos.push(self.payer.0.clone());
300 if let Some(system_program) = self.system_program {
301 account_infos.push(system_program.clone());
302 }
303 remaining_accounts
304 .iter()
305 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
306
307 if signers_seeds.is_empty() {
308 solana_program::program::invoke(&instruction, &account_infos)
309 } else {
310 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
311 }
312 }
313}
314
315pub struct ResizeCpiBuilder<'a, 'b> {
324 instruction: Box<ResizeCpiBuilderInstruction<'a, 'b>>,
325}
326
327impl<'a, 'b> ResizeCpiBuilder<'a, 'b> {
328 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
329 let instruction = Box::new(ResizeCpiBuilderInstruction {
330 __program: program,
331 asset: None,
332 authority: None,
333 payer: None,
334 system_program: None,
335 strategy: None,
336 __remaining_accounts: Vec::new(),
337 });
338 Self { instruction }
339 }
340 #[inline(always)]
342 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
343 self.instruction.asset = Some(asset);
344 self
345 }
346 #[inline(always)]
348 pub fn authority(
349 &mut self,
350 authority: &'b solana_program::account_info::AccountInfo<'a>,
351 ) -> &mut Self {
352 self.instruction.authority = Some(authority);
353 self
354 }
355 #[inline(always)]
357 pub fn payer(
358 &mut self,
359 payer: &'b solana_program::account_info::AccountInfo<'a>,
360 as_signer: bool,
361 ) -> &mut Self {
362 self.instruction.payer = Some((payer, as_signer));
363 self
364 }
365 #[inline(always)]
368 pub fn system_program(
369 &mut self,
370 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
371 ) -> &mut Self {
372 self.instruction.system_program = system_program;
373 self
374 }
375 #[inline(always)]
376 pub fn strategy(&mut self, strategy: Strategy) -> &mut Self {
377 self.instruction.strategy = Some(strategy);
378 self
379 }
380 #[inline(always)]
382 pub fn add_remaining_account(
383 &mut self,
384 account: &'b solana_program::account_info::AccountInfo<'a>,
385 is_writable: bool,
386 is_signer: bool,
387 ) -> &mut Self {
388 self.instruction
389 .__remaining_accounts
390 .push((account, is_writable, is_signer));
391 self
392 }
393 #[inline(always)]
398 pub fn add_remaining_accounts(
399 &mut self,
400 accounts: &[(
401 &'b solana_program::account_info::AccountInfo<'a>,
402 bool,
403 bool,
404 )],
405 ) -> &mut Self {
406 self.instruction
407 .__remaining_accounts
408 .extend_from_slice(accounts);
409 self
410 }
411 #[inline(always)]
412 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
413 self.invoke_signed(&[])
414 }
415 #[allow(clippy::clone_on_copy)]
416 #[allow(clippy::vec_init_then_push)]
417 pub fn invoke_signed(
418 &self,
419 signers_seeds: &[&[&[u8]]],
420 ) -> solana_program::entrypoint::ProgramResult {
421 let args = ResizeInstructionArgs {
422 strategy: self
423 .instruction
424 .strategy
425 .clone()
426 .expect("strategy is not set"),
427 };
428 let instruction = ResizeCpi {
429 __program: self.instruction.__program,
430
431 asset: self.instruction.asset.expect("asset is not set"),
432
433 authority: self.instruction.authority.expect("authority is not set"),
434
435 payer: self.instruction.payer.expect("payer is not set"),
436
437 system_program: self.instruction.system_program,
438 __args: args,
439 };
440 instruction.invoke_signed_with_remaining_accounts(
441 signers_seeds,
442 &self.instruction.__remaining_accounts,
443 )
444 }
445}
446
447struct ResizeCpiBuilderInstruction<'a, 'b> {
448 __program: &'b solana_program::account_info::AccountInfo<'a>,
449 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
450 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
451 payer: Option<(&'b solana_program::account_info::AccountInfo<'a>, bool)>,
452 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
453 strategy: Option<Strategy>,
454 __remaining_accounts: Vec<(
456 &'b solana_program::account_info::AccountInfo<'a>,
457 bool,
458 bool,
459 )>,
460}