This commit is contained in:
Hardhat Chad
2025-09-25 20:03:03 -07:00
parent 8a29165789
commit 037aa5e480
7 changed files with 87 additions and 11 deletions

View File

@@ -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>(
seeker_info,
system_program,
signer_info,
&ore_api::ID,
&[SEEKER, &mint_info.key.to_bytes()],
)?;
let seeker = seeker_info.as_account_mut::<Seeker>(&ore_api::ID)?;
seeker.mint = *mint_info.key;
// Open miner account.
let miner = if miner_info.data_is_empty() {
create_program_account::<Miner>(
miner_info,
system_program,
signer_info,
&ore_api::ID,
&[MINER, &signer_info.key.to_bytes()],
)?;
let miner = miner_info.as_account_mut::<Miner>(&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::<Miner>(&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(())
}