pyth_solana_receiver_sdk_legacy/
config.rs

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