mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-03 15:11:20 +00:00
docs
This commit is contained in:
@@ -4,7 +4,6 @@ use solana_program::{keccak::Hash, pubkey, pubkey::Pubkey};
|
|||||||
/// The unix timestamp after which mining is allowed.
|
/// The unix timestamp after which mining is allowed.
|
||||||
pub const START_AT: i64 = 0;
|
pub const START_AT: i64 = 0;
|
||||||
|
|
||||||
// SHA2 const stable
|
|
||||||
/// Bus pubkeys
|
/// Bus pubkeys
|
||||||
pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [
|
pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [
|
||||||
pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"),
|
pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"),
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ impl_instruction_from_bytes!(ClaimArgs);
|
|||||||
impl_instruction_from_bytes!(UpdateAdminArgs);
|
impl_instruction_from_bytes!(UpdateAdminArgs);
|
||||||
impl_instruction_from_bytes!(UpdateDifficultyArgs);
|
impl_instruction_from_bytes!(UpdateDifficultyArgs);
|
||||||
|
|
||||||
|
/// Builds an initialize instruction.
|
||||||
pub fn initialize(signer: Pubkey) -> Instruction {
|
pub fn initialize(signer: Pubkey) -> Instruction {
|
||||||
let treasury_tokens = spl_associated_token_account::get_associated_token_address(
|
let treasury_tokens = spl_associated_token_account::get_associated_token_address(
|
||||||
&TREASURY_ADDRESS,
|
&TREASURY_ADDRESS,
|
||||||
@@ -208,6 +209,7 @@ pub fn initialize(signer: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a claim instruction.
|
||||||
pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction {
|
pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction {
|
||||||
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
|
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
|
||||||
let treasury_tokens = spl_associated_token_account::get_associated_token_address(
|
let treasury_tokens = spl_associated_token_account::get_associated_token_address(
|
||||||
@@ -237,6 +239,7 @@ pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a mine instruction.
|
||||||
pub fn mine(signer: Pubkey, bus: Pubkey, hash: Hash, nonce: u64) -> Instruction {
|
pub fn mine(signer: Pubkey, bus: Pubkey, hash: Hash, nonce: u64) -> Instruction {
|
||||||
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
|
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
|
||||||
Instruction {
|
Instruction {
|
||||||
@@ -261,6 +264,7 @@ pub fn mine(signer: Pubkey, bus: Pubkey, hash: Hash, nonce: u64) -> Instruction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a register instruction.
|
||||||
pub fn register(signer: Pubkey) -> Instruction {
|
pub fn register(signer: Pubkey) -> Instruction {
|
||||||
let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id());
|
let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id());
|
||||||
Instruction {
|
Instruction {
|
||||||
@@ -278,6 +282,7 @@ pub fn register(signer: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a reset instruction.
|
||||||
pub fn reset(signer: Pubkey) -> Instruction {
|
pub fn reset(signer: Pubkey) -> Instruction {
|
||||||
let bus_0 = Pubkey::find_program_address(&[BUS, &[0]], &crate::id()).0;
|
let bus_0 = Pubkey::find_program_address(&[BUS, &[0]], &crate::id()).0;
|
||||||
let bus_1 = Pubkey::find_program_address(&[BUS, &[1]], &crate::id()).0;
|
let bus_1 = Pubkey::find_program_address(&[BUS, &[1]], &crate::id()).0;
|
||||||
@@ -312,6 +317,7 @@ pub fn reset(signer: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds an update_admin instruction.
|
||||||
pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: crate::id(),
|
program_id: crate::id(),
|
||||||
@@ -327,6 +333,7 @@ pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds an update_difficulty instruction.
|
||||||
pub fn update_difficulty(signer: Pubkey, new_difficulty: Hash) -> Instruction {
|
pub fn update_difficulty(signer: Pubkey, new_difficulty: Hash) -> Instruction {
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: crate::id(),
|
program_id: crate::id(),
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use solana_program::{
|
|||||||
program_error::ProgramError, pubkey::Pubkey,
|
program_error::ProgramError, pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO Test admin and difficulty adjustment functions
|
|
||||||
// TODO Increase decimals?
|
// TODO Increase decimals?
|
||||||
|
|
||||||
declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
|
declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
|
||||||
@@ -22,7 +21,6 @@ declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
|
|||||||
#[cfg(not(feature = "no-entrypoint"))]
|
#[cfg(not(feature = "no-entrypoint"))]
|
||||||
solana_program::entrypoint!(process_instruction);
|
solana_program::entrypoint!(process_instruction);
|
||||||
|
|
||||||
/// Processes the incoming instruction
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
accounts: &[AccountInfo],
|
accounts: &[AccountInfo],
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ pub fn process_mine<'a, 'info>(
|
|||||||
bus.rewards = bus.rewards.saturating_sub(treasury.reward_rate);
|
bus.rewards = bus.rewards.saturating_sub(treasury.reward_rate);
|
||||||
proof.claimable_rewards = proof.claimable_rewards.saturating_add(treasury.reward_rate);
|
proof.claimable_rewards = proof.claimable_rewards.saturating_add(treasury.reward_rate);
|
||||||
|
|
||||||
// Hash most recent slot hash into the next challenge to prevent pre-mining attacks
|
// Hash recent slot hash into the next challenge to prevent pre-mining attacks
|
||||||
proof.hash = hashv(&[
|
proof.hash = hashv(&[
|
||||||
KeccakHash::from(args.hash).as_ref(),
|
KeccakHash::from(args.hash).as_ref(),
|
||||||
&slot_hashes_info.data.borrow()[0..size_of::<SlotHash>()],
|
&slot_hashes_info.data.borrow()[0..size_of::<SlotHash>()],
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ pub(crate) fn create_pda<'a, 'info>(
|
|||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||||
pub enum AccountDiscriminator {
|
pub enum AccountDiscriminator {
|
||||||
Bus = 0,
|
Bus = 1,
|
||||||
Proof = 1,
|
Proof = 2,
|
||||||
Treasury = 2,
|
Treasury = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Discriminator {
|
pub trait Discriminator {
|
||||||
|
|||||||
Reference in New Issue
Block a user