mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 15:10:20 +00:00
proof of wager
This commit is contained in:
36
api/src/state/block.rs
Normal file
36
api/src/state/block.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Block {
|
||||
/// The current round.
|
||||
pub current_round: u64,
|
||||
|
||||
/// The cumulative amount of SOL risked in the current round, up to and including this bet.
|
||||
pub total_bets: u64,
|
||||
|
||||
/// The number of bets made in the current round.
|
||||
pub bet_count: u64,
|
||||
|
||||
/// The time time the current round started.
|
||||
pub started_at: u64,
|
||||
|
||||
/// The slot at which the current round ends.
|
||||
pub ends_at: u64,
|
||||
|
||||
/// Whether or not the current round has ended.
|
||||
pub payed_out: u64,
|
||||
|
||||
/// The mint used to track wagers of the current round.
|
||||
pub mint: Pubkey,
|
||||
|
||||
/// The amount of ORE to distribute to the winner.
|
||||
pub reward: u64,
|
||||
|
||||
/// The noise used for the current round.
|
||||
pub noise: [u8; 32],
|
||||
}
|
||||
|
||||
account!(OreAccount, Block);
|
||||
@@ -1,25 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
/// Bus accounts are responsible for distributing mining rewards. There are 8 busses total
|
||||
/// to minimize write-lock contention and allow Solana to process mine instructions in parallel.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Bus {
|
||||
/// The ID of the bus account.
|
||||
pub id: u64,
|
||||
|
||||
/// The remaining rewards this bus has left to payout in the current epoch.
|
||||
pub rewards: u64,
|
||||
|
||||
/// The rewards this bus would have paid out in the current epoch if there no limit.
|
||||
/// This is used to calculate the updated reward rate.
|
||||
pub theoretical_rewards: u64,
|
||||
|
||||
/// The largest known stake balance seen by the bus this epoch.
|
||||
#[deprecated(since = "2.8.0", note = "Top balance is no longer tracked or used")]
|
||||
pub top_balance: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Bus);
|
||||
@@ -1,43 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use super::{OldOreAccount, OreAccount};
|
||||
|
||||
/// Config is a singleton account which manages program global variables.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Config {
|
||||
/// The timestamp of the last reset.
|
||||
pub last_reset_at: i64,
|
||||
|
||||
/// The best difficulty score of this epoch.
|
||||
pub best_hash: [u8; 32],
|
||||
|
||||
/// The proof of the best submitted hash of this epoch.
|
||||
pub best_proof: Pubkey,
|
||||
|
||||
/// The challenge of this epoch.
|
||||
pub challenge: [u8; 32],
|
||||
|
||||
/// The target emissions rate in ORE/min.
|
||||
pub block_reward: u64,
|
||||
}
|
||||
|
||||
/// Config is a singleton account which manages program global variables.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct OldConfig {
|
||||
/// The base reward rate paid out for a hash of minimum difficulty.
|
||||
pub base_reward_rate: u64,
|
||||
|
||||
/// The timestamp of the last reset.
|
||||
pub last_reset_at: i64,
|
||||
|
||||
/// The minimum accepted difficulty.
|
||||
pub min_difficulty: u64,
|
||||
|
||||
/// The target emissions rate in ORE/min.
|
||||
pub target_emmissions_rate: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Config);
|
||||
account!(OldOreAccount, OldConfig);
|
||||
@@ -1,12 +1,12 @@
|
||||
mod bus;
|
||||
mod config;
|
||||
mod block;
|
||||
mod proof;
|
||||
mod treasury;
|
||||
mod wager;
|
||||
|
||||
pub use bus::*;
|
||||
pub use config::*;
|
||||
pub use block::*;
|
||||
pub use proof::*;
|
||||
pub use treasury::*;
|
||||
pub use wager::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
@@ -15,29 +15,27 @@ use crate::consts::*;
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreAccount {
|
||||
Bus = 100,
|
||||
Config = 101,
|
||||
Proof = 102,
|
||||
Treasury = 103,
|
||||
Block = 104,
|
||||
Wager = 105,
|
||||
}
|
||||
|
||||
/// Derive the PDA of the config account.
|
||||
pub fn config_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[CONFIG], &crate::id())
|
||||
pub fn block_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[BLOCK], &crate::ID)
|
||||
}
|
||||
|
||||
/// Derive the PDA of a proof account.
|
||||
pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
|
||||
}
|
||||
|
||||
/// Derive the PDA of the treasury account.
|
||||
pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[TREASURY], &crate::id())
|
||||
pub fn wager_pda(round: u64, id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[WAGER, &round.to_le_bytes(), &id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OldOreAccount {
|
||||
OldConfig = 101,
|
||||
pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[TREASURY], &crate::ID)
|
||||
}
|
||||
|
||||
27
api/src/state/wager.rs
Normal file
27
api/src/state/wager.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Wager {
|
||||
/// The signer authorized to use this wager.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The current round this miner is betting in.
|
||||
pub round: u64,
|
||||
|
||||
/// The ID of the bet.
|
||||
pub id: u64,
|
||||
|
||||
/// The quantity of SOL this miner has bet in the current round.
|
||||
pub amount: u64,
|
||||
|
||||
/// The cumulative amount of SOL bet in the current round, up to and including this wager.
|
||||
pub cumulative_bets: u64,
|
||||
|
||||
/// The timestamp of the wager.
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Wager);
|
||||
Reference in New Issue
Block a user