This commit is contained in:
Hardhat Chad
2025-10-01 15:59:38 -07:00
parent 48a21e4ecd
commit c694dba2a2
6 changed files with 31 additions and 14 deletions

View File

@@ -2,8 +2,6 @@ use ore_api::prelude::*;
use solana_program::rent::Rent;
use steel::*;
// TODO Bot fees
/// Checkpoints a miner's rewards.
pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
@@ -36,7 +34,7 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
// Ensure round is not expired.
if clock.slot >= round.expires_at {
// In this case, the miner forfeits any potential rewards and their checkpoint is recorded.
miner.checkpoint_id = round.id;
miner.checkpoint_id = miner.round_id;
return Ok(());
}
@@ -116,7 +114,8 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
miner_info.send(bot_fee, &signer_info);
}
// Assert round has sufficient funds for rent.
// Assert round has sufficient funds for rent + debts.
// TODO Debts
let account_size = 8 + std::mem::size_of::<Round>();
let required_rent = Rent::get()?.minimum_balance(account_size);
assert!(
@@ -127,8 +126,8 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
let account_size = 8 + std::mem::size_of::<Miner>();
let required_rent = Rent::get()?.minimum_balance(account_size);
assert!(
miner_info.lamports() >= required_rent,
"Miner does not have sufficient funds for rent"
miner_info.lamports() >= required_rent + miner.checkpoint_fee + miner.rewards_sol,
"Miner does not have sufficient funds for rent and rewards"
);
Ok(())

View File

@@ -153,6 +153,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
// Update board
round.deployed[square_id] += amount;
round.total_deployed += amount;
round.count[square_id] += 1;
// Update total amount
total_amount += amount;
@@ -165,7 +166,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
}
}
// Pay checkpoint fee.
// Top up checkpoint fee.
if miner.checkpoint_fee == 0 {
miner.checkpoint_fee = CHECKPOINT_FEE;
miner_info.collect(CHECKPOINT_FEE, &signer_info)?;

View File

@@ -6,7 +6,7 @@ use steel::*;
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let clock = Clock::get()?;
let [signer_info, board_info, config_info, fee_collector_info, mint_info, round_info, round_next_info, treasury_info, treasury_tokens_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
let [signer_info, board_info, config_info, fee_collector_info, mint_info, round_info, round_next_info, top_miner_info, treasury_info, treasury_tokens_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
@@ -67,7 +67,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
start_slot: board.start_slot,
end_slot: board.end_slot,
winning_square: winning_square as u64,
top_miner: round.top_miner,
top_miner: Pubkey::default(),
num_winners: 0,
total_deployed: round.total_deployed,
total_vaulted: round.total_vaulted,
@@ -107,6 +107,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
// Mint 1 ORE for the winning miner.
let mint_amount = MAX_SUPPLY.saturating_sub(mint.supply()).min(ONE_ORE);
round.top_miner_reward = mint_amount;
mint_to_signed(
mint_info,
treasury_tokens_info,
@@ -151,6 +152,17 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
treasury.motherlode += motherlode_mint_amount;
}
// Validate top miner.
// TODO Safety checks here.
let top_miner_sample = round.top_miner_sample(r, winning_square);
let top_miner = top_miner_info
.as_account::<Miner>(&ore_api::ID)?
.assert(|m| m.round_id == round.id)?
.assert(|m| {
m.cumulative[winning_square] >= top_miner_sample
&& top_miner_sample < m.cumulative[winning_square] + m.deployed[winning_square]
})?;
// Emit event.
program_log(
&[board_info.clone(), ore_program.clone()],
@@ -160,8 +172,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
start_slot: board.start_slot,
end_slot: board.end_slot,
winning_square: winning_square as u64,
top_miner: Pubkey::default(), // Unknown
num_winners: 0, // Unknown
top_miner: top_miner.authority,
num_winners: round.count[winning_square],
total_deployed: round.total_deployed,
total_vaulted: round.total_vaulted,
total_winnings: round.total_winnings,
@@ -182,12 +194,13 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
ore_program,
signer_info,
&ore_api::ID,
&[ROUND, &(board.round_id + 1).to_le_bytes()],
&[ROUND, &board.round_id.to_le_bytes()],
)?;
let round_next = round_next_info.as_account_mut::<Round>(&ore_api::ID)?;
round_next.id = board.round_id + 1;
round_next.id = board.round_id;
round_next.deployed = [0; 25];
round_next.slot_hash = [0; 32];
round_next.count = [0; 25];
round_next.expires_at = board.end_slot + ONE_WEEK_SLOTS;
round_next.rent_payer = *signer_info.key;
round_next.motherlode = 0;