sbod_itf/accounts.rs
1use anchor_lang::prelude::*;
2
3pub const PRECISION: i32 = 18;
4
5#[derive(Debug)]
6#[zero_copy]
7pub struct CurrentResult {
8 /// The median value of the submissions needed for quorom size
9 pub value: i128,
10 /// The standard deviation of the submissions needed for quorom size
11 pub std_dev: i128,
12 /// The mean of the submissions needed for quorom size
13 pub mean: i128,
14 /// The range of the submissions needed for quorom size
15 pub range: i128,
16 /// The minimum value of the submissions needed for quorom size
17 pub min_value: i128,
18 /// The maximum value of the submissions needed for quorom size
19 pub max_value: i128,
20 /// The number of samples used to calculate this result
21 pub num_samples: u8,
22 pub padding1: [u8; 7],
23 /// The slot at which this value was signed.
24 pub slot: u64,
25 /// The slot at which the first considered submission was made
26 pub min_slot: u64,
27 /// The slot at which the last considered submission was made
28 pub max_slot: u64,
29}
30
31impl CurrentResult {
32 /// The median value of the submissions needed for quorom size
33 pub fn value(&self) -> Option<(i128, i32)> {
34 if self.slot == 0 {
35 return None;
36 }
37 //Some(Decimal::from_i128_with_scale(self.value, PRECISION))
38 return Some((self.value, PRECISION));
39 }
40}
41
42#[derive(Debug)]
43#[zero_copy]
44pub struct OracleSubmission {
45 /// The public key of the oracle that submitted this value.
46 pub oracle: Pubkey,
47 /// The slot at which this value was signed.
48 pub slot: u64,
49 padding1: [u8; 8],
50 /// The value that was submitted.
51 pub value: i128,
52}
53
54static_assertions::const_assert_eq!(3200, std::mem::size_of::<PullFeedAccountData>());
55
56/// A representation of the data in a pull feed account.
57#[derive(Debug)]
58#[account(zero_copy)]
59pub struct PullFeedAccountData {
60 /// The oracle submissions for this feed.
61 pub submissions: [OracleSubmission; 32],
62 /// The public key of the authority that can update the feed hash that
63 /// this account will use for registering updates.
64 pub authority: Pubkey,
65 /// The public key of the queue which oracles must be bound to in order to
66 /// submit data to this feed.
67 pub queue: Pubkey,
68 /// SHA-256 hash of the job schema oracles will execute to produce data
69 /// for this feed.
70 pub feed_hash: [u8; 32],
71 /// The slot at which this account was initialized.
72 pub initialized_at: i64,
73 pub permissions: u64,
74 pub max_variance: u64,
75 pub min_responses: u32,
76 pub name: [u8; 32],
77 padding1: [u8; 2],
78 pub historical_result_idx: u8,
79 pub min_sample_size: u8,
80 pub last_update_timestamp: i64,
81 pub lut_slot: u64,
82 _reserved1: [u8; 32],
83 pub result: CurrentResult,
84 pub max_staleness: u32,
85 padding2: [u8; 12],
86 pub historical_results: [CompactResult; 32],
87 _ebuf4: [u8; 8],
88 _ebuf3: [u8; 24],
89 _ebuf2: [u8; 256],
90}
91
92// lifted from IDL
93pub const PULL_FEED_ACCOUNT_DISCRIMINATOR: [u8; 8] = [196, 27, 108, 196, 10, 215, 219, 40];
94
95#[derive(Debug)]
96#[zero_copy]
97pub struct CompactResult {
98 /// The standard deviation of the submissions needed for quorom size
99 pub std_dev: f32,
100 /// The mean of the submissions needed for quorom size
101 pub mean: f32,
102 /// The slot at which this value was signed.
103 pub slot: u64,
104}