mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
close
This commit is contained in:
@@ -10,9 +10,6 @@ pub struct Board {
|
||||
/// The current round number.
|
||||
pub round_id: u64,
|
||||
|
||||
/// The timestamp at which the current round starts mining.
|
||||
pub start_at: i64,
|
||||
|
||||
/// The slot at which the current round starts mining.
|
||||
pub start_slot: u64,
|
||||
|
||||
@@ -20,82 +17,6 @@ pub struct Board {
|
||||
pub end_slot: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Round {
|
||||
/// The round number.
|
||||
pub id: u64,
|
||||
|
||||
/// The amount of SOL deployed in each square.
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// The hash of the end slot, provided by solana, used for random number generation.
|
||||
pub slot_hash: [u8; 32],
|
||||
|
||||
/// The slot at which claims for this round account end.
|
||||
pub expires_at: i64,
|
||||
|
||||
/// The amount of ORE in the motherlode.
|
||||
pub motherlode: u64,
|
||||
|
||||
/// The account to which rent should be returned when this account is closed.
|
||||
pub rent_payer: Pubkey,
|
||||
|
||||
/// The top miner of the round.
|
||||
pub top_miner: Pubkey,
|
||||
|
||||
/// The amount of ORE to distribute to the top miner.
|
||||
pub top_miner_reward: u64,
|
||||
|
||||
/// The total amount of SOL deployed in the round.
|
||||
pub total_deployed: u64,
|
||||
|
||||
/// The total amount of SOL put in the ORE vault.
|
||||
pub total_vaulted: u64,
|
||||
|
||||
/// The total amount of SOL won by miners for the round.
|
||||
pub total_winnings: u64,
|
||||
}
|
||||
|
||||
impl Round {
|
||||
pub fn rng(&self) -> u64 {
|
||||
if self.slot_hash == [0; 32] {
|
||||
return 0;
|
||||
}
|
||||
let r1 = u64::from_le_bytes(self.slot_hash[0..8].try_into().unwrap());
|
||||
let r2 = u64::from_le_bytes(self.slot_hash[8..16].try_into().unwrap());
|
||||
let r3 = u64::from_le_bytes(self.slot_hash[16..24].try_into().unwrap());
|
||||
let r4 = u64::from_le_bytes(self.slot_hash[24..32].try_into().unwrap());
|
||||
let r = r1 ^ r2 ^ r3 ^ r4;
|
||||
r
|
||||
}
|
||||
|
||||
pub fn winning_square(&self, rng: u64) -> usize {
|
||||
(rng % 25) as usize
|
||||
}
|
||||
|
||||
pub fn top_miner_sample(&self, rng: u64, winning_square: usize) -> u64 {
|
||||
if self.deployed[winning_square] == 0 {
|
||||
return 0;
|
||||
}
|
||||
rng.reverse_bits() % self.deployed[winning_square]
|
||||
}
|
||||
|
||||
pub fn calculate_total_winnings(&self, winning_square: usize) -> u64 {
|
||||
let mut total_winnings = 0;
|
||||
for (i, &deployed) in self.deployed.iter().enumerate() {
|
||||
if i != winning_square {
|
||||
total_winnings += deployed;
|
||||
}
|
||||
}
|
||||
total_winnings
|
||||
}
|
||||
|
||||
pub fn did_hit_motherlode(&self, rng: u64) -> bool {
|
||||
rng.reverse_bits() % 625 == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl Board {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
board_pda()
|
||||
@@ -103,20 +24,3 @@ impl Board {
|
||||
}
|
||||
|
||||
account!(OreAccount, Board);
|
||||
|
||||
account!(OreAccount, Round);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use solana_program::rent::Rent;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_rent() {
|
||||
let size_of_round = 8 + std::mem::size_of::<Round>();
|
||||
let required_rent = Rent::default().minimum_balance(size_of_round);
|
||||
println!("required_rent: {}", required_rent);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user