checkpoint

This commit is contained in:
Hardhat Chad
2025-10-01 11:33:17 -07:00
parent bef1c56ee3
commit cf248d7a28
9 changed files with 280 additions and 228 deletions

View File

@@ -41,6 +41,9 @@ pub const SQUARE: &[u8] = b"square";
/// The seed of the stake account PDA.
pub const STAKE: &[u8] = b"stake";
/// The seed of the round account PDA.
pub const ROUND: &[u8] = b"round";
/// The seed of the treasury account PDA.
pub const TREASURY: &[u8] = b"treasury";

View File

@@ -6,26 +6,27 @@ pub enum OreInstruction {
// Miner
Automate = 0,
Boost = 1,
ClaimSOL = 2,
ClaimORE = 3,
Deploy = 4,
Initialize = 5,
Log = 6,
Reset = 7,
Checkpoint = 2,
ClaimSOL = 3,
ClaimORE = 4,
Deploy = 5,
Initialize = 6,
Log = 7,
Reset = 8,
// Staker
Deposit = 8,
Withdraw = 9,
ClaimYield = 10,
Deposit = 9,
Withdraw = 10,
ClaimYield = 11,
// Admin
Bury = 11,
Wrap = 12,
SetAdmin = 13,
SetFeeCollector = 14,
Bury = 12,
Wrap = 13,
SetAdmin = 14,
SetFeeCollector = 15,
// Seeker
ClaimSeeker = 15,
ClaimSeeker = 16,
}
#[repr(C)]
@@ -144,8 +145,13 @@ pub struct ClaimYield {
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimSeeker {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Checkpoint {}
instruction!(OreInstruction, Automate);
instruction!(OreInstruction, Boost);
instruction!(OreInstruction, Checkpoint);
instruction!(OreInstruction, ClaimSOL);
instruction!(OreInstruction, ClaimORE);
instruction!(OreInstruction, Deploy);

View File

@@ -160,7 +160,7 @@ pub fn deploy(
let automation_address = automation_pda(authority).0;
let board_address = board_pda().0;
let miner_address = miner_pda(authority).0;
let square_address = square_pda().0;
// let square_address = square_pda().0;
// Convert array of 25 booleans into a 32-bit mask where each bit represents whether
// that square index is selected (1) or not (0)
@@ -177,7 +177,7 @@ pub fn deploy(
AccountMeta::new(automation_address, false),
AccountMeta::new(board_address, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(square_address, false),
// AccountMeta::new(square_address, false),
AccountMeta::new_readonly(system_program::ID, false),
];
@@ -285,7 +285,7 @@ pub fn reset(signer: Pubkey, fee_collector: Pubkey, miners: Vec<Pubkey>) -> Inst
let board_address = board_pda().0;
let config_address = config_pda().0;
let mint_address = MINT_ADDRESS;
let square_address = square_pda().0;
// let square_address = square_pda().0;
let treasury_address = TREASURY_ADDRESS;
let treasury_tokens_address = treasury_tokens_address();
let mut accounts = vec![
@@ -294,7 +294,7 @@ pub fn reset(signer: Pubkey, fee_collector: Pubkey, miners: Vec<Pubkey>) -> Inst
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(square_address, false),
// AccountMeta::new(square_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new_readonly(system_program::ID, false),

View File

@@ -6,7 +6,7 @@ use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Game {
pub struct Board {
/// The current round number.
pub round_id: u64,
@@ -35,9 +35,18 @@ pub struct Round {
/// 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,
@@ -48,23 +57,66 @@ pub struct Round {
pub total_winnings: u64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Move {
/// The authority of the move.
pub authority: Pubkey,
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
}
/// The amount of SOL deployed in each square.
pub deployed: [u64; 25],
pub fn winning_square(&self, rng: u64) -> usize {
(rng % 25) as usize
}
/// The round number.
pub round_id: u64,
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_motherlode_hit(&self, rng: u64) -> bool {
rng.reverse_bits() % 625 == 0
}
}
// impl Board {
// pub fn pda(&self) -> (Pubkey, u8) {
// board_pda()
// }
// }
impl Board {
pub fn pda(&self) -> (Pubkey, u8) {
board_pda()
}
}
// account!(OreAccount, 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);
}
}

View File

@@ -13,9 +13,14 @@ pub struct Miner {
/// The miner's prospects in the current round.
pub deployed: [u64; 25],
/// Unused buffer.
#[deprecated(note = "No longer used")]
pub buffer: [u8; 32],
/// The cumulative amount of SOL deployed on each square prior to this miner's move.
pub cumulative: [u64; 25],
/// SOL witheld in reserve to pay for checkpointing.
pub checkpoint_fee: u64,
/// The last round that this miner checkpointed.
pub checkpoint_id: u64,
/// The amount of SOL this miner has had refunded and may claim.
pub refund_sol: u64,

View File

@@ -3,7 +3,7 @@ mod board;
mod config;
mod miner;
mod seeker;
mod square;
// mod square;
mod stake;
mod treasury;
@@ -12,7 +12,7 @@ pub use board::*;
pub use config::*;
pub use miner::*;
pub use seeker::*;
pub use square::*;
// pub use square::*;
pub use stake::*;
pub use treasury::*;
@@ -30,9 +30,10 @@ pub enum OreAccount {
//
Board = 105,
Square = 106,
// Square = 106,
Seeker = 107,
Stake = 108,
Round = 109,
}
pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) {
@@ -55,8 +56,12 @@ pub fn seeker_pda(mint: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[SEEKER, &mint.to_bytes()], &crate::ID)
}
pub fn square_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[SQUARE], &crate::ID)
// pub fn square_pda() -> (Pubkey, u8) {
// Pubkey::find_program_address(&[SQUARE], &crate::ID)
// }
pub fn round_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[ROUND, &id.to_le_bytes()], &crate::ID)
}
pub fn stake_pda(authority: Pubkey) -> (Pubkey, u8) {