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