riptide_amm/generated/instructions/
program_version.rs1use borsh::{BorshDeserialize, BorshSerialize};
8
9pub const PROGRAM_VERSION_DISCRIMINATOR: u8 = 0;
10
11#[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)]
38#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
39pub struct ProgramVersionInstructionData {
40 discriminator: u8,
41}
42
43impl ProgramVersionInstructionData {
44 pub fn new() -> Self {
45 Self { discriminator: 0 }
46 }
47
48 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
49 borsh::to_vec(self)
50 }
51}
52
53impl Default for ProgramVersionInstructionData {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59#[derive(Clone, Debug, Default)]
63pub struct ProgramVersionBuilder {
64 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
65}
66
67impl ProgramVersionBuilder {
68 pub fn new() -> Self {
69 Self::default()
70 }
71 #[inline(always)]
73 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
74 self.__remaining_accounts.push(account);
75 self
76 }
77 #[inline(always)]
79 pub fn add_remaining_accounts(
80 &mut self,
81 accounts: &[solana_instruction::AccountMeta],
82 ) -> &mut Self {
83 self.__remaining_accounts.extend_from_slice(accounts);
84 self
85 }
86 #[allow(clippy::clone_on_copy)]
87 pub fn instruction(&self) -> solana_instruction::Instruction {
88 let accounts = ProgramVersion {};
89
90 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
91 }
92}
93
94pub struct ProgramVersionCpi<'a, 'b> {
96 pub __program: &'b solana_account_info::AccountInfo<'a>,
98}
99
100impl<'a, 'b> ProgramVersionCpi<'a, 'b> {
101 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
102 Self { __program: program }
103 }
104 #[inline(always)]
105 pub fn invoke(&self) -> solana_program_error::ProgramResult {
106 self.invoke_signed_with_remaining_accounts(&[], &[])
107 }
108 #[inline(always)]
109 pub fn invoke_with_remaining_accounts(
110 &self,
111 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
112 ) -> solana_program_error::ProgramResult {
113 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
114 }
115 #[inline(always)]
116 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
117 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
118 }
119 #[allow(clippy::arithmetic_side_effects)]
120 #[allow(clippy::clone_on_copy)]
121 #[allow(clippy::vec_init_then_push)]
122 pub fn invoke_signed_with_remaining_accounts(
123 &self,
124 signers_seeds: &[&[&[u8]]],
125 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
126 ) -> solana_program_error::ProgramResult {
127 let mut accounts = Vec::with_capacity(remaining_accounts.len());
128 remaining_accounts.iter().for_each(|remaining_account| {
129 accounts.push(solana_instruction::AccountMeta {
130 pubkey: *remaining_account.0.key,
131 is_signer: remaining_account.1,
132 is_writable: remaining_account.2,
133 })
134 });
135 let data = ProgramVersionInstructionData::new().try_to_vec().unwrap();
136
137 let instruction = solana_instruction::Instruction {
138 program_id: crate::RIPTIDE_ID,
139 accounts,
140 data,
141 };
142 let mut account_infos = Vec::with_capacity(1 + remaining_accounts.len());
143 account_infos.push(self.__program.clone());
144 remaining_accounts
145 .iter()
146 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
147
148 if signers_seeds.is_empty() {
149 solana_cpi::invoke(&instruction, &account_infos)
150 } else {
151 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
152 }
153 }
154}
155
156#[derive(Clone, Debug)]
160pub struct ProgramVersionCpiBuilder<'a, 'b> {
161 instruction: Box<ProgramVersionCpiBuilderInstruction<'a, 'b>>,
162}
163
164impl<'a, 'b> ProgramVersionCpiBuilder<'a, 'b> {
165 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
166 let instruction = Box::new(ProgramVersionCpiBuilderInstruction {
167 __program: program,
168 __remaining_accounts: Vec::new(),
169 });
170 Self { instruction }
171 }
172 #[inline(always)]
174 pub fn add_remaining_account(
175 &mut self,
176 account: &'b solana_account_info::AccountInfo<'a>,
177 is_writable: bool,
178 is_signer: bool,
179 ) -> &mut Self {
180 self.instruction
181 .__remaining_accounts
182 .push((account, is_writable, is_signer));
183 self
184 }
185 #[inline(always)]
191 pub fn add_remaining_accounts(
192 &mut self,
193 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
194 ) -> &mut Self {
195 self.instruction
196 .__remaining_accounts
197 .extend_from_slice(accounts);
198 self
199 }
200 #[inline(always)]
201 pub fn invoke(&self) -> solana_program_error::ProgramResult {
202 self.invoke_signed(&[])
203 }
204 #[allow(clippy::clone_on_copy)]
205 #[allow(clippy::vec_init_then_push)]
206 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
207 let instruction = ProgramVersionCpi {
208 __program: self.instruction.__program,
209 };
210 instruction.invoke_signed_with_remaining_accounts(
211 signers_seeds,
212 &self.instruction.__remaining_accounts,
213 )
214 }
215}
216
217#[derive(Clone, Debug)]
218struct ProgramVersionCpiBuilderInstruction<'a, 'b> {
219 __program: &'b solana_account_info::AccountInfo<'a>,
220 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
222}