mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-09 15:11:40 +00:00
motherlode fix
This commit is contained in:
@@ -128,7 +128,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
|||||||
|
|
||||||
// Record ORE motherlode winnings.
|
// Record ORE motherlode winnings.
|
||||||
if motherlode_activated {
|
if motherlode_activated {
|
||||||
let motherlode_winnings = treasury.motherlode * miner_deployed / square_deployed;
|
let motherlode_winnings = ((treasury.motherlode as u128 * miner_deployed as u128)
|
||||||
|
/ square_deployed as u128) as u64;
|
||||||
miner.rewards_ore += motherlode_winnings;
|
miner.rewards_ore += motherlode_winnings;
|
||||||
miner.lifetime_rewards_ore += motherlode_winnings;
|
miner.lifetime_rewards_ore += motherlode_winnings;
|
||||||
}
|
}
|
||||||
@@ -295,12 +296,12 @@ fn get_winning_square(r: u64) -> usize {
|
|||||||
(r % 25) as usize
|
(r % 25) as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if the motherlode was activated, with 1 in 625 chance.
|
||||||
fn is_motherlode_activated(r: u64) -> bool {
|
fn is_motherlode_activated(r: u64) -> bool {
|
||||||
// Returns true if the motherlode was activated with 1/625 chance.
|
|
||||||
let r = r.reverse_bits();
|
let r = r.reverse_bits();
|
||||||
let x = r % 625;
|
let x = r % 625;
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
sol_log("Motherlode was activated");
|
sol_log("Motherlode hit!");
|
||||||
} else {
|
} else {
|
||||||
sol_log(&format!("Motherlode missed by {}", x).as_str());
|
sol_log(&format!("Motherlode missed by {}", x).as_str());
|
||||||
}
|
}
|
||||||
@@ -335,6 +336,9 @@ fn get_winning_miner(r: u64, total_deployed: u64, miner_deployed: [u64; 16]) ->
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use ore_api::consts::ONE_ORE;
|
||||||
|
use solana_program::native_token::sol_to_lamports;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_winning_square() {
|
fn test_get_winning_square() {
|
||||||
let capacity = 400u64;
|
let capacity = 400u64;
|
||||||
@@ -356,4 +360,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
// assert!(false);
|
// assert!(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_motherlode_math() {
|
||||||
|
let motherlode = ONE_ORE * 250;
|
||||||
|
let sol_deployed = sol_to_lamports(1.0);
|
||||||
|
let total_sol_deploy = sol_deployed * 2;
|
||||||
|
let motherlode_winnings =
|
||||||
|
((motherlode as u128 * sol_deployed as u128) / total_sol_deploy as u128) as u64;
|
||||||
|
println!("Motherlode winnings: {}", motherlode_winnings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub fn process_wrap(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult
|
|||||||
// Check min balance.
|
// Check min balance.
|
||||||
let min_balance = Rent::get()?.minimum_balance(std::mem::size_of::<Treasury>());
|
let min_balance = Rent::get()?.minimum_balance(std::mem::size_of::<Treasury>());
|
||||||
assert!(
|
assert!(
|
||||||
treasury_sol_info.lamports() >= min_balance,
|
treasury_info.lamports() >= min_balance,
|
||||||
"Insufficient SOL balance"
|
"Insufficient SOL balance"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user