This commit is contained in:
Hardhat Chad
2025-09-17 14:15:13 -07:00
parent 959fd70c44
commit 69d0383cf6
17 changed files with 350 additions and 168 deletions

View File

@@ -17,18 +17,12 @@ pub const ONE_MINUTE: i64 = 60;
/// The maximum token supply (5 million).
pub const MAX_SUPPLY: u64 = ONE_ORE * 5_000_000;
/// The seed of the block account PDA.
pub const BLOCK: &[u8] = b"block";
/// The seed of the board account PDA.
pub const BOARD: &[u8] = b"board";
/// The seed of the config account PDA.
pub const CONFIG: &[u8] = b"config";
/// The seed of the market account PDA.
pub const MARKET: &[u8] = b"market";
/// The seed of the miner account PDA.
pub const MINER: &[u8] = b"miner";
@@ -55,29 +49,8 @@ pub const TREASURY_ADDRESS: Pubkey =
/// The address of the treasury account.
pub const TREASURY_BUMP: u8 = ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).1;
/// Swap fee in lamports.
pub const FEE_LAMPORTS: u64 = 100_000; // 0.0001 SOL
/// Denominator for fee calculations.
pub const DENOMINATOR_BPS: u64 = 10_000;
/// Window to submit hashes, in slots.
pub const INITIAL_BLOCK_DURATION: u64 = 1500;
/// Window to submit hashes, in slots.
pub const INITIAL_SNIPER_FEE_DURATION: u64 = 50;
/// Window to submit hashes, in slots.
pub const MINING_WINDOW: u64 = 150; // 150 slots is 150 * 0.4 = 60 seconds
/// Slot window size, used for sandwich resistance.
pub const SLOT_WINDOW: u64 = 4;
/// Amount of hash tokens to mint to market.
pub const HASHPOWER_LIQUIDITY: u64 = 1_000_000;
/// The ORE liquidity to seed the markets with.
pub const ORE_LIQUIDITY: u64 = ONE_ORE * 100;
/// The address of the boost reserve token account.
pub const BOOST_RESERVE_TOKEN: Pubkey = pubkey!("Gce36ZUsBDJsoLrfCBxUB5Sfq2DsGunofStvxFx6rBiD");

View File

@@ -4,11 +4,13 @@ use steel::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum OreInstruction {
// User
Claim = 0,
Initialize = 1,
InitializeSquare = 2,
Prospect = 3,
Reset = 4,
ClaimSOL = 0,
ClaimORE = 1,
Initialize = 2,
InitializeSquares = 3,
Prospect = 4,
Redeem = 5,
Reset = 6,
// Admin
SetAdmin = 8,
@@ -20,7 +22,13 @@ pub enum OreInstruction {
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Claim {
pub struct ClaimSOL {
pub amount: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimORE {
pub amount: [u8; 8],
}
@@ -30,7 +38,13 @@ pub struct Initialize {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitializeSquare {}
pub struct InitializeSquares {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Redeem {
pub amount: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
@@ -97,11 +111,13 @@ pub struct SetSniperFeeDuration {
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct ClaimSeeker {}
instruction!(OreInstruction, Claim);
instruction!(OreInstruction, ClaimSOL);
instruction!(OreInstruction, ClaimORE);
instruction!(OreInstruction, Redeem);
instruction!(OreInstruction, Reset);
instruction!(OreInstruction, Prospect);
instruction!(OreInstruction, Initialize);
instruction!(OreInstruction, InitializeSquare);
instruction!(OreInstruction, InitializeSquares);
instruction!(OreInstruction, SetAdmin);
instruction!(OreInstruction, SetFeeCollector);
instruction!(OreInstruction, ClaimSeeker);

View File

@@ -2,7 +2,7 @@ use spl_associated_token_account::get_associated_token_address;
use steel::*;
use crate::{
consts::{BOOST_RESERVE_TOKEN, MARKET, MINT_ADDRESS, TREASURY_ADDRESS},
consts::{BOOST_RESERVE_TOKEN, MINT_ADDRESS, TREASURY_ADDRESS},
instruction::*,
state::*,
};
@@ -14,7 +14,7 @@ pub fn initialize(signer: Pubkey) -> Instruction {
let board_address = board_pda().0;
let mint_address = MINT_ADDRESS;
let treasury_address = TREASURY_ADDRESS;
let vault_address = vault_address();
let treasury_tokens_address = treasury_tokens_address();
Instruction {
program_id: crate::ID,
accounts: vec![
@@ -23,7 +23,7 @@ pub fn initialize(signer: Pubkey) -> Instruction {
AccountMeta::new(config_address, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(vault_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
@@ -66,27 +66,47 @@ pub fn initialize_squares(signer: Pubkey) -> Instruction {
AccountMeta::new(square_pda(23).0, false),
AccountMeta::new(square_pda(24).0, false),
],
data: InitializeSquare {}.to_bytes(),
data: InitializeSquares {}.to_bytes(),
}
}
pub fn claim(signer: Pubkey, amount: u64) -> Instruction {
pub fn claim_sol(signer: Pubkey, amount: u64) -> Instruction {
let miner_address = miner_pda(signer).0;
let miner_tokens_address = get_associated_token_address(&miner_address, &MINT_ADDRESS);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(miner_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: ClaimSOL {
amount: amount.to_le_bytes(),
}
.to_bytes(),
}
}
// let [signer_info, miner_info, mint_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
pub fn claim_ore(signer: Pubkey, amount: u64) -> Instruction {
let miner_address = miner_pda(signer).0;
let treasury_address = treasury_pda().0;
let treasury_tokens_address = get_associated_token_address(&treasury_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(miner_address, false),
AccountMeta::new(miner_tokens_address, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(MINT_ADDRESS, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
],
data: Claim {
data: ClaimORE {
amount: amount.to_le_bytes(),
}
.to_bytes(),
@@ -100,14 +120,14 @@ pub fn reset(signer: Pubkey, miners: Vec<Pubkey>) -> Instruction {
let mint_address = MINT_ADDRESS;
let treasury_address = TREASURY_ADDRESS;
let reserve_tokens_address = BOOST_RESERVE_TOKEN;
let vault_address = vault_address();
let treasury_tokens_address = treasury_tokens_address();
let mut accounts = vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(reserve_tokens_address, false),
AccountMeta::new(vault_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new(treasury_tokens_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
@@ -124,15 +144,13 @@ pub fn reset(signer: Pubkey, miners: Vec<Pubkey>) -> Instruction {
}
}
// let [signer_info, board_info, config_info, fee_collector_info, miner_info, mint_info, sender_info, square_info, vault_info, system_program, token_program, associated_token_program] =
// let [signer_info, board_info, config_info, fee_collector_info, miner_info, sender_info, square_info, system_program] =
pub fn prospect(signer: Pubkey, fee_collector: Pubkey, amount: u64, square_id: u64) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
let miner_address = miner_pda(signer).0;
let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
let square_address = square_pda(square_id).0;
let vault_address = vault_address();
Instruction {
program_id: crate::ID,
accounts: vec![
@@ -141,11 +159,8 @@ pub fn prospect(signer: Pubkey, fee_collector: Pubkey, amount: u64, square_id: u
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(sender_address, false),
AccountMeta::new(square_address, false),
AccountMeta::new(vault_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
],
data: Prospect {
amount: amount.to_le_bytes(),

View File

@@ -25,13 +25,16 @@ pub struct Board {
/// The hash of the end slot, provided by solana, used for random number generation.
pub slot_hash: [u8; 32],
/// The total amount of ORE burned for the round.
pub total_burned: u64,
/// The top winner of the round.
pub top_winner: Pubkey,
/// The total amount of ORE committed for the round.
pub total_commits: u64,
/// The total amount of SOL prospected in the round.
pub total_prospects: u64,
/// The total amount of ORE won by miners for the round.
/// 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,
}

View File

@@ -13,14 +13,20 @@ pub struct Miner {
/// The miner's committed square in the current round round.
pub commits: [u64; 25],
/// The amount of SOL this miner can claim.
pub rewards_sol: u64,
/// The amount of ORE this miner can claim.
pub rewards: u64,
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 total_rewards: u64,
pub lifetime_rewards_ore: u64,
}
impl Miner {

View File

@@ -42,15 +42,15 @@ pub fn square_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[SQUARE, &id.to_le_bytes()], &crate::ID)
}
pub fn vault_address() -> Pubkey {
let board_address = board_pda().0;
spl_associated_token_account::get_associated_token_address(&board_address, &MINT_ADDRESS)
}
// pub fn vault_address() -> Pubkey {
// let board_address = board_pda().0;
// spl_associated_token_account::get_associated_token_address(&board_address, &MINT_ADDRESS)
// }
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::ID)
}
// pub fn treasury_tokens_address() -> Pubkey {
// spl_associated_token_account::get_associated_token_address(&TREASURY_ADDRESS, &MINT_ADDRESS)
// }
pub fn treasury_tokens_address() -> Pubkey {
spl_associated_token_account::get_associated_token_address(&TREASURY_ADDRESS, &MINT_ADDRESS)
}

View File

@@ -8,7 +8,9 @@ use super::OreAccount;
/// the program's global token account.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Treasury {}
pub struct Treasury {
pub balance: u64,
}
impl Treasury {
pub fn pda() -> (Pubkey, u8) {