1use borsh::BorshDeserialize;
4use solana_program::{
5 account_info::AccountInfo,
6 entrypoint::ProgramResult,
7 pubkey::Pubkey,
8 program_error::ProgramError
9};
10
11use crate::{
12 instruction::PythClientInstruction, load_price,
13};
14
15pub fn process_instruction(
16 _program_id: &Pubkey,
17 _accounts: &[AccountInfo],
18 input: &[u8],
19) -> ProgramResult {
20 let instruction = PythClientInstruction::try_from_slice(input).unwrap();
21 match instruction {
22 PythClientInstruction::Divide { numerator, denominator } => {
23 numerator.div(&denominator);
24 Ok(())
25 }
26 PythClientInstruction::Multiply { x, y } => {
27 x.mul(&y);
28 Ok(())
29 }
30 PythClientInstruction::Add { x, y } => {
31 x.add(&y);
32 Ok(())
33 }
34 PythClientInstruction::Normalize { x } => {
35 x.normalize();
36 Ok(())
37 }
38 PythClientInstruction::ScaleToExponent { x, expo } => {
39 x.scale_to_exponent(expo);
40 Ok(())
41 }
42 PythClientInstruction::Noop => {
43 Ok(())
44 }
45 PythClientInstruction::PriceStatusCheck { price_account_data, expected_price_status } => {
46 let price = load_price(&price_account_data[..])?;
47
48 if price.get_current_price_status() == expected_price_status {
49 Ok(())
50 } else {
51 Err(ProgramError::Custom(0))
52 }
53 }
54 }
55}