mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +00:00
cleanup
This commit is contained in:
@@ -307,11 +307,11 @@ pub fn reset(
|
||||
data: Reset {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, automation_info, board_info, miner_info, round_info, treasury_info, system_program] =
|
||||
|
||||
pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
|
||||
let miner_address = miner_pda(authority).0;
|
||||
let automation_address = automation_pda(authority).0;
|
||||
let board_address = board_pda().0;
|
||||
let round_address = round_pda(round_id).0;
|
||||
let treasury_address = TREASURY_ADDRESS;
|
||||
@@ -319,7 +319,6 @@ pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instructi
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(automation_address, false),
|
||||
AccountMeta::new(board_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(round_address, false),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::board_pda;
|
||||
use crate::state::{board_pda, OreAccountOLD};
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
@@ -17,6 +17,40 @@ pub struct Board {
|
||||
pub end_slot: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct BoardOLD {
|
||||
/// The round number.
|
||||
pub id: u64,
|
||||
|
||||
/// The deployed SOL for the round.
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// The timestamp at which the block starts mining.
|
||||
pub start_at: i64,
|
||||
|
||||
/// The slot at which the block starts trading.
|
||||
pub start_slot: u64,
|
||||
|
||||
/// The slot at which the block ends trading.
|
||||
pub end_slot: u64,
|
||||
|
||||
/// The hash of the end slot, provided by solana, used for random number generation.
|
||||
pub slot_hash: [u8; 32],
|
||||
|
||||
/// The top miner of the round.
|
||||
pub top_miner: Pubkey,
|
||||
|
||||
/// 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 Board {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
board_pda()
|
||||
@@ -24,3 +58,4 @@ impl Board {
|
||||
}
|
||||
|
||||
account!(OreAccount, Board);
|
||||
account!(OreAccountOLD, BoardOLD);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::miner_pda;
|
||||
use crate::state::{miner_pda, OreAccountOLD};
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
@@ -38,6 +38,38 @@ pub struct Miner {
|
||||
pub lifetime_rewards_ore: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct MinerOLD {
|
||||
/// The authority of this miner account.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The miner's prospects in the current round.
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// Unused buffer.
|
||||
#[deprecated(note = "No longer used")]
|
||||
pub buffer: [u8; 32],
|
||||
|
||||
/// The amount of SOL this miner has had refunded and may claim.
|
||||
pub refund_sol: u64,
|
||||
|
||||
/// The amount of SOL this miner can claim.
|
||||
pub rewards_sol: u64,
|
||||
|
||||
/// The amount of ORE this miner can claim.
|
||||
pub rewards_ore: u64,
|
||||
|
||||
/// The ID of the round this miner last played in.
|
||||
pub round_id: u64,
|
||||
|
||||
/// The total amount of SOL this miner has mined across all blocks.
|
||||
pub lifetime_rewards_sol: u64,
|
||||
|
||||
/// The total amount of ORE this miner has mined across all blocks.
|
||||
pub lifetime_rewards_ore: u64,
|
||||
}
|
||||
|
||||
impl Miner {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
miner_pda(self.authority)
|
||||
@@ -45,3 +77,4 @@ impl Miner {
|
||||
}
|
||||
|
||||
account!(OreAccount, Miner);
|
||||
account!(OreAccountOLD, MinerOLD);
|
||||
|
||||
@@ -35,6 +35,13 @@ pub enum OreAccount {
|
||||
Round = 109,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreAccountOLD {
|
||||
MinerOLD = 103,
|
||||
BoardOLD = 105,
|
||||
}
|
||||
|
||||
pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[AUTOMATION, &authority.to_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
@@ -49,16 +49,16 @@ impl Round {
|
||||
round_pda(self.id)
|
||||
}
|
||||
|
||||
pub fn rng(&self) -> u64 {
|
||||
if self.slot_hash == [0; 32] {
|
||||
return 0;
|
||||
pub fn rng(&self) -> Option<u64> {
|
||||
if self.slot_hash == [0; 32] || self.slot_hash == [u8::MAX; 32] {
|
||||
return None;
|
||||
}
|
||||
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
|
||||
Some(r)
|
||||
}
|
||||
|
||||
pub fn winning_square(&self, rng: u64) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user