orca_wavebreak/generated/instructions/
config_update.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 crate::generated::types::ConfigUpdateType;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct ConfigUpdate {
15    /// The authority of the config
16    pub authority: solana_program::pubkey::Pubkey,
17    /// The config account
18    pub config: solana_program::pubkey::Pubkey,
19}
20
21impl ConfigUpdate {
22    pub fn instruction(
23        &self,
24        args: ConfigUpdateInstructionArgs,
25    ) -> solana_program::instruction::Instruction {
26        self.instruction_with_remaining_accounts(args, &[])
27    }
28    #[allow(clippy::arithmetic_side_effects)]
29    #[allow(clippy::vec_init_then_push)]
30    pub fn instruction_with_remaining_accounts(
31        &self,
32        args: ConfigUpdateInstructionArgs,
33        remaining_accounts: &[solana_program::instruction::AccountMeta],
34    ) -> solana_program::instruction::Instruction {
35        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
36        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
37            self.authority,
38            true,
39        ));
40        accounts.push(solana_program::instruction::AccountMeta::new(
41            self.config,
42            false,
43        ));
44        accounts.extend_from_slice(remaining_accounts);
45        let mut data = borsh::to_vec(&ConfigUpdateInstructionData::new()).unwrap();
46        let mut args = borsh::to_vec(&args).unwrap();
47        data.append(&mut args);
48
49        solana_program::instruction::Instruction {
50            program_id: crate::WAVEBREAK_ID,
51            accounts,
52            data,
53        }
54    }
55}
56
57#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct ConfigUpdateInstructionData {
60    discriminator: u8,
61}
62
63impl ConfigUpdateInstructionData {
64    pub fn new() -> Self {
65        Self { discriminator: 17 }
66    }
67}
68
69impl Default for ConfigUpdateInstructionData {
70    fn default() -> Self {
71        Self::new()
72    }
73}
74
75#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
76#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
77pub struct ConfigUpdateInstructionArgs {
78    pub update: ConfigUpdateType,
79}
80
81/// Instruction builder for `ConfigUpdate`.
82///
83/// ### Accounts:
84///
85///   0. `[signer]` authority
86///   1. `[writable]` config
87#[derive(Clone, Debug, Default)]
88pub struct ConfigUpdateBuilder {
89    authority: Option<solana_program::pubkey::Pubkey>,
90    config: Option<solana_program::pubkey::Pubkey>,
91    update: Option<ConfigUpdateType>,
92    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
93}
94
95impl ConfigUpdateBuilder {
96    pub fn new() -> Self {
97        Self::default()
98    }
99    /// The authority of the config
100    #[inline(always)]
101    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
102        self.authority = Some(authority);
103        self
104    }
105    /// The config account
106    #[inline(always)]
107    pub fn config(&mut self, config: solana_program::pubkey::Pubkey) -> &mut Self {
108        self.config = Some(config);
109        self
110    }
111    #[inline(always)]
112    pub fn update(&mut self, update: ConfigUpdateType) -> &mut Self {
113        self.update = Some(update);
114        self
115    }
116    /// Add an additional account to the instruction.
117    #[inline(always)]
118    pub fn add_remaining_account(
119        &mut self,
120        account: solana_program::instruction::AccountMeta,
121    ) -> &mut Self {
122        self.__remaining_accounts.push(account);
123        self
124    }
125    /// Add additional accounts to the instruction.
126    #[inline(always)]
127    pub fn add_remaining_accounts(
128        &mut self,
129        accounts: &[solana_program::instruction::AccountMeta],
130    ) -> &mut Self {
131        self.__remaining_accounts.extend_from_slice(accounts);
132        self
133    }
134    #[allow(clippy::clone_on_copy)]
135    pub fn instruction(&self) -> solana_program::instruction::Instruction {
136        let accounts = ConfigUpdate {
137            authority: self.authority.expect("authority is not set"),
138            config: self.config.expect("config is not set"),
139        };
140        let args = ConfigUpdateInstructionArgs {
141            update: self.update.clone().expect("update is not set"),
142        };
143
144        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
145    }
146}
147
148/// `config_update` CPI accounts.
149pub struct ConfigUpdateCpiAccounts<'a, 'b> {
150    /// The authority of the config
151    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
152    /// The config account
153    pub config: &'b solana_program::account_info::AccountInfo<'a>,
154}
155
156/// `config_update` CPI instruction.
157pub struct ConfigUpdateCpi<'a, 'b> {
158    /// The program to invoke.
159    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
160    /// The authority of the config
161    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
162    /// The config account
163    pub config: &'b solana_program::account_info::AccountInfo<'a>,
164    /// The arguments for the instruction.
165    pub __args: ConfigUpdateInstructionArgs,
166}
167
168impl<'a, 'b> ConfigUpdateCpi<'a, 'b> {
169    pub fn new(
170        program: &'b solana_program::account_info::AccountInfo<'a>,
171        accounts: ConfigUpdateCpiAccounts<'a, 'b>,
172        args: ConfigUpdateInstructionArgs,
173    ) -> Self {
174        Self {
175            __program: program,
176            authority: accounts.authority,
177            config: accounts.config,
178            __args: args,
179        }
180    }
181    #[inline(always)]
182    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
183        self.invoke_signed_with_remaining_accounts(&[], &[])
184    }
185    #[inline(always)]
186    pub fn invoke_with_remaining_accounts(
187        &self,
188        remaining_accounts: &[(
189            &'b solana_program::account_info::AccountInfo<'a>,
190            bool,
191            bool,
192        )],
193    ) -> solana_program::entrypoint::ProgramResult {
194        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
195    }
196    #[inline(always)]
197    pub fn invoke_signed(
198        &self,
199        signers_seeds: &[&[&[u8]]],
200    ) -> solana_program::entrypoint::ProgramResult {
201        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
202    }
203    #[allow(clippy::arithmetic_side_effects)]
204    #[allow(clippy::clone_on_copy)]
205    #[allow(clippy::vec_init_then_push)]
206    pub fn invoke_signed_with_remaining_accounts(
207        &self,
208        signers_seeds: &[&[&[u8]]],
209        remaining_accounts: &[(
210            &'b solana_program::account_info::AccountInfo<'a>,
211            bool,
212            bool,
213        )],
214    ) -> solana_program::entrypoint::ProgramResult {
215        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
216        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
217            *self.authority.key,
218            true,
219        ));
220        accounts.push(solana_program::instruction::AccountMeta::new(
221            *self.config.key,
222            false,
223        ));
224        remaining_accounts.iter().for_each(|remaining_account| {
225            accounts.push(solana_program::instruction::AccountMeta {
226                pubkey: *remaining_account.0.key,
227                is_signer: remaining_account.1,
228                is_writable: remaining_account.2,
229            })
230        });
231        let mut data = borsh::to_vec(&ConfigUpdateInstructionData::new()).unwrap();
232        let mut args = borsh::to_vec(&self.__args).unwrap();
233        data.append(&mut args);
234
235        let instruction = solana_program::instruction::Instruction {
236            program_id: crate::WAVEBREAK_ID,
237            accounts,
238            data,
239        };
240        let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
241        account_infos.push(self.__program.clone());
242        account_infos.push(self.authority.clone());
243        account_infos.push(self.config.clone());
244        remaining_accounts
245            .iter()
246            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
247
248        if signers_seeds.is_empty() {
249            solana_program::program::invoke(&instruction, &account_infos)
250        } else {
251            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
252        }
253    }
254}
255
256/// Instruction builder for `ConfigUpdate` via CPI.
257///
258/// ### Accounts:
259///
260///   0. `[signer]` authority
261///   1. `[writable]` config
262#[derive(Clone, Debug)]
263pub struct ConfigUpdateCpiBuilder<'a, 'b> {
264    instruction: Box<ConfigUpdateCpiBuilderInstruction<'a, 'b>>,
265}
266
267impl<'a, 'b> ConfigUpdateCpiBuilder<'a, 'b> {
268    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
269        let instruction = Box::new(ConfigUpdateCpiBuilderInstruction {
270            __program: program,
271            authority: None,
272            config: None,
273            update: None,
274            __remaining_accounts: Vec::new(),
275        });
276        Self { instruction }
277    }
278    /// The authority of the config
279    #[inline(always)]
280    pub fn authority(
281        &mut self,
282        authority: &'b solana_program::account_info::AccountInfo<'a>,
283    ) -> &mut Self {
284        self.instruction.authority = Some(authority);
285        self
286    }
287    /// The config account
288    #[inline(always)]
289    pub fn config(
290        &mut self,
291        config: &'b solana_program::account_info::AccountInfo<'a>,
292    ) -> &mut Self {
293        self.instruction.config = Some(config);
294        self
295    }
296    #[inline(always)]
297    pub fn update(&mut self, update: ConfigUpdateType) -> &mut Self {
298        self.instruction.update = Some(update);
299        self
300    }
301    /// Add an additional account to the instruction.
302    #[inline(always)]
303    pub fn add_remaining_account(
304        &mut self,
305        account: &'b solana_program::account_info::AccountInfo<'a>,
306        is_writable: bool,
307        is_signer: bool,
308    ) -> &mut Self {
309        self.instruction
310            .__remaining_accounts
311            .push((account, is_writable, is_signer));
312        self
313    }
314    /// Add additional accounts to the instruction.
315    ///
316    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
317    /// and a `bool` indicating whether the account is a signer or not.
318    #[inline(always)]
319    pub fn add_remaining_accounts(
320        &mut self,
321        accounts: &[(
322            &'b solana_program::account_info::AccountInfo<'a>,
323            bool,
324            bool,
325        )],
326    ) -> &mut Self {
327        self.instruction
328            .__remaining_accounts
329            .extend_from_slice(accounts);
330        self
331    }
332    #[inline(always)]
333    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
334        self.invoke_signed(&[])
335    }
336    #[allow(clippy::clone_on_copy)]
337    #[allow(clippy::vec_init_then_push)]
338    pub fn invoke_signed(
339        &self,
340        signers_seeds: &[&[&[u8]]],
341    ) -> solana_program::entrypoint::ProgramResult {
342        let args = ConfigUpdateInstructionArgs {
343            update: self.instruction.update.clone().expect("update is not set"),
344        };
345        let instruction = ConfigUpdateCpi {
346            __program: self.instruction.__program,
347
348            authority: self.instruction.authority.expect("authority is not set"),
349
350            config: self.instruction.config.expect("config is not set"),
351            __args: args,
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 ConfigUpdateCpiBuilderInstruction<'a, 'b> {
362    __program: &'b solana_program::account_info::AccountInfo<'a>,
363    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
364    config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
365    update: Option<ConfigUpdateType>,
366    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
367    __remaining_accounts: Vec<(
368        &'b solana_program::account_info::AccountInfo<'a>,
369        bool,
370        bool,
371    )>,
372}