Skip to main content

tengu_api/state/
forge.rs

1use super::DojosAccount;
2use steel::*;
3
4#[repr(C)]
5#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
6pub struct Forge {
7    pub dojo: Pubkey,
8    pub level: u64,
9    pub ore_queued: u64,
10    pub last_refine_slot: u64,
11    pub upgrade_cooldown_slot: u64,
12    pub buffer1: u64,
13    pub buffer2: u64,
14    pub buffer3: u64,
15    pub buffer4: u64,
16}
17
18account!(DojosAccount, Forge);
19
20impl Forge {
21    /// Ore per second throughput.
22    pub fn throughput(level: u64) -> f64 {
23        match level {
24            1 => 1.0 / 8.0,
25            2 => 1.0 / 6.0,
26            3 => 1.0 / 5.0,
27            4 => 1.0 / 4.0,
28            5 => 1.0 / 3.0,
29            6 => 1.0 / 2.0,
30            7 => 1.0,       // Lv.7 max: 1.0 ore/s = 1.0 $DOJO/s
31            _ => 1.0 / 8.0,
32        }
33    }
34
35    /// Raw $DOJO (6 decimals) per ore. 1:1 (matches Hyper Ninja: throughput only, no separate refine rate).
36    pub fn refine_rate(_level: u64) -> u64 {
37        crate::consts::ONE_DOJO // 1 ore = 1 $DOJO
38    }
39
40    pub fn upgrade_cost(from_level: u64) -> u64 {
41        match from_level {
42            1 => crate::consts::FORGE_COST_1_2,
43            2 => crate::consts::FORGE_COST_2_3,
44            3 => crate::consts::FORGE_COST_3_4,
45            4 => crate::consts::FORGE_COST_4_5,
46            5 => crate::consts::FORGE_COST_5_6,
47            6 => crate::consts::FORGE_COST_6_7,
48            _ => u64::MAX,
49        }
50    }
51
52    /// Forge upgrades always pay SOL.
53    pub fn upgrade_pays_sol(_from_level: u64) -> bool {
54        true
55    }
56
57    pub fn upgrade_cooldown(from_level: u64) -> u64 {
58        match from_level {
59            1 => crate::consts::FORGE_COOLDOWN_1_2,
60            2 => crate::consts::FORGE_COOLDOWN_2_3,
61            3 => crate::consts::FORGE_COOLDOWN_3_4,
62            4 => crate::consts::FORGE_COOLDOWN_4_5,
63            5 => crate::consts::FORGE_COOLDOWN_5_6,
64            6 => crate::consts::FORGE_COOLDOWN_6_7,
65            _ => 0,
66        }
67    }
68
69    /// Remaining seconds until cooldown ends. 0 when no cooldown or timer has ended.
70    /// `now` is current Solana slot.
71    pub fn cooldown_remaining_seconds(&self, now: u64) -> u64 {
72        if self.upgrade_cooldown_slot == 0 || now >= self.upgrade_cooldown_slot {
73            return 0;
74        }
75        let remaining_slots = self.upgrade_cooldown_slot - now;
76        (remaining_slots as f64 * crate::consts::SECONDS_PER_SLOT) as u64
77    }
78
79    /// Remaining minutes (floor). For display: 0 when in last minute (e.g. 30 sec left → 0 mins).
80    pub fn cooldown_remaining_minutes(&self, now: u64) -> u64 {
81        self.cooldown_remaining_seconds(now) / 60
82    }
83}