This commit is contained in:
Hardhat Chad
2025-07-16 16:24:41 -07:00
parent 9470c573f3
commit 084757cc8d
23 changed files with 262 additions and 1430 deletions

View File

@@ -4,12 +4,6 @@ use crate::state::block_pda;
use super::OreAccount;
// What could be variable?
// - Payout style (winner take all / difficulty / both)
// - Payout skew (larger / neutral / smaller)
// - Jackpot possiblity (yes / no)
// - Known / unknown
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Block {
@@ -20,42 +14,19 @@ pub struct Block {
pub opener: Pubkey,
/// The reward configuration.
pub reward: RewardConfig,
pub reward: u64,
/// The hash of the starting slot.
pub slot_hash: [u8; 32],
/// The starting slot of the block.
pub start_slot: u64,
/// The total number of hashes submitted to the block.
pub total_committed: u64,
/// The total number of hashes deployed to the block.
pub total_deployed: u64,
/// The total amount of rewards paid out to miners.
pub total_rewards: u64,
}
/// Configuration specifying how rewards are paid out.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct RewardConfig {
/// The reward paid to the submitter of the best hash.
pub lode_reward: u64,
/// The best hash submitted to the block.
pub best_hash: [u8; 32],
/// The authority of the miner who submitted the best hash.
pub lode_authority: Pubkey,
pub best_hash_miner: Pubkey,
/// The best hash.
pub lode_hash: [u8; 32],
/// The hash of the starting slot, used for random number generation.
pub slot_hash: [u8; 32],
/// The reward rate paid to hashes satisfying the difficulty threshold.
pub nugget_reward: u64,
/// The minimum difficulty required for payout.
pub nugget_threshold: u64,
/// The total amount of hashpower bought in the block.
pub total_hashpower: u64,
}
impl Block {

View File

@@ -10,9 +10,6 @@ pub struct Config {
// The address that can set the admin.
pub admin: Pubkey,
/// Number of blocks that can be open for trading at one time.
pub block_limit: u64,
// The address that receives fees.
pub fee_collector: Pubkey,

View File

@@ -20,13 +20,13 @@ pub struct Market {
/// Snapshot of the market state at the time of the last swap.
pub snapshot: Snapshot,
/// The id of the block this market is associated with.
pub id: u64,
/// The id of the current block.
pub block_id: u64,
}
impl Market {
pub fn pda(&self) -> (Pubkey, u8) {
market_pda(self.id)
market_pda()
}
pub fn base_vault(&self) -> Pubkey {
@@ -449,7 +449,7 @@ mod tests {
quote_balance: 0,
slot: 0,
},
id: 0,
block_id: 0,
}
}
}

View File

@@ -16,11 +16,14 @@ pub struct Miner {
/// The hash of the last block this miner mined in.
pub hash: [u8; 32],
/// The total number of hashes this miner has committed to the block.
pub total_committed: u64,
/// The amount of hashpower this miner has committed to the current block.
pub hashpower: u64,
/// The total number of hashes this miner has deployed to the block.
pub total_deployed: u64,
/// A user-supplied seed for random number generation.
pub seed: [u8; 32],
/// The total amount of hashpower this miner has committed across all blocks.
pub total_hashpower: u64,
/// The total amount of ORE this miner has mined across all blocks.
pub total_rewards: u64,

View File

@@ -2,16 +2,12 @@ mod block;
mod config;
mod market;
mod miner;
mod permit;
mod stake;
mod treasury;
pub use block::*;
pub use config::*;
pub use market::*;
pub use miner::*;
pub use permit::*;
pub use stake::*;
pub use treasury::*;
use crate::consts::*;
@@ -25,9 +21,7 @@ pub enum OreAccount {
Config = 101,
Market = 102,
Miner = 103,
Permit = 104,
Stake = 105,
Treasury = 106,
Treasury = 104,
}
pub fn block_pda(id: u64) -> (Pubkey, u8) {
@@ -38,58 +32,16 @@ pub fn config_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[CONFIG], &crate::ID)
}
pub fn market_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[MARKET, &id.to_le_bytes()], &crate::ID)
pub fn market_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[MARKET], &crate::ID)
}
pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
}
pub fn mint_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[MINT, &id.to_le_bytes()], &crate::ID)
}
pub fn collateral_pda(block_id: u64) -> (Pubkey, u8) {
let block_address = block_pda(block_id).0;
Pubkey::find_program_address(
&[
&block_address.to_bytes(),
&spl_token::ID.to_bytes(),
&MINT_ADDRESS.to_bytes(),
],
&crate::ID,
)
}
pub fn commitment_pda(block_id: u64) -> (Pubkey, u8) {
let block_address = block_pda(block_id).0;
let mint_address = mint_pda(block_id).0;
Pubkey::find_program_address(
&[
&block_address.to_bytes(),
&spl_token::ID.to_bytes(),
&mint_address.to_bytes(),
],
&crate::ID,
)
}
pub fn vault_base_pda(block_id: u64) -> (Pubkey, u8) {
let market_address = market_pda(block_id).0;
let mint_address = mint_pda(block_id).0;
Pubkey::find_program_address(
&[
&market_address.to_bytes(),
&spl_token::ID.to_bytes(),
&mint_address.to_bytes(),
],
&crate::ID,
)
}
pub fn vault_quote_pda(block_id: u64) -> (Pubkey, u8) {
let market_address = market_pda(block_id).0;
pub fn vault_pda() -> (Pubkey, u8) {
let market_address = market_pda().0;
Pubkey::find_program_address(
&[
&market_address.to_bytes(),
@@ -100,20 +52,6 @@ pub fn vault_quote_pda(block_id: u64) -> (Pubkey, u8) {
)
}
pub fn permit_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[PERMIT, &authority.to_bytes(), &block_id.to_le_bytes()],
&crate::ID,
)
}
pub fn stake_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[STAKE, &authority.to_bytes(), &block_id.to_le_bytes()],
&crate::ID,
)
}
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::ID)
}

View File

@@ -1,35 +0,0 @@
use steel::*;
use crate::state::permit_pda;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Permit {
/// The authority of the miner account.
pub authority: Pubkey,
/// The ID of the block this permit is for.
pub block_id: u64,
/// The amount of hash tokens this miner has committed to the block.
pub commitment: u64,
/// The executor of the permit.
pub executor: Pubkey,
/// The fee paid to the executor.
pub fee: u64,
/// A user-supplied seed for random number generation.
pub seed: [u8; 32],
}
impl Permit {
pub fn pda(&self) -> (Pubkey, u8) {
permit_pda(self.authority, self.block_id)
}
}
account!(OreAccount, Permit);

View File

@@ -1,29 +0,0 @@
use steel::*;
use crate::state::stake_pda;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Stake {
/// The authority of the miner account.
pub authority: Pubkey,
/// The ID of the block this collateral is associated with.
pub block_id: u64,
/// The amount of ORE this miner has deposited as collateral for trading.
pub collateral: u64,
/// The amount of ORE this miner has spent on hashpower in this market.
pub spend: u64,
}
impl Stake {
pub fn pda(&self) -> (Pubkey, u8) {
stake_pda(self.authority, self.block_id)
}
}
account!(OreAccount, Stake);