light_registry/
utils.rs

1use anchor_lang::solana_program::pubkey::Pubkey;
2
3use crate::constants::{FORESTER_EPOCH_SEED, FORESTER_SEED, PROTOCOL_CONFIG_PDA_SEED};
4
5pub fn get_protocol_config_pda_address() -> (Pubkey, u8) {
6    Pubkey::find_program_address(&[PROTOCOL_CONFIG_PDA_SEED], &crate::ID)
7}
8
9pub fn get_cpi_authority_pda() -> (Pubkey, u8) {
10    Pubkey::find_program_address(&[crate::CPI_AUTHORITY_PDA_SEED], &crate::ID)
11}
12
13pub fn get_forester_epoch_pda_from_authority(authority: &Pubkey, epoch: u64) -> (Pubkey, u8) {
14    let forester_pda = get_forester_pda(authority);
15    get_forester_epoch_pda(&forester_pda.0, epoch)
16}
17
18pub fn get_forester_epoch_pda_from_derivation(derivation: &Pubkey, epoch: u64) -> (Pubkey, u8) {
19    let forester_pda = get_forester_pda(derivation);
20    get_forester_epoch_pda(&forester_pda.0, epoch)
21}
22
23pub fn get_forester_epoch_pda(forester_pda: &Pubkey, epoch: u64) -> (Pubkey, u8) {
24    Pubkey::find_program_address(
25        &[
26            FORESTER_EPOCH_SEED,
27            forester_pda.as_ref(),
28            epoch.to_le_bytes().as_slice(),
29        ],
30        &crate::ID,
31    )
32}
33
34pub fn get_forester_pda(authority: &Pubkey) -> (Pubkey, u8) {
35    Pubkey::find_program_address(&[FORESTER_SEED, authority.as_ref()], &crate::ID)
36}
37
38pub fn get_epoch_pda_address(epoch: u64) -> Pubkey {
39    Pubkey::find_program_address(&[&epoch.to_le_bytes()], &crate::ID).0
40}