ore_api/state/
automation.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::{miner_pda, OreAccountOLD};
5
6use super::OreAccount;
7
8#[derive(Debug, PartialEq, Clone, Copy)]
9pub enum VersionedAutomation {
10    V2(Automation),
11    V1(AutomationOLD),
12}
13
14impl VersionedAutomation {
15    pub fn amount(&self) -> u64 {
16        match self {
17            VersionedAutomation::V2(automation) => automation.amount,
18            VersionedAutomation::V1(automation) => automation.amount,
19        }
20    }
21    pub fn authority(&self) -> Pubkey {
22        match self {
23            VersionedAutomation::V2(automation) => automation.authority,
24            VersionedAutomation::V1(automation) => automation.authority,
25        }
26    }
27    pub fn balance(&self) -> u64 {
28        match self {
29            VersionedAutomation::V2(automation) => automation.balance,
30            VersionedAutomation::V1(automation) => automation.balance,
31        }
32    }
33    pub fn executor(&self) -> Pubkey {
34        match self {
35            VersionedAutomation::V2(automation) => automation.executor,
36            VersionedAutomation::V1(automation) => automation.executor,
37        }
38    }
39    pub fn fee(&self) -> u64 {
40        match self {
41            VersionedAutomation::V2(automation) => automation.fee,
42            VersionedAutomation::V1(automation) => automation.fee,
43        }
44    }
45    pub fn strategy(&self) -> u64 {
46        match self {
47            VersionedAutomation::V2(automation) => automation.strategy,
48            VersionedAutomation::V1(automation) => automation.strategy,
49        }
50    }
51    pub fn mask(&self) -> u64 {
52        match self {
53            VersionedAutomation::V2(automation) => automation.mask,
54            VersionedAutomation::V1(automation) => automation.mask,
55        }
56    }
57    pub fn reload(&self) -> u64 {
58        match self {
59            VersionedAutomation::V2(automation) => automation.reload,
60            VersionedAutomation::V1(_) => 0,
61        }
62    }
63}
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
67pub struct Automation {
68    /// The amount of SOL to deploy on each territory per round.
69    pub amount: u64,
70
71    /// The authority of this automation account.
72    pub authority: Pubkey,
73
74    /// The amount of SOL this automation has left.
75    pub balance: u64,
76
77    /// The executor of this automation account.
78    pub executor: Pubkey,
79
80    /// The amount of SOL the executor should receive in fees.
81    pub fee: u64,
82
83    /// The strategy this automation uses.
84    pub strategy: u64,
85
86    /// The mask of squares this automation should deploy to if preferred strategy.
87    /// If strategy is Random, first bit is used to determine how many squares to deploy to.
88    pub mask: u64,
89
90    /// Whether or not to auto-reload SOL when the balance is low.
91    pub reload: u64,
92}
93
94#[repr(C)]
95#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
96pub struct AutomationOLD {
97    /// The amount of SOL to deploy on each territory per round.
98    pub amount: u64,
99
100    /// The authority of this automation account.
101    pub authority: Pubkey,
102
103    /// The amount of SOL this automation has left.
104    pub balance: u64,
105
106    /// The executor of this automation account.
107    pub executor: Pubkey,
108
109    /// The amount of SOL the executor should receive in fees.
110    pub fee: u64,
111
112    /// The strategy this automation uses.
113    pub strategy: u64,
114
115    /// The mask of squares this automation should deploy to if preferred strategy.
116    /// If strategy is Random, first bit is used to determine how many squares to deploy to.
117    pub mask: u64,
118}
119
120#[repr(u8)]
121#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
122pub enum AutomationStrategy {
123    Random = 0,
124    Preferred = 1,
125}
126
127impl AutomationStrategy {
128    pub fn from_u64(value: u64) -> Self {
129        Self::try_from(value as u8).unwrap()
130    }
131}
132
133impl Automation {
134    pub fn pda(&self) -> (Pubkey, u8) {
135        miner_pda(self.authority)
136    }
137}
138
139account!(OreAccount, Automation);
140account!(OreAccountOLD, AutomationOLD);