miner-api 0.1.0

Instructions, state and SDK for the MINER protocol - a proof-of-work mined SPL token where holdings boost mining power
Documentation
use bytemuck::{Pod, Zeroable};

/// Dyskryminatory kont.
pub const CONFIG_DISCRIMINATOR: u64 = 1;
pub const ROUND_DISCRIMINATOR: u64 = 2;
pub const MINER_DISCRIMINATOR: u64 = 3;

/// Globalna konfiguracja programu (PDA "config", singleton).
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Config {
    pub discriminator: u64,
    /// Admin (update_config). Docelowo multisig/timelock.
    pub admin: [u8; 32],
    /// Mint tokena (mint authority = PDA "treasury").
    pub mint: [u8; 32],
    /// Indeks bieżącej (otwartej) rundy.
    pub current_round: u64,
    /// Timestamp startu bieżącej rundy.
    pub round_start_ts: i64,
    /// Minimalna trudność hasha (wiodące bity zerowe).
    pub min_difficulty: u64,
    /// Waga bazowa free tier w natywnych jednostkach tokena
    /// (~$1; docelowo aktualizowana z EMA ceny poola).
    pub base_weight: u64,
    /// Długość rundy w sekundach (kadencja submitów; budżet rundy
    /// skaluje się pro-rata, więc emisja/min jest stała).
    pub round_seconds: u64,
    /// Bump PDA config.
    pub config_bump: u64,
    /// Bump PDA treasury.
    pub treasury_bump: u64,
}

/// Jedna runda dystrybucji (PDA "round" + index LE).
/// Runda jest otwarta gdy index == config.current_round; rozliczalna gdy
/// index < config.current_round; zamykalna (odzysk rentu) po ROUND_RETENTION.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Round {
    pub discriminator: u64,
    pub index: u64,
    /// Suma wag wszystkich submitów w rundzie (jednostki natywne tokena).
    pub total_weight: u64,
    /// Timestamp otwarcia rundy.
    pub start_ts: i64,
    /// Budżet emisji rundy (zamrożony przy otwarciu z config.round_seconds,
    /// żeby zmiana kadencji nie ruszała rozliczeń starych rund).
    pub budget: u64,
}

/// Konto minera (PDA "miner" + authority).
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Miner {
    pub discriminator: u64,
    /// Wallet-właściciel (burner z przeglądarki albo podłączony wallet).
    pub authority: [u8; 32],
    /// Session key uprawniony do submitów (zero = brak).
    pub session_key: [u8; 32],
    /// Bieżące challenge PoW.
    pub challenge: [u8; 32],
    /// Indeks rundy ostatniego submitu.
    pub last_round: u64,
    /// Waga zgłoszona w rundzie last_round (nierozliczona, jeśli > 0).
    pub last_round_weight: u64,
    /// Saldo tokenów przy ostatnim submicie (reguła min-salda / anty-cycling).
    pub last_balance: u64,
    /// Naliczone, nieodebrane nagrody (jednostki natywne).
    pub pending_rewards: u64,
    /// Statystyki lifetime.
    pub total_mined: u64,
    pub total_hashes: u64,
    /// Bump PDA.
    pub bump: u64,
}

impl Config {
    pub const SIZE: usize = core::mem::size_of::<Config>();
}
impl Round {
    pub const SIZE: usize = core::mem::size_of::<Round>();
}
impl Miner {
    pub const SIZE: usize = core::mem::size_of::<Miner>();
}