Skip to main content

reflect_sdk/generated/instructions/
update_recipients.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_pubkey::Pubkey;
11
12pub const UPDATE_RECIPIENTS_DISCRIMINATOR: [u8; 8] = [92, 134, 20, 47, 48, 34, 175, 112];
13
14/// Accounts.
15#[derive(Debug)]
16pub struct UpdateRecipients {
17    pub main: solana_pubkey::Pubkey,
18
19    pub admin: solana_pubkey::Pubkey,
20
21    pub system_program: solana_pubkey::Pubkey,
22
23    pub strategy: solana_pubkey::Pubkey,
24
25    pub admin_permissions: solana_pubkey::Pubkey,
26}
27
28impl UpdateRecipients {
29    pub fn instruction(
30        &self,
31        args: UpdateRecipientsInstructionArgs,
32    ) -> solana_instruction::Instruction {
33        self.instruction_with_remaining_accounts(args, &[])
34    }
35    #[allow(clippy::arithmetic_side_effects)]
36    #[allow(clippy::vec_init_then_push)]
37    pub fn instruction_with_remaining_accounts(
38        &self,
39        args: UpdateRecipientsInstructionArgs,
40        remaining_accounts: &[solana_instruction::AccountMeta],
41    ) -> solana_instruction::Instruction {
42        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
43        accounts.push(solana_instruction::AccountMeta::new(self.main, false));
44        accounts.push(solana_instruction::AccountMeta::new(self.admin, true));
45        accounts.push(solana_instruction::AccountMeta::new_readonly(
46            self.system_program,
47            false,
48        ));
49        accounts.push(solana_instruction::AccountMeta::new(self.strategy, false));
50        accounts.push(solana_instruction::AccountMeta::new(
51            self.admin_permissions,
52            false,
53        ));
54        accounts.extend_from_slice(remaining_accounts);
55        let mut data = UpdateRecipientsInstructionData::new().try_to_vec().unwrap();
56        let mut args = args.try_to_vec().unwrap();
57        data.append(&mut args);
58
59        solana_instruction::Instruction {
60            program_id: crate::REFLECT_MAIN_ID,
61            accounts,
62            data,
63        }
64    }
65}
66
67#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
68#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
69pub struct UpdateRecipientsInstructionData {
70    discriminator: [u8; 8],
71}
72
73impl UpdateRecipientsInstructionData {
74    pub fn new() -> Self {
75        Self {
76            discriminator: [92, 134, 20, 47, 48, 34, 175, 112],
77        }
78    }
79
80    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
81        borsh::to_vec(self)
82    }
83}
84
85impl Default for UpdateRecipientsInstructionData {
86    fn default() -> Self {
87        Self::new()
88    }
89}
90
91#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93pub struct UpdateRecipientsInstructionArgs {
94    pub recipient_addresses: Vec<Pubkey>,
95    pub recipient_cuts: Vec<u16>,
96}
97
98impl UpdateRecipientsInstructionArgs {
99    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
100        borsh::to_vec(self)
101    }
102}
103
104/// Instruction builder for `UpdateRecipients`.
105///
106/// ### Accounts:
107///
108///   0. `[writable]` main
109///   1. `[writable, signer]` admin
110///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
111///   3. `[writable]` strategy
112///   4. `[writable]` admin_permissions
113#[derive(Clone, Debug, Default)]
114pub struct UpdateRecipientsBuilder {
115    main: Option<solana_pubkey::Pubkey>,
116    admin: Option<solana_pubkey::Pubkey>,
117    system_program: Option<solana_pubkey::Pubkey>,
118    strategy: Option<solana_pubkey::Pubkey>,
119    admin_permissions: Option<solana_pubkey::Pubkey>,
120    recipient_addresses: Option<Vec<Pubkey>>,
121    recipient_cuts: Option<Vec<u16>>,
122    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
123}
124
125impl UpdateRecipientsBuilder {
126    pub fn new() -> Self {
127        Self::default()
128    }
129    #[inline(always)]
130    pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
131        self.main = Some(main);
132        self
133    }
134    #[inline(always)]
135    pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
136        self.admin = Some(admin);
137        self
138    }
139    /// `[optional account, default to '11111111111111111111111111111111']`
140    #[inline(always)]
141    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
142        self.system_program = Some(system_program);
143        self
144    }
145    #[inline(always)]
146    pub fn strategy(&mut self, strategy: solana_pubkey::Pubkey) -> &mut Self {
147        self.strategy = Some(strategy);
148        self
149    }
150    #[inline(always)]
151    pub fn admin_permissions(&mut self, admin_permissions: solana_pubkey::Pubkey) -> &mut Self {
152        self.admin_permissions = Some(admin_permissions);
153        self
154    }
155    #[inline(always)]
156    pub fn recipient_addresses(&mut self, recipient_addresses: Vec<Pubkey>) -> &mut Self {
157        self.recipient_addresses = Some(recipient_addresses);
158        self
159    }
160    #[inline(always)]
161    pub fn recipient_cuts(&mut self, recipient_cuts: Vec<u16>) -> &mut Self {
162        self.recipient_cuts = Some(recipient_cuts);
163        self
164    }
165    /// Add an additional account to the instruction.
166    #[inline(always)]
167    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
168        self.__remaining_accounts.push(account);
169        self
170    }
171    /// Add additional accounts to the instruction.
172    #[inline(always)]
173    pub fn add_remaining_accounts(
174        &mut self,
175        accounts: &[solana_instruction::AccountMeta],
176    ) -> &mut Self {
177        self.__remaining_accounts.extend_from_slice(accounts);
178        self
179    }
180    #[allow(clippy::clone_on_copy)]
181    pub fn instruction(&self) -> solana_instruction::Instruction {
182        let accounts = UpdateRecipients {
183            main: self.main.expect("main is not set"),
184            admin: self.admin.expect("admin is not set"),
185            system_program: self
186                .system_program
187                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
188            strategy: self.strategy.expect("strategy is not set"),
189            admin_permissions: self
190                .admin_permissions
191                .expect("admin_permissions is not set"),
192        };
193        let args = UpdateRecipientsInstructionArgs {
194            recipient_addresses: self
195                .recipient_addresses
196                .clone()
197                .expect("recipient_addresses is not set"),
198            recipient_cuts: self
199                .recipient_cuts
200                .clone()
201                .expect("recipient_cuts is not set"),
202        };
203
204        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
205    }
206}
207
208/// `update_recipients` CPI accounts.
209pub struct UpdateRecipientsCpiAccounts<'a, 'b> {
210    pub main: &'b solana_account_info::AccountInfo<'a>,
211
212    pub admin: &'b solana_account_info::AccountInfo<'a>,
213
214    pub system_program: &'b solana_account_info::AccountInfo<'a>,
215
216    pub strategy: &'b solana_account_info::AccountInfo<'a>,
217
218    pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
219}
220
221/// `update_recipients` CPI instruction.
222pub struct UpdateRecipientsCpi<'a, 'b> {
223    /// The program to invoke.
224    pub __program: &'b solana_account_info::AccountInfo<'a>,
225
226    pub main: &'b solana_account_info::AccountInfo<'a>,
227
228    pub admin: &'b solana_account_info::AccountInfo<'a>,
229
230    pub system_program: &'b solana_account_info::AccountInfo<'a>,
231
232    pub strategy: &'b solana_account_info::AccountInfo<'a>,
233
234    pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
235    /// The arguments for the instruction.
236    pub __args: UpdateRecipientsInstructionArgs,
237}
238
239impl<'a, 'b> UpdateRecipientsCpi<'a, 'b> {
240    pub fn new(
241        program: &'b solana_account_info::AccountInfo<'a>,
242        accounts: UpdateRecipientsCpiAccounts<'a, 'b>,
243        args: UpdateRecipientsInstructionArgs,
244    ) -> Self {
245        Self {
246            __program: program,
247            main: accounts.main,
248            admin: accounts.admin,
249            system_program: accounts.system_program,
250            strategy: accounts.strategy,
251            admin_permissions: accounts.admin_permissions,
252            __args: args,
253        }
254    }
255    #[inline(always)]
256    pub fn invoke(&self) -> solana_program_error::ProgramResult {
257        self.invoke_signed_with_remaining_accounts(&[], &[])
258    }
259    #[inline(always)]
260    pub fn invoke_with_remaining_accounts(
261        &self,
262        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
263    ) -> solana_program_error::ProgramResult {
264        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
265    }
266    #[inline(always)]
267    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
268        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
269    }
270    #[allow(clippy::arithmetic_side_effects)]
271    #[allow(clippy::clone_on_copy)]
272    #[allow(clippy::vec_init_then_push)]
273    pub fn invoke_signed_with_remaining_accounts(
274        &self,
275        signers_seeds: &[&[&[u8]]],
276        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
277    ) -> solana_program_error::ProgramResult {
278        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
279        accounts.push(solana_instruction::AccountMeta::new(*self.main.key, false));
280        accounts.push(solana_instruction::AccountMeta::new(*self.admin.key, true));
281        accounts.push(solana_instruction::AccountMeta::new_readonly(
282            *self.system_program.key,
283            false,
284        ));
285        accounts.push(solana_instruction::AccountMeta::new(
286            *self.strategy.key,
287            false,
288        ));
289        accounts.push(solana_instruction::AccountMeta::new(
290            *self.admin_permissions.key,
291            false,
292        ));
293        remaining_accounts.iter().for_each(|remaining_account| {
294            accounts.push(solana_instruction::AccountMeta {
295                pubkey: *remaining_account.0.key,
296                is_signer: remaining_account.1,
297                is_writable: remaining_account.2,
298            })
299        });
300        let mut data = UpdateRecipientsInstructionData::new().try_to_vec().unwrap();
301        let mut args = self.__args.try_to_vec().unwrap();
302        data.append(&mut args);
303
304        let instruction = solana_instruction::Instruction {
305            program_id: crate::REFLECT_MAIN_ID,
306            accounts,
307            data,
308        };
309        let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
310        account_infos.push(self.__program.clone());
311        account_infos.push(self.main.clone());
312        account_infos.push(self.admin.clone());
313        account_infos.push(self.system_program.clone());
314        account_infos.push(self.strategy.clone());
315        account_infos.push(self.admin_permissions.clone());
316        remaining_accounts
317            .iter()
318            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
319
320        if signers_seeds.is_empty() {
321            solana_cpi::invoke(&instruction, &account_infos)
322        } else {
323            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
324        }
325    }
326}
327
328/// Instruction builder for `UpdateRecipients` via CPI.
329///
330/// ### Accounts:
331///
332///   0. `[writable]` main
333///   1. `[writable, signer]` admin
334///   2. `[]` system_program
335///   3. `[writable]` strategy
336///   4. `[writable]` admin_permissions
337#[derive(Clone, Debug)]
338pub struct UpdateRecipientsCpiBuilder<'a, 'b> {
339    instruction: Box<UpdateRecipientsCpiBuilderInstruction<'a, 'b>>,
340}
341
342impl<'a, 'b> UpdateRecipientsCpiBuilder<'a, 'b> {
343    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
344        let instruction = Box::new(UpdateRecipientsCpiBuilderInstruction {
345            __program: program,
346            main: None,
347            admin: None,
348            system_program: None,
349            strategy: None,
350            admin_permissions: None,
351            recipient_addresses: None,
352            recipient_cuts: None,
353            __remaining_accounts: Vec::new(),
354        });
355        Self { instruction }
356    }
357    #[inline(always)]
358    pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
359        self.instruction.main = Some(main);
360        self
361    }
362    #[inline(always)]
363    pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
364        self.instruction.admin = Some(admin);
365        self
366    }
367    #[inline(always)]
368    pub fn system_program(
369        &mut self,
370        system_program: &'b solana_account_info::AccountInfo<'a>,
371    ) -> &mut Self {
372        self.instruction.system_program = Some(system_program);
373        self
374    }
375    #[inline(always)]
376    pub fn strategy(&mut self, strategy: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
377        self.instruction.strategy = Some(strategy);
378        self
379    }
380    #[inline(always)]
381    pub fn admin_permissions(
382        &mut self,
383        admin_permissions: &'b solana_account_info::AccountInfo<'a>,
384    ) -> &mut Self {
385        self.instruction.admin_permissions = Some(admin_permissions);
386        self
387    }
388    #[inline(always)]
389    pub fn recipient_addresses(&mut self, recipient_addresses: Vec<Pubkey>) -> &mut Self {
390        self.instruction.recipient_addresses = Some(recipient_addresses);
391        self
392    }
393    #[inline(always)]
394    pub fn recipient_cuts(&mut self, recipient_cuts: Vec<u16>) -> &mut Self {
395        self.instruction.recipient_cuts = Some(recipient_cuts);
396        self
397    }
398    /// Add an additional account to the instruction.
399    #[inline(always)]
400    pub fn add_remaining_account(
401        &mut self,
402        account: &'b solana_account_info::AccountInfo<'a>,
403        is_writable: bool,
404        is_signer: bool,
405    ) -> &mut Self {
406        self.instruction
407            .__remaining_accounts
408            .push((account, is_writable, is_signer));
409        self
410    }
411    /// Add additional accounts to the instruction.
412    ///
413    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
414    /// and a `bool` indicating whether the account is a signer or not.
415    #[inline(always)]
416    pub fn add_remaining_accounts(
417        &mut self,
418        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
419    ) -> &mut Self {
420        self.instruction
421            .__remaining_accounts
422            .extend_from_slice(accounts);
423        self
424    }
425    #[inline(always)]
426    pub fn invoke(&self) -> solana_program_error::ProgramResult {
427        self.invoke_signed(&[])
428    }
429    #[allow(clippy::clone_on_copy)]
430    #[allow(clippy::vec_init_then_push)]
431    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
432        let args = UpdateRecipientsInstructionArgs {
433            recipient_addresses: self
434                .instruction
435                .recipient_addresses
436                .clone()
437                .expect("recipient_addresses is not set"),
438            recipient_cuts: self
439                .instruction
440                .recipient_cuts
441                .clone()
442                .expect("recipient_cuts is not set"),
443        };
444        let instruction = UpdateRecipientsCpi {
445            __program: self.instruction.__program,
446
447            main: self.instruction.main.expect("main is not set"),
448
449            admin: self.instruction.admin.expect("admin is not set"),
450
451            system_program: self
452                .instruction
453                .system_program
454                .expect("system_program is not set"),
455
456            strategy: self.instruction.strategy.expect("strategy is not set"),
457
458            admin_permissions: self
459                .instruction
460                .admin_permissions
461                .expect("admin_permissions is not set"),
462            __args: args,
463        };
464        instruction.invoke_signed_with_remaining_accounts(
465            signers_seeds,
466            &self.instruction.__remaining_accounts,
467        )
468    }
469}
470
471#[derive(Clone, Debug)]
472struct UpdateRecipientsCpiBuilderInstruction<'a, 'b> {
473    __program: &'b solana_account_info::AccountInfo<'a>,
474    main: Option<&'b solana_account_info::AccountInfo<'a>>,
475    admin: Option<&'b solana_account_info::AccountInfo<'a>>,
476    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
477    strategy: Option<&'b solana_account_info::AccountInfo<'a>>,
478    admin_permissions: Option<&'b solana_account_info::AccountInfo<'a>>,
479    recipient_addresses: Option<Vec<Pubkey>>,
480    recipient_cuts: Option<Vec<u16>>,
481    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
482    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
483}