pyth_solana_receiver_sdk/
config.rs

1use {anchor_lang::prelude::*, solana_program::pubkey::Pubkey};
2
3#[account]
4#[derive(Debug, PartialEq)]
5pub struct Config {
6    pub governance_authority: Pubkey, // This authority can update the other fields
7    pub target_governance_authority: Option<Pubkey>, // This field is used for a two-step governance authority transfer
8    pub wormhole: Pubkey,                            // The address of the wormhole receiver
9    pub valid_data_sources: Vec<DataSource>, // The list of valid data sources for oracle price updates
10    pub single_update_fee_in_lamports: u64,  // The fee in lamports for a single price update
11    pub minimum_signatures: u8, // The minimum number of signatures required to accept a VAA
12}
13
14#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Debug)]
15pub struct DataSource {
16    pub chain: u16,
17    pub emitter: Pubkey,
18}
19
20impl Config {
21    pub const LEN: usize = 370; // This is two times the current size of a Config account with 2 data sources, to leave space for more fields
22}
23
24#[cfg(test)]
25pub mod tests {
26    use {
27        super::DataSource,
28        crate::config::Config,
29        anchor_lang::{AnchorSerialize, Discriminator},
30        solana_program::pubkey::Pubkey,
31    };
32
33    #[test]
34    fn check_size() {
35        let test_config = Config {
36            governance_authority: Pubkey::new_unique(),
37            target_governance_authority: Some(Pubkey::new_unique()),
38            wormhole: Pubkey::new_unique(),
39            valid_data_sources: vec![
40                DataSource {
41                    chain: 1,
42                    emitter: Pubkey::new_unique(),
43                },
44                DataSource {
45                    chain: 2,
46                    emitter: Pubkey::new_unique(),
47                },
48            ],
49            single_update_fee_in_lamports: 0,
50            minimum_signatures: 0,
51        };
52
53        assert_eq!(
54            test_config.try_to_vec().unwrap().len(),
55            32 + 1 + 32 + 32 + 4 + 1 + 33 + 1 + 33 + 8 + 1
56        );
57        assert!(
58            Config::discriminator().len() + test_config.try_to_vec().unwrap().len() <= Config::LEN
59        );
60    }
61}