mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-17 07:26:52 +00:00
automation
This commit is contained in:
52
api/src/state/automation.rs
Normal file
52
api/src/state/automation.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::miner_pda;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Automation {
|
||||
/// The amount of SOL to deploy on each territory per round.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of this automation account.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The amount of SOL this automation has left.
|
||||
pub balance: u64,
|
||||
|
||||
/// The executor of this automation account.
|
||||
pub executor: Pubkey,
|
||||
|
||||
/// The amount of SOL the executor should receive in fees.
|
||||
pub fee: u64,
|
||||
|
||||
/// The strategy this automation uses.
|
||||
pub strategy: u64,
|
||||
|
||||
/// The mask of squares this automation should deploy to if preferred strategy.
|
||||
/// If strategy is Random, first bit is used to determine how many squares to deploy to.
|
||||
pub mask: u64,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum AutomationStrategy {
|
||||
Random = 0,
|
||||
Preferred = 1,
|
||||
}
|
||||
|
||||
impl AutomationStrategy {
|
||||
pub fn from_u64(value: u64) -> Self {
|
||||
Self::try_from(value as u8).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Automation {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
miner_pda(self.authority)
|
||||
}
|
||||
}
|
||||
|
||||
account!(OreAccount, Automation);
|
||||
@@ -14,6 +14,7 @@ pub struct Miner {
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// The executor with permmission to deploy capital with this account.
|
||||
#[deprecated(note = "Use automation executor instead")]
|
||||
pub executor: Pubkey,
|
||||
|
||||
/// The amount of SOL this miner can claim.
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
mod automation;
|
||||
mod board;
|
||||
mod config;
|
||||
mod miner;
|
||||
mod square;
|
||||
mod treasury;
|
||||
|
||||
pub use automation::*;
|
||||
pub use board::*;
|
||||
pub use config::*;
|
||||
pub use miner::*;
|
||||
@@ -17,6 +19,7 @@ use steel::*;
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreAccount {
|
||||
Automation = 100,
|
||||
Config = 101,
|
||||
Miner = 103,
|
||||
Treasury = 104,
|
||||
@@ -26,6 +29,10 @@ pub enum OreAccount {
|
||||
Square = 106,
|
||||
}
|
||||
|
||||
pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[AUTOMATION, &authority.to_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn board_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[BOARD], &crate::ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user