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