This commit is contained in:
Hardhat Chad
2024-02-16 21:34:36 +00:00
parent ebf03bf618
commit 21767bba4e
5 changed files with 11 additions and 7 deletions

View File

@@ -4,7 +4,6 @@ use solana_program::{keccak::Hash, pubkey, pubkey::Pubkey};
/// The unix timestamp after which mining is allowed.
pub const START_AT: i64 = 0;
// SHA2 const stable
/// Bus pubkeys
pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [
pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"),

View File

@@ -150,6 +150,7 @@ impl_instruction_from_bytes!(ClaimArgs);
impl_instruction_from_bytes!(UpdateAdminArgs);
impl_instruction_from_bytes!(UpdateDifficultyArgs);
/// Builds an initialize instruction.
pub fn initialize(signer: Pubkey) -> Instruction {
let treasury_tokens = spl_associated_token_account::get_associated_token_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 {
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
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 {
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
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 {
let proof_pda = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id());
Instruction {
@@ -278,6 +282,7 @@ pub fn register(signer: Pubkey) -> Instruction {
}
}
/// Builds a reset instruction.
pub fn reset(signer: Pubkey) -> Instruction {
let bus_0 = Pubkey::find_program_address(&[BUS, &[0]], &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 {
Instruction {
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 {
Instruction {
program_id: crate::id(),

View File

@@ -14,7 +14,6 @@ use solana_program::{
program_error::ProgramError, pubkey::Pubkey,
};
// TODO Test admin and difficulty adjustment functions
// TODO Increase decimals?
declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
@@ -22,7 +21,6 @@ declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
#[cfg(not(feature = "no-entrypoint"))]
solana_program::entrypoint!(process_instruction);
/// Processes the incoming instruction
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],

View File

@@ -69,7 +69,7 @@ pub fn process_mine<'a, 'info>(
bus.rewards = bus.rewards.saturating_sub(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(&[
KeccakHash::from(args.hash).as_ref(),
&slot_hashes_info.data.borrow()[0..size_of::<SlotHash>()],

View File

@@ -36,9 +36,9 @@ pub(crate) fn create_pda<'a, 'info>(
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum AccountDiscriminator {
Bus = 0,
Proof = 1,
Treasury = 2,
Bus = 1,
Proof = 2,
Treasury = 3,
}
pub trait Discriminator {