Skip to main content

riptide_amm/generated/instructions/
market_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
7use crate::generated::types::MarketUpdateType;
8use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const MARKET_UPDATE_DISCRIMINATOR: u8 = 9;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct MarketUpdate {
15    /// The authority
16    pub authority: solana_pubkey::Pubkey,
17    /// The market
18    pub market: solana_pubkey::Pubkey,
19    /// The system program
20    pub system_program: solana_pubkey::Pubkey,
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)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62pub struct MarketUpdateInstructionData {
63    discriminator: u8,
64}
65
66impl MarketUpdateInstructionData {
67    pub fn new() -> Self {
68        Self { discriminator: 9 }
69    }
70
71    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
72        borsh::to_vec(self)
73    }
74}
75
76impl Default for MarketUpdateInstructionData {
77    fn default() -> Self {
78        Self::new()
79    }
80}
81
82#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
83#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
84pub struct MarketUpdateInstructionArgs {
85    pub update: MarketUpdateType,
86}
87
88impl MarketUpdateInstructionArgs {
89    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
90        borsh::to_vec(self)
91    }
92}
93
94/// Instruction builder for `MarketUpdate`.
95///
96/// ### Accounts:
97///
98///   0. `[signer]` authority
99///   1. `[writable]` market
100///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
101#[derive(Clone, Debug, Default)]
102pub struct MarketUpdateBuilder {
103    authority: Option<solana_pubkey::Pubkey>,
104    market: Option<solana_pubkey::Pubkey>,
105    system_program: Option<solana_pubkey::Pubkey>,
106    update: Option<MarketUpdateType>,
107    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
108}
109
110impl MarketUpdateBuilder {
111    pub fn new() -> Self {
112        Self::default()
113    }
114    /// The authority
115    #[inline(always)]
116    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
117        self.authority = Some(authority);
118        self
119    }
120    /// The market
121    #[inline(always)]
122    pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
123        self.market = Some(market);
124        self
125    }
126    /// `[optional account, default to '11111111111111111111111111111111']`
127    /// The system program
128    #[inline(always)]
129    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
130        self.system_program = Some(system_program);
131        self
132    }
133    #[inline(always)]
134    pub fn update(&mut self, update: MarketUpdateType) -> &mut Self {
135        self.update = Some(update);
136        self
137    }
138    /// Add an additional account to the instruction.
139    #[inline(always)]
140    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
141        self.__remaining_accounts.push(account);
142        self
143    }
144    /// Add additional accounts to the instruction.
145    #[inline(always)]
146    pub fn add_remaining_accounts(
147        &mut self,
148        accounts: &[solana_instruction::AccountMeta],
149    ) -> &mut Self {
150        self.__remaining_accounts.extend_from_slice(accounts);
151        self
152    }
153    #[allow(clippy::clone_on_copy)]
154    pub fn instruction(&self) -> solana_instruction::Instruction {
155        let accounts = MarketUpdate {
156            authority: self.authority.expect("authority is not set"),
157            market: self.market.expect("market is not set"),
158            system_program: self
159                .system_program
160                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
161        };
162        let args = MarketUpdateInstructionArgs {
163            update: self.update.clone().expect("update is not set"),
164        };
165
166        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
167    }
168}
169
170/// `market_update` CPI accounts.
171pub struct MarketUpdateCpiAccounts<'a, 'b> {
172    /// The authority
173    pub authority: &'b solana_account_info::AccountInfo<'a>,
174    /// The market
175    pub market: &'b solana_account_info::AccountInfo<'a>,
176    /// The system program
177    pub system_program: &'b solana_account_info::AccountInfo<'a>,
178}
179
180/// `market_update` CPI instruction.
181pub struct MarketUpdateCpi<'a, 'b> {
182    /// The program to invoke.
183    pub __program: &'b solana_account_info::AccountInfo<'a>,
184    /// The authority
185    pub authority: &'b solana_account_info::AccountInfo<'a>,
186    /// The market
187    pub market: &'b solana_account_info::AccountInfo<'a>,
188    /// The system program
189    pub system_program: &'b solana_account_info::AccountInfo<'a>,
190    /// The arguments for the instruction.
191    pub __args: MarketUpdateInstructionArgs,
192}
193
194impl<'a, 'b> MarketUpdateCpi<'a, 'b> {
195    pub fn new(
196        program: &'b solana_account_info::AccountInfo<'a>,
197        accounts: MarketUpdateCpiAccounts<'a, 'b>,
198        args: MarketUpdateInstructionArgs,
199    ) -> Self {
200        Self {
201            __program: program,
202            authority: accounts.authority,
203            market: accounts.market,
204            system_program: accounts.system_program,
205            __args: args,
206        }
207    }
208    #[inline(always)]
209    pub fn invoke(&self) -> solana_program_error::ProgramResult {
210        self.invoke_signed_with_remaining_accounts(&[], &[])
211    }
212    #[inline(always)]
213    pub fn invoke_with_remaining_accounts(
214        &self,
215        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
216    ) -> solana_program_error::ProgramResult {
217        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
218    }
219    #[inline(always)]
220    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
221        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
222    }
223    #[allow(clippy::arithmetic_side_effects)]
224    #[allow(clippy::clone_on_copy)]
225    #[allow(clippy::vec_init_then_push)]
226    pub fn invoke_signed_with_remaining_accounts(
227        &self,
228        signers_seeds: &[&[&[u8]]],
229        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
230    ) -> solana_program_error::ProgramResult {
231        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
232        accounts.push(solana_instruction::AccountMeta::new_readonly(
233            *self.authority.key,
234            true,
235        ));
236        accounts.push(solana_instruction::AccountMeta::new(
237            *self.market.key,
238            false,
239        ));
240        accounts.push(solana_instruction::AccountMeta::new_readonly(
241            *self.system_program.key,
242            false,
243        ));
244        remaining_accounts.iter().for_each(|remaining_account| {
245            accounts.push(solana_instruction::AccountMeta {
246                pubkey: *remaining_account.0.key,
247                is_signer: remaining_account.1,
248                is_writable: remaining_account.2,
249            })
250        });
251        let mut data = MarketUpdateInstructionData::new().try_to_vec().unwrap();
252        let mut args = self.__args.try_to_vec().unwrap();
253        data.append(&mut args);
254
255        let instruction = solana_instruction::Instruction {
256            program_id: crate::RIPTIDE_ID,
257            accounts,
258            data,
259        };
260        let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
261        account_infos.push(self.__program.clone());
262        account_infos.push(self.authority.clone());
263        account_infos.push(self.market.clone());
264        account_infos.push(self.system_program.clone());
265        remaining_accounts
266            .iter()
267            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
268
269        if signers_seeds.is_empty() {
270            solana_cpi::invoke(&instruction, &account_infos)
271        } else {
272            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
273        }
274    }
275}
276
277/// Instruction builder for `MarketUpdate` via CPI.
278///
279/// ### Accounts:
280///
281///   0. `[signer]` authority
282///   1. `[writable]` market
283///   2. `[]` system_program
284#[derive(Clone, Debug)]
285pub struct MarketUpdateCpiBuilder<'a, 'b> {
286    instruction: Box<MarketUpdateCpiBuilderInstruction<'a, 'b>>,
287}
288
289impl<'a, 'b> MarketUpdateCpiBuilder<'a, 'b> {
290    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
291        let instruction = Box::new(MarketUpdateCpiBuilderInstruction {
292            __program: program,
293            authority: None,
294            market: None,
295            system_program: None,
296            update: None,
297            __remaining_accounts: Vec::new(),
298        });
299        Self { instruction }
300    }
301    /// The authority
302    #[inline(always)]
303    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
304        self.instruction.authority = Some(authority);
305        self
306    }
307    /// The market
308    #[inline(always)]
309    pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
310        self.instruction.market = Some(market);
311        self
312    }
313    /// The system program
314    #[inline(always)]
315    pub fn system_program(
316        &mut self,
317        system_program: &'b solana_account_info::AccountInfo<'a>,
318    ) -> &mut Self {
319        self.instruction.system_program = Some(system_program);
320        self
321    }
322    #[inline(always)]
323    pub fn update(&mut self, update: MarketUpdateType) -> &mut Self {
324        self.instruction.update = Some(update);
325        self
326    }
327    /// Add an additional account to the instruction.
328    #[inline(always)]
329    pub fn add_remaining_account(
330        &mut self,
331        account: &'b solana_account_info::AccountInfo<'a>,
332        is_writable: bool,
333        is_signer: bool,
334    ) -> &mut Self {
335        self.instruction
336            .__remaining_accounts
337            .push((account, is_writable, is_signer));
338        self
339    }
340    /// Add additional accounts to the instruction.
341    ///
342    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the
343    /// account is writable or not, and a `bool` indicating whether the account is a signer or
344    /// not.
345    #[inline(always)]
346    pub fn add_remaining_accounts(
347        &mut self,
348        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
349    ) -> &mut Self {
350        self.instruction
351            .__remaining_accounts
352            .extend_from_slice(accounts);
353        self
354    }
355    #[inline(always)]
356    pub fn invoke(&self) -> solana_program_error::ProgramResult {
357        self.invoke_signed(&[])
358    }
359    #[allow(clippy::clone_on_copy)]
360    #[allow(clippy::vec_init_then_push)]
361    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
362        let args = MarketUpdateInstructionArgs {
363            update: self.instruction.update.clone().expect("update is not set"),
364        };
365        let instruction = MarketUpdateCpi {
366            __program: self.instruction.__program,
367
368            authority: self.instruction.authority.expect("authority is not set"),
369
370            market: self.instruction.market.expect("market is not set"),
371
372            system_program: self
373                .instruction
374                .system_program
375                .expect("system_program is not set"),
376            __args: args,
377        };
378        instruction.invoke_signed_with_remaining_accounts(
379            signers_seeds,
380            &self.instruction.__remaining_accounts,
381        )
382    }
383}
384
385#[derive(Clone, Debug)]
386struct MarketUpdateCpiBuilderInstruction<'a, 'b> {
387    __program: &'b solana_account_info::AccountInfo<'a>,
388    authority: Option<&'b solana_account_info::AccountInfo<'a>>,
389    market: Option<&'b solana_account_info::AccountInfo<'a>>,
390    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
391    update: Option<MarketUpdateType>,
392    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
393    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
394}