Skip to main content

riptide_amm/generated/instructions/
program_version.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
7use borsh::{BorshDeserialize, BorshSerialize};
8
9pub const PROGRAM_VERSION_DISCRIMINATOR: u8 = 0;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct ProgramVersion {}
14
15impl ProgramVersion {
16    pub fn instruction(&self) -> solana_instruction::Instruction {
17        self.instruction_with_remaining_accounts(&[])
18    }
19    #[allow(clippy::arithmetic_side_effects)]
20    #[allow(clippy::vec_init_then_push)]
21    pub fn instruction_with_remaining_accounts(
22        &self,
23        remaining_accounts: &[solana_instruction::AccountMeta],
24    ) -> solana_instruction::Instruction {
25        let mut accounts = Vec::with_capacity(remaining_accounts.len());
26        accounts.extend_from_slice(remaining_accounts);
27        let data = ProgramVersionInstructionData::new().try_to_vec().unwrap();
28
29        solana_instruction::Instruction {
30            program_id: crate::RIPTIDE_ID,
31            accounts,
32            data,
33        }
34    }
35}
36
37#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
38pub struct ProgramVersionInstructionData {
39    discriminator: u8,
40}
41
42impl ProgramVersionInstructionData {
43    pub fn new() -> Self {
44        Self { discriminator: 0 }
45    }
46
47    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
48        borsh::to_vec(self)
49    }
50}
51
52impl Default for ProgramVersionInstructionData {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58/// Instruction builder for `ProgramVersion`.
59///
60/// ### Accounts:
61#[derive(Clone, Debug, Default)]
62pub struct ProgramVersionBuilder {
63    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
64}
65
66impl ProgramVersionBuilder {
67    pub fn new() -> Self {
68        Self::default()
69    }
70    /// Add an additional account to the instruction.
71    #[inline(always)]
72    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
73        self.__remaining_accounts.push(account);
74        self
75    }
76    /// Add additional accounts to the instruction.
77    #[inline(always)]
78    pub fn add_remaining_accounts(
79        &mut self,
80        accounts: &[solana_instruction::AccountMeta],
81    ) -> &mut Self {
82        self.__remaining_accounts.extend_from_slice(accounts);
83        self
84    }
85    #[allow(clippy::clone_on_copy)]
86    pub fn instruction(&self) -> solana_instruction::Instruction {
87        let accounts = ProgramVersion {};
88
89        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
90    }
91}
92
93/// `program_version` CPI instruction.
94pub struct ProgramVersionCpi<'a, 'b> {
95    /// The program to invoke.
96    pub __program: &'b solana_account_info::AccountInfo<'a>,
97}
98
99impl<'a, 'b> ProgramVersionCpi<'a, 'b> {
100    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
101        Self { __program: program }
102    }
103    #[inline(always)]
104    pub fn invoke(&self) -> solana_program_error::ProgramResult {
105        self.invoke_signed_with_remaining_accounts(&[], &[])
106    }
107    #[inline(always)]
108    pub fn invoke_with_remaining_accounts(
109        &self,
110        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
111    ) -> solana_program_error::ProgramResult {
112        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
113    }
114    #[inline(always)]
115    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
116        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
117    }
118    #[allow(clippy::arithmetic_side_effects)]
119    #[allow(clippy::clone_on_copy)]
120    #[allow(clippy::vec_init_then_push)]
121    pub fn invoke_signed_with_remaining_accounts(
122        &self,
123        signers_seeds: &[&[&[u8]]],
124        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
125    ) -> solana_program_error::ProgramResult {
126        let mut accounts = Vec::with_capacity(remaining_accounts.len());
127        remaining_accounts.iter().for_each(|remaining_account| {
128            accounts.push(solana_instruction::AccountMeta {
129                pubkey: *remaining_account.0.key,
130                is_signer: remaining_account.1,
131                is_writable: remaining_account.2,
132            })
133        });
134        let data = ProgramVersionInstructionData::new().try_to_vec().unwrap();
135
136        let instruction = solana_instruction::Instruction {
137            program_id: crate::RIPTIDE_ID,
138            accounts,
139            data,
140        };
141        let mut account_infos = Vec::with_capacity(1 + remaining_accounts.len());
142        account_infos.push(self.__program.clone());
143        remaining_accounts
144            .iter()
145            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
146
147        if signers_seeds.is_empty() {
148            solana_cpi::invoke(&instruction, &account_infos)
149        } else {
150            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
151        }
152    }
153}
154
155/// Instruction builder for `ProgramVersion` via CPI.
156///
157/// ### Accounts:
158#[derive(Clone, Debug)]
159pub struct ProgramVersionCpiBuilder<'a, 'b> {
160    instruction: Box<ProgramVersionCpiBuilderInstruction<'a, 'b>>,
161}
162
163impl<'a, 'b> ProgramVersionCpiBuilder<'a, 'b> {
164    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
165        let instruction = Box::new(ProgramVersionCpiBuilderInstruction {
166            __program: program,
167            __remaining_accounts: Vec::new(),
168        });
169        Self { instruction }
170    }
171    /// Add an additional account to the instruction.
172    #[inline(always)]
173    pub fn add_remaining_account(
174        &mut self,
175        account: &'b solana_account_info::AccountInfo<'a>,
176        is_writable: bool,
177        is_signer: bool,
178    ) -> &mut Self {
179        self.instruction
180            .__remaining_accounts
181            .push((account, is_writable, is_signer));
182        self
183    }
184    /// Add additional accounts to the instruction.
185    ///
186    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the
187    /// account is writable or not, and a `bool` indicating whether the account is a signer or
188    /// not.
189    #[inline(always)]
190    pub fn add_remaining_accounts(
191        &mut self,
192        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
193    ) -> &mut Self {
194        self.instruction
195            .__remaining_accounts
196            .extend_from_slice(accounts);
197        self
198    }
199    #[inline(always)]
200    pub fn invoke(&self) -> solana_program_error::ProgramResult {
201        self.invoke_signed(&[])
202    }
203    #[allow(clippy::clone_on_copy)]
204    #[allow(clippy::vec_init_then_push)]
205    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
206        let instruction = ProgramVersionCpi {
207            __program: self.instruction.__program,
208        };
209        instruction.invoke_signed_with_remaining_accounts(
210            signers_seeds,
211            &self.instruction.__remaining_accounts,
212        )
213    }
214}
215
216#[derive(Clone, Debug)]
217struct ProgramVersionCpiBuilderInstruction<'a, 'b> {
218    __program: &'b solana_account_info::AccountInfo<'a>,
219    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
220    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
221}