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
//! Program instruction processor for end-to-end testing and instruction counts

use borsh::BorshDeserialize;
use solana_program::{
  account_info::AccountInfo,
  entrypoint::ProgramResult,
  pubkey::Pubkey,
};

use crate::{
  instruction::PythClientInstruction,
};

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(())
    }
  }
}