This commit is contained in:
Hardhat Chad
2025-06-04 15:13:44 -07:00
parent 79a9ac3b40
commit fa1fb5e30c
28 changed files with 341 additions and 4167 deletions

View File

@@ -5,32 +5,23 @@ use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Block {
/// The cumulative amount deployed in the current round.
pub cumulative_sum: u64,
/// The best hash.
pub best_hash: [u8; 32],
/// The current round.
pub current_round: u64,
/// The miner who submitted the best hash.
pub best_miner: Pubkey,
/// The slot at which the current round ends.
pub ends_at: u64,
/// The block number.
pub id: u64,
/// The mint used for commits of the current round.
pub mint: Pubkey,
/// The noise used for the current round for provably fair randomness.
pub noise: [u8; 32],
/// Whether or not the current round has paid out.
pub paid: u64,
/// The amount of ORE to distribute to the winner.
/// The amount of ORE to payout to the miner who submitted the best hash.
pub reward: u64,
/// The time the current round started at.
pub started_at: u64,
/// The hash of the starting slot.
pub slot_hash: [u8; 32],
/// The number of commits made in the current round.
pub total_commits: u64,
/// The starting slot of the block.
pub start_slot: u64,
}
account!(OreAccount, Block);

View File

@@ -1,27 +0,0 @@
use steel::*;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Commit {
/// The amount deployed in this commit.
pub amount: u64,
/// The signer authorized to use this commit.
pub authority: Pubkey,
/// The cumulative amount deployed in the current round prior to this commit.
pub cumulative_sum: u64,
/// The current round this commit is for.
pub round: u64,
/// The ID of the commit, used for provably fair randomness.
pub seed: [u8; 32],
/// The timestamp of the commit.
pub timestamp: u64,
}
account!(OreAccount, Commit);

11
api/src/state/config.rs Normal file
View File

@@ -0,0 +1,11 @@
use steel::*;
use super::OreAccount;
// TODO Config stuff
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Config {}
account!(OreAccount, Config);

14
api/src/state/market.rs Normal file
View File

@@ -0,0 +1,14 @@
use steel::*;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Market {
/// The id of the block this market is associated with.
pub block_id: u64,
}
// TODO Bonding curve stuff
account!(OreAccount, Market);

30
api/src/state/miner.rs Normal file
View File

@@ -0,0 +1,30 @@
use steel::*;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Miner {
/// The authority of this miner account.
pub authority: Pubkey,
/// The ID of the last block this miner mined in.
pub block_id: u64,
/// The amount of ORE this miner can deploy into hashpower markets.
pub capacity: u64,
/// The hash of the last block this miner mined in.
pub hash: [u8; 32],
/// The amount of ORE this miner has staked.
pub stake: u64,
/// The total number of hashes this miner has submitted.
pub total_hashes: u64,
/// The amount of ORE this miner has mined.
pub total_rewards: u64,
}
account!(OreAccount, Miner);

View File

@@ -1,38 +1,55 @@
mod block;
mod commit;
mod proof;
mod config;
mod market;
mod miner;
mod receipt;
mod treasury;
pub use block::*;
pub use commit::*;
pub use proof::*;
pub use config::*;
pub use market::*;
pub use miner::*;
pub use receipt::*;
pub use treasury::*;
use steel::*;
use crate::consts::*;
use steel::*;
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum OreAccount {
Proof = 102,
Treasury = 103,
Block = 104,
Commit = 105,
Block = 100,
Config = 101,
Market = 102,
Miner = 103,
Receipt = 104,
Treasury = 105,
}
pub fn block_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[BLOCK], &crate::ID)
pub fn block_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[BLOCK, &id.to_le_bytes()], &crate::ID)
}
pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
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 miner_pda(authority: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
}
pub fn receipt_pda(authority: Pubkey, id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[RECEIPT, &authority.to_bytes(), &id.to_le_bytes()],
&crate::ID,
)
}
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::ID)
}
pub fn commit_pda(round: u64, seed: [u8; 32]) -> (Pubkey, u8) {
Pubkey::find_program_address(&[COMMIT, &round.to_le_bytes(), &seed], &crate::ID)
}

View File

@@ -1,38 +0,0 @@
use steel::*;
use super::OreAccount;
/// Proof accounts track a miner's current hash, claimable rewards, and lifetime stats.
/// Every miner is allowed one proof account which is required by the program to mine or claim rewards.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Proof {
/// The signer authorized to use this proof.
pub authority: Pubkey,
/// The quantity of tokens this miner has staked or earned.
pub balance: u64,
/// The current mining challenge.
pub challenge: [u8; 32],
/// The last hash the miner provided.
pub last_hash: [u8; 32],
/// Timestamp of the last time this account provided a hash.
pub last_hash_at: i64,
/// Timestamp of the last claim.
pub last_claim_at: i64,
/// The keypair which has permission to submit hashes for mining.
pub miner: Pubkey,
/// The total lifetime hashes provided by this miner.
pub total_hashes: u64,
/// The total lifetime rewards distributed to this miner.
pub total_rewards: u64,
}
account!(OreAccount, Proof);

18
api/src/state/receipt.rs Normal file
View File

@@ -0,0 +1,18 @@
use steel::*;
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Receipt {
/// The authority of this receipt account.
pub authority: Pubkey,
/// The amount of ORE this miner has deployed in the hashpower market corresponding to the block id.
pub amount: u64,
/// The id of the block this receipt is associated with.
pub block_id: u64,
}
account!(OreAccount, Receipt);