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 Some(11 * ONE_OIL), 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!("Unknown Rig #{}", rig_id + 1);
91 }
92 let type_name = Self::rig_type_display_name(rig_type);
93 format!("{} #{}", type_name, rig_id + 1)
94 }
95
96 pub fn rig_type_display_name(rig_type: u64) -> &'static str {
98 const NAMES: [&str; 15] = [
99 "Basic Rig",
100 "Small Rig",
101 "Sensor Rig",
102 "Compressor Rig",
103 "Medium Rig",
104 "Large Rig",
105 "Advanced Sensor Rig",
106 "Turbo Compressor Rig",
107 "Deep Rig",
108 "Mega Rig",
109 "Epic Sensor Rig",
110 "Ultra Compressor Rig",
111 "Legendary Rig",
112 "Master Rig",
113 "Ultimate Rig",
114 ];
115 if rig_type >= 15 {
116 "Unknown Rig"
117 } else {
118 NAMES[rig_type as usize]
119 }
120 }
121
122 pub fn get_rig_metadata_uri(rig_type: u64) -> String {
124 if rig_type >= 15 {
125 return String::new();
126 }
127 format!(
128 "https://raw.githubusercontent.com/oil-protocol/token-metadata/main/metadata/rigs/rig_{}.json",
129 rig_type + 1
130 )
131 }
132
133 pub fn model_name(rig_type: u64) -> &'static str {
135 const MODELS: [&str; 15] = [
136 "rig_1", "rig_2", "rig_3", "rig_4", "rig_5", "rig_6", "rig_7", "rig_8",
137 "rig_9", "rig_10", "rig_11", "rig_12", "rig_13", "rig_14", "rig_15",
138 ];
139 if rig_type >= 15 {
140 "rig_unknown"
141 } else {
142 MODELS[rig_type as usize]
143 }
144 }
145
146 pub fn initialize(
147 &mut self,
148 authority: Pubkey,
149 mint: Pubkey,
150 rig_type: u64,
151 rig_id: u64,
152 mining_power: u64,
153 fuel_requirement: u64,
154 fuel_consumption_rate: u64,
155 purchase_price: u64,
156 clock: &Clock,
157 ) {
158 self.authority = authority;
159 self.mint = mint;
160 self.rig_type = rig_type;
161 self.rig_id = rig_id;
162 self.mining_power = mining_power;
163 self.fuel_requirement = fuel_requirement;
164 self.fuel_consumption_rate = fuel_consumption_rate;
165 self.purchase_price = purchase_price;
166 self.purchased_at = clock.unix_timestamp;
167 self.plot_slot = 0; self.buffer_a = 0;
169 self.buffer_b = 0;
170 self.buffer_c = 0;
171 }
172
173 pub fn is_staked(&self) -> bool {
175 self.plot_slot > 0
176 }
177
178 pub fn place(&mut self, slot: u64) {
180 self.plot_slot = slot;
181 }
182
183 pub fn remove(&mut self) {
185 self.plot_slot = 0;
186 }
187}
188
189account!(OilAccount, Rig);