oil_api/state/
automation.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::miner_pda;
5
6use super::OilAccount;
7
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct Automation {
11    /// The amount of SOL to deploy on each territory per round.
12    pub amount: u64,
13
14    /// The authority of this automation account.
15    pub authority: Pubkey,
16
17    /// The amount of SOL this automation has left.
18    pub balance: u64,
19
20    /// The executor of this automation account.
21    pub executor: Pubkey,
22
23    /// The amount of SOL the executor should receive in fees.
24    pub fee: u64,
25
26    /// The strategy this automation uses.
27    pub strategy: u64,
28
29    /// The mask of squares this automation should deploy to.
30    /// - Preferred: bit flags for which squares to deploy to
31    /// - Random: first byte is number of squares to randomly select
32    /// - Repeat: bit flags for which squares to deploy to (auto-updated after each deployment)
33    pub mask: u64,
34
35    /// Whether or not to auto-reload SOL winnings into the automation balance.
36    pub reload: u64,
37
38    /// Whether automated deployments should be pooled (1 = pooled, 0 = not pooled).
39    pub pooled: u64,
40}
41
42#[repr(u8)]
43#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
44pub enum AutomationStrategy {
45    Random = 0,
46    Preferred = 1,
47    Repeat = 2,
48}
49
50impl AutomationStrategy {
51    pub fn from_u64(value: u64) -> Self {
52        Self::try_from(value as u8).unwrap()
53    }
54}
55
56impl Automation {
57    pub fn pda(&self) -> (Pubkey, u8) {
58        miner_pda(self.authority)
59    }
60}
61
62account!(OilAccount, Automation);