Skip to main content

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