mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +00:00
fix overflow issue
This commit is contained in:
@@ -14,7 +14,6 @@ use ore_boost_api::{
|
||||
state::{Boost, Stake},
|
||||
};
|
||||
use ore_utils::*;
|
||||
use solana_program::program::set_return_data;
|
||||
#[allow(deprecated)]
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
@@ -28,6 +27,7 @@ use solana_program::{
|
||||
slot_hashes::SlotHash,
|
||||
sysvar::{self, Sysvar},
|
||||
};
|
||||
use solana_program::{log, program::set_return_data};
|
||||
|
||||
/// Mine validates hashes and increments a miner's collectable balance.
|
||||
pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
@@ -105,15 +105,17 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let normalized_difficulty = difficulty
|
||||
.checked_sub(config.min_difficulty as u32)
|
||||
.unwrap();
|
||||
let mut reward = config
|
||||
let base_reward = config
|
||||
.base_reward_rate
|
||||
.checked_mul(2u64.checked_pow(normalized_difficulty).unwrap())
|
||||
.unwrap();
|
||||
let mut reward = base_reward;
|
||||
|
||||
// Apply boosts.
|
||||
//
|
||||
// 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.
|
||||
log::sol_log(&format!("Base: {}", base_reward));
|
||||
let mut boosts = [Pubkey::new_from_array([0; 32]); 3];
|
||||
for i in 0..3 {
|
||||
if optional_accounts.len().gt(&(i * 2)) {
|
||||
@@ -140,14 +142,15 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Apply multiplier if last stake was greater than one minute ago.
|
||||
if stake.last_stake_at.saturating_add(ONE_MINUTE).le(&t) {
|
||||
let multiplier = boost.multiplier.checked_sub(1).unwrap();
|
||||
let multiplier_reward = reward
|
||||
.checked_mul(multiplier)
|
||||
let boost_reward = (base_reward as u128)
|
||||
.checked_mul(multiplier as u128)
|
||||
.unwrap()
|
||||
.checked_mul(stake.balance)
|
||||
.checked_mul(stake.balance as u128)
|
||||
.unwrap()
|
||||
.checked_div(boost.total_stake)
|
||||
.unwrap();
|
||||
reward = reward.checked_add(multiplier_reward).unwrap();
|
||||
.checked_div(boost.total_stake as u128)
|
||||
.unwrap() as u64;
|
||||
log::sol_log(&format!("Boost: {}", boost_reward));
|
||||
reward = reward.checked_add(boost_reward).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user