riptide_amm/generated/instructions/
oracle_update.rs1use borsh::{BorshDeserialize, BorshSerialize};
8
9pub const ORACLE_UPDATE_DISCRIMINATOR: u8 = 1;
10
11#[derive(Debug)]
13pub struct OracleUpdate {
14 pub market: solana_address::Address,
16 pub updater: solana_address::Address,
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)]
54pub struct OracleUpdateInstructionData {
55 discriminator: u8,
56}
57
58impl OracleUpdateInstructionData {
59 pub fn new() -> Self {
60 Self { discriminator: 1 }
61 }
62
63 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
64 borsh::to_vec(self)
65 }
66}
67
68impl Default for OracleUpdateInstructionData {
69 fn default() -> Self {
70 Self::new()
71 }
72}
73
74#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
75pub struct OracleUpdateInstructionArgs {
76 pub sequence: u64,
77 pub valid_until: u64,
78 pub data: [u8; 512],
79}
80
81impl OracleUpdateInstructionArgs {
82 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
83 borsh::to_vec(self)
84 }
85}
86
87#[derive(Clone, Debug, Default)]
94pub struct OracleUpdateBuilder {
95 market: Option<solana_address::Address>,
96 updater: Option<solana_address::Address>,
97 sequence: Option<u64>,
98 valid_until: Option<u64>,
99 data: Option<[u8; 512]>,
100 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
101}
102
103impl OracleUpdateBuilder {
104 pub fn new() -> Self {
105 Self::default()
106 }
107 #[inline(always)]
109 pub fn market(&mut self, market: solana_address::Address) -> &mut Self {
110 self.market = Some(market);
111 self
112 }
113 #[inline(always)]
115 pub fn updater(&mut self, updater: solana_address::Address) -> &mut Self {
116 self.updater = Some(updater);
117 self
118 }
119 #[inline(always)]
120 pub fn sequence(&mut self, sequence: u64) -> &mut Self {
121 self.sequence = Some(sequence);
122 self
123 }
124 #[inline(always)]
125 pub fn valid_until(&mut self, valid_until: u64) -> &mut Self {
126 self.valid_until = Some(valid_until);
127 self
128 }
129 #[inline(always)]
130 pub fn data(&mut self, data: [u8; 512]) -> &mut Self {
131 self.data = Some(data);
132 self
133 }
134 #[inline(always)]
136 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
137 self.__remaining_accounts.push(account);
138 self
139 }
140 #[inline(always)]
142 pub fn add_remaining_accounts(
143 &mut self,
144 accounts: &[solana_instruction::AccountMeta],
145 ) -> &mut Self {
146 self.__remaining_accounts.extend_from_slice(accounts);
147 self
148 }
149 #[allow(clippy::clone_on_copy)]
150 pub fn instruction(&self) -> solana_instruction::Instruction {
151 let accounts = OracleUpdate {
152 market: self.market.expect("market is not set"),
153 updater: self.updater.expect("updater is not set"),
154 };
155 let args = OracleUpdateInstructionArgs {
156 sequence: self.sequence.clone().expect("sequence is not set"),
157 valid_until: self.valid_until.clone().expect("valid_until is not set"),
158 data: self.data.clone().expect("data is not set"),
159 };
160
161 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
162 }
163}
164
165pub struct OracleUpdateCpiAccounts<'a, 'b> {
167 pub market: &'b solana_account_info::AccountInfo<'a>,
169 pub updater: &'b solana_account_info::AccountInfo<'a>,
171}
172
173pub struct OracleUpdateCpi<'a, 'b> {
175 pub __program: &'b solana_account_info::AccountInfo<'a>,
177 pub market: &'b solana_account_info::AccountInfo<'a>,
179 pub updater: &'b solana_account_info::AccountInfo<'a>,
181 pub __args: OracleUpdateInstructionArgs,
183}
184
185impl<'a, 'b> OracleUpdateCpi<'a, 'b> {
186 pub fn new(
187 program: &'b solana_account_info::AccountInfo<'a>,
188 accounts: OracleUpdateCpiAccounts<'a, 'b>,
189 args: OracleUpdateInstructionArgs,
190 ) -> Self {
191 Self {
192 __program: program,
193 market: accounts.market,
194 updater: accounts.updater,
195 __args: args,
196 }
197 }
198 #[inline(always)]
199 pub fn invoke(&self) -> solana_program_error::ProgramResult {
200 self.invoke_signed_with_remaining_accounts(&[], &[])
201 }
202 #[inline(always)]
203 pub fn invoke_with_remaining_accounts(
204 &self,
205 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
206 ) -> solana_program_error::ProgramResult {
207 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
208 }
209 #[inline(always)]
210 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
211 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
212 }
213 #[allow(clippy::arithmetic_side_effects)]
214 #[allow(clippy::clone_on_copy)]
215 #[allow(clippy::vec_init_then_push)]
216 pub fn invoke_signed_with_remaining_accounts(
217 &self,
218 signers_seeds: &[&[&[u8]]],
219 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
220 ) -> solana_program_error::ProgramResult {
221 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
222 accounts.push(solana_instruction::AccountMeta::new(
223 *self.market.key,
224 false,
225 ));
226 accounts.push(solana_instruction::AccountMeta::new_readonly(
227 *self.updater.key,
228 true,
229 ));
230 remaining_accounts.iter().for_each(|remaining_account| {
231 accounts.push(solana_instruction::AccountMeta {
232 pubkey: *remaining_account.0.key,
233 is_signer: remaining_account.1,
234 is_writable: remaining_account.2,
235 })
236 });
237 let mut data = OracleUpdateInstructionData::new().try_to_vec().unwrap();
238 let mut args = self.__args.try_to_vec().unwrap();
239 data.append(&mut args);
240
241 let instruction = solana_instruction::Instruction {
242 program_id: crate::RIPTIDE_ID,
243 accounts,
244 data,
245 };
246 let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
247 account_infos.push(self.__program.clone());
248 account_infos.push(self.market.clone());
249 account_infos.push(self.updater.clone());
250 remaining_accounts
251 .iter()
252 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
253
254 if signers_seeds.is_empty() {
255 solana_cpi::invoke(&instruction, &account_infos)
256 } else {
257 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
258 }
259 }
260}
261
262#[derive(Clone, Debug)]
269pub struct OracleUpdateCpiBuilder<'a, 'b> {
270 instruction: Box<OracleUpdateCpiBuilderInstruction<'a, 'b>>,
271}
272
273impl<'a, 'b> OracleUpdateCpiBuilder<'a, 'b> {
274 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
275 let instruction = Box::new(OracleUpdateCpiBuilderInstruction {
276 __program: program,
277 market: None,
278 updater: None,
279 sequence: None,
280 valid_until: None,
281 data: None,
282 __remaining_accounts: Vec::new(),
283 });
284 Self { instruction }
285 }
286 #[inline(always)]
288 pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
289 self.instruction.market = Some(market);
290 self
291 }
292 #[inline(always)]
294 pub fn updater(&mut self, updater: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
295 self.instruction.updater = Some(updater);
296 self
297 }
298 #[inline(always)]
299 pub fn sequence(&mut self, sequence: u64) -> &mut Self {
300 self.instruction.sequence = Some(sequence);
301 self
302 }
303 #[inline(always)]
304 pub fn valid_until(&mut self, valid_until: u64) -> &mut Self {
305 self.instruction.valid_until = Some(valid_until);
306 self
307 }
308 #[inline(always)]
309 pub fn data(&mut self, data: [u8; 512]) -> &mut Self {
310 self.instruction.data = Some(data);
311 self
312 }
313 #[inline(always)]
315 pub fn add_remaining_account(
316 &mut self,
317 account: &'b solana_account_info::AccountInfo<'a>,
318 is_writable: bool,
319 is_signer: bool,
320 ) -> &mut Self {
321 self.instruction
322 .__remaining_accounts
323 .push((account, is_writable, is_signer));
324 self
325 }
326 #[inline(always)]
332 pub fn add_remaining_accounts(
333 &mut self,
334 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
335 ) -> &mut Self {
336 self.instruction
337 .__remaining_accounts
338 .extend_from_slice(accounts);
339 self
340 }
341 #[inline(always)]
342 pub fn invoke(&self) -> solana_program_error::ProgramResult {
343 self.invoke_signed(&[])
344 }
345 #[allow(clippy::clone_on_copy)]
346 #[allow(clippy::vec_init_then_push)]
347 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
348 let args = OracleUpdateInstructionArgs {
349 sequence: self
350 .instruction
351 .sequence
352 .clone()
353 .expect("sequence is not set"),
354 valid_until: self
355 .instruction
356 .valid_until
357 .clone()
358 .expect("valid_until is not set"),
359 data: self.instruction.data.clone().expect("data is not set"),
360 };
361 let instruction = OracleUpdateCpi {
362 __program: self.instruction.__program,
363
364 market: self.instruction.market.expect("market is not set"),
365
366 updater: self.instruction.updater.expect("updater is not set"),
367 __args: args,
368 };
369 instruction.invoke_signed_with_remaining_accounts(
370 signers_seeds,
371 &self.instruction.__remaining_accounts,
372 )
373 }
374}
375
376#[derive(Clone, Debug)]
377struct OracleUpdateCpiBuilderInstruction<'a, 'b> {
378 __program: &'b solana_account_info::AccountInfo<'a>,
379 market: Option<&'b solana_account_info::AccountInfo<'a>>,
380 updater: Option<&'b solana_account_info::AccountInfo<'a>>,
381 sequence: Option<u64>,
382 valid_until: Option<u64>,
383 data: Option<[u8; 512]>,
384 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
386}