This commit is contained in:
Hardhat Chad
2025-05-12 08:22:46 -07:00
parent 9bb6b476f4
commit 3c4cc8f3b6
2 changed files with 20 additions and 27 deletions

View File

@@ -2,15 +2,11 @@ use steel::*;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct MineEvent {
pub balance: u64,
pub difficulty: u64,
pub last_hash_at: i64,
pub timing: i64,
pub net_reward: u64,
pub net_base_reward: u64,
pub net_miner_boost_reward: u64,
pub net_staker_boost_reward: u64,
pub struct BlockEvent {
pub score: u64,
pub block_reward: u64,
pub boost_reward: u64,
pub ts: u64,
}
event!(MineEvent);
event!(BlockEvent);

View File

@@ -7,6 +7,7 @@ use steel::*;
/// Reset tops up the bus balances and updates the emissions and reward rates.
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let clock = Clock::get()?;
let (required_accounts, boost_accounts) = accounts.split_at(7);
let [signer_info, config_info, mint_info, proof_info, treasury_info, treasury_tokens_info, token_program, slot_hashes_sysvar] =
required_accounts
@@ -39,7 +40,6 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
.assert_mut(|p| p.authority == *boost_config_info.key)?;
// Validate enough time has passed since the last reset.
let clock = Clock::get()?;
if config
.last_reset_at
.saturating_add(EPOCH_DURATION)
@@ -49,7 +49,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
}
// Record difficulty.
let difficulty = difficulty(config.best_hash) as u64;
let score = difficulty(config.best_hash) as u64;
// Reset the challenge.
config.challenge = hashv(&[
@@ -59,40 +59,37 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
.to_bytes();
// Reset the config.
config.block_reward = get_block_reward(mint.supply());
let block_reward = get_block_reward(mint.supply());
config.block_reward = block_reward;
config.best_proof = Pubkey::default();
config.best_hash = [u8::MAX; 32];
config.last_reset_at = clock.unix_timestamp;
// Calculate boost reward.
let take_rate = boost_config.take_rate.min(9900); // Cap at 99%
let boost_reward = config.block_reward * take_rate / ore_boost_api::consts::DENOMINATOR_BPS;
let miner_reward = config.block_reward - boost_reward;
let boost_reward = block_reward * take_rate / ore_boost_api::consts::DENOMINATOR_BPS;
let miner_reward = block_reward - boost_reward;
// Update proof balance.
// Update proof balances.
proof.balance += miner_reward;
boost_proof.balance += boost_reward;
// Fund the treasury token account.
// Fund the treasury.
mint_to_signed(
mint_info,
treasury_tokens_info,
treasury_info,
token_program,
config.block_reward,
block_reward,
&[TREASURY],
)?;
// Emit event.
MineEvent {
balance: proof.balance,
difficulty,
last_hash_at: 0,
timing: 0,
net_reward: config.block_reward,
net_base_reward: miner_reward,
net_miner_boost_reward: boost_reward,
net_staker_boost_reward: 0,
BlockEvent {
score,
block_reward,
boost_reward,
ts: clock.unix_timestamp as u64,
}
.log_return();