1use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const REALLOC_POOL_DISCRIMINATOR: [u8; 8] = [114, 128, 37, 167, 71, 227, 40, 178];
11
12#[derive(Debug)]
14pub struct ReallocPool {
15 pub keeper: solana_program::pubkey::Pubkey,
16
17 pub pool: solana_program::pubkey::Pubkey,
18
19 pub system_program: solana_program::pubkey::Pubkey,
20
21 pub rent: solana_program::pubkey::Pubkey,
22}
23
24impl ReallocPool {
25 pub fn instruction(&self) -> solana_program::instruction::Instruction {
26 self.instruction_with_remaining_accounts(&[])
27 }
28 #[allow(clippy::arithmetic_side_effects)]
29 #[allow(clippy::vec_init_then_push)]
30 pub fn instruction_with_remaining_accounts(
31 &self,
32 remaining_accounts: &[solana_program::instruction::AccountMeta],
33 ) -> solana_program::instruction::Instruction {
34 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
35 accounts.push(solana_program::instruction::AccountMeta::new(
36 self.keeper,
37 true,
38 ));
39 accounts.push(solana_program::instruction::AccountMeta::new(
40 self.pool, false,
41 ));
42 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
43 self.system_program,
44 false,
45 ));
46 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
47 self.rent, false,
48 ));
49 accounts.extend_from_slice(remaining_accounts);
50 let data = borsh::to_vec(&ReallocPoolInstructionData::new()).unwrap();
51
52 solana_program::instruction::Instruction {
53 program_id: crate::PERPETUALS_ID,
54 accounts,
55 data,
56 }
57 }
58}
59
60#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62pub struct ReallocPoolInstructionData {
63 discriminator: [u8; 8],
64}
65
66impl ReallocPoolInstructionData {
67 pub fn new() -> Self {
68 Self {
69 discriminator: [114, 128, 37, 167, 71, 227, 40, 178],
70 }
71 }
72}
73
74impl Default for ReallocPoolInstructionData {
75 fn default() -> Self {
76 Self::new()
77 }
78}
79
80#[derive(Clone, Debug, Default)]
89pub struct ReallocPoolBuilder {
90 keeper: Option<solana_program::pubkey::Pubkey>,
91 pool: Option<solana_program::pubkey::Pubkey>,
92 system_program: Option<solana_program::pubkey::Pubkey>,
93 rent: Option<solana_program::pubkey::Pubkey>,
94 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
95}
96
97impl ReallocPoolBuilder {
98 pub fn new() -> Self {
99 Self::default()
100 }
101 #[inline(always)]
102 pub fn keeper(&mut self, keeper: solana_program::pubkey::Pubkey) -> &mut Self {
103 self.keeper = Some(keeper);
104 self
105 }
106 #[inline(always)]
107 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
108 self.pool = Some(pool);
109 self
110 }
111 #[inline(always)]
113 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
114 self.system_program = Some(system_program);
115 self
116 }
117 #[inline(always)]
119 pub fn rent(&mut self, rent: solana_program::pubkey::Pubkey) -> &mut Self {
120 self.rent = Some(rent);
121 self
122 }
123 #[inline(always)]
125 pub fn add_remaining_account(
126 &mut self,
127 account: solana_program::instruction::AccountMeta,
128 ) -> &mut Self {
129 self.__remaining_accounts.push(account);
130 self
131 }
132 #[inline(always)]
134 pub fn add_remaining_accounts(
135 &mut self,
136 accounts: &[solana_program::instruction::AccountMeta],
137 ) -> &mut Self {
138 self.__remaining_accounts.extend_from_slice(accounts);
139 self
140 }
141 #[allow(clippy::clone_on_copy)]
142 pub fn instruction(&self) -> solana_program::instruction::Instruction {
143 let accounts = ReallocPool {
144 keeper: self.keeper.expect("keeper is not set"),
145 pool: self.pool.expect("pool is not set"),
146 system_program: self
147 .system_program
148 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
149 rent: self.rent.unwrap_or(solana_program::pubkey!(
150 "SysvarRent111111111111111111111111111111111"
151 )),
152 };
153
154 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
155 }
156}
157
158pub struct ReallocPoolCpiAccounts<'a, 'b> {
160 pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
161
162 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
163
164 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
165
166 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
167}
168
169pub struct ReallocPoolCpi<'a, 'b> {
171 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
173
174 pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
175
176 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
177
178 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
179
180 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
181}
182
183impl<'a, 'b> ReallocPoolCpi<'a, 'b> {
184 pub fn new(
185 program: &'b solana_program::account_info::AccountInfo<'a>,
186 accounts: ReallocPoolCpiAccounts<'a, 'b>,
187 ) -> Self {
188 Self {
189 __program: program,
190 keeper: accounts.keeper,
191 pool: accounts.pool,
192 system_program: accounts.system_program,
193 rent: accounts.rent,
194 }
195 }
196 #[inline(always)]
197 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
198 self.invoke_signed_with_remaining_accounts(&[], &[])
199 }
200 #[inline(always)]
201 pub fn invoke_with_remaining_accounts(
202 &self,
203 remaining_accounts: &[(
204 &'b solana_program::account_info::AccountInfo<'a>,
205 bool,
206 bool,
207 )],
208 ) -> solana_program::entrypoint::ProgramResult {
209 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
210 }
211 #[inline(always)]
212 pub fn invoke_signed(
213 &self,
214 signers_seeds: &[&[&[u8]]],
215 ) -> solana_program::entrypoint::ProgramResult {
216 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
217 }
218 #[allow(clippy::arithmetic_side_effects)]
219 #[allow(clippy::clone_on_copy)]
220 #[allow(clippy::vec_init_then_push)]
221 pub fn invoke_signed_with_remaining_accounts(
222 &self,
223 signers_seeds: &[&[&[u8]]],
224 remaining_accounts: &[(
225 &'b solana_program::account_info::AccountInfo<'a>,
226 bool,
227 bool,
228 )],
229 ) -> solana_program::entrypoint::ProgramResult {
230 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
231 accounts.push(solana_program::instruction::AccountMeta::new(
232 *self.keeper.key,
233 true,
234 ));
235 accounts.push(solana_program::instruction::AccountMeta::new(
236 *self.pool.key,
237 false,
238 ));
239 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
240 *self.system_program.key,
241 false,
242 ));
243 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
244 *self.rent.key,
245 false,
246 ));
247 remaining_accounts.iter().for_each(|remaining_account| {
248 accounts.push(solana_program::instruction::AccountMeta {
249 pubkey: *remaining_account.0.key,
250 is_signer: remaining_account.1,
251 is_writable: remaining_account.2,
252 })
253 });
254 let data = borsh::to_vec(&ReallocPoolInstructionData::new()).unwrap();
255
256 let instruction = solana_program::instruction::Instruction {
257 program_id: crate::PERPETUALS_ID,
258 accounts,
259 data,
260 };
261 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
262 account_infos.push(self.__program.clone());
263 account_infos.push(self.keeper.clone());
264 account_infos.push(self.pool.clone());
265 account_infos.push(self.system_program.clone());
266 account_infos.push(self.rent.clone());
267 remaining_accounts
268 .iter()
269 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
270
271 if signers_seeds.is_empty() {
272 solana_program::program::invoke(&instruction, &account_infos)
273 } else {
274 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
275 }
276 }
277}
278
279#[derive(Clone, Debug)]
288pub struct ReallocPoolCpiBuilder<'a, 'b> {
289 instruction: Box<ReallocPoolCpiBuilderInstruction<'a, 'b>>,
290}
291
292impl<'a, 'b> ReallocPoolCpiBuilder<'a, 'b> {
293 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
294 let instruction = Box::new(ReallocPoolCpiBuilderInstruction {
295 __program: program,
296 keeper: None,
297 pool: None,
298 system_program: None,
299 rent: None,
300 __remaining_accounts: Vec::new(),
301 });
302 Self { instruction }
303 }
304 #[inline(always)]
305 pub fn keeper(
306 &mut self,
307 keeper: &'b solana_program::account_info::AccountInfo<'a>,
308 ) -> &mut Self {
309 self.instruction.keeper = Some(keeper);
310 self
311 }
312 #[inline(always)]
313 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
314 self.instruction.pool = Some(pool);
315 self
316 }
317 #[inline(always)]
318 pub fn system_program(
319 &mut self,
320 system_program: &'b solana_program::account_info::AccountInfo<'a>,
321 ) -> &mut Self {
322 self.instruction.system_program = Some(system_program);
323 self
324 }
325 #[inline(always)]
326 pub fn rent(&mut self, rent: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
327 self.instruction.rent = Some(rent);
328 self
329 }
330 #[inline(always)]
332 pub fn add_remaining_account(
333 &mut self,
334 account: &'b solana_program::account_info::AccountInfo<'a>,
335 is_writable: bool,
336 is_signer: bool,
337 ) -> &mut Self {
338 self.instruction
339 .__remaining_accounts
340 .push((account, is_writable, is_signer));
341 self
342 }
343 #[inline(always)]
348 pub fn add_remaining_accounts(
349 &mut self,
350 accounts: &[(
351 &'b solana_program::account_info::AccountInfo<'a>,
352 bool,
353 bool,
354 )],
355 ) -> &mut Self {
356 self.instruction
357 .__remaining_accounts
358 .extend_from_slice(accounts);
359 self
360 }
361 #[inline(always)]
362 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
363 self.invoke_signed(&[])
364 }
365 #[allow(clippy::clone_on_copy)]
366 #[allow(clippy::vec_init_then_push)]
367 pub fn invoke_signed(
368 &self,
369 signers_seeds: &[&[&[u8]]],
370 ) -> solana_program::entrypoint::ProgramResult {
371 let instruction = ReallocPoolCpi {
372 __program: self.instruction.__program,
373
374 keeper: self.instruction.keeper.expect("keeper is not set"),
375
376 pool: self.instruction.pool.expect("pool is not set"),
377
378 system_program: self
379 .instruction
380 .system_program
381 .expect("system_program is not set"),
382
383 rent: self.instruction.rent.expect("rent is not set"),
384 };
385 instruction.invoke_signed_with_remaining_accounts(
386 signers_seeds,
387 &self.instruction.__remaining_accounts,
388 )
389 }
390}
391
392#[derive(Clone, Debug)]
393struct ReallocPoolCpiBuilderInstruction<'a, 'b> {
394 __program: &'b solana_program::account_info::AccountInfo<'a>,
395 keeper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
396 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
397 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
398 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
399 __remaining_accounts: Vec<(
401 &'b solana_program::account_info::AccountInfo<'a>,
402 bool,
403 bool,
404 )>,
405}