diff --git a/program/src/mine.rs b/program/src/mine.rs index 8bdc6a5..6aaac46 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -124,6 +124,7 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // Boosts are incentives that can multiply a miner's rewards by staking tokens in the ORE Boosts program. // Up to 3 boosts can be applied on any given mine operation. let base_reward = reward; + let mut boost_events: Vec = vec![]; let mut applied_boosts = [Pubkey::new_from_array([0; 32]); 3]; for i in 0..3 { if optional_accounts.len().gt(&(i * 2)) { @@ -155,20 +156,16 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { .checked_div(boost.total_stake as u128) .unwrap() as u64; reward = reward.checked_add(boost_reward).unwrap(); - - // Log event - sol_log_data(&[(BoostEvent { + // push boost event + boost_events.push(BoostEvent { mint: boost.mint, reward: boost_reward, - }) - .to_bytes()]); + }); } } } - // Log base reward after boost rewards. - // Parser looks for base reward first, and then for the variable number of boost rewards. - sol_log(&format!("Base: {}", base_reward)); + let reward_before_penalties = reward; // Apply liveness penalty. // // The liveness penalty exists to ensure there is no "invisible" hashpower on the network. It @@ -203,6 +200,17 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // for any given hash. let reward_actual = reward.min(bus.rewards).min(ONE_ORE); + // Scale boost rewards by the limitted actual rewards. + for mut event in boost_events.into_iter() { + // scale boost reward + let scaled = + (reward_actual as u128) * (event.reward as u128) / (reward_before_penalties as u128); + event.reward = scaled as u64; + // log + sol_log_data(&[event.to_bytes()]); + } + sol_log(&format!("Base: {}", reward_actual)); + // Update balances. // // We track the theoretical rewards that would have been paid out ignoring the bus limit, so the