Skip to main content

orca_sol/instructions/
initialize_reward.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;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct InitializeReward {
14    pub reward_authority: solana_pubkey::Pubkey,
15
16    pub funder: solana_pubkey::Pubkey,
17
18    pub whirlpool: solana_pubkey::Pubkey,
19
20    pub reward_mint: solana_pubkey::Pubkey,
21
22    pub reward_vault: solana_pubkey::Pubkey,
23
24    pub token_program: solana_pubkey::Pubkey,
25
26    pub system_program: solana_pubkey::Pubkey,
27
28    pub rent: solana_pubkey::Pubkey,
29}
30
31impl InitializeReward {
32    pub fn instruction(
33        &self,
34        args: InitializeRewardInstructionArgs,
35    ) -> solana_instruction::Instruction {
36        self.instruction_with_remaining_accounts(args, &[])
37    }
38    #[allow(clippy::arithmetic_side_effects)]
39    #[allow(clippy::vec_init_then_push)]
40    pub fn instruction_with_remaining_accounts(
41        &self,
42        args: InitializeRewardInstructionArgs,
43        remaining_accounts: &[solana_instruction::AccountMeta],
44    ) -> solana_instruction::Instruction {
45        let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
46        accounts.push(solana_instruction::AccountMeta::new_readonly(
47            self.reward_authority,
48            true,
49        ));
50        accounts.push(solana_instruction::AccountMeta::new(self.funder, true));
51        accounts.push(solana_instruction::AccountMeta::new(self.whirlpool, false));
52        accounts.push(solana_instruction::AccountMeta::new_readonly(
53            self.reward_mint,
54            false,
55        ));
56        accounts.push(solana_instruction::AccountMeta::new(
57            self.reward_vault,
58            true,
59        ));
60        accounts.push(solana_instruction::AccountMeta::new_readonly(
61            self.token_program,
62            false,
63        ));
64        accounts.push(solana_instruction::AccountMeta::new_readonly(
65            self.system_program,
66            false,
67        ));
68        accounts.push(solana_instruction::AccountMeta::new_readonly(
69            self.rent, false,
70        ));
71        accounts.extend_from_slice(remaining_accounts);
72        let mut data = borsh::to_vec(&InitializeRewardInstructionData::new()).unwrap();
73        let mut args = borsh::to_vec(&args).unwrap();
74        data.append(&mut args);
75
76        solana_instruction::Instruction {
77            program_id: crate::WHIRLPOOL_ID,
78            accounts,
79            data,
80        }
81    }
82}
83
84#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
86pub struct InitializeRewardInstructionData {
87    discriminator: [u8; 8],
88}
89
90impl InitializeRewardInstructionData {
91    pub fn new() -> Self {
92        Self {
93            discriminator: [95, 135, 192, 196, 242, 129, 230, 68],
94        }
95    }
96}
97
98impl Default for InitializeRewardInstructionData {
99    fn default() -> Self {
100        Self::new()
101    }
102}
103
104#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106pub struct InitializeRewardInstructionArgs {
107    pub reward_index: u8,
108}
109
110/// Instruction builder for `InitializeReward`.
111///
112/// ### Accounts:
113///
114///   0. `[signer]` reward_authority
115///   1. `[writable, signer]` funder
116///   2. `[writable]` whirlpool
117///   3. `[]` reward_mint
118///   4. `[writable, signer]` reward_vault
119///   5. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
120///   6. `[optional]` system_program (default to `11111111111111111111111111111111`)
121///   7. `[optional]` rent (default to `SysvarRent111111111111111111111111111111111`)
122#[derive(Clone, Debug, Default)]
123pub struct InitializeRewardBuilder {
124    reward_authority: Option<solana_pubkey::Pubkey>,
125    funder: Option<solana_pubkey::Pubkey>,
126    whirlpool: Option<solana_pubkey::Pubkey>,
127    reward_mint: Option<solana_pubkey::Pubkey>,
128    reward_vault: Option<solana_pubkey::Pubkey>,
129    token_program: Option<solana_pubkey::Pubkey>,
130    system_program: Option<solana_pubkey::Pubkey>,
131    rent: Option<solana_pubkey::Pubkey>,
132    reward_index: Option<u8>,
133    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
134}
135
136impl InitializeRewardBuilder {
137    pub fn new() -> Self {
138        Self::default()
139    }
140    #[inline(always)]
141    pub fn reward_authority(&mut self, reward_authority: solana_pubkey::Pubkey) -> &mut Self {
142        self.reward_authority = Some(reward_authority);
143        self
144    }
145    #[inline(always)]
146    pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
147        self.funder = Some(funder);
148        self
149    }
150    #[inline(always)]
151    pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
152        self.whirlpool = Some(whirlpool);
153        self
154    }
155    #[inline(always)]
156    pub fn reward_mint(&mut self, reward_mint: solana_pubkey::Pubkey) -> &mut Self {
157        self.reward_mint = Some(reward_mint);
158        self
159    }
160    #[inline(always)]
161    pub fn reward_vault(&mut self, reward_vault: solana_pubkey::Pubkey) -> &mut Self {
162        self.reward_vault = Some(reward_vault);
163        self
164    }
165    /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']`
166    #[inline(always)]
167    pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
168        self.token_program = Some(token_program);
169        self
170    }
171    /// `[optional account, default to '11111111111111111111111111111111']`
172    #[inline(always)]
173    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
174        self.system_program = Some(system_program);
175        self
176    }
177    /// `[optional account, default to 'SysvarRent111111111111111111111111111111111']`
178    #[inline(always)]
179    pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
180        self.rent = Some(rent);
181        self
182    }
183    #[inline(always)]
184    pub fn reward_index(&mut self, reward_index: u8) -> &mut Self {
185        self.reward_index = Some(reward_index);
186        self
187    }
188    /// Add an additional account to the instruction.
189    #[inline(always)]
190    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
191        self.__remaining_accounts.push(account);
192        self
193    }
194    /// Add additional accounts to the instruction.
195    #[inline(always)]
196    pub fn add_remaining_accounts(
197        &mut self,
198        accounts: &[solana_instruction::AccountMeta],
199    ) -> &mut Self {
200        self.__remaining_accounts.extend_from_slice(accounts);
201        self
202    }
203    #[allow(clippy::clone_on_copy)]
204    pub fn instruction(&self) -> solana_instruction::Instruction {
205        let accounts = InitializeReward {
206            reward_authority: self.reward_authority.expect("reward_authority is not set"),
207            funder: self.funder.expect("funder is not set"),
208            whirlpool: self.whirlpool.expect("whirlpool is not set"),
209            reward_mint: self.reward_mint.expect("reward_mint is not set"),
210            reward_vault: self.reward_vault.expect("reward_vault is not set"),
211            token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
212                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
213            )),
214            system_program: self
215                .system_program
216                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
217            rent: self.rent.unwrap_or(solana_pubkey::pubkey!(
218                "SysvarRent111111111111111111111111111111111"
219            )),
220        };
221        let args = InitializeRewardInstructionArgs {
222            reward_index: self.reward_index.clone().expect("reward_index is not set"),
223        };
224
225        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
226    }
227}
228
229/// `initialize_reward` CPI accounts.
230pub struct InitializeRewardCpiAccounts<'a, 'b> {
231    pub reward_authority: &'b solana_account_info::AccountInfo<'a>,
232
233    pub funder: &'b solana_account_info::AccountInfo<'a>,
234
235    pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
236
237    pub reward_mint: &'b solana_account_info::AccountInfo<'a>,
238
239    pub reward_vault: &'b solana_account_info::AccountInfo<'a>,
240
241    pub token_program: &'b solana_account_info::AccountInfo<'a>,
242
243    pub system_program: &'b solana_account_info::AccountInfo<'a>,
244
245    pub rent: &'b solana_account_info::AccountInfo<'a>,
246}
247
248/// `initialize_reward` CPI instruction.
249pub struct InitializeRewardCpi<'a, 'b> {
250    /// The program to invoke.
251    pub __program: &'b solana_account_info::AccountInfo<'a>,
252
253    pub reward_authority: &'b solana_account_info::AccountInfo<'a>,
254
255    pub funder: &'b solana_account_info::AccountInfo<'a>,
256
257    pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
258
259    pub reward_mint: &'b solana_account_info::AccountInfo<'a>,
260
261    pub reward_vault: &'b solana_account_info::AccountInfo<'a>,
262
263    pub token_program: &'b solana_account_info::AccountInfo<'a>,
264
265    pub system_program: &'b solana_account_info::AccountInfo<'a>,
266
267    pub rent: &'b solana_account_info::AccountInfo<'a>,
268    /// The arguments for the instruction.
269    pub __args: InitializeRewardInstructionArgs,
270}
271
272impl<'a, 'b> InitializeRewardCpi<'a, 'b> {
273    pub fn new(
274        program: &'b solana_account_info::AccountInfo<'a>,
275        accounts: InitializeRewardCpiAccounts<'a, 'b>,
276        args: InitializeRewardInstructionArgs,
277    ) -> Self {
278        Self {
279            __program: program,
280            reward_authority: accounts.reward_authority,
281            funder: accounts.funder,
282            whirlpool: accounts.whirlpool,
283            reward_mint: accounts.reward_mint,
284            reward_vault: accounts.reward_vault,
285            token_program: accounts.token_program,
286            system_program: accounts.system_program,
287            rent: accounts.rent,
288            __args: args,
289        }
290    }
291    #[inline(always)]
292    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
293        self.invoke_signed_with_remaining_accounts(&[], &[])
294    }
295    #[inline(always)]
296    pub fn invoke_with_remaining_accounts(
297        &self,
298        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
299    ) -> solana_program_entrypoint::ProgramResult {
300        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
301    }
302    #[inline(always)]
303    pub fn invoke_signed(
304        &self,
305        signers_seeds: &[&[&[u8]]],
306    ) -> solana_program_entrypoint::ProgramResult {
307        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
308    }
309    #[allow(clippy::arithmetic_side_effects)]
310    #[allow(clippy::clone_on_copy)]
311    #[allow(clippy::vec_init_then_push)]
312    pub fn invoke_signed_with_remaining_accounts(
313        &self,
314        signers_seeds: &[&[&[u8]]],
315        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
316    ) -> solana_program_entrypoint::ProgramResult {
317        let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
318        accounts.push(solana_instruction::AccountMeta::new_readonly(
319            *self.reward_authority.key,
320            true,
321        ));
322        accounts.push(solana_instruction::AccountMeta::new(*self.funder.key, true));
323        accounts.push(solana_instruction::AccountMeta::new(
324            *self.whirlpool.key,
325            false,
326        ));
327        accounts.push(solana_instruction::AccountMeta::new_readonly(
328            *self.reward_mint.key,
329            false,
330        ));
331        accounts.push(solana_instruction::AccountMeta::new(
332            *self.reward_vault.key,
333            true,
334        ));
335        accounts.push(solana_instruction::AccountMeta::new_readonly(
336            *self.token_program.key,
337            false,
338        ));
339        accounts.push(solana_instruction::AccountMeta::new_readonly(
340            *self.system_program.key,
341            false,
342        ));
343        accounts.push(solana_instruction::AccountMeta::new_readonly(
344            *self.rent.key,
345            false,
346        ));
347        remaining_accounts.iter().for_each(|remaining_account| {
348            accounts.push(solana_instruction::AccountMeta {
349                pubkey: *remaining_account.0.key,
350                is_signer: remaining_account.1,
351                is_writable: remaining_account.2,
352            })
353        });
354        let mut data = borsh::to_vec(&InitializeRewardInstructionData::new()).unwrap();
355        let mut args = borsh::to_vec(&self.__args).unwrap();
356        data.append(&mut args);
357
358        let instruction = solana_instruction::Instruction {
359            program_id: crate::WHIRLPOOL_ID,
360            accounts,
361            data,
362        };
363        let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
364        account_infos.push(self.__program.clone());
365        account_infos.push(self.reward_authority.clone());
366        account_infos.push(self.funder.clone());
367        account_infos.push(self.whirlpool.clone());
368        account_infos.push(self.reward_mint.clone());
369        account_infos.push(self.reward_vault.clone());
370        account_infos.push(self.token_program.clone());
371        account_infos.push(self.system_program.clone());
372        account_infos.push(self.rent.clone());
373        remaining_accounts
374            .iter()
375            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
376
377        if signers_seeds.is_empty() {
378            solana_cpi::invoke(&instruction, &account_infos)
379        } else {
380            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
381        }
382    }
383}
384
385/// Instruction builder for `InitializeReward` via CPI.
386///
387/// ### Accounts:
388///
389///   0. `[signer]` reward_authority
390///   1. `[writable, signer]` funder
391///   2. `[writable]` whirlpool
392///   3. `[]` reward_mint
393///   4. `[writable, signer]` reward_vault
394///   5. `[]` token_program
395///   6. `[]` system_program
396///   7. `[]` rent
397#[derive(Clone, Debug)]
398pub struct InitializeRewardCpiBuilder<'a, 'b> {
399    instruction: Box<InitializeRewardCpiBuilderInstruction<'a, 'b>>,
400}
401
402impl<'a, 'b> InitializeRewardCpiBuilder<'a, 'b> {
403    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
404        let instruction = Box::new(InitializeRewardCpiBuilderInstruction {
405            __program: program,
406            reward_authority: None,
407            funder: None,
408            whirlpool: None,
409            reward_mint: None,
410            reward_vault: None,
411            token_program: None,
412            system_program: None,
413            rent: None,
414            reward_index: None,
415            __remaining_accounts: Vec::new(),
416        });
417        Self { instruction }
418    }
419    #[inline(always)]
420    pub fn reward_authority(
421        &mut self,
422        reward_authority: &'b solana_account_info::AccountInfo<'a>,
423    ) -> &mut Self {
424        self.instruction.reward_authority = Some(reward_authority);
425        self
426    }
427    #[inline(always)]
428    pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
429        self.instruction.funder = Some(funder);
430        self
431    }
432    #[inline(always)]
433    pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
434        self.instruction.whirlpool = Some(whirlpool);
435        self
436    }
437    #[inline(always)]
438    pub fn reward_mint(
439        &mut self,
440        reward_mint: &'b solana_account_info::AccountInfo<'a>,
441    ) -> &mut Self {
442        self.instruction.reward_mint = Some(reward_mint);
443        self
444    }
445    #[inline(always)]
446    pub fn reward_vault(
447        &mut self,
448        reward_vault: &'b solana_account_info::AccountInfo<'a>,
449    ) -> &mut Self {
450        self.instruction.reward_vault = Some(reward_vault);
451        self
452    }
453    #[inline(always)]
454    pub fn token_program(
455        &mut self,
456        token_program: &'b solana_account_info::AccountInfo<'a>,
457    ) -> &mut Self {
458        self.instruction.token_program = Some(token_program);
459        self
460    }
461    #[inline(always)]
462    pub fn system_program(
463        &mut self,
464        system_program: &'b solana_account_info::AccountInfo<'a>,
465    ) -> &mut Self {
466        self.instruction.system_program = Some(system_program);
467        self
468    }
469    #[inline(always)]
470    pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
471        self.instruction.rent = Some(rent);
472        self
473    }
474    #[inline(always)]
475    pub fn reward_index(&mut self, reward_index: u8) -> &mut Self {
476        self.instruction.reward_index = Some(reward_index);
477        self
478    }
479    /// Add an additional account to the instruction.
480    #[inline(always)]
481    pub fn add_remaining_account(
482        &mut self,
483        account: &'b solana_account_info::AccountInfo<'a>,
484        is_writable: bool,
485        is_signer: bool,
486    ) -> &mut Self {
487        self.instruction
488            .__remaining_accounts
489            .push((account, is_writable, is_signer));
490        self
491    }
492    /// Add additional accounts to the instruction.
493    ///
494    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
495    /// and a `bool` indicating whether the account is a signer or not.
496    #[inline(always)]
497    pub fn add_remaining_accounts(
498        &mut self,
499        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
500    ) -> &mut Self {
501        self.instruction
502            .__remaining_accounts
503            .extend_from_slice(accounts);
504        self
505    }
506    #[inline(always)]
507    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
508        self.invoke_signed(&[])
509    }
510    #[allow(clippy::clone_on_copy)]
511    #[allow(clippy::vec_init_then_push)]
512    pub fn invoke_signed(
513        &self,
514        signers_seeds: &[&[&[u8]]],
515    ) -> solana_program_entrypoint::ProgramResult {
516        let args = InitializeRewardInstructionArgs {
517            reward_index: self
518                .instruction
519                .reward_index
520                .clone()
521                .expect("reward_index is not set"),
522        };
523        let instruction = InitializeRewardCpi {
524            __program: self.instruction.__program,
525
526            reward_authority: self
527                .instruction
528                .reward_authority
529                .expect("reward_authority is not set"),
530
531            funder: self.instruction.funder.expect("funder is not set"),
532
533            whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
534
535            reward_mint: self
536                .instruction
537                .reward_mint
538                .expect("reward_mint is not set"),
539
540            reward_vault: self
541                .instruction
542                .reward_vault
543                .expect("reward_vault is not set"),
544
545            token_program: self
546                .instruction
547                .token_program
548                .expect("token_program is not set"),
549
550            system_program: self
551                .instruction
552                .system_program
553                .expect("system_program is not set"),
554
555            rent: self.instruction.rent.expect("rent is not set"),
556            __args: args,
557        };
558        instruction.invoke_signed_with_remaining_accounts(
559            signers_seeds,
560            &self.instruction.__remaining_accounts,
561        )
562    }
563}
564
565#[derive(Clone, Debug)]
566struct InitializeRewardCpiBuilderInstruction<'a, 'b> {
567    __program: &'b solana_account_info::AccountInfo<'a>,
568    reward_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
569    funder: Option<&'b solana_account_info::AccountInfo<'a>>,
570    whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
571    reward_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
572    reward_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
573    token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
574    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
575    rent: Option<&'b solana_account_info::AccountInfo<'a>>,
576    reward_index: Option<u8>,
577    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
578    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
579}