automation

This commit is contained in:
Hardhat Chad
2025-09-23 12:42:38 -07:00
parent 3abe0e080b
commit da5cf4b09d
11 changed files with 307 additions and 89 deletions

View File

@@ -20,6 +20,9 @@ pub const INTERMISSION_SLOTS: u64 = 35;
/// The maximum token supply (5 million).
pub const MAX_SUPPLY: u64 = ONE_ORE * 5_000_000;
/// The seed of the automation account PDA.
pub const AUTOMATION: &[u8] = b"automation";
/// The seed of the board account PDA.
pub const BOARD: &[u8] = b"board";

View File

@@ -4,24 +4,34 @@ use steel::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum OreInstruction {
// User
Boost = 0,
ClaimSOL = 1,
ClaimORE = 2,
Deploy = 3,
Initialize = 4,
Log = 5,
Automate = 0,
Boost = 1,
ClaimSOL = 2,
ClaimORE = 3,
Deploy = 4,
Initialize = 5,
Log = 6,
Reset = 7,
SetExecutor = 9,
// Admin
Bury = 10,
SetAdmin = 11,
SetFeeCollector = 12,
Bury = 9,
SetAdmin = 10,
SetFeeCollector = 11,
// Seeker
ClaimSeeker = 14,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Automate {
pub amount: [u8; 8],
pub deposit: [u8; 8],
pub fee: [u8; 8],
pub mask: [u8; 8],
pub strategy: u8,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Boost {}
@@ -78,12 +88,6 @@ pub struct Uncommit {
pub amount: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetExecutor {
pub executor: [u8; 32],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct SetAdmin {
@@ -112,6 +116,7 @@ pub struct Bury {
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimSeeker {}
instruction!(OreInstruction, Automate);
instruction!(OreInstruction, Boost);
instruction!(OreInstruction, ClaimSOL);
instruction!(OreInstruction, ClaimORE);
@@ -120,7 +125,6 @@ instruction!(OreInstruction, Initialize);
instruction!(OreInstruction, Log);
instruction!(OreInstruction, Bury);
instruction!(OreInstruction, Reset);
instruction!(OreInstruction, SetExecutor);
instruction!(OreInstruction, SetAdmin);
instruction!(OreInstruction, SetFeeCollector);
instruction!(OreInstruction, ClaimSeeker);

View File

@@ -21,6 +21,39 @@ pub fn program_log(accounts: &[AccountInfo], msg: &[u8]) -> Result<(), ProgramEr
invoke_signed(&log(*accounts[0].key, msg), accounts, &crate::ID, &[BOARD])
}
// let [signer_info, automation_info, executor_info, miner_info, system_program] = accounts else {
pub fn automate(
signer: Pubkey,
amount: u64,
deposit: u64,
executor: Pubkey,
fee: u64,
mask: u64,
strategy: u8,
) -> Instruction {
let automation_address = automation_pda(signer).0;
let miner_address = miner_pda(signer).0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(automation_address, false),
AccountMeta::new(executor, false),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Automate {
amount: amount.to_le_bytes(),
deposit: deposit.to_le_bytes(),
fee: fee.to_le_bytes(),
mask: mask.to_le_bytes(),
strategy: strategy as u8,
}
.to_bytes(),
}
}
// let [signer_info, config_info, mint_info, reserve_tokens_info, treasury_info, system_program, token_program] =
pub fn boost(signer: Pubkey) -> Instruction {
@@ -115,13 +148,15 @@ pub fn claim_ore(signer: Pubkey, amount: u64) -> Instruction {
pub fn deploy(
signer: Pubkey,
authority: Pubkey,
fee_collector: Pubkey,
amount: u64,
squares: [bool; 25],
) -> Instruction {
let automation_address = automation_pda(authority).0;
let board_address = board_pda().0;
let config_address = config_pda().0;
let miner_address = miner_pda(signer).0;
let miner_address = miner_pda(authority).0;
let square_address = square_pda().0;
// Convert array of 25 booleans into a 32-bit mask where each bit represents whether
@@ -137,6 +172,7 @@ pub fn deploy(
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(automation_address, false),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),

View 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);

View File

@@ -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.

View File

@@ -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)
}