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 × 0.25 $DOJO/ore = 0.25 $DOJO/s
31            _ => 1.0 / 8.0,
32        }
33    }
34
35    /// Raw $DOJO (6 decimals) per ore. Ore → $DOJO directly (shards).
36    pub fn refine_rate(level: u64) -> u64 {
37        match level {
38            1 => 100_000,   // 0.1 $DOJO/ore
39            2 => 120_000,   // 0.12 $DOJO/ore
40            3 => 150_000,   // 0.15 $DOJO/ore
41            4 => 200_000,   // 0.2 $DOJO/ore
42            5 => 250_000,   // 0.25 $DOJO/ore → 0.25 $DOJO/s
43            6 => 250_000,
44            7 => 250_000,   // 0.25 $DOJO/ore → 0.25 $DOJO/s (max)
45            _ => 100_000,
46        }
47    }
48
49    pub fn upgrade_cost(from_level: u64) -> u64 {
50        match from_level {
51            1 => crate::consts::FORGE_COST_1_2,
52            2 => crate::consts::FORGE_COST_2_3,
53            3 => crate::consts::FORGE_COST_3_4,
54            4 => crate::consts::FORGE_COST_4_5,
55            5 => crate::consts::FORGE_COST_5_6,
56            6 => crate::consts::FORGE_COST_6_7,
57            _ => u64::MAX,
58        }
59    }
60
61    /// Forge upgrades always pay SOL.
62    pub fn upgrade_pays_sol(_from_level: u64) -> bool {
63        true
64    }
65
66    pub fn upgrade_cooldown(from_level: u64) -> u64 {
67        match from_level {
68            1 => crate::consts::FORGE_COOLDOWN_1_2,
69            2 => crate::consts::FORGE_COOLDOWN_2_3,
70            3 => crate::consts::FORGE_COOLDOWN_3_4,
71            4 => crate::consts::FORGE_COOLDOWN_4_5,
72            5 => crate::consts::FORGE_COOLDOWN_5_6,
73            6 => crate::consts::FORGE_COOLDOWN_6_7,
74            _ => 0,
75        }
76    }
77
78    /// Remaining seconds until cooldown ends. 0 when no cooldown or timer has ended.
79    /// `now` is current Solana slot.
80    pub fn cooldown_remaining_seconds(&self, now: u64) -> u64 {
81        if self.upgrade_cooldown_slot == 0 || now >= self.upgrade_cooldown_slot {
82            return 0;
83        }
84        let remaining_slots = self.upgrade_cooldown_slot - now;
85        (remaining_slots as f64 * crate::consts::SECONDS_PER_SLOT) as u64
86    }
87
88    /// Remaining minutes (floor). For display: 0 when in last minute (e.g. 30 sec left → 0 mins).
89    pub fn cooldown_remaining_minutes(&self, now: u64) -> u64 {
90        self.cooldown_remaining_seconds(now) / 60
91    }
92}