ore_api/state/
automation.rs1use 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 pub amount: u64,
70
71 pub authority: Pubkey,
73
74 pub balance: u64,
76
77 pub executor: Pubkey,
79
80 pub fee: u64,
82
83 pub strategy: u64,
85
86 pub mask: u64,
89
90 pub reload: u64,
92}
93
94#[repr(C)]
95#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
96pub struct AutomationOLD {
97 pub amount: u64,
99
100 pub authority: Pubkey,
102
103 pub balance: u64,
105
106 pub executor: Pubkey,
108
109 pub fee: u64,
111
112 pub strategy: u64,
114
115 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);