use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Uint128};
use cw_storage_plus::{Item, Map};
#[cw_serde]
pub struct WindowEntry {
pub difficulty: u32,
pub timestamp: u64,
}
#[cw_serde]
pub struct SlidingWindow {
pub entries: Vec<WindowEntry>,
pub head: u32,
pub count: u64,
pub total_d: u64,
pub t_first: u64,
pub t_last: u64,
}
#[cw_serde]
pub struct PidState {
pub alpha: u64,
pub beta: u64,
pub e_eff_prev: i64,
pub e_cov_prev: i64,
pub de_eff: i64,
pub de_cov: i64,
pub cached_staking_share: u64,
}
#[cw_serde]
pub struct FeeBucket {
pub epoch: u64,
pub amount: Uint128,
}
#[cw_serde]
pub struct FeeHistory {
pub buckets: Vec<FeeBucket>,
pub bucket_duration: u64,
}
#[cw_serde]
pub struct MineConfig {
pub max_proof_age: u64,
pub estimated_gas_cost_uboot: Uint128,
pub core_contract: Addr,
pub stake_contract: Addr,
pub refer_contract: Addr,
pub token_contract: String,
pub admin: Addr,
pub paused: bool,
pub window_size: u32,
pub pid_interval: u64,
pub genesis_time: u64,
pub warmup_base_rate: Uint128,
pub fee_bucket_duration: u64,
pub fee_num_buckets: u32,
}
#[cw_serde]
pub struct Stats {
pub total_proofs: u64,
pub total_rewards: Uint128,
pub unique_miners: u64,
pub total_difficulty_bits: u64,
}
#[cw_serde]
pub struct MinerStats {
pub proofs_submitted: u64,
pub total_rewards: Uint128,
pub last_proof_time: u64,
}
pub const CONFIG: Item<MineConfig> = Item::new("config");
pub const STATS: Item<Stats> = Item::new("stats");
pub const SLIDING_WINDOW: Item<SlidingWindow> = Item::new("sliding_window");
pub const PID_STATE: Item<PidState> = Item::new("pid_state");
pub const FEE_HISTORY: Item<FeeHistory> = Item::new("fee_history");
pub const MINER_STATS: Map<&Addr, MinerStats> = Map::new("miner_stats");
pub const USED_PROOF_HASHES: Map<&[u8], u64> = Map::new("used_proof_hashes");
pub const PROOF_PRUNE_CURSOR: Item<Vec<u8>> = Item::new("proof_prune_cursor");