Skip to main content

airdrop_api/
pda.rs

1use solana_program::pubkey::Pubkey;
2// use steel::*;
3
4use crate::consts::{ALLOCATION, CAMPAIGN, CONFIG, FEE_ACCOUNT, MINT, MINT_AUTHORITY, TREASURY};
5
6/// Derive the PDA of the config account
7pub fn config_pda() -> (Pubkey, u8) {
8    Pubkey::find_program_address(&[CONFIG], &crate::id())
9}
10
11/// Derive the PDA of the fee account
12pub fn fee_account_pda() -> (Pubkey, u8) {
13    Pubkey::find_program_address(&[FEE_ACCOUNT], &crate::id())
14}
15
16/// Derive the PDA of a campaign account
17pub fn campaign_pda(campaign_id: &[u8]) -> (Pubkey, u8) {
18    Pubkey::find_program_address(&[CAMPAIGN, campaign_id], &crate::id())
19}
20
21/// Derive the PDA of a mint
22/// mint_id can be:
23/// - KOL's wallet bytes (for deterministic mint: kol_wallet.to_bytes())
24/// - Random bytes (for default/random mint)
25/// noise: 4-byte noise value for address grinding/pattern matching
26///   - [0, 0, 0, 0] = no noise (default)
27///   - Users can grind offline to find noise that produces desired address pattern
28///   - Example: noise that makes mint address start with "Kol..." or end with "...XYZ"
29pub fn mint_pda(mint_id: &[u8], noise: &[u8; 4]) -> (Pubkey, u8) {
30    Pubkey::find_program_address(&[MINT, mint_id, noise], &crate::id())
31}
32
33/// Derive the PDA of a mint's authority (shared across campaigns using same mint)
34/// This is the key function: one PDA per mint, not per campaign
35pub fn mint_authority_pda(mint: &Pubkey) -> (Pubkey, u8) {
36    Pubkey::find_program_address(&[MINT_AUTHORITY, mint.as_ref()], &crate::id())
37}
38
39/// Derive the PDA of a mint's treasury (one per mint, holds all minted tokens)
40/// Similar to miracle-copy's single treasury, but one per mint
41/// This treasury holds all tokens minted for a specific mint
42pub fn mint_treasury_pda(mint: &Pubkey) -> (Pubkey, u8) {
43    Pubkey::find_program_address(&[TREASURY, mint.as_ref()], &crate::id())
44}
45
46/// Derive the PDA of a campaign's treasury (one per campaign, for distribution)
47pub fn campaign_treasury_pda(campaign_id: &[u8]) -> (Pubkey, u8) {
48    Pubkey::find_program_address(&[TREASURY, campaign_id], &crate::id())
49}
50
51/// Derive the PDA of an allocation account
52pub fn allocation_pda(campaign: Pubkey, recipient: Pubkey) -> (Pubkey, u8) {
53    Pubkey::find_program_address(
54        &[ALLOCATION, campaign.as_ref(), recipient.as_ref()],
55        &crate::id(),
56    )
57}