pyth_solana_receiver_sdk/
config.rs

1use anchor_lang::prelude::*;
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::prelude::*
30    };
31
32    #[test]
33    fn check_size() {
34        let test_config = Config {
35            governance_authority: Pubkey::new_unique(),
36            target_governance_authority: Some(Pubkey::new_unique()),
37            wormhole: Pubkey::new_unique(),
38            valid_data_sources: vec![
39                DataSource {
40                    chain: 1,
41                    emitter: Pubkey::new_unique(),
42                },
43                DataSource {
44                    chain: 2,
45                    emitter: Pubkey::new_unique(),
46                },
47            ],
48            single_update_fee_in_lamports: 0,
49            minimum_signatures: 0,
50        };
51
52        assert_eq!(
53            test_config.try_to_vec().unwrap().len(),
54            32 + 1 + 32 + 32 + 4 + 1 + 33 + 1 + 33 + 8 + 1
55        );
56        assert!(
57            Config::DISCRIMINATOR.len() + test_config.try_to_vec().unwrap().len() <= Config::LEN
58        );
59    }
60}