riptide_amm/generated/instructions/
market_update.rs1use crate::generated::types::MarketUpdateType;
8use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const MARKET_UPDATE_DISCRIMINATOR: u8 = 9;
11
12#[derive(Debug)]
14pub struct MarketUpdate {
15 pub authority: solana_address::Address,
17 pub market: solana_address::Address,
19 pub system_program: solana_address::Address,
21}
22
23impl MarketUpdate {
24 pub fn instruction(
25 &self,
26 args: MarketUpdateInstructionArgs,
27 ) -> solana_instruction::Instruction {
28 self.instruction_with_remaining_accounts(args, &[])
29 }
30 #[allow(clippy::arithmetic_side_effects)]
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(
33 &self,
34 args: MarketUpdateInstructionArgs,
35 remaining_accounts: &[solana_instruction::AccountMeta],
36 ) -> solana_instruction::Instruction {
37 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
38 accounts.push(solana_instruction::AccountMeta::new_readonly(
39 self.authority,
40 true,
41 ));
42 accounts.push(solana_instruction::AccountMeta::new(self.market, false));
43 accounts.push(solana_instruction::AccountMeta::new_readonly(
44 self.system_program,
45 false,
46 ));
47 accounts.extend_from_slice(remaining_accounts);
48 let mut data = MarketUpdateInstructionData::new().try_to_vec().unwrap();
49 let mut args = args.try_to_vec().unwrap();
50 data.append(&mut args);
51
52 solana_instruction::Instruction {
53 program_id: crate::RIPTIDE_ID,
54 accounts,
55 data,
56 }
57 }
58}
59
60#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
61pub struct MarketUpdateInstructionData {
62 discriminator: u8,
63}
64
65impl MarketUpdateInstructionData {
66 pub fn new() -> Self {
67 Self { discriminator: 9 }
68 }
69
70 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
71 borsh::to_vec(self)
72 }
73}
74
75impl Default for MarketUpdateInstructionData {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
82pub struct MarketUpdateInstructionArgs {
83 pub update: MarketUpdateType,
84}
85
86impl MarketUpdateInstructionArgs {
87 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
88 borsh::to_vec(self)
89 }
90}
91
92#[derive(Clone, Debug, Default)]
100pub struct MarketUpdateBuilder {
101 authority: Option<solana_address::Address>,
102 market: Option<solana_address::Address>,
103 system_program: Option<solana_address::Address>,
104 update: Option<MarketUpdateType>,
105 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
106}
107
108impl MarketUpdateBuilder {
109 pub fn new() -> Self {
110 Self::default()
111 }
112 #[inline(always)]
114 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
115 self.authority = Some(authority);
116 self
117 }
118 #[inline(always)]
120 pub fn market(&mut self, market: solana_address::Address) -> &mut Self {
121 self.market = Some(market);
122 self
123 }
124 #[inline(always)]
127 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
128 self.system_program = Some(system_program);
129 self
130 }
131 #[inline(always)]
132 pub fn update(&mut self, update: MarketUpdateType) -> &mut Self {
133 self.update = Some(update);
134 self
135 }
136 #[inline(always)]
138 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
139 self.__remaining_accounts.push(account);
140 self
141 }
142 #[inline(always)]
144 pub fn add_remaining_accounts(
145 &mut self,
146 accounts: &[solana_instruction::AccountMeta],
147 ) -> &mut Self {
148 self.__remaining_accounts.extend_from_slice(accounts);
149 self
150 }
151 #[allow(clippy::clone_on_copy)]
152 pub fn instruction(&self) -> solana_instruction::Instruction {
153 let accounts = MarketUpdate {
154 authority: self.authority.expect("authority is not set"),
155 market: self.market.expect("market is not set"),
156 system_program: self
157 .system_program
158 .unwrap_or(solana_address::address!("11111111111111111111111111111111")),
159 };
160 let args = MarketUpdateInstructionArgs {
161 update: self.update.clone().expect("update is not set"),
162 };
163
164 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
165 }
166}
167
168pub struct MarketUpdateCpiAccounts<'a, 'b> {
170 pub authority: &'b solana_account_info::AccountInfo<'a>,
172 pub market: &'b solana_account_info::AccountInfo<'a>,
174 pub system_program: &'b solana_account_info::AccountInfo<'a>,
176}
177
178pub struct MarketUpdateCpi<'a, 'b> {
180 pub __program: &'b solana_account_info::AccountInfo<'a>,
182 pub authority: &'b solana_account_info::AccountInfo<'a>,
184 pub market: &'b solana_account_info::AccountInfo<'a>,
186 pub system_program: &'b solana_account_info::AccountInfo<'a>,
188 pub __args: MarketUpdateInstructionArgs,
190}
191
192impl<'a, 'b> MarketUpdateCpi<'a, 'b> {
193 pub fn new(
194 program: &'b solana_account_info::AccountInfo<'a>,
195 accounts: MarketUpdateCpiAccounts<'a, 'b>,
196 args: MarketUpdateInstructionArgs,
197 ) -> Self {
198 Self {
199 __program: program,
200 authority: accounts.authority,
201 market: accounts.market,
202 system_program: accounts.system_program,
203 __args: args,
204 }
205 }
206 #[inline(always)]
207 pub fn invoke(&self) -> solana_program_error::ProgramResult {
208 self.invoke_signed_with_remaining_accounts(&[], &[])
209 }
210 #[inline(always)]
211 pub fn invoke_with_remaining_accounts(
212 &self,
213 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
214 ) -> solana_program_error::ProgramResult {
215 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
216 }
217 #[inline(always)]
218 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
219 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
220 }
221 #[allow(clippy::arithmetic_side_effects)]
222 #[allow(clippy::clone_on_copy)]
223 #[allow(clippy::vec_init_then_push)]
224 pub fn invoke_signed_with_remaining_accounts(
225 &self,
226 signers_seeds: &[&[&[u8]]],
227 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
228 ) -> solana_program_error::ProgramResult {
229 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
230 accounts.push(solana_instruction::AccountMeta::new_readonly(
231 *self.authority.key,
232 true,
233 ));
234 accounts.push(solana_instruction::AccountMeta::new(
235 *self.market.key,
236 false,
237 ));
238 accounts.push(solana_instruction::AccountMeta::new_readonly(
239 *self.system_program.key,
240 false,
241 ));
242 remaining_accounts.iter().for_each(|remaining_account| {
243 accounts.push(solana_instruction::AccountMeta {
244 pubkey: *remaining_account.0.key,
245 is_signer: remaining_account.1,
246 is_writable: remaining_account.2,
247 })
248 });
249 let mut data = MarketUpdateInstructionData::new().try_to_vec().unwrap();
250 let mut args = self.__args.try_to_vec().unwrap();
251 data.append(&mut args);
252
253 let instruction = solana_instruction::Instruction {
254 program_id: crate::RIPTIDE_ID,
255 accounts,
256 data,
257 };
258 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
259 account_infos.push(self.__program.clone());
260 account_infos.push(self.authority.clone());
261 account_infos.push(self.market.clone());
262 account_infos.push(self.system_program.clone());
263 remaining_accounts
264 .iter()
265 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
266
267 if signers_seeds.is_empty() {
268 solana_cpi::invoke(&instruction, &account_infos)
269 } else {
270 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
271 }
272 }
273}
274
275#[derive(Clone, Debug)]
283pub struct MarketUpdateCpiBuilder<'a, 'b> {
284 instruction: Box<MarketUpdateCpiBuilderInstruction<'a, 'b>>,
285}
286
287impl<'a, 'b> MarketUpdateCpiBuilder<'a, 'b> {
288 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
289 let instruction = Box::new(MarketUpdateCpiBuilderInstruction {
290 __program: program,
291 authority: None,
292 market: None,
293 system_program: None,
294 update: None,
295 __remaining_accounts: Vec::new(),
296 });
297 Self { instruction }
298 }
299 #[inline(always)]
301 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
302 self.instruction.authority = Some(authority);
303 self
304 }
305 #[inline(always)]
307 pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
308 self.instruction.market = Some(market);
309 self
310 }
311 #[inline(always)]
313 pub fn system_program(
314 &mut self,
315 system_program: &'b solana_account_info::AccountInfo<'a>,
316 ) -> &mut Self {
317 self.instruction.system_program = Some(system_program);
318 self
319 }
320 #[inline(always)]
321 pub fn update(&mut self, update: MarketUpdateType) -> &mut Self {
322 self.instruction.update = Some(update);
323 self
324 }
325 #[inline(always)]
327 pub fn add_remaining_account(
328 &mut self,
329 account: &'b solana_account_info::AccountInfo<'a>,
330 is_writable: bool,
331 is_signer: bool,
332 ) -> &mut Self {
333 self.instruction
334 .__remaining_accounts
335 .push((account, is_writable, is_signer));
336 self
337 }
338 #[inline(always)]
344 pub fn add_remaining_accounts(
345 &mut self,
346 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
347 ) -> &mut Self {
348 self.instruction
349 .__remaining_accounts
350 .extend_from_slice(accounts);
351 self
352 }
353 #[inline(always)]
354 pub fn invoke(&self) -> solana_program_error::ProgramResult {
355 self.invoke_signed(&[])
356 }
357 #[allow(clippy::clone_on_copy)]
358 #[allow(clippy::vec_init_then_push)]
359 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
360 let args = MarketUpdateInstructionArgs {
361 update: self.instruction.update.clone().expect("update is not set"),
362 };
363 let instruction = MarketUpdateCpi {
364 __program: self.instruction.__program,
365
366 authority: self.instruction.authority.expect("authority is not set"),
367
368 market: self.instruction.market.expect("market is not set"),
369
370 system_program: self
371 .instruction
372 .system_program
373 .expect("system_program is not set"),
374 __args: args,
375 };
376 instruction.invoke_signed_with_remaining_accounts(
377 signers_seeds,
378 &self.instruction.__remaining_accounts,
379 )
380 }
381}
382
383#[derive(Clone, Debug)]
384struct MarketUpdateCpiBuilderInstruction<'a, 'b> {
385 __program: &'b solana_account_info::AccountInfo<'a>,
386 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
387 market: Option<&'b solana_account_info::AccountInfo<'a>>,
388 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
389 update: Option<MarketUpdateType>,
390 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
392}