diff --git a/api/src/consts.rs b/api/src/consts.rs index 76a37d2..d781432 100644 --- a/api/src/consts.rs +++ b/api/src/consts.rs @@ -32,6 +32,9 @@ pub const CONFIG: &[u8] = b"config"; /// The seed of the miner account PDA. pub const MINER: &[u8] = b"miner"; +/// The seed of the seeker account PDA. +pub const SEEKER: &[u8] = b"seeker"; + /// The seed of the square account PDA. pub const SQUARE: &[u8] = b"square"; diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 1557116..6c24fca 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -345,12 +345,16 @@ pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction { } pub fn claim_seeker(signer: Pubkey, mint: Pubkey) -> Instruction { + let seeker_address = seeker_pda(mint).0; + let token_account_address = get_associated_token_address(&signer, &mint); Instruction { program_id: crate::ID, accounts: vec![ AccountMeta::new(signer, true), AccountMeta::new_readonly(mint, false), - AccountMeta::new_readonly(spl_token::ID, false), + AccountMeta::new(seeker_address, false), + AccountMeta::new(token_account_address, false), + AccountMeta::new_readonly(system_program::ID, false), ], data: ClaimSeeker {}.to_bytes(), } diff --git a/api/src/state/miner.rs b/api/src/state/miner.rs index c1a0a0a..86532e1 100644 --- a/api/src/state/miner.rs +++ b/api/src/state/miner.rs @@ -13,9 +13,12 @@ pub struct Miner { /// The miner's prospects in the current round. pub deployed: [u64; 25], - /// The executor with permmission to deploy capital with this account. + /// Unused buffer. #[deprecated(note = "Use automation executor instead")] - pub executor: Pubkey, + pub buffer: [u8; 24], + + /// Whether this miner is associated with a Solana Seeker. + pub is_seeker: u64, /// The amount of SOL this miner has had refunded and may claim. pub refund_sol: u64, diff --git a/api/src/state/mod.rs b/api/src/state/mod.rs index 63cc36b..6499465 100644 --- a/api/src/state/mod.rs +++ b/api/src/state/mod.rs @@ -2,6 +2,7 @@ mod automation; mod board; mod config; mod miner; +mod seeker; mod square; mod treasury; @@ -9,6 +10,7 @@ pub use automation::*; pub use board::*; pub use config::*; pub use miner::*; +pub use seeker::*; pub use square::*; pub use treasury::*; @@ -27,6 +29,7 @@ pub enum OreAccount { // Board = 105, Square = 106, + Seeker = 107, } pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) { @@ -45,6 +48,10 @@ pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID) } +pub fn seeker_pda(mint: Pubkey) -> (Pubkey, u8) { + Pubkey::find_program_address(&[SEEKER, &mint.to_bytes()], &crate::ID) +} + pub fn square_pda() -> (Pubkey, u8) { Pubkey::find_program_address(&[SQUARE], &crate::ID) } diff --git a/api/src/state/seeker.rs b/api/src/state/seeker.rs new file mode 100644 index 0000000..d45a6c5 --- /dev/null +++ b/api/src/state/seeker.rs @@ -0,0 +1,13 @@ +use steel::*; + +use super::OreAccount; + +/// Seeker is an account which prevents multiple Seeker genesis tokens from being claimed. +#[repr(C)] +#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] +pub struct Seeker { + // The mint address of the Seeker token. + pub mint: Pubkey, +} + +account!(OreAccount, Seeker); diff --git a/api/src/state/treasury.rs b/api/src/state/treasury.rs index 330222d..298a4f3 100644 --- a/api/src/state/treasury.rs +++ b/api/src/state/treasury.rs @@ -14,11 +14,4 @@ pub struct Treasury { pub motherlode: u64, } -#[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] -pub struct TreasuryOLD { - // The amount of SOL collected for buy-bury operations. - pub balance: u64, -} - account!(OreAccount, Treasury); diff --git a/program/src/claim_seeker.rs b/program/src/claim_seeker.rs index 6382980..b844926 100644 --- a/program/src/claim_seeker.rs +++ b/program/src/claim_seeker.rs @@ -1,3 +1,7 @@ +use ore_api::{ + consts::{MINER, SEEKER}, + state::{Miner, Seeker}, +}; use solana_program::pubkey; use steel::*; @@ -11,11 +15,57 @@ use spl_token_2022::{ /// Claims ORE for seeker device. pub fn process_claim_seeker(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. - let [signer_info, mint_info, _token_info] = accounts else { + let [signer_info, miner_info, mint_info, seeker_info, token_account_info, system_program] = + accounts + else { return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; + miner_info.is_writable()?; mint_info.has_owner(&spl_token_2022::ID)?; + seeker_info.is_writable()?.is_empty()?; + token_account_info + .as_associated_token_account(signer_info.key, mint_info.key)? + .assert(|t| t.amount() == 1)?; + system_program.is_program(&system_program::ID)?; + + // Open seeker account. + // Each genesis token can only be claimed once. + create_program_account::( + seeker_info, + system_program, + signer_info, + &ore_api::ID, + &[SEEKER, &mint_info.key.to_bytes()], + )?; + let seeker = seeker_info.as_account_mut::(&ore_api::ID)?; + seeker.mint = *mint_info.key; + + // Open miner account. + let miner = if miner_info.data_is_empty() { + create_program_account::( + miner_info, + system_program, + signer_info, + &ore_api::ID, + &[MINER, &signer_info.key.to_bytes()], + )?; + let miner = miner_info.as_account_mut::(&ore_api::ID)?; + miner.authority = *signer_info.key; + miner.deployed = [0; 25]; + miner.is_seeker = 0; + miner.refund_sol = 0; + miner.rewards_sol = 0; + miner.rewards_ore = 0; + miner.round_id = 0; + miner.lifetime_rewards_sol = 0; + miner.lifetime_rewards_ore = 0; + miner + } else { + miner_info + .as_account_mut::(&ore_api::ID)? + .assert_mut(|m| m.authority == *signer_info.key)? + }; // Load mint. let mint_data = mint_info.try_borrow_data()?; @@ -39,5 +89,8 @@ pub fn process_claim_seeker(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Progr "metadata address mismatch" ); + // Give miner a Seeker designation. + miner.is_seeker = 1; + Ok(()) }