1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::rig_pda;
5
6use super::OilAccount;
7
8#[repr(C)]
10#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
11pub struct Rig {
12 pub authority: Pubkey,
14
15 pub mint: Pubkey,
17
18 pub rig_type: u64,
20
21 pub rig_id: u64,
23
24 pub mining_power: u64,
26
27 pub fuel_requirement: u64,
29
30 pub fuel_consumption_rate: u64,
32
33 pub purchase_price: u64,
35
36 pub purchased_at: i64,
38
39 pub plot_slot: u64,
41
42 pub buffer_a: u64,
44
45 pub buffer_b: u64,
47
48 pub buffer_c: u64,
50}
51
52impl Rig {
53 pub fn pda(&self) -> (Pubkey, u8) {
54 rig_pda(self.mint)
55 }
56
57 pub fn get_purchase_cost(rig_type: u64) -> Option<u64> {
60 use crate::consts::ONE_OIL;
61
62 const RIG_COSTS: [Option<u64>; 15] = [
64 None, Some(21 * ONE_OIL), Some(42 * ONE_OIL), Some(84 * ONE_OIL), Some(168 * ONE_OIL), Some(336 * ONE_OIL), Some(672 * ONE_OIL), Some(1_344 * ONE_OIL), Some(2_688 * ONE_OIL), Some(5_376 * ONE_OIL), Some(10_752 * ONE_OIL), Some(21_504 * ONE_OIL), Some(43_008 * ONE_OIL), Some(86_016 * ONE_OIL), Some(172_032 * ONE_OIL), ];
80
81 if rig_type >= 15 {
82 return None;
83 }
84 RIG_COSTS[rig_type as usize]
85 }
86
87 pub fn get_rig_name(rig_type: u64, rig_id: u64) -> String {
89 if rig_type >= 15 {
90 return format!("rig_unknown #{}", rig_id + 1);
91 }
92 format!("rig_{} #{}", rig_type + 1, rig_id + 1)
93 }
94
95 pub fn get_rig_metadata_uri(rig_type: u64) -> String {
97 if rig_type >= 15 {
98 return String::new();
99 }
100 format!(
101 "https://raw.githubusercontent.com/oil-protocol/token-metadata/main/metadata/rigs/rig_{}.json",
102 rig_type + 1
103 )
104 }
105
106 pub fn model_name(rig_type: u64) -> &'static str {
108 const MODELS: [&str; 15] = [
109 "rig_1", "rig_2", "rig_3", "rig_4", "rig_5", "rig_6", "rig_7", "rig_8",
110 "rig_9", "rig_10", "rig_11", "rig_12", "rig_13", "rig_14", "rig_15",
111 ];
112 if rig_type >= 15 {
113 "rig_unknown"
114 } else {
115 MODELS[rig_type as usize]
116 }
117 }
118
119 pub fn initialize(
120 &mut self,
121 authority: Pubkey,
122 mint: Pubkey,
123 rig_type: u64,
124 rig_id: u64,
125 mining_power: u64,
126 fuel_requirement: u64,
127 fuel_consumption_rate: u64,
128 purchase_price: u64,
129 clock: &Clock,
130 ) {
131 self.authority = authority;
132 self.mint = mint;
133 self.rig_type = rig_type;
134 self.rig_id = rig_id;
135 self.mining_power = mining_power;
136 self.fuel_requirement = fuel_requirement;
137 self.fuel_consumption_rate = fuel_consumption_rate;
138 self.purchase_price = purchase_price;
139 self.purchased_at = clock.unix_timestamp;
140 self.plot_slot = 0; self.buffer_a = 0;
142 self.buffer_b = 0;
143 self.buffer_c = 0;
144 }
145
146 pub fn is_staked(&self) -> bool {
148 self.plot_slot > 0
149 }
150
151 pub fn place(&mut self, slot: u64) {
153 self.plot_slot = slot;
154 }
155
156 pub fn remove(&mut self) {
158 self.plot_slot = 0;
159 }
160}
161
162account!(OilAccount, Rig);