mpl_token_auth_rules/
pda.rs

1//! The helper functions for the PDA accounts.
2use solana_program::pubkey::Pubkey;
3
4/// The string prefix for Rule Set PDA seeds.
5pub const PREFIX: &str = "rule_set";
6
7/// The string prefix for Rule Set State PDA seeds.
8pub const STATE_PDA: &str = "rule_set_state";
9
10/// Find the PDA for a Rule Set account.
11pub fn find_rule_set_address(creator: Pubkey, rule_set_name: String) -> (Pubkey, u8) {
12    Pubkey::find_program_address(
13        &[
14            PREFIX.as_bytes(),
15            creator.as_ref(),
16            rule_set_name.as_bytes(),
17        ],
18        &crate::ID,
19    )
20}
21
22/// Find the PDA for a Rule Set State account.
23pub fn find_rule_set_state_address(
24    creator: Pubkey,
25    rule_set_name: String,
26    mint: Pubkey,
27) -> (Pubkey, u8) {
28    Pubkey::find_program_address(
29        &[
30            STATE_PDA.as_bytes(),
31            creator.as_ref(),
32            rule_set_name.as_bytes(),
33            mint.as_ref(),
34        ],
35        &crate::ID,
36    )
37}
38
39/// Find the PDA for the Rule Set buffer account.
40pub fn find_buffer_address(creator: Pubkey) -> (Pubkey, u8) {
41    Pubkey::find_program_address(&[PREFIX.as_bytes(), creator.as_ref()], &crate::ID)
42}