airdrop-api 0.1.0

Mint and Airdrop Framework on Solana for Sovereign Individuals
Documentation
use solana_program::pubkey::Pubkey;
// use steel::*;

use crate::consts::{ALLOCATION, CAMPAIGN, CONFIG, FEE_ACCOUNT, MINT, MINT_AUTHORITY, TREASURY};

/// Derive the PDA of the config account
pub fn config_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[CONFIG], &crate::id())
}

/// Derive the PDA of the fee account
pub fn fee_account_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[FEE_ACCOUNT], &crate::id())
}

/// Derive the PDA of a campaign account
pub fn campaign_pda(campaign_id: &[u8]) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[CAMPAIGN, campaign_id], &crate::id())
}

/// Derive the PDA of a mint
/// mint_id can be:
/// - KOL's wallet bytes (for deterministic mint: kol_wallet.to_bytes())
/// - Random bytes (for default/random mint)
/// noise: 4-byte noise value for address grinding/pattern matching
///   - [0, 0, 0, 0] = no noise (default)
///   - Users can grind offline to find noise that produces desired address pattern
///   - Example: noise that makes mint address start with "Kol..." or end with "...XYZ"
pub fn mint_pda(mint_id: &[u8], noise: &[u8; 4]) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[MINT, mint_id, noise], &crate::id())
}

/// Derive the PDA of a mint's authority (shared across campaigns using same mint)
/// This is the key function: one PDA per mint, not per campaign
pub fn mint_authority_pda(mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[MINT_AUTHORITY, mint.as_ref()], &crate::id())
}

/// Derive the PDA of a mint's treasury (one per mint, holds all minted tokens)
/// Similar to miracle-copy's single treasury, but one per mint
/// This treasury holds all tokens minted for a specific mint
pub fn mint_treasury_pda(mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[TREASURY, mint.as_ref()], &crate::id())
}

/// Derive the PDA of a campaign's treasury (one per campaign, for distribution)
pub fn campaign_treasury_pda(campaign_id: &[u8]) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[TREASURY, campaign_id], &crate::id())
}

/// Derive the PDA of an allocation account
pub fn allocation_pda(campaign: Pubkey, recipient: Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[ALLOCATION, campaign.as_ref(), recipient.as_ref()],
        &crate::id(),
    )
}