ore_api/state/
automation.rs1use ore_mint_api::consts::ONE_ORE;
2use serde::{Deserialize, Serialize};
3use steel::*;
4
5use crate::state::{automation_pda, OreAccountV4};
6
7#[repr(C)]
8#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
9pub struct Automation {
10 pub amount: u64,
12
13 pub authority: Pubkey,
15
16 pub balance: u64,
18
19 pub executor: Pubkey,
21
22 pub fee: u64,
24
25 pub strategy: u64,
27
28 pub mask: u64,
31
32 pub reload: u64,
34
35 pub total_sol_spent: u64,
37
38 pub total_ore_earned: u64,
40
41 pub conditions: AutomationConditions,
43}
44
45#[repr(C)]
47#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
48pub struct AutomationConditions {
49 pub max_production_cost: u64,
52
53 pub min_motherlode: u64,
56
57 pub max_motherlode: u64,
60}
61
62#[repr(u8)]
63#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
64pub enum AutomationStrategy {
65 Random = 0,
66 Preferred = 1,
67 Discretionary = 2,
68}
69
70impl AutomationStrategy {
71 pub fn from_u64(value: u64) -> Self {
72 Self::try_from(value as u8).unwrap()
73 }
74}
75
76impl Default for AutomationConditions {
77 fn default() -> Self {
78 Self {
79 max_production_cost: u64::MAX,
80 min_motherlode: 0,
81 max_motherlode: u64::MAX,
82 }
83 }
84}
85
86impl Automation {
87 pub fn pda(&self) -> (Pubkey, u8) {
88 automation_pda(self.authority)
89 }
90
91 pub fn production_cost(&self) -> u64 {
92 if self.total_ore_earned == 0 {
93 return 0;
94 }
95 ((self.total_sol_spent as u128) * (ONE_ORE as u128) / (self.total_ore_earned as u128))
96 as u64
97 }
98}
99
100account!(OreAccountV4, Automation);