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

@@ -95,4 +95,4 @@ pub const DENOMINATOR_BPS: u64 = 10_000;
pub const BOOST_RESERVE_TOKEN: Pubkey = pubkey!("Gce36ZUsBDJsoLrfCBxUB5Sfq2DsGunofStvxFx6rBiD"); pub const BOOST_RESERVE_TOKEN: Pubkey = pubkey!("Gce36ZUsBDJsoLrfCBxUB5Sfq2DsGunofStvxFx6rBiD");
/// The fee paid to bots if they checkpoint a user. /// The fee paid to bots if they checkpoint a user.
pub const CHECKPOINT_FEE: u64 = 10_000; // 0.00001 SOL pub const CHECKPOINT_FEE: u64 = 100_000; // 0.0001 SOL

View File

@@ -23,6 +23,7 @@ pub struct Miner {
pub checkpoint_id: u64, pub checkpoint_id: u64,
/// The amount of SOL this miner has had refunded and may claim. /// The amount of SOL this miner has had refunded and may claim.
#[deprecated]
pub refund_sol: u64, pub refund_sol: u64,
/// The amount of SOL this miner can claim. /// The amount of SOL this miner can claim.

View File

@@ -16,6 +16,9 @@ pub struct Round {
/// The hash of the end slot, provided by solana, used for random number generation. /// The hash of the end slot, provided by solana, used for random number generation.
pub slot_hash: [u8; 32], pub slot_hash: [u8; 32],
/// The count of miners on each square.
pub count: [u64; 25],
/// The slot at which claims for this round account end. /// The slot at which claims for this round account end.
pub expires_at: u64, pub expires_at: u64,

View File

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

View File

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

View File

@@ -6,7 +6,7 @@ use steel::*;
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts. // Load accounts.
let clock = Clock::get()?; 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 accounts
else { else {
return Err(ProgramError::NotEnoughAccountKeys); return Err(ProgramError::NotEnoughAccountKeys);
@@ -67,7 +67,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
start_slot: board.start_slot, start_slot: board.start_slot,
end_slot: board.end_slot, end_slot: board.end_slot,
winning_square: winning_square as u64, winning_square: winning_square as u64,
top_miner: round.top_miner, top_miner: Pubkey::default(),
num_winners: 0, num_winners: 0,
total_deployed: round.total_deployed, total_deployed: round.total_deployed,
total_vaulted: round.total_vaulted, 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. // Mint 1 ORE for the winning miner.
let mint_amount = MAX_SUPPLY.saturating_sub(mint.supply()).min(ONE_ORE); let mint_amount = MAX_SUPPLY.saturating_sub(mint.supply()).min(ONE_ORE);
round.top_miner_reward = mint_amount;
mint_to_signed( mint_to_signed(
mint_info, mint_info,
treasury_tokens_info, treasury_tokens_info,
@@ -151,6 +152,17 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
treasury.motherlode += motherlode_mint_amount; 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. // Emit event.
program_log( program_log(
&[board_info.clone(), ore_program.clone()], &[board_info.clone(), ore_program.clone()],
@@ -160,8 +172,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
start_slot: board.start_slot, start_slot: board.start_slot,
end_slot: board.end_slot, end_slot: board.end_slot,
winning_square: winning_square as u64, winning_square: winning_square as u64,
top_miner: Pubkey::default(), // Unknown top_miner: top_miner.authority,
num_winners: 0, // Unknown num_winners: round.count[winning_square],
total_deployed: round.total_deployed, total_deployed: round.total_deployed,
total_vaulted: round.total_vaulted, total_vaulted: round.total_vaulted,
total_winnings: round.total_winnings, total_winnings: round.total_winnings,
@@ -182,12 +194,13 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
ore_program, ore_program,
signer_info, signer_info,
&ore_api::ID, &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)?; 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.deployed = [0; 25];
round_next.slot_hash = [0; 32]; round_next.slot_hash = [0; 32];
round_next.count = [0; 25];
round_next.expires_at = board.end_slot + ONE_WEEK_SLOTS; round_next.expires_at = board.end_slot + ONE_WEEK_SLOTS;
round_next.rent_payer = *signer_info.key; round_next.rent_payer = *signer_info.key;
round_next.motherlode = 0; round_next.motherlode = 0;