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
use crate::*;

// TODO: Add a base_mint, base_wallet, and base_cost_per_byte to the program state for wrapped SOL costs. Then other fees can be in a custom mint.
// TODO: Add the ability to unwrap rewards to fund the hot wallet

/// Program global state for processing randomness requests.
#[account]
#[derive(Debug, InitSpace)]
pub struct State {
    /// The PDA bump.
    pub bump: u8,
    /// The program authority.
    pub authority: Pubkey,
    /// The token mint for the program reward.
    pub mint: Pubkey,
    /// The Switchboard Service responsible for responding to randomness requests
    pub switchboard_service: Pubkey,
    /// Token wallet used for rewards
    pub wallet: Pubkey,
    /// The cost for each randomness request.
    pub cost_per_byte: u64,
    /// The unix timestamp when the cost per byte was last updated.
    pub last_updated: i64,
    /// Reserved for future use.
    pub _ebuf: [u8; 512],
}
impl State {
    /// Returns the size of the function account data in bytes. Includes the discriminator.
    pub fn size() -> usize {
        8 + State::INIT_SPACE
    }

    pub fn request_cost(&self, num_bytes: u8, options: &TransactionOptions) -> u64 {
        10000u64 + (self.cost_per_byte * u64::from(num_bytes)) + options.get_priority_fee_lamports()
    }
}